Merge pull request #25 from alrajdev/fix_showing_app_name

Show Launch activity label instead of app name
This commit is contained in:
ottop 2024-12-10 16:18:18 +02:00 committed by GitHub
commit 8dc3cb3d99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 83 additions and 81 deletions

View file

@ -33,10 +33,9 @@ class AppActionMenu(private val activity: MainActivity, private val binding: Act
textView: TextView, textView: TextView,
editLayout: LinearLayout, editLayout: LinearLayout,
actionMenu: View, actionMenu: View,
appInfo: ApplicationInfo, appActivity: LauncherActivityInfo,
userHandle: UserHandle, userHandle: UserHandle,
workProfile: Int, workProfile: Int
appActivity: LauncherActivityInfo?
){ ){
@ -52,32 +51,32 @@ class AppActionMenu(private val activity: MainActivity, private val binding: Act
} }
ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_uninstall)) { _, _ -> ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_uninstall)) { _, _ ->
uninstallApp(appInfo, userHandle) uninstallApp(appActivity.applicationInfo, userHandle)
true true
} }
actionMenu.findViewById<TextView>(R.id.uninstall).setOnClickListener { actionMenu.findViewById<TextView>(R.id.uninstall).setOnClickListener {
uninstallApp(appInfo, userHandle) uninstallApp(appActivity.applicationInfo, userHandle)
animations.fadeViewOut(actionMenu) animations.fadeViewOut(actionMenu)
textView.visibility = View.VISIBLE textView.visibility = View.VISIBLE
} }
ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_rename)) { _, _ -> ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_rename)) { _, _ ->
renameApp(textView, editLayout, actionMenu, appActivity, appInfo, userHandle, workProfile) renameApp(textView, editLayout, actionMenu, appActivity, userHandle, workProfile)
true true
} }
actionMenu.findViewById<TextView>(R.id.rename).setOnClickListener { actionMenu.findViewById<TextView>(R.id.rename).setOnClickListener {
renameApp(textView, editLayout, actionMenu, appActivity, appInfo, userHandle, workProfile) renameApp(textView, editLayout, actionMenu, appActivity, userHandle, workProfile)
} }
ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_hide)) { _, _ -> ViewCompat.addAccessibilityAction(textView, activity.getString(R.string.accessibility_hide)) { _, _ ->
hideApp(editLayout, textView, actionMenu, appInfo, workProfile) hideApp(editLayout, textView, actionMenu, appActivity, workProfile)
true true
} }
actionMenu.findViewById<TextView>(R.id.hide).setOnClickListener { actionMenu.findViewById<TextView>(R.id.hide).setOnClickListener {
hideApp(editLayout, textView, actionMenu, appInfo, workProfile) hideApp(editLayout, textView, actionMenu, appActivity, workProfile)
} }
actionMenu.findViewById<TextView>(R.id.close).setOnClickListener { actionMenu.findViewById<TextView>(R.id.close).setOnClickListener {
@ -109,7 +108,7 @@ class AppActionMenu(private val activity: MainActivity, private val binding: Act
activity.returnAllowed = false activity.returnAllowed = false
} }
private fun renameApp(textView: TextView, editLayout: LinearLayout, actionMenu: View, appActivity: LauncherActivityInfo?, appInfo: ApplicationInfo, userHandle: UserHandle, workProfile: Int) { private fun renameApp(textView: TextView, editLayout: LinearLayout, actionMenu: View, appActivity: LauncherActivityInfo, userHandle: UserHandle, workProfile: Int) {
activity.disableAppMenuScroll() activity.disableAppMenuScroll()
textView.visibility = View.INVISIBLE textView.visibility = View.INVISIBLE
animations.fadeViewIn(editLayout) animations.fadeViewIn(editLayout)
@ -117,7 +116,7 @@ class AppActionMenu(private val activity: MainActivity, private val binding: Act
val editText = editLayout.findViewById<EditText>(R.id.appNameEdit) val editText = editLayout.findViewById<EditText>(R.id.appNameEdit)
val resetButton = editLayout.findViewById<AppCompatButton>(R.id.reset) val resetButton = editLayout.findViewById<AppCompatButton>(R.id.reset)
val app = Triple(appActivity!!, userHandle, workProfile) val app = Triple(appActivity, userHandle, workProfile)
val searchEnabled = sharedPreferenceManager.isSearchEnabled() val searchEnabled = sharedPreferenceManager.isSearchEnabled()
@ -166,7 +165,7 @@ class AppActionMenu(private val activity: MainActivity, private val binding: Act
activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(editText.windowToken, 0) imm.hideSoftInputFromWindow(editText.windowToken, 0)
sharedPreferenceManager.setAppName( sharedPreferenceManager.setAppName(
appInfo.packageName, app.first.componentName.flattenToString(),
workProfile, workProfile,
editText.text.toString() editText.text.toString()
) )
@ -187,7 +186,7 @@ class AppActionMenu(private val activity: MainActivity, private val binding: Act
activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(editLayout.windowToken, 0) imm.hideSoftInputFromWindow(editLayout.windowToken, 0)
sharedPreferenceManager.resetAppName( sharedPreferenceManager.resetAppName(
app.first.applicationInfo.packageName, app.first.componentName.flattenToString(),
app.third app.third
) )
@ -197,12 +196,12 @@ class AppActionMenu(private val activity: MainActivity, private val binding: Act
} }
} }
private fun hideApp(editLayout: LinearLayout, textView: TextView, actionMenu: View, appInfo: ApplicationInfo, workProfile: Int) { private fun hideApp(editLayout: LinearLayout, textView: TextView, actionMenu: View, appActivity: LauncherActivityInfo, workProfile: Int) {
editLayout.visibility = View.GONE editLayout.visibility = View.GONE
textView.visibility = View.GONE textView.visibility = View.GONE
actionMenu.visibility = View.GONE actionMenu.visibility = View.GONE
activity.lifecycleScope.launch { activity.lifecycleScope.launch {
sharedPreferenceManager.setAppHidden(appInfo.packageName, workProfile, true) sharedPreferenceManager.setAppHidden(appActivity.componentName.flattenToString(), workProfile, true)
activity.refreshAppMenu() activity.refreshAppMenu()
} }
} }

View file

@ -131,25 +131,23 @@ class AppMenuAdapter(
holder.textView.setTextColor(sharedPreferenceManager.getTextColor()) holder.textView.setTextColor(sharedPreferenceManager.getTextColor())
// Update the application information (allows updating apps to work) // Update the application information (allows updating apps to work)
val appInfo = appUtils.getAppInfo( val isAppInstalled = appUtils.getAppInfo(
app.first.applicationInfo.packageName, app.first.applicationInfo.packageName,
app.third app.third
) ) != null
// Set app name on the menu. If the app has been uninstalled, replace it with "Removing" until the app menu updates. // Set app name on the menu. If the app has been uninstalled, replace it with "Removing" until the app menu updates.
val appLabel: CharSequence = appInfo?.let { activity.packageManager.getApplicationLabel(it) } ?: activity.getString(R.string.removing) if (isAppInstalled) {
if (appInfo != null) {
holder.textView.text = sharedPreferenceManager.getAppName( holder.textView.text = sharedPreferenceManager.getAppName(
appInfo.packageName, app.first.componentName.flattenToString(),
app.third, app.third,
appLabel app.first.label
) )
holder.editText.setText(holder.textView.text) holder.editText.setText(holder.textView.text)
// Remove the uninstall icon for system apps // Remove the uninstall icon for system apps
if (appInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) { if (app.first.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) {
holder.actionMenuLayout.findViewById<TextView>(R.id.uninstall).visibility = holder.actionMenuLayout.findViewById<TextView>(R.id.uninstall).visibility =
View.GONE View.GONE
} else { } else {
@ -157,22 +155,20 @@ class AppMenuAdapter(
View.VISIBLE View.VISIBLE
} }
} }
else {holder.textView.text = appLabel} else {
holder.textView.text = activity.getString(R.string.removing)
}
holder.textView.visibility = View.VISIBLE holder.textView.visibility = View.VISIBLE
if (appInfo != null) { if (isAppInstalled) {
val appActivity = launcherApps.getActivityList(appInfo.packageName, app.second).firstOrNull()
appActionMenu.setActionListeners( appActionMenu.setActionListeners(
holder.textView, holder.textView,
holder.editView, holder.editView,
holder.actionMenuLayout, holder.actionMenuLayout,
appInfo, app.first,
app.second, app.second,
app.third, app.third,
appActivity
) )
} }
ViewCompat.addAccessibilityAction(holder.textView, activity.getString(R.string.close_app_menu)) { _, _ -> ViewCompat.addAccessibilityAction(holder.textView, activity.getString(R.string.close_app_menu)) { _, _ ->

View file

@ -4,6 +4,7 @@ import android.Manifest
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.SearchManager import android.app.SearchManager
import android.content.ActivityNotFoundException import android.content.ActivityNotFoundException
import android.content.ComponentName
import android.content.ContentResolver import android.content.ContentResolver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
@ -375,7 +376,20 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private fun setShortcutListeners(textView: TextView, savedView: List<String>?) { private fun setShortcutListeners(textView: TextView, savedView: List<String>?) {
textView.setOnClickListener { textView.setOnClickListener {
if (savedView != null && canLaunchShortcut) { if (savedView != null && canLaunchShortcut) {
appUtils.launchApp(savedView[0], launcherApps.profiles[savedView[1].toInt()]) val componentName = if (savedView[0].contains("/")) {
val (packageName, className) = savedView[0].split("/")
ComponentName(packageName, className)
} else {
val userHandle = launcherApps.profiles[savedView[1].toInt()]
val mainActivity = launcherApps.getActivityList(savedView[0], userHandle).firstOrNull()
if (mainActivity != null) {
mainActivity.componentName
} else {
Toast.makeText(this, this.getString(R.string.launch_error), Toast.LENGTH_SHORT).show()
return@setOnClickListener
}
}
appUtils.launchApp(componentName, launcherApps.profiles[savedView[1].toInt()])
} }
} }
} }
@ -993,9 +1007,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
updatedApps.forEach { updatedApps.forEach {
val cleanItemText = stringUtils.cleanString(sharedPreferenceManager.getAppName( val cleanItemText = stringUtils.cleanString(sharedPreferenceManager.getAppName(
it.first.applicationInfo.packageName, it.first.componentName.flattenToString(),
it.third, it.third,
packageManager.getApplicationLabel(it.first.applicationInfo) it.first.label
).toString()) ).toString())
if (cleanItemText != null) { if (cleanItemText != null) {
if ( if (
@ -1012,7 +1026,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private suspend fun applySearchFilter(newFilteredApps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>) { private suspend fun applySearchFilter(newFilteredApps: MutableList<Triple<LauncherActivityInfo, UserHandle, Int>>) {
if (sharedPreferenceManager.isAutoLaunchEnabled() && menuView.displayedChild == 0 && appAdapter?.shortcutTextView == null && newFilteredApps.size == 1) { if (sharedPreferenceManager.isAutoLaunchEnabled() && menuView.displayedChild == 0 && appAdapter?.shortcutTextView == null && newFilteredApps.size == 1) {
appUtils.launchApp(newFilteredApps[0].first.applicationInfo.packageName, newFilteredApps[0].second) appUtils.launchApp(newFilteredApps[0].first.componentName, newFilteredApps[0].second)
} else if (!listsEqual(installedApps, newFilteredApps)) { } else if (!listsEqual(installedApps, newFilteredApps)) {
updateMenu(newFilteredApps) updateMenu(newFilteredApps)
@ -1072,7 +1086,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) { override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
appUtils.launchApp(appInfo.applicationInfo.packageName, userHandle) appUtils.launchApp(appInfo.componentName, userHandle)
} }
override fun onShortcut( override fun onShortcut(
@ -1096,12 +1110,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
shortcutView.text = textView.text.toString() shortcutView.text = textView.text.toString()
shortcutView.setOnClickListener { shortcutView.setOnClickListener {
appUtils.launchApp(appInfo.applicationInfo.packageName, userHandle) appUtils.launchApp(appInfo.componentName, userHandle)
} }
sharedPreferenceManager.setShortcut( sharedPreferenceManager.setShortcut(
shortcutIndex, shortcutIndex,
shortcutView.text, shortcutView.text,
appInfo.applicationInfo.packageName, appInfo.componentName.flattenToString(),
userProfile userProfile
) )
uiUtils.setDrawables(shortcutView, sharedPreferenceManager.getShortcutAlignment()) uiUtils.setDrawables(shortcutView, sharedPreferenceManager.getShortcutAlignment())

View file

@ -67,12 +67,10 @@ class GestureAppsAdapter(
uiUtils.setItemSpacing(holder.textView) uiUtils.setItemSpacing(holder.textView)
// Does not need to be specially updated since it's in a separate activity and thus reloads when opened again // Does not need to be specially updated since it's in a separate activity and thus reloads when opened again
val appInfo = app.first.activityInfo.applicationInfo
holder.textView.text = sharedPreferenceManager.getAppName( holder.textView.text = sharedPreferenceManager.getAppName(
app.first.applicationInfo.packageName, app.first.componentName.flattenToString(),
app.third, app.third,
context.packageManager.getApplicationLabel(appInfo) app.first.label
) )
holder.textView.visibility = View.VISIBLE holder.textView.visibility = View.VISIBLE

View file

@ -122,9 +122,9 @@ class GestureAppsFragment(private val direction: String) : Fragment(),
} }
updatedApps.forEach { updatedApps.forEach {
val cleanItemText = stringUtils.cleanString(sharedPreferenceManager.getAppName( val cleanItemText = stringUtils.cleanString(sharedPreferenceManager.getAppName(
it.first.applicationInfo.packageName, it.first.componentName.flattenToString(),
it.third, it.third,
requireContext().packageManager.getApplicationLabel(it.first.applicationInfo) it.first.label
).toString()) ).toString())
if (cleanItemText != null) { if (cleanItemText != null) {
if ( if (
@ -159,7 +159,7 @@ class GestureAppsFragment(private val direction: String) : Fragment(),
private fun performConfirmedAction(appInfo: LauncherActivityInfo, appName: String, profile: Int) { private fun performConfirmedAction(appInfo: LauncherActivityInfo, appName: String, profile: Int) {
sharedPreferenceManager.setGestures( sharedPreferenceManager.setGestures(
direction, "$appName§splitter§${appInfo.applicationInfo.packageName}§splitter§$profile" direction, "$appName§splitter§${appInfo.componentName.flattenToString()}§splitter§$profile"
) )
requireActivity().supportFragmentManager.popBackStack() requireActivity().supportFragmentManager.popBackStack()
} }
@ -167,9 +167,9 @@ class GestureAppsFragment(private val direction: String) : Fragment(),
override fun onItemClick(appInfo: LauncherActivityInfo, profile: Int) { override fun onItemClick(appInfo: LauncherActivityInfo, profile: Int) {
showConfirmationDialog(appInfo, sharedPreferenceManager.getAppName( showConfirmationDialog(appInfo, sharedPreferenceManager.getAppName(
appInfo.applicationInfo.packageName, appInfo.componentName.flattenToString(),
profile, profile,
requireContext().packageManager.getApplicationLabel(appInfo.applicationInfo) appInfo.label
).toString(), profile) ).toString(), profile)
} }

View file

@ -68,11 +68,10 @@ class HiddenAppsAdapter(
uiUtils.setItemSpacing(holder.textView) uiUtils.setItemSpacing(holder.textView)
// Separate activity from Main so does not need special update // Separate activity from Main so does not need special update
val appInfo = app.first.activityInfo.applicationInfo
holder.textView.text = sharedPreferenceManager.getAppName( holder.textView.text = sharedPreferenceManager.getAppName(
app.first.applicationInfo.packageName, app.first.componentName.flattenToString(),
app.third, app.third,
context.packageManager.getApplicationLabel(appInfo) app.first.label
) )
holder.textView.visibility = View.VISIBLE holder.textView.visibility = View.VISIBLE

View file

@ -122,9 +122,9 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener, Ti
} }
updatedApps.forEach { updatedApps.forEach {
val cleanItemText = stringUtils.cleanString(sharedPreferenceManager.getAppName( val cleanItemText = stringUtils.cleanString(sharedPreferenceManager.getAppName(
it.first.applicationInfo.packageName, it.first.componentName.flattenToString(),
it.third, it.third,
requireContext().packageManager.getApplicationLabel(it.first.applicationInfo) it.first.label
).toString()) ).toString())
if (cleanItemText != null) { if (cleanItemText != null) {
if ( if (
@ -158,15 +158,15 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener, Ti
} }
private suspend fun performConfirmedAction(appInfo: LauncherActivityInfo, profile: Int) { private suspend fun performConfirmedAction(appInfo: LauncherActivityInfo, profile: Int) {
sharedPreferenceManager.setAppVisible(appInfo.applicationInfo.packageName, profile) sharedPreferenceManager.setAppVisible(appInfo.componentName.flattenToString(), profile)
adapter?.updateApps(appUtils.getHiddenApps()) adapter?.updateApps(appUtils.getHiddenApps())
} }
override fun onItemClick(appInfo: LauncherActivityInfo, profile: Int) { override fun onItemClick(appInfo: LauncherActivityInfo, profile: Int) {
showConfirmationDialog(appInfo, sharedPreferenceManager.getAppName( showConfirmationDialog(appInfo, sharedPreferenceManager.getAppName(
appInfo.applicationInfo.packageName, appInfo.componentName.flattenToString(),
profile, profile,
requireContext().packageManager.getApplicationLabel(appInfo.applicationInfo) appInfo.label
).toString(), profile) ).toString(), profile)
} }

View file

@ -88,9 +88,9 @@ class SharedPreferenceManager (private val context: Context) {
return preferences.getString("dateSize", "medium") return preferences.getString("dateSize", "medium")
} }
fun setShortcut(index: Int, text: CharSequence, packageName: String, profile: Int, isContact: Boolean = false) { fun setShortcut(index: Int, text: CharSequence, componentName: String, profile: Int, isContact: Boolean = false) {
val editor = preferences.edit() val editor = preferences.edit()
editor.putString("shortcut${index}", "$packageName§splitter§$profile§splitter§${text}§splitter§${isContact}") editor.putString("shortcut${index}", "$componentName§splitter§$profile§splitter§${text}§splitter§${isContact}")
editor.apply() editor.apply()
} }
@ -245,36 +245,36 @@ class SharedPreferenceManager (private val context: Context) {
} }
// Hidden Apps // Hidden Apps
fun setAppHidden(packageName: String, profile: Int, hidden: Boolean) { fun setAppHidden(componentName: String, profile: Int, hidden: Boolean) {
val editor = preferences.edit() val editor = preferences.edit()
editor.putBoolean("hidden$packageName-$profile", hidden) editor.putBoolean("hidden$componentName-$profile", hidden)
editor.apply() editor.apply()
} }
fun isAppHidden(packageName: String, profile: Int): Boolean { fun isAppHidden(componentName: String, profile: Int): Boolean {
return preferences.getBoolean("hidden$packageName-$profile", false) // Default to false (visible) return preferences.getBoolean("hidden$componentName-$profile", false) // Default to false (visible)
} }
fun setAppVisible(packageName: String, profile: Int) { fun setAppVisible(componentName: String, profile: Int) {
val editor = preferences.edit() val editor = preferences.edit()
editor.remove("hidden$packageName-$profile") editor.remove("hidden$componentName-$profile")
editor.apply() editor.apply()
} }
//Renaming apps //Renaming apps
fun setAppName(packageName: String, profile: Int, newName: String) { fun setAppName(componentName: String, profile: Int, newName: String) {
val editor = preferences.edit() val editor = preferences.edit()
editor.putString("name$packageName-$profile", newName) editor.putString("name$componentName-$profile", newName)
editor.apply() editor.apply()
} }
fun getAppName(packageName: String, profile: Int, appName: CharSequence): CharSequence? { fun getAppName(componentName: String, profile: Int, appName: CharSequence): CharSequence? {
return preferences.getString("name$packageName-$profile", appName.toString()) return preferences.getString("name$componentName-$profile", appName.toString())
} }
fun resetAppName(packageName: String, profile: Int) { fun resetAppName(componentName: String, profile: Int) {
val editor = preferences.edit() val editor = preferences.edit()
editor.remove("name$packageName-$profile") editor.remove("name$componentName-$profile")
editor.apply() editor.apply()
} }

View file

@ -1,5 +1,6 @@
package eu.ottop.yamlauncher.utils package eu.ottop.yamlauncher.utils
import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.pm.ApplicationInfo import android.content.pm.ApplicationInfo
import android.content.pm.LauncherActivityInfo import android.content.pm.LauncherActivityInfo
@ -22,7 +23,7 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
for (i in launcherApps.profiles.indices) { // Check apps on both, normal and work profiles for (i in launcherApps.profiles.indices) { // Check apps on both, normal and work profiles
launcherApps.getActivityList(null, launcherApps.profiles[i]).forEach { app -> launcherApps.getActivityList(null, launcherApps.profiles[i]).forEach { app ->
if (!sharedPreferenceManager.isAppHidden( // Only include the app if it isn't set as hidden if (!sharedPreferenceManager.isAppHidden( // Only include the app if it isn't set as hidden
app.applicationInfo.packageName, app.componentName.flattenToString(),
i i
) && app.applicationInfo.packageName != context.applicationInfo.packageName // Hide the launcher itself ) && app.applicationInfo.packageName != context.applicationInfo.packageName // Hide the launcher itself
) { ) {
@ -34,9 +35,9 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
// Sort apps by name // Sort apps by name
sortedApps = allApps.sortedBy { sortedApps = allApps.sortedBy {
sharedPreferenceManager.getAppName( sharedPreferenceManager.getAppName(
it.first.applicationInfo.packageName, it.first.componentName.flattenToString(),
it.third, it.third,
context.packageManager.getApplicationLabel(it.first.applicationInfo) it.first.label
).toString().lowercase() ).toString().lowercase()
} }
} }
@ -51,7 +52,7 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
withContext(Dispatchers.Default) { withContext(Dispatchers.Default) {
for (i in launcherApps.profiles.indices) { for (i in launcherApps.profiles.indices) {
launcherApps.getActivityList(null, launcherApps.profiles[i]).forEach { app -> launcherApps.getActivityList(null, launcherApps.profiles[i]).forEach { app ->
if (sharedPreferenceManager.isAppHidden(app.applicationInfo.packageName, i)) { if (sharedPreferenceManager.isAppHidden(app.componentName.flattenToString(), i)) {
allApps.add(Triple(app, launcherApps.profiles[i], i)) allApps.add(Triple(app, launcherApps.profiles[i], i))
} }
} }
@ -60,9 +61,9 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
//Sort apps by name //Sort apps by name
sortedApps = allApps.sortedBy { sortedApps = allApps.sortedBy {
sharedPreferenceManager.getAppName( sharedPreferenceManager.getAppName(
it.first.applicationInfo.packageName, it.first.componentName.flattenToString(),
it.third, it.third,
context.packageManager.getApplicationLabel(it.first.applicationInfo) it.first.label
).toString().lowercase() ).toString().lowercase()
} }
} }
@ -80,12 +81,7 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
} }
} }
fun launchApp(packageName: String, userHandle: UserHandle) { fun launchApp(componentName: ComponentName, userHandle: UserHandle) {
val mainActivity = launcherApps.getActivityList(packageName, userHandle).firstOrNull() launcherApps.startMainActivity(componentName, userHandle, null, null)
if (mainActivity != null) {
launcherApps.startMainActivity(mainActivity.componentName, userHandle, null, null)
} else {
Toast.makeText(context, context.getString(R.string.launch_error), Toast.LENGTH_SHORT).show()
}
} }
} }