From 3b3f9d716a532120faf5c474ebed7609962fdd10 Mon Sep 17 00:00:00 2001 From: ottoptj Date: Sat, 10 Aug 2024 21:27:01 +0300 Subject: [PATCH] Fixed bugs with shortcut selection: - Incorrect drawable alignment - Action menu working in shortcut selection view --- .../java/eu/ottop/yamlauncher/Animations.kt | 12 +-- .../eu/ottop/yamlauncher/AppMenuAdapter.kt | 34 ++++---- .../java/eu/ottop/yamlauncher/MainActivity.kt | 20 +++-- .../main/java/eu/ottop/yamlauncher/UIUtils.kt | 79 ++++++++++++------- 4 files changed, 85 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/eu/ottop/yamlauncher/Animations.kt b/app/src/main/java/eu/ottop/yamlauncher/Animations.kt index 1e4805e..431d981 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/Animations.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/Animations.kt @@ -22,14 +22,14 @@ class Animations (context: Context) { fun fadeViewOut(view: View, duration: Long = 100) { view.fadeOut(duration) } - fun showHome(binding: ActivityMainBinding) { - binding.appView.slideOutToBottom() - binding.homeView.fadeIn() + fun showHome(homeView: View, appView: View) { + appView.slideOutToBottom() + homeView.fadeIn() } - fun showApps(binding: ActivityMainBinding) { - binding.appView.slideInFromBottom() - binding.homeView.fadeOut() + fun showApps(homeView: View, appView: View) { + appView.slideInFromBottom() + homeView.fadeOut() } fun backgroundIn(activity: Activity, duration: Long = 100) { diff --git a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt index bd17066..792205a 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/AppMenuAdapter.kt @@ -52,7 +52,8 @@ class AppMenuAdapter( textView: TextView, actionMenuLayout: LinearLayout, editView: LinearLayout, - position: Int + position: Int, + shortcutTextView: TextView? ) } @@ -78,25 +79,24 @@ class AppMenuAdapter( } } - if (shortcutTextView == null) { - textView.setOnLongClickListener { - val position = bindingAdapterPosition - - val app = apps[position].first - itemLongClickListener.onItemLongClick( - app, - apps[position].second.first, - apps[position].second.second, - textView, - actionMenuLayout, - editView, - position - ) - return@setOnLongClickListener true - } + textView.setOnLongClickListener { + val position = bindingAdapterPosition + val app = apps[position].first + itemLongClickListener.onItemLongClick( + app, + apps[position].second.first, + apps[position].second.second, + textView, + actionMenuLayout, + editView, + position, + shortcutTextView + ) + return@setOnLongClickListener true } + } } diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 7b603e9..c6a2edb 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -155,7 +155,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh uiUtils.setClockSize(clock) uiUtils.setDateSize(dateText) - uiUtils.setShortcutSize(binding.homeView) + uiUtils.setShortcutsSize(binding.homeView) uiUtils.setSearchSize(searchView) uiUtils.setStatusBar(window) @@ -188,7 +188,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh setShortcutSetup(textView, savedView) } - uiUtils.setShortcutAlignment(binding.homeView) + uiUtils.setShortcutsAlignment(binding.homeView) } } @@ -223,7 +223,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } private fun toAppMenu() { - animations.showApps(binding) + animations.showApps(binding.homeView, binding.appView) animations.backgroundIn(this@MainActivity) if (sharedPreferenceManager.isAutoKeyboardEnabled()) { val imm = @@ -309,7 +309,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } "shortcutAlignment" -> { - uiUtils.setShortcutAlignment(binding.homeView) + uiUtils.setShortcutsAlignment(binding.homeView) } "searchAlignment" -> { @@ -325,7 +325,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } "shortcutSize" -> { - uiUtils.setShortcutSize(binding.homeView) + uiUtils.setShortcutsSize(binding.homeView) } "searchSize" -> { @@ -368,7 +368,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh fun backToHome() { closeKeyboard() - animations.showHome(binding) + animations.showHome(binding.homeView, binding.appView) animations.backgroundOut(this@MainActivity) val handler = Handler(Looper.getMainLooper()) handler.postDelayed({ @@ -623,6 +623,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh appInfo.applicationInfo.packageName, userProfile ) + uiUtils.setShortcutDrawables(shortcutView, sharedPreferenceManager.getShortcutAlignment()) backToHome() } @@ -634,8 +635,13 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh textView: TextView, actionMenuLayout: LinearLayout, editView: LinearLayout, - position: Int + position: Int, + shortcutTextView: TextView? ) { + if (shortcutTextView != null) { + onShortcut(appInfo, userHandle, textView, userProfile, shortcutTextView) + return + } textView.visibility = View.INVISIBLE animations.fadeViewIn(actionMenuLayout) val mainActivity = diff --git a/app/src/main/java/eu/ottop/yamlauncher/UIUtils.kt b/app/src/main/java/eu/ottop/yamlauncher/UIUtils.kt index ac8c7a1..b9b21f1 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/UIUtils.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/UIUtils.kt @@ -94,45 +94,64 @@ class UIUtils(private val context: Context) { setTextAlignment(dateText, alignment) } - fun setShortcutAlignment(shortcuts: LinearLayout) { + fun setShortcutsAlignment(shortcuts: LinearLayout) { + val alignment = sharedPreferenceManager.getShortcutAlignment() shortcuts.children.forEach { if (it is TextView) { try { - when (sharedPreferenceManager.getShortcutAlignment()) { - "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 - } - } + setShortcutAlignment(it, alignment) + setShortcutDrawables(it, alignment) } catch(_: Exception) {} } } } + fun setShortcutAlignment(shortcut: TextView, alignment: String?) { + when (alignment) { + "left" -> { + shortcut.gravity = Gravity.CENTER_VERTICAL or Gravity.START + } + + "center" -> { + shortcut.gravity = Gravity.CENTER + } + + "right" -> { + shortcut.gravity = Gravity.CENTER_VERTICAL or Gravity.END + } + } + } + + fun setShortcutDrawables(shortcut: TextView, alignment: String?) { + when (alignment) { + "left" -> { + shortcut.setCompoundDrawablesWithIntrinsicBounds( + shortcut.compoundDrawables.filterNotNull().first(), null, null, null + ) + } + + "center" -> { + shortcut.setCompoundDrawablesWithIntrinsicBounds( + shortcut.compoundDrawables.filterNotNull().first(), + null, + shortcut.compoundDrawables.filterNotNull().first(), + null + ) + } + + "right" -> { + shortcut.setCompoundDrawablesWithIntrinsicBounds( + null, + null, + shortcut.compoundDrawables.filterNotNull().first(), + null + ) + } + } + } + fun setAppAlignment( textView: TextView, editText: TextInputEditText? = null, @@ -207,7 +226,7 @@ class UIUtils(private val context: Context) { setTextSize(dateText, sharedPreferenceManager.getDateSize(), 17F, 20F, 23F) } - fun setShortcutSize(shortcuts: LinearLayout) { + fun setShortcutsSize(shortcuts: LinearLayout) { val viewTreeObserver = shortcuts.viewTreeObserver val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener {