From 2d269cddd4aacfad951031c9918742ba83eaaae4 Mon Sep 17 00:00:00 2001 From: gustav-langer Date: Wed, 30 Oct 2024 20:53:53 +0100 Subject: [PATCH 1/2] Changed renaming behaviour to use the component name instead of the package name. Apps with multiple launching activities can now be separately renamed. --- app/src/main/java/app/olauncher/data/Prefs.kt | 4 ++-- app/src/main/java/app/olauncher/helper/Utils.kt | 2 +- app/src/main/java/app/olauncher/ui/AppDrawerFragment.kt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/app/olauncher/data/Prefs.kt b/app/src/main/java/app/olauncher/data/Prefs.kt index c281b8cf5..dd8f5a00b 100644 --- a/app/src/main/java/app/olauncher/data/Prefs.kt +++ b/app/src/main/java/app/olauncher/data/Prefs.kt @@ -445,7 +445,7 @@ class Prefs(context: Context) { } } - fun getAppRenameLabel(appPackage: String): String = prefs.getString(appPackage, "").toString() + fun getAppRenameLabel(componentName: String?): String = prefs.getString(componentName, "").toString() - fun setAppRenameLabel(appPackage: String, renameLabel: String) = prefs.edit().putString(appPackage, renameLabel).apply() + fun setAppRenameLabel(componentName: String?, renameLabel: String) = prefs.edit().putString(componentName, renameLabel).apply() } \ No newline at end of file diff --git a/app/src/main/java/app/olauncher/helper/Utils.kt b/app/src/main/java/app/olauncher/helper/Utils.kt index 181dfac26..21da1c28f 100644 --- a/app/src/main/java/app/olauncher/helper/Utils.kt +++ b/app/src/main/java/app/olauncher/helper/Utils.kt @@ -83,7 +83,7 @@ suspend fun getAppsList( for (profile in userManager.userProfiles) { for (app in launcherApps.getActivityList(null, profile)) { - val appLabelShown = prefs.getAppRenameLabel(app.applicationInfo.packageName).ifBlank { app.label.toString() } + val appLabelShown = prefs.getAppRenameLabel(app.componentName.className).ifBlank { app.label.toString() } val appModel = AppModel( appLabelShown, collator.getCollationKey(app.label.toString()), diff --git a/app/src/main/java/app/olauncher/ui/AppDrawerFragment.kt b/app/src/main/java/app/olauncher/ui/AppDrawerFragment.kt index 1986300fd..07c8846e0 100644 --- a/app/src/main/java/app/olauncher/ui/AppDrawerFragment.kt +++ b/app/src/main/java/app/olauncher/ui/AppDrawerFragment.kt @@ -159,7 +159,7 @@ class AppDrawerFragment : Fragment() { viewModel.getHiddenApps() }, appRenameListener = { appModel, renameLabel -> - prefs.setAppRenameLabel(appModel.appPackage, renameLabel) + prefs.setAppRenameLabel(appModel.activityClassName, renameLabel) viewModel.getAppList() } ) From aaaabe0cf65a079360c02794fa4633697c965062 Mon Sep 17 00:00:00 2001 From: gustav-langer Date: Thu, 31 Oct 2024 13:16:00 +0100 Subject: [PATCH 2/2] Added originalLabel field to AppModel that stores an app's label before any renames. This field is used as the hint for the rename field, allowing renames of applications with multiple launching activities to be reset correctly. --- .../main/java/app/olauncher/data/AppModel.kt | 1 + app/src/main/java/app/olauncher/data/Prefs.kt | 2 +- .../main/java/app/olauncher/helper/Utils.kt | 1 + .../java/app/olauncher/ui/AppDrawerAdapter.kt | 26 +++++-------------- .../java/app/olauncher/ui/HomeFragment.kt | 1 + 5 files changed, 10 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/app/olauncher/data/AppModel.kt b/app/src/main/java/app/olauncher/data/AppModel.kt index 7c1196587..c19a848d3 100644 --- a/app/src/main/java/app/olauncher/data/AppModel.kt +++ b/app/src/main/java/app/olauncher/data/AppModel.kt @@ -8,6 +8,7 @@ data class AppModel( val key: CollationKey?, val appPackage: String, val activityClassName: String?, + val originalLabel: String, val isNew: Boolean? = false, val user: UserHandle, ) : Comparable { diff --git a/app/src/main/java/app/olauncher/data/Prefs.kt b/app/src/main/java/app/olauncher/data/Prefs.kt index dd8f5a00b..abfe49f1d 100644 --- a/app/src/main/java/app/olauncher/data/Prefs.kt +++ b/app/src/main/java/app/olauncher/data/Prefs.kt @@ -447,5 +447,5 @@ class Prefs(context: Context) { fun getAppRenameLabel(componentName: String?): String = prefs.getString(componentName, "").toString() - fun setAppRenameLabel(componentName: String?, renameLabel: String) = prefs.edit().putString(componentName, renameLabel).apply() + fun setAppRenameLabel(componentName: String?, renameLabel: String?) = prefs.edit().putString(componentName, renameLabel).apply() } \ No newline at end of file diff --git a/app/src/main/java/app/olauncher/helper/Utils.kt b/app/src/main/java/app/olauncher/helper/Utils.kt index 21da1c28f..613fe084f 100644 --- a/app/src/main/java/app/olauncher/helper/Utils.kt +++ b/app/src/main/java/app/olauncher/helper/Utils.kt @@ -89,6 +89,7 @@ suspend fun getAppsList( collator.getCollationKey(app.label.toString()), app.applicationInfo.packageName, app.componentName.className, + app.label.toString(), (System.currentTimeMillis() - app.firstInstallTime) < Constants.ONE_HOUR_IN_MILLIS, profile ) diff --git a/app/src/main/java/app/olauncher/ui/AppDrawerAdapter.kt b/app/src/main/java/app/olauncher/ui/AppDrawerAdapter.kt index cc9dd2c92..552613540 100644 --- a/app/src/main/java/app/olauncher/ui/AppDrawerAdapter.kt +++ b/app/src/main/java/app/olauncher/ui/AppDrawerAdapter.kt @@ -1,6 +1,5 @@ package app.olauncher.ui -import android.content.Context import android.os.UserHandle import android.text.Editable import android.text.TextWatcher @@ -30,7 +29,7 @@ class AppDrawerAdapter( private val appInfoListener: (AppModel) -> Unit, private val appDeleteListener: (AppModel) -> Unit, private val appHideListener: (AppModel, Int) -> Unit, - private val appRenameListener: (AppModel, String) -> Unit, + private val appRenameListener: (AppModel, String?) -> Unit, ) : ListAdapter(DIFF_CALLBACK), Filterable { companion object { @@ -130,7 +129,7 @@ class AppDrawerAdapter( fun setAppList(appsList: MutableList) { // Add empty app for bottom padding in recyclerview - appsList.add(AppModel("", null, "", "", false, android.os.Process.myUserHandle())) + appsList.add(AppModel("", null, "", "", "", false, android.os.Process.myUserHandle())) this.appsList = appsList this.appFilteredList = appsList submitList(appsList) @@ -152,7 +151,7 @@ class AppDrawerAdapter( appDeleteListener: (AppModel) -> Unit, appInfoListener: (AppModel) -> Unit, appHideListener: (AppModel, Int) -> Unit, - appRenameListener: (AppModel, String) -> Unit, + appRenameListener: (AppModel, String?) -> Unit, ) = with(binding) { appHideLayout.visibility = View.GONE @@ -178,7 +177,7 @@ class AppDrawerAdapter( } appRename.setOnClickListener { if (appModel.appPackage.isNotEmpty()) { - etAppRename.hint = getAppName(etAppRename.context, appModel.appPackage) + etAppRename.hint = appModel.originalLabel etAppRename.setText(appModel.appLabel) etAppRename.setSelectAllOnFocus(true) renameLayout.visibility = View.VISIBLE @@ -195,7 +194,7 @@ class AppDrawerAdapter( } etAppRename.addTextChangedListener(object : TextWatcher { override fun afterTextChanged(s: Editable?) { - etAppRename.hint = getAppName(etAppRename.context, appModel.appPackage) + etAppRename.hint = appModel.originalLabel } override fun beforeTextChanged( @@ -233,13 +232,7 @@ class AppDrawerAdapter( appRenameListener(appModel, renameLabel) renameLayout.visibility = View.GONE } else { - val packageManager = etAppRename.context.packageManager - appRenameListener( - appModel, - packageManager.getApplicationLabel( - packageManager.getApplicationInfo(appModel.appPackage, 0) - ).toString() - ) + appRenameListener(appModel, null) renameLayout.visibility = View.GONE } } @@ -255,12 +248,5 @@ class AppDrawerAdapter( } appHide.setOnClickListener { appHideListener(appModel, bindingAdapterPosition) } } - - private fun getAppName(context: Context, appPackage: String): String { - val packageManager = context.packageManager - return packageManager.getApplicationLabel( - packageManager.getApplicationInfo(appPackage, 0) - ).toString() - } } } diff --git a/app/src/main/java/app/olauncher/ui/HomeFragment.kt b/app/src/main/java/app/olauncher/ui/HomeFragment.kt index b60361167..7d43ff274 100644 --- a/app/src/main/java/app/olauncher/ui/HomeFragment.kt +++ b/app/src/main/java/app/olauncher/ui/HomeFragment.kt @@ -333,6 +333,7 @@ class HomeFragment : Fragment(), View.OnClickListener, View.OnLongClickListener null, packageName, activityClassName, + appName, false, getUserHandleFromString(requireContext(), userString) ),