Skip to content

Commit dc1a81f

Browse files
Refactor: Use activityLabel directly, removing customLabel and label
The `AppListItem` data class has been simplified by removing the `customLabel` and computed `label` properties. All parts of the app now directly use `activityLabel` for the original app name and retrieve custom aliases from `Prefs` when needed. This change streamlines the data model and clarifies how app names are handled, centralizing alias logic within `Prefs` rather than duplicating it in `AppListItem`. Key changes include: - Removing `customLabel` and `label` from `AppListItem`. - Updating sorting, searching, and display logic across the app to use `activityLabel` and fetch aliases from `Prefs` on-demand. - Removing the now-unused `APP_ALIAS` preference key and related storage logic. - Deleting the "Rename" button from the `SetHomeApp` screen, as renaming is now handled within the app drawer context menu.
1 parent 3a63768 commit dc1a81f

File tree

12 files changed

+37
-90
lines changed

12 files changed

+37
-90
lines changed

app/src/main/java/com/github/codeworkscreativehub/fuzzywuzzy/FuzzyFinder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.util.Locale
99
object FuzzyFinder {
1010

1111
fun scoreApp(app: AppListItem, searchChars: String, topScore: Int): Int {
12-
val appLabel = app.label
12+
val appLabel = app.activityLabel
1313
val normalizedAppLabel = normalizeString(appLabel)
1414
val normalizedSearchChars = normalizeString(searchChars)
1515

app/src/main/java/com/github/codeworkscreativehub/mlauncher/MainViewModel.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,14 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
621621
activityClass = raw.cls,
622622
user = raw.user,
623623
profileType = raw.profileType,
624-
customLabel = prefs.getAppAlias(raw.pkg),
625624
customTag = prefs.getAppTag(raw.pkg, raw.user),
626625
category = raw.category
627626
)
628627
}
629628
// 🔹 Sort pinned apps first, then regular/recent alphabetically
630629
.sortedWith(
631630
compareByDescending<AppListItem> { it.category == AppCategory.PINNED }
632-
.thenBy { normalizeForSort(it.label) }
631+
.thenBy { normalizeForSort(it.activityLabel) }
633632
)
634633
.toMutableList()
635634

@@ -643,7 +642,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
643642
isHidden = { it.activityPackage in hiddenAppsSet },
644643
isPinned = { it.activityPackage in pinnedPackages },
645644
buildItem = { it },
646-
getLabel = { it.label },
645+
getLabel = { it.activityLabel },
647646
normalize = ::normalizeForSort
648647
)
649648
}
@@ -816,7 +815,6 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
816815
obj.put("class", item.activityClass)
817816
obj.put("userHash", item.user.hashCode())
818817
obj.put("profileType", item.profileType)
819-
obj.put("customLabel", item.customLabel)
820818
obj.put("customTag", item.customTag)
821819
obj.put("category", item.category.ordinal)
822820
array.put(obj)
@@ -850,7 +848,6 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
850848
activityClass = obj.optString("class", ""),
851849
user = userHandle,
852850
profileType = obj.optString("profileType", "SYSTEM"),
853-
customLabel = obj.optString("customLabel", ""),
854851
customTag = obj.optString("customTag", ""),
855852
category = AppCategory.entries.getOrNull(obj.optInt("category", 1)) ?: AppCategory.REGULAR
856853
)

app/src/main/java/com/github/codeworkscreativehub/mlauncher/data/AppListItem.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,21 @@ val collator: Collator = Collator.getInstance()
2525
* userHandle is needed to resolve and start an activity.
2626
* And also we mark with a special icon the apps which belong to a managed user.
2727
*
28-
* @property customLabel
29-
* When user renames an app, we store the rename in Preferences.
30-
*
31-
* @property label
32-
* Use this property to render the list item.
33-
* It's either the original activity label (`activityLabel`) or a user-defined label (`definedLabel`).
3428
*/
3529
data class AppListItem(
3630
val activityLabel: String,
3731
val activityPackage: String,
3832
val activityClass: String,
3933
val user: UserHandle,
4034
val profileType: String = "SYSTEM",
41-
var customLabel: String,
4235
var customTag: String,
4336
var category: AppCategory = AppCategory.REGULAR
4437
) : Comparable<AppListItem> {
4538

46-
val label = customLabel.ifEmpty { activityLabel }
4739
val tag = customTag.ifEmpty { emptyString() }
4840

4941
/** Speed up sort and search */
50-
private val collationKey = collator.getCollationKey(label)
42+
private val collationKey = collator.getCollationKey(activityLabel)
5143

5244
override fun compareTo(other: AppListItem): Int =
5345
collationKey.compareTo(other.collationKey)

app/src/main/java/com/github/codeworkscreativehub/mlauncher/data/Prefs.kt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,6 @@ class Prefs(val context: Context) {
626626
storeApp("$i", appListItem)
627627
}
628628

629-
fun setHomeAppName(i: Int, name: String) {
630-
val nameId = "${APP_NAME}_$i"
631-
prefsNormal.edit { putString(nameId, name) }
632-
}
633-
634629
var appShortSwipeUp: AppListItem
635630
get() = loadApp(SHORT_SWIPE_UP)
636631
set(appModel) = storeApp(SHORT_SWIPE_UP, appModel)
@@ -684,7 +679,6 @@ class Prefs(val context: Context) {
684679
private fun loadApp(id: String): AppListItem {
685680
val appName = prefsNormal.getString("${APP_NAME}_$id", emptyString()).toString()
686681
val appPackage = prefsNormal.getString("${APP_PACKAGE}_$id", emptyString()).toString()
687-
val appAlias = prefsNormal.getString("${APP_ALIAS}_$id", emptyString()).toString()
688682
val appActivityName = prefsNormal.getString("${APP_ACTIVITY}_$id", emptyString()).toString()
689683

690684
val userHandleString = try {
@@ -697,7 +691,6 @@ class Prefs(val context: Context) {
697691
return AppListItem(
698692
activityLabel = appName,
699693
activityPackage = appPackage,
700-
customLabel = appAlias,
701694
customTag = emptyString(),
702695
activityClass = appActivityName,
703696
user = userHandle,
@@ -707,16 +700,14 @@ class Prefs(val context: Context) {
707700
private fun storeApp(id: String, app: AppListItem) {
708701
prefsNormal.edit {
709702
if (app.activityPackage.isNotEmpty() && app.activityClass.isNotEmpty()) {
710-
putString("${APP_NAME}_$id", app.label)
703+
putString("${APP_NAME}_$id", app.activityLabel)
711704
putString("${APP_PACKAGE}_$id", app.activityPackage)
712705
putString("${APP_ACTIVITY}_$id", app.activityClass)
713-
putString("${APP_ALIAS}_$id", app.customLabel)
714706
putString("${APP_USER}_$id", app.user.toString())
715707
} else {
716708
remove("${APP_NAME}_$id")
717709
remove("${APP_PACKAGE}_$id")
718710
remove("${APP_ACTIVITY}_$id")
719-
remove("${APP_ALIAS}_$id")
720711
remove("${APP_USER}_$id")
721712
}
722713
}
@@ -824,7 +815,7 @@ class Prefs(val context: Context) {
824815

825816
// return app label
826817
fun getAppName(location: Int): String {
827-
return getHomeAppModel(location).label
818+
return getHomeAppModel(location).activityLabel
828819
}
829820

830821
fun getAppAlias(appPackage: String): String {

app/src/main/java/com/github/codeworkscreativehub/mlauncher/data/PrefsKeys.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ internal const val LAUNCHER_FONT = "LAUNCHER_FONT"
105105
internal const val APP_NAME = "APP_NAME"
106106
internal const val APP_PACKAGE = "APP_PACKAGE"
107107
internal const val APP_USER = "APP_USER"
108-
internal const val APP_ALIAS = "APP_ALIAS"
109108
internal const val APP_ACTIVITY = "APP_ACTIVITY"
110109
internal const val APP_USAGE_STATS = "APP_USAGE_STATS"
111110
internal const val APP_OPACITY = "APP_OPACITY"

app/src/main/java/com/github/codeworkscreativehub/mlauncher/ui/AppDrawerFragment.kt

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ class AppDrawerFragment : BaseFragment() {
164164
AppDrawerFlag.SetAppUsage,
165165
AppDrawerFlag.SetClickDate,
166166
AppDrawerFlag.SetFloating -> {
167-
binding.drawerButton.setOnClickListener {
168-
findNavController().popBackStack()
169-
}
170167
}
171168

172169
AppDrawerFlag.SetHomeApp -> {
@@ -179,15 +176,10 @@ class AppDrawerFragment : BaseFragment() {
179176
activityClass = emptyString(),
180177
user = userManager.userProfiles[0], // or use Process.myUserHandle() if it makes more sense
181178
profileType = "SYSTEM",
182-
customLabel = "Clear",
183179
customTag = emptyString(),
184180
category = AppCategory.REGULAR
185181
)
186182

187-
binding.drawerButton.setOnClickListener {
188-
findNavController().popBackStack()
189-
}
190-
191183
binding.clearHomeButton.apply {
192184
val currentApp = prefs.getHomeAppModel(n)
193185
if (currentApp.activityPackage.isNotEmpty() && currentApp.activityClass.isNotEmpty()) {
@@ -309,7 +301,7 @@ class AppDrawerFragment : BaseFragment() {
309301

310302
val sectionLetter = when (item.category) {
311303
AppCategory.PINNED -> ""
312-
else -> item.label.firstOrNull()?.uppercaseChar()?.toString() ?: return
304+
else -> item.activityLabel.firstOrNull()?.uppercaseChar()?.toString() ?: return
313305
}
314306

315307
// Skip redundant updates
@@ -502,11 +494,6 @@ class AppDrawerFragment : BaseFragment() {
502494

503495
override fun onQueryTextChange(newText: String?): Boolean {
504496
if (flag == AppDrawerFlag.SetHomeApp) {
505-
binding.drawerButton.apply {
506-
isVisible = !newText.isNullOrEmpty()
507-
text = if (isVisible) getLocalizedString(R.string.rename) else null
508-
setOnClickListener { if (isVisible) renameListener(flag, n) }
509-
}
510497
binding.clearHomeButton.apply {
511498
isVisible = newText.isNullOrEmpty()
512499
}
@@ -823,16 +810,6 @@ class AppDrawerFragment : BaseFragment() {
823810
findNavController().popBackStack()
824811
}
825812

826-
private fun renameListener(flag: AppDrawerFlag, i: Int) {
827-
val name = binding.search.query.toString().trim()
828-
if (name.isEmpty()) return
829-
if (flag == AppDrawerFlag.SetHomeApp) {
830-
Prefs(requireContext()).setHomeAppName(i, name)
831-
}
832-
833-
findNavController().popBackStack()
834-
}
835-
836813
private fun appShowHideListener(): (flag: AppDrawerFlag, appListItem: AppListItem) -> Unit = { flag, appModel ->
837814
val prefs = Prefs(requireContext())
838815
val newSet = mutableSetOf<String>()
@@ -877,7 +854,7 @@ class AppDrawerFragment : BaseFragment() {
877854
when (item.category) {
878855
AppCategory.PINNED -> letters.add("")
879856
else -> {
880-
item.label.firstOrNull()
857+
item.activityLabel.firstOrNull()
881858
?.uppercaseChar()
882859
?.toString()
883860
?.let { letters.add(it) }

app/src/main/java/com/github/codeworkscreativehub/mlauncher/ui/HomeFragment.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -989,13 +989,15 @@ class HomeFragment : BaseFragment(), View.OnClickListener, View.OnLongClickListe
989989
for (i in oldAppsNum until newAppsNum) {
990990
val homeAppLabel = layoutInflater.inflate(R.layout.home_app_button, null) as TextView
991991
homeAppLabel.apply {
992+
val homeApp = prefs.getHomeAppModel(i)
992993
textSize = prefs.appSize.toFloat()
993994
id = i
994-
text = if (prefs.getHomeAppModel(i).activityPackage.isBlank()) {
995+
text = if (homeApp.activityPackage.isBlank()) {
995996
getLocalizedString(R.string.select_app)
996997
} else {
997-
prefs.getHomeAppModel(i).activityLabel
998+
prefs.getAppAlias(homeApp.activityPackage).takeIf { it.isNotBlank() } ?: homeApp.activityLabel
998999
}
1000+
9991001
getHomeAppsGestureListener()
10001002
setOnClickListener(this@HomeFragment)
10011003

@@ -1088,7 +1090,7 @@ class HomeFragment : BaseFragment(), View.OnClickListener, View.OnLongClickListe
10881090

10891091
this.text = if (count > 0) {
10901092
val circledNumber = getCircledDigit(count)
1091-
val newText = "${appModel.label} $circledNumber"
1093+
val newText = "${appModel.activityLabel} $circledNumber"
10921094
val spannable = SpannableString(newText)
10931095

10941096
val start = newText.indexOf(circledNumber)
@@ -1118,7 +1120,7 @@ class HomeFragment : BaseFragment(), View.OnClickListener, View.OnLongClickListe
11181120

11191121
spannable
11201122
} else {
1121-
appModel.label
1123+
appModel.activityLabel
11221124
}
11231125

11241126
AppLogger.d("HomeFragment", "Notification count updated for $packageName: $count")

app/src/main/java/com/github/codeworkscreativehub/mlauncher/ui/SettingsFragment.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,6 @@ class SettingsFragment : BaseFragment() {
832832
activityClass = emptyString(),
833833
user = userManager.userProfiles[0], // or use Process.myUserHandle() if it makes more sense
834834
profileType = "SYSTEM",
835-
customLabel = "Clear",
836835
customTag = emptyString(),
837836
category = AppCategory.REGULAR
838837
)

app/src/main/java/com/github/codeworkscreativehub/mlauncher/ui/adapter/AppDrawerAdapter.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ class AppDrawerAdapter(
103103
}
104104

105105
val appModel = appFilteredList[holder.absoluteAdapterPosition]
106-
AppLogger.d("AppListDebug", "🔧 Binding position=$position, label=${appModel.label}, package=${appModel.activityPackage}")
106+
AppLogger.d("AppListDebug", "🔧 Binding position=$position, label=${appModel.activityLabel}, package=${appModel.activityPackage}")
107107

108108
// Pass icon cache and loading scope to bind
109109
holder.bind(flag, gravity, appModel, appClickListener, appInfoListener, appDeleteListener, iconCache, iconLoadingScope, prefs)
110110

111111
holder.appHide.setOnClickListener {
112-
AppLogger.d("AppListDebug", "❌ Hide clicked for ${appModel.label} (${appModel.activityPackage})")
112+
AppLogger.d("AppListDebug", "❌ Hide clicked for ${appModel.activityLabel} (${appModel.activityPackage})")
113113

114114
appFilteredList.removeAt(holder.absoluteAdapterPosition)
115115
appsList.remove(appModel)
@@ -161,10 +161,9 @@ class AppDrawerAdapter(
161161
holder.appSaveRename.setOnClickListener {
162162
val name = holder.appRenameEdit.text.toString().trim()
163163
AppLogger.d("AppListDebug", "✏️ Renaming ${appModel.activityPackage} to $name")
164-
appModel.customLabel = name
165164
notifyItemChanged(holder.absoluteAdapterPosition)
166165
AppLogger.d("AppListDebug", "🔁 notifyItemChanged at ${holder.absoluteAdapterPosition}")
167-
appRenameListener(appModel.activityPackage, appModel.customLabel)
166+
appRenameListener(appModel.activityPackage, name)
168167
}
169168

170169
holder.appSaveTag.setOnClickListener {
@@ -194,7 +193,7 @@ class AppDrawerAdapter(
194193

195194
val isTagSearch = searchChars.startsWith("#")
196195
val query = if (isTagSearch) searchChars.substringAfter("#") else searchChars
197-
val normalizeField: (AppListItem) -> String = { app -> if (isTagSearch) normalize(app.tag) else normalize(app.label) }
196+
val normalizeField: (AppListItem) -> String = { app -> if (isTagSearch) normalize(app.tag) else normalize(app.activityLabel) }
198197

199198
// Scoring logic
200199
val scoredApps: Map<AppListItem, Int> = if (prefs.enableFilterStrength) {
@@ -289,7 +288,7 @@ class AppDrawerAdapter(
289288

290289
fun getFirstInList(): String? {
291290
if (appFilteredList.isNotEmpty())
292-
return appFilteredList[0].label
291+
return appFilteredList[0].activityLabel
293292
return null
294293
}
295294

@@ -410,14 +409,15 @@ class AppDrawerAdapter(
410409
}
411410

412411
appRenameEdit.apply {
413-
text = Editable.Factory.getInstance().newEditable(appListItem.label)
412+
text = Editable.Factory.getInstance().newEditable(prefs.getAppAlias(appListItem.activityPackage).takeIf { it.isNotBlank() } ?: appListItem.activityLabel)
414413
addTextChangedListener(object : TextWatcher {
415414
override fun afterTextChanged(s: Editable) {}
416415
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
417416
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
417+
val activityLabel = prefs.getAppAlias(appListItem.activityPackage).takeIf { it.isNotBlank() } ?: appListItem.activityLabel
418418
appSaveRename.text = when {
419419
text.isEmpty() -> getLocalizedString(R.string.reset)
420-
text.toString() == appListItem.customLabel -> getLocalizedString(R.string.cancel)
420+
text.toString() == activityLabel -> getLocalizedString(R.string.cancel)
421421
else -> getLocalizedString(R.string.rename)
422422
}
423423
}
@@ -448,7 +448,7 @@ class AppDrawerAdapter(
448448

449449
// ----------------------------
450450
// 5️⃣ App title
451-
appTitle.text = appListItem.label
451+
appTitle.text = prefs.getAppAlias(appListItem.activityPackage).takeIf { it.isNotBlank() } ?: appListItem.activityLabel
452452
val params = appTitle.layoutParams as FrameLayout.LayoutParams
453453
params.gravity = appLabelGravity
454454
appTitle.layoutParams = params
@@ -474,7 +474,7 @@ class AppDrawerAdapter(
474474
getSystemIcons(context, prefs, IconCacheTarget.APP_LIST, nonNullDrawable) ?: nonNullDrawable
475475
}
476476
iconCache[packageName] = icon
477-
if (appTitle.text == appListItem.label) setAppTitleIcon(appTitle, icon, prefs)
477+
if (appTitle.text == appListItem.activityLabel) setAppTitleIcon(appTitle, icon, prefs)
478478
}
479479
}
480480

@@ -502,7 +502,8 @@ class AppDrawerAdapter(
502502
sidebarContainer?.isVisible = false
503503
openedContextMenuPosition = currentPos
504504

505-
} catch (_: Exception) {
505+
} catch (e: Exception) {
506+
e.printStackTrace()
506507
}
507508
}
508509
true

app/src/main/java/com/github/codeworkscreativehub/mlauncher/ui/adapter/FavoriteAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FavoriteAdapter(
3636
val appItem = apps[position]
3737

3838
// Set the label text from the app item
39-
holder.appTextView.text = appItem.label
39+
holder.appTextView.text = appItem.activityLabel
4040

4141
// Set the text size and color dynamically using prefs
4242
holder.appTextView.setTextColor(prefs.appColor) // Get color from prefs

0 commit comments

Comments
 (0)