From 7d540aa76dd02032c9ddca3c1235e98e4e45dc0e Mon Sep 17 00:00:00 2001 From: ottoptj Date: Mon, 20 May 2024 14:16:44 +0300 Subject: [PATCH] Added search back as it was --- .../eu/ottop/yamlauncher/AppMenuActivity.kt | 31 +++++-------------- .../eu/ottop/yamlauncher/AppMenuAdapter.kt | 9 ++++++ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuActivity.kt index 548e2f2..d37ebfb 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuActivity.kt @@ -160,7 +160,7 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, if (cleanQuery.isNullOrEmpty()) { filteredApps.addAll(installedApps) } else { - installedApps.forEach { + installedApps.forEachIndexed {index, it -> val cleanItemText = sharedPreferenceManager.getAppName(this@AppMenuActivity, it.first.applicationInfo.packageName, it.second.second, it.first.applicationInfo.loadLabel(packageManager)).toString().clean() if (cleanItemText.contains(cleanQuery, ignoreCase = true)) { filteredApps.add(it) @@ -168,7 +168,7 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, } } withContext(Dispatchers.Main) { - //adapter.updateApps(filteredApps) + adapter.updateAllApps(filteredApps) } } @@ -210,33 +210,16 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, job = CoroutineScope(Dispatchers.Default).launch { while (true) { val updatedApps = getInstalledApps() - if (!listsEqual(installedApps, updatedApps)) { - val changes = detectChanges(installedApps, updatedApps) - installedApps = updatedApps - withContext(Dispatchers.Main) { - applyChanges(changes, installedApps) - } + val changes = detectChanges(installedApps, updatedApps) + installedApps = updatedApps + withContext(Dispatchers.Main) { + applyChanges(changes, installedApps) } delay(5000) } } } - private fun listsEqual( - list1: List>>, - list2: List>> - ): Boolean { - if (list1.size != list2.size) return false - - for (i in list1.indices) { - if (list1[i].first.componentName != list2[i].first.componentName || list1[i].second.first != list2[i].second.first) { - return false - } - } - - return true - } - data class Change(val type: ChangeType, val position: Int) enum class ChangeType { @@ -305,4 +288,4 @@ class AppMenuActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, adapter.notifyItemChanged(position) } -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt index 4b66212..b2a0ae5 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt @@ -1,5 +1,6 @@ package eu.ottop.yamlauncher +import android.annotation.SuppressLint import android.content.Context import android.content.pm.LauncherActivityInfo import android.os.UserHandle @@ -67,6 +68,7 @@ class AppMenuAdapter( itemClickListener.onItemClick(app, apps[position].second.first) } } + if (menuMode == "app") { textView.setOnLongClickListener { val position = bindingAdapterPosition @@ -135,4 +137,11 @@ class AppMenuAdapter( fun updateApp(position: Int, app: Pair>) { apps[position] = app } + + @SuppressLint("NotifyDataSetChanged") + fun updateAllApps(newApps: List>>) { + apps.clear() + apps.addAll(newApps) + notifyDataSetChanged() + } } \ No newline at end of file