From 914c7a0ed48d13dc580bf95dbc032dcbcf42cc27 Mon Sep 17 00:00:00 2001 From: ottoptj Date: Tue, 6 Aug 2024 18:02:22 +0300 Subject: [PATCH] Fixed an issue with shortcuts and gestures with apps that have a dash on the name. --- .../ottop/yamlauncher/GestureAppsFragment.kt | 2 +- .../java/eu/ottop/yamlauncher/MainActivity.kt | 105 ++++++++++++++---- .../eu/ottop/yamlauncher/SettingsFragment.kt | 18 +-- .../yamlauncher/SharedPreferenceManager.kt | 14 +-- app/src/main/res/layout/activity_main.xml | 45 +------- app/src/main/res/values/arrays.xml | 12 ++ app/src/main/res/xml/root_preferences.xml | 17 ++- 7 files changed, 129 insertions(+), 84 deletions(-) diff --git a/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt index 42e1d78..e2d7da0 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/GestureAppsFragment.kt @@ -143,7 +143,7 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener { private fun performConfirmedAction(appInfo: LauncherActivityInfo, appName: String, profile: Int) { val result = Bundle().apply { - putString("gesture_app", "$appName-${appInfo.applicationInfo.packageName}-$profile") + putString("gesture_app", "$appName§splitter§${appInfo.applicationInfo.packageName}§splitter§$profile") } setFragmentResult("request_key", result) requireActivity().supportFragmentManager.popBackStack() diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 09094d3..0e8ab85 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -294,6 +294,10 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } } } + + "shortcutNo" -> { + handleListItems() + } } } @@ -432,14 +436,14 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } private fun getSwipeInfo(direction: String): Pair { - val app = preferences.getString("${direction}SwipeApp", "")?.split("-") + val app = preferences.getString("${direction}SwipeApp", "")?.split("§splitter§") if (app != null) { if (app.size >= 3) return Pair( launcherApps.getActivityList( - app?.get(1), launcherApps.profiles[app.get(2)!! + app[1], launcherApps.profiles[app[2] .toInt()] ).firstOrNull(), app[2].toInt() ) @@ -461,16 +465,30 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } private fun handleListItems() { - for (i in arrayOf(R.id.app1, R.id.app2, R.id.app3, R.id.app4, R.id.app5, R.id.app6, R.id.app7, R.id.app8)) { + val shortcuts = arrayOf(R.id.app1, R.id.app2, R.id.app3, R.id.app4, R.id.app5, R.id.app6, R.id.app7, R.id.app8) - val textView = findViewById(i) + for (i in shortcuts.indices) { - unselectedSetup(textView) + val textView = findViewById(shortcuts[i]) - val savedView = sharedPreferenceManager.getShortcut(this, textView) + val shortcutNo = preferences.getString("shortcutNo", "4")?.toInt() - if (savedView?.get(1) != "e") { - selectedSetup(textView, savedView) + if (i >= shortcutNo!!) { + textView.visibility = View.GONE + } + + else { + textView.visibility = View.VISIBLE + + unselectedSetup(textView) + + val savedView = sharedPreferenceManager.getShortcut(this, textView) + + if (savedView?.get(1) != "e") { + selectedSetup(textView, savedView) + } + + setShortcutAlignment(preferences.getString("shortcutAlignment", "left"), binding.homeView) } } @@ -702,6 +720,35 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh shortcutView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, R.drawable.ic_empty, null),null,null,null) } + when (preferences.getString("shortcutAlignment", "left")) { + "left" -> { + shortcutView.setCompoundDrawablesWithIntrinsicBounds( + textView.compoundDrawables.filterNotNull().first(), null, null, null + ) + shortcutView.gravity = Gravity.CENTER_VERTICAL or Gravity.START + } + + "center" -> { + shortcutView.setCompoundDrawablesWithIntrinsicBounds( + shortcutView.compoundDrawables.filterNotNull().first(), + null, + shortcutView.compoundDrawables.filterNotNull().first(), + null + ) + shortcutView.gravity = Gravity.CENTER + } + + "right" -> { + shortcutView.setCompoundDrawablesWithIntrinsicBounds( + null, + null, + shortcutView.compoundDrawables.filterNotNull().first(), + null + ) + shortcutView.gravity = Gravity.CENTER_VERTICAL or Gravity.END + } + } + shortcutView.text = textView.text.toString() shortcutView.setOnClickListener { val mainActivity = launcherApps.getActivityList(appInfo.applicationInfo.packageName, userHandle).firstOrNull() @@ -808,22 +855,36 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh if (it is TextView) { + try { + when (alignment) { + "left" -> { + it.setCompoundDrawablesWithIntrinsicBounds( + it.compoundDrawables.filterNotNull().first(), null, null, null + ) + it.gravity = Gravity.CENTER_VERTICAL or Gravity.START + } - when (alignment) { - "left" -> { - it.setCompoundDrawablesWithIntrinsicBounds(it.compoundDrawables.filterNotNull().first(),null, null, null) - it.gravity = Gravity.CENTER_VERTICAL or Gravity.START - } - "center" -> { - it.setCompoundDrawablesWithIntrinsicBounds(it.compoundDrawables.filterNotNull().first(),null,it.compoundDrawables.filterNotNull().first(), null) - it.gravity = Gravity.CENTER - } - "right" -> { - it.setCompoundDrawablesWithIntrinsicBounds(null,null, it.compoundDrawables.filterNotNull().first(), null) - it.gravity = Gravity.CENTER_VERTICAL or Gravity.END - } - } + "center" -> { + it.setCompoundDrawablesWithIntrinsicBounds( + it.compoundDrawables.filterNotNull().first(), + null, + it.compoundDrawables.filterNotNull().first(), + null + ) + it.gravity = Gravity.CENTER + } + "right" -> { + it.setCompoundDrawablesWithIntrinsicBounds( + null, + null, + it.compoundDrawables.filterNotNull().first(), + null + ) + it.gravity = Gravity.CENTER_VERTICAL or Gravity.END + } + } + } catch(_: Exception) {} } } } diff --git a/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt b/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt index 918fdcb..1abbc22 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SettingsFragment.kt @@ -70,15 +70,16 @@ class SettingsFragment : PreferenceFragmentCompat() { .replace(R.id.settings_layout, GestureAppsFragment()) .addToBackStack(null) .commit() - setFragmentResultListener("request_key") { requestKey, bundle -> + setFragmentResultListener("request_key") { _, bundle -> clearFragmentResultListener("request_key") val result = bundle.getString("gesture_app") - val appDetails = result?.split("-") + val appDetails = result?.split("§splitter§") if (leftSwipePref != null && result != null) { setPreference("leftSwipeApp", result) } - sharedPreferenceManager.setGestures(requireContext(), "left", - appDetails?.get(0), appDetails?.get(1), appDetails?.get(2) + sharedPreferenceManager.setGestures( + requireContext(), "left", + appDetails?.get(0) ) val appName = appDetails?.get(0) leftSwipePref?.summary = appName @@ -92,15 +93,16 @@ class SettingsFragment : PreferenceFragmentCompat() { .replace(R.id.settings_layout, GestureAppsFragment()) .addToBackStack(null) .commit() - setFragmentResultListener("request_key") { requestKey, bundle -> + setFragmentResultListener("request_key") { _, bundle -> clearFragmentResultListener("request_key") val result = bundle.getString("gesture_app") - val appDetails = result?.split("-") + val appDetails = result?.split("§splitter§") if (rightSwipePref != null && result != null) { setPreference("rightSwipeApp", result) } - sharedPreferenceManager.setGestures(requireContext(), "right", - appDetails?.get(0), appDetails?.get(1), appDetails?.get(2) + sharedPreferenceManager.setGestures( + requireContext(), "right", + appDetails?.get(0) ) val appName = appDetails?.get(0) rightSwipePref?.summary = appName diff --git a/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt b/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt index 12c9e69..ac3e1b4 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/SharedPreferenceManager.kt @@ -9,15 +9,15 @@ class SharedPreferenceManager { fun setShortcut(cont: Context, textView: TextView, packageName: String, profile: Int) { val editor = cont.getSharedPreferences("shortcuts", AppCompatActivity.MODE_PRIVATE).edit() val key = textView.id.toString() - editor.putString(key, "$packageName-$profile-${textView.text}") + editor.putString(key, "$packageName§splitter§$profile§splitter§${textView.text}") editor.apply() } fun getShortcut(cont: Context, textView: TextView): List? { val sharedPref = cont.getSharedPreferences("shortcuts", AppCompatActivity.MODE_PRIVATE) val key = textView.id.toString() - val value = sharedPref.getString(key, "e-e") - return value?.split("-") + val value = sharedPref.getString(key, "e§splitter§e") + return value?.split("§splitter§") } fun setAppHidden(cont: Context, packageName: String, profile: Int, hidden: Boolean) { @@ -81,20 +81,14 @@ class SharedPreferenceManager { return sharedPreferences.getString(key, "") } - fun setGestures(cont: Context, direction: String, appName: String?, packageName: String?, profile: String?) { + fun setGestures(cont: Context, direction: String, appName: String?) { val editor = cont.getSharedPreferences("gestures", AppCompatActivity.MODE_PRIVATE).edit() val nameKey = "$direction-name" - editor.putString(direction, "$packageName-$profile") editor.putString(nameKey, appName) editor.apply() } - fun getGestureApp(cont: Context, direction: String) : String? { - val sharedPreferences = cont.getSharedPreferences("gestures", AppCompatActivity.MODE_PRIVATE) - return sharedPreferences.getString(direction, "") - } - fun getGestureName(cont: Context, direction: String) : String? { val sharedPreferences = cont.getSharedPreferences("gestures", AppCompatActivity.MODE_PRIVATE) val key = "$direction-name" diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 0a9ed5e..8721ed5 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -144,12 +144,7 @@ android:text="@string/shortcut_default" android:textAppearance="@android:style/TextAppearance.DeviceDefault" android:textColor="#F3F3F3" - android:visibility="visible" /> - - + android:visibility="gone" /> - - + android:visibility="gone" /> - - + android:visibility="gone" /> - - - - - - - - #FFF3F3F3 #FF0C0C0C + + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + \ No newline at end of file diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index d78cb35..be30ced 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -1,6 +1,21 @@ + + +