fixed bug: custom labels not shown in app list

This commit is contained in:
Josia Pietsch 2024-11-28 00:49:54 +01:00
parent 98274fbd4f
commit 2c4f5176b7
3 changed files with 16 additions and 10 deletions

View file

@ -1,5 +1,6 @@
package de.jrpie.android.launcher
import android.content.SharedPreferences
import android.os.Build
import android.os.Build.VERSION_CODES
import androidx.preference.PreferenceManager
@ -9,7 +10,13 @@ import de.jrpie.android.launcher.preferences.LauncherPreferences
class Application : android.app.Application() {
var torchManager: TorchManager? = null
var customAppNames: HashMap<AppInfo, String> = HashMap()
private var customAppNames: HashMap<AppInfo, String>? = null
private val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, pref ->
if (pref == getString(R.string.settings_apps_custom_names_key)) {
customAppNames = LauncherPreferences.apps().customNames()
}
}
override fun onCreate() {
super.onCreate()
@ -20,13 +27,12 @@ class Application : android.app.Application() {
val preferences = PreferenceManager.getDefaultSharedPreferences(this)
LauncherPreferences.init(preferences, this.resources)
customAppNames = LauncherPreferences.apps().customNames()
LauncherPreferences.getSharedPreferences()
.registerOnSharedPreferenceChangeListener { _, pref ->
if (pref == getString(R.string.settings_apps_custom_names_key)) {
customAppNames = LauncherPreferences.apps().customNames()
}
}
.registerOnSharedPreferenceChangeListener(listener)
}
fun getCustomAppNames(): HashMap<AppInfo, String> {
return (customAppNames ?: LauncherPreferences.apps().customNames() ?: HashMap())
.also { customAppNames = it }
}
}

View file

@ -30,7 +30,7 @@ class DetailedAppInfo(
)
fun getCustomLabel(context: Context): CharSequence {
val map = (context.applicationContext as? Application)?.customAppNames ?: return label
val map = (context.applicationContext as? Application)?.getCustomAppNames() ?: return label
return map[app] ?: label
}

View file

@ -76,7 +76,7 @@ class AppsRecyclerAdapter(
override fun onBindViewHolder(viewHolder: ViewHolder, i: Int) {
var appLabel = appsListDisplayed[i].label.toString()
var appLabel = appsListDisplayed[i].getCustomLabel(activity)
if (layout.useBadgedText) {
appLabel = activity.packageManager.getUserBadgedLabel(