mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +00:00
Now passively checks for moved apps (for app name changing between updates, etc)
This commit is contained in:
parent
d0112bbbe4
commit
de79b2752d
10 changed files with 64 additions and 25 deletions
|
|
@ -24,6 +24,7 @@
|
||||||
tools:targetApi="34">
|
tools:targetApi="34">
|
||||||
<activity
|
<activity
|
||||||
android:name=".SettingsActivity"
|
android:name=".SettingsActivity"
|
||||||
|
android:theme="@style/SettingsTheme"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
|
|
|
||||||
|
|
@ -110,10 +110,12 @@ class AppActionMenu {
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
val newPosition = appUtils.getInstalledApps(activity)
|
val newPosition = appUtils.getInstalledApps(activity)
|
||||||
.indexOfFirst { it.first.applicationInfo.packageName == appInfo.packageName && it.second.second == workProfile }
|
.indexOfFirst { it.first.applicationInfo.packageName == appInfo.packageName && it.second.second == workProfile }
|
||||||
|
activity.appUpdate = false
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
activity.updateItem(position, app)
|
activity.updateItem(position, app)
|
||||||
activity.moveItem(position, newPosition)
|
activity.moveItem(position, newPosition)
|
||||||
}
|
}
|
||||||
|
activity.updateInstalledApps()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -135,10 +137,12 @@ class AppActionMenu {
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
val newPosition = appUtils.getInstalledApps(activity)
|
val newPosition = appUtils.getInstalledApps(activity)
|
||||||
.indexOfFirst { it.first.applicationInfo.packageName == appInfo.packageName && it.second.second == workProfile }
|
.indexOfFirst { it.first.applicationInfo.packageName == appInfo.packageName && it.second.second == workProfile }
|
||||||
|
activity.appUpdate = false
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
activity.updateItem(position, app)
|
activity.updateItem(position, app)
|
||||||
activity.moveItem(position, newPosition)
|
activity.moveItem(position, newPosition)
|
||||||
}
|
}
|
||||||
|
activity.updateInstalledApps()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -140,4 +140,8 @@ class AppMenuAdapter(
|
||||||
apps.add(newPosition, app)
|
apps.add(newPosition, app)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateApps(newApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||||
|
apps = newApps.toMutableList()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,7 +16,6 @@ import android.text.TextWatcher
|
||||||
import android.view.GestureDetector
|
import android.view.GestureDetector
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowManager
|
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
|
@ -65,6 +64,8 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
private val swipeThreshold = 100
|
private val swipeThreshold = 100
|
||||||
private val swipeVelocityThreshold = 100
|
private val swipeVelocityThreshold = 100
|
||||||
|
|
||||||
|
var appUpdate = true
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
@ -120,9 +121,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
startTask()
|
startTask()
|
||||||
|
|
||||||
// Keyboard is sometimes open when going back to the app, so close it.
|
// Keyboard is sometimes open when going back to the app, so close it.
|
||||||
val imm =
|
closeKeyboard()
|
||||||
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
||||||
imm.hideSoftInputFromWindow(binding.root.windowToken, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
open inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
||||||
|
|
@ -187,10 +186,12 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
val newApps = installedApps.toMutableList()
|
val newApps = installedApps.toMutableList()
|
||||||
|
|
||||||
setupRecyclerView(newApps)
|
setupRecyclerView(newApps)
|
||||||
|
|
||||||
|
searchView = findViewById(R.id.searchView)
|
||||||
|
setupSearch()
|
||||||
}
|
}
|
||||||
|
|
||||||
searchView = findViewById(R.id.searchView)
|
|
||||||
setupSearch()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -284,19 +285,20 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupSearch() {
|
private fun setupSearch() {
|
||||||
binding.root.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
recyclerView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
||||||
|
|
||||||
if (bottom - top > oldBottom - oldTop) {
|
if (bottom - top > oldBottom - oldTop) {
|
||||||
|
|
||||||
searchView.clearFocus()
|
searchView.clearFocus()
|
||||||
|
|
||||||
if (searchView.text.isNullOrEmpty()) {
|
if (searchView.text.isNullOrEmpty()) {
|
||||||
job?.cancel()
|
|
||||||
startTask()
|
startTask()
|
||||||
|
appUpdate = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (bottom - top < oldBottom - oldTop) {
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
|
appUpdate = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -355,6 +357,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startTask() {
|
private fun startTask() {
|
||||||
|
job?.cancel()
|
||||||
job = CoroutineScope(Dispatchers.Default).launch {
|
job = CoroutineScope(Dispatchers.Default).launch {
|
||||||
while (true) {
|
while (true) {
|
||||||
refreshAppMenu()
|
refreshAppMenu()
|
||||||
|
|
@ -371,6 +374,8 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
}
|
}
|
||||||
|
|
||||||
fun backToHome() {
|
fun backToHome() {
|
||||||
|
closeKeyboard()
|
||||||
|
searchView.setText("")
|
||||||
animations.showHome(binding)
|
animations.showHome(binding)
|
||||||
animations.backgroundOut(this@MainActivity, binding)
|
animations.backgroundOut(this@MainActivity, binding)
|
||||||
val handler = Handler(Looper.getMainLooper())
|
val handler = Handler(Looper.getMainLooper())
|
||||||
|
|
@ -464,6 +469,12 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun closeKeyboard() {
|
||||||
|
val imm =
|
||||||
|
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
|
imm.hideSoftInputFromWindow(binding.root.windowToken, 0)
|
||||||
|
}
|
||||||
|
|
||||||
private fun detectChanges(oldList: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, newList: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>): List<Change> {
|
private fun detectChanges(oldList: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, newList: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>): List<Change> {
|
||||||
val changes = mutableListOf<Change>()
|
val changes = mutableListOf<Change>()
|
||||||
val removalChanges = mutableListOf<Change>()
|
val removalChanges = mutableListOf<Change>()
|
||||||
|
|
@ -477,6 +488,12 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
if (oldItem.first.componentName != newList[newIndex].first.componentName) {
|
if (oldItem.first.componentName != newList[newIndex].first.componentName) {
|
||||||
changes.add(Change(ChangeType.UPDATE, index))
|
changes.add(Change(ChangeType.UPDATE, index))
|
||||||
}
|
}
|
||||||
|
if (index != newIndex) {
|
||||||
|
if (appUpdate) {
|
||||||
|
changes.add(Change(ChangeType.MOVE, index))
|
||||||
|
appUpdate = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -500,6 +517,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
return changes
|
return changes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun applyChanges(changes: List<Change>, updatedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
private fun applyChanges(changes: List<Change>, updatedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>) {
|
||||||
changes.forEach { change ->
|
changes.forEach { change ->
|
||||||
when (change.type) {
|
when (change.type) {
|
||||||
|
|
@ -516,6 +534,14 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
ChangeType.UPDATE -> {
|
ChangeType.UPDATE -> {
|
||||||
updateItem(change.position, updatedApps[change.position])
|
updateItem(change.position, updatedApps[change.position])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChangeType.MOVE -> {
|
||||||
|
adapter.updateApps(updatedApps)
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
|
println("moved")
|
||||||
|
appUpdate = true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -538,10 +564,15 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
adapter.moveApp(position, newPosition)
|
adapter.moveApp(position, newPosition)
|
||||||
adapter.notifyItemMoved(position, newPosition)
|
adapter.notifyItemMoved(position, newPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateInstalledApps() {
|
||||||
|
installedApps = appUtils.getInstalledApps(this@MainActivity)
|
||||||
|
appUpdate = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Change(val type: ChangeType, val position: Int, val newPosition: Int = 0)
|
data class Change(val type: ChangeType, val position: Int, val newPosition: Int = 0)
|
||||||
|
|
||||||
enum class ChangeType {
|
enum class ChangeType {
|
||||||
INSERT, REMOVE, UPDATE
|
INSERT, REMOVE, UPDATE, MOVE
|
||||||
}
|
}
|
||||||
|
|
@ -12,6 +12,5 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
window.statusBarColor = getColor(R.color.settings_bg)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
4
app/src/main/java/eu/ottop/yamlauncher/WeatherSystem.kt
Normal file
4
app/src/main/java/eu/ottop/yamlauncher/WeatherSystem.kt
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
package eu.ottop.yamlauncher
|
||||||
|
|
||||||
|
class WeatherSystem {
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
android:id="@+id/linearLayout"
|
android:id="@+id/linearLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/settings_bg"
|
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".SettingsActivity">
|
tools:context=".SettingsActivity">
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,4 @@
|
||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
<!-- Base application theme. -->
|
|
||||||
<style name="Base.Theme.YamLauncher" parent="Theme.AppCompat.NoActionBar">
|
|
||||||
<item name="android:windowBackground">@android:color/transparent</item>
|
|
||||||
<item name="android:colorBackgroundCacheHint">@android:color/transparent</item>
|
|
||||||
<item name="android:windowShowWallpaper">true</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -1,10 +1,3 @@
|
||||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<style name="Theme.YamLauncher" parent="Base.Theme.YamLauncher">
|
|
||||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
|
||||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
|
||||||
<item name="android:windowLightStatusBar">?attr/isLightTheme</item>
|
|
||||||
<item name="android:windowFullscreen">true</item>
|
|
||||||
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
|
||||||
</style>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -4,9 +4,18 @@
|
||||||
<item name="android:windowBackground">@android:color/transparent</item>
|
<item name="android:windowBackground">@android:color/transparent</item>
|
||||||
<item name="android:colorBackgroundCacheHint">@android:color/transparent</item>
|
<item name="android:colorBackgroundCacheHint">@android:color/transparent</item>
|
||||||
<item name="android:windowShowWallpaper">true</item>
|
<item name="android:windowShowWallpaper">true</item>
|
||||||
|
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||||
|
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||||
|
<item name="android:windowLightStatusBar">?attr/isLightTheme</item>
|
||||||
|
<item name="android:windowFullscreen">true</item>
|
||||||
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="SettingsTheme" parent="Base.Theme.YamLauncher">
|
||||||
|
<item name="android:windowBackground">@color/settings_bg</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="AppSearchView" parent="Widget.AppCompat.SearchView" >
|
<style name="AppSearchView" parent="Widget.AppCompat.SearchView" >
|
||||||
<item name="android:textSize">25sp</item>
|
<item name="android:textSize">25sp</item>
|
||||||
<item name="android:editTextColor">#f3f3f3</item>
|
<item name="android:editTextColor">#f3f3f3</item>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue