Skip to content

Commit 8ec4f80

Browse files
feat: Add reset functionality to app renaming
This commit enhances the app renaming feature in the app drawer. When an app has a custom name (alias), the "Rename" button is now replaced with a "Reset" button if the string is empty. Tapping "Reset" will revert the app's name to its default label. If the app name has not been changed, the button will continue to show "Cancel". This is achieved by: - Checking the button's text in the `onClickListener` to differentiate between "Rename" and "Reset" actions. - Sending an empty string to the `appRenameListener` to signal a reset to the default name. - Updating the button's text to "Cancel" when the rename dialog is opened.
1 parent 0654b04 commit 8ec4f80

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import com.github.codeworkscreativehub.mlauncher.databinding.AdapterAppDrawerBin
4141
import com.github.codeworkscreativehub.mlauncher.helper.IconCacheTarget
4242
import com.github.codeworkscreativehub.mlauncher.helper.IconPackHelper.getSafeAppIcon
4343
import com.github.codeworkscreativehub.mlauncher.helper.dp2px
44+
import com.github.codeworkscreativehub.mlauncher.helper.emptyString
4445
import com.github.codeworkscreativehub.mlauncher.helper.getSystemIcons
4546
import com.github.codeworkscreativehub.mlauncher.helper.utils.BiometricHelper
4647
import kotlinx.coroutines.CoroutineScope
@@ -159,11 +160,27 @@ class AppDrawerAdapter(
159160
}
160161

161162
holder.appSaveRename.setOnClickListener {
162-
val name = holder.appRenameEdit.text.toString().trim()
163-
AppLogger.d("AppListDebug", "✏️ Renaming ${appModel.activityPackage} to $name")
164-
notifyItemChanged(holder.absoluteAdapterPosition)
165-
AppLogger.d("AppListDebug", "🔁 notifyItemChanged at ${holder.absoluteAdapterPosition}")
166-
appRenameListener(appModel.activityPackage, name)
163+
when (holder.appSaveRename.text) {
164+
getLocalizedString(R.string.rename) -> {
165+
val name = holder.appRenameEdit.text.toString().trim()
166+
AppLogger.d("AppListDebug", "✏️ Renaming ${appModel.activityPackage} to $name")
167+
notifyItemChanged(holder.absoluteAdapterPosition)
168+
AppLogger.d("AppListDebug", "🔁 notifyItemChanged at ${holder.absoluteAdapterPosition}")
169+
appRenameListener(appModel.activityPackage, name)
170+
}
171+
172+
getLocalizedString(R.string.reset) -> {
173+
AppLogger.d("AppListDebug", "✏️ Resetting ${appModel.activityPackage} to default")
174+
notifyItemChanged(holder.absoluteAdapterPosition)
175+
AppLogger.d("AppListDebug", "🔁 notifyItemChanged at ${holder.absoluteAdapterPosition}")
176+
appRenameListener(appModel.activityPackage, emptyString()) // empty string signals default
177+
}
178+
179+
else -> {
180+
notifyItemChanged(holder.absoluteAdapterPosition)
181+
}
182+
}
183+
167184
}
168185

169186
holder.appSaveTag.setOnClickListener {
@@ -410,6 +427,7 @@ class AppDrawerAdapter(
410427

411428
appRenameEdit.apply {
412429
text = Editable.Factory.getInstance().newEditable(prefs.getAppAlias(appListItem.activityPackage).takeIf { it.isNotBlank() } ?: appListItem.activityLabel)
430+
appSaveRename.text = getLocalizedString(R.string.cancel)
413431
addTextChangedListener(object : TextWatcher {
414432
override fun afterTextChanged(s: Editable) {}
415433
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}

0 commit comments

Comments
 (0)