Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename multiple activities from one app separately #535

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/java/app/olauncher/data/AppModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppModel> {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/app/olauncher/data/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
3 changes: 2 additions & 1 deletion app/src/main/java/app/olauncher/helper/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
26 changes: 6 additions & 20 deletions app/src/main/java/app/olauncher/ui/AppDrawerAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package app.olauncher.ui

import android.content.Context
import android.os.UserHandle
import android.text.Editable
import android.text.TextWatcher
Expand Down Expand Up @@ -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<AppModel, AppDrawerAdapter.ViewHolder>(DIFF_CALLBACK), Filterable {

companion object {
Expand Down Expand Up @@ -130,7 +129,7 @@ class AppDrawerAdapter(

fun setAppList(appsList: MutableList<AppModel>) {
// 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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -195,7 +194,7 @@ class AppDrawerAdapter(
}
etAppRename.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
etAppRename.hint = getAppName(etAppRename.context, appModel.appPackage)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this piece of code. It seems to reload the app name every time something is typed. For what is this needed?

The updated code currently does not do this, and always uses the originalLabel set in Utils/getAppsList, which might need to be changed to restore the original behavior.

etAppRename.hint = appModel.originalLabel
}

override fun beforeTextChanged(
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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()
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/app/olauncher/ui/AppDrawerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class AppDrawerFragment : Fragment() {
viewModel.getHiddenApps()
},
appRenameListener = { appModel, renameLabel ->
prefs.setAppRenameLabel(appModel.appPackage, renameLabel)
prefs.setAppRenameLabel(appModel.activityClassName, renameLabel)
viewModel.getAppList()
}
)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/app/olauncher/ui/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class HomeFragment : Fragment(), View.OnClickListener, View.OnLongClickListener
null,
packageName,
activityClassName,
appName,
false,
getUserHandleFromString(requireContext(), userString)
),
Expand Down