diff --git a/app/src/main/java/app/olauncher/data/AppModel.kt b/app/src/main/java/app/olauncher/data/AppModel.kt index 7c119658..c19a848d 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 c281b8cf..abfe49f1 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 181dfac2..613fe084 100644 --- a/app/src/main/java/app/olauncher/helper/Utils.kt +++ b/app/src/main/java/app/olauncher/helper/Utils.kt @@ -83,12 +83,13 @@ 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()), 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 cc9dd2c9..55261354 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/AppDrawerFragment.kt b/app/src/main/java/app/olauncher/ui/AppDrawerFragment.kt index 1986300f..07c8846e 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() } ) diff --git a/app/src/main/java/app/olauncher/ui/HomeFragment.kt b/app/src/main/java/app/olauncher/ui/HomeFragment.kt index b6036116..7d43ff27 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) ),