From 5d913b120ccc6fcb1195276b0808e1ae15d00190 Mon Sep 17 00:00:00 2001 From: ottoptj Date: Wed, 20 Nov 2024 01:30:20 +0200 Subject: [PATCH] Added a function to lock shortcuts. --- .../java/eu/ottop/yamlauncher/MainActivity.kt | 29 ++++++++++--------- .../settings/SharedPreferenceManager.kt | 4 +++ app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-fi/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/home_preferences.xml | 6 ++++ 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt index 5a3bb96..2b70037 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt @@ -239,19 +239,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } ViewCompat.addAccessibilityAction(textView, getString(R.string.accessibility_set_shortcut)) { _, _ -> - uiUtils.setMenuTitleAlignment(menuTitle) - uiUtils.setMenuTitleSize(menuTitle) - menuTitle.hint = textView.text - menuTitle.setText(textView.text) - menuTitle.visibility = View.VISIBLE - if (savedView != null) { - setRenameShortcutListener(index, textView) - } - - appAdapter?.shortcutTextView = textView - contactAdapter?.shortcutTextView = textView - toAppMenu() - true + launchShortcutSelection(index, textView, savedView) } ViewCompat.addAccessibilityAction(textView, getString(R.string.settings_title)) { _, _ -> @@ -265,6 +253,13 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh } textView.setOnLongClickListener { + launchShortcutSelection(index, textView, savedView) + } + } + + private fun launchShortcutSelection(index: Int, textView: TextView, savedView: List?) : Boolean { + + if (!sharedPreferenceManager.areShortcutsLocked()) { uiUtils.setMenuTitleAlignment(menuTitle) uiUtils.setMenuTitleSize(menuTitle) menuTitle.hint = textView.text @@ -279,8 +274,10 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh contactAdapter?.shortcutTextView = textView toAppMenu() - return@setOnLongClickListener true + return true } + + return false } private fun setRenameShortcutListener(index: Int, textView: TextView) { @@ -672,6 +669,10 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh setPreferences() setShortcuts() } + + "lockShortcuts" -> { + setShortcuts() + } } } } diff --git a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt index fabd8ec..2bfd9ad 100644 --- a/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt +++ b/app/src/main/java/eu/ottop/yamlauncher/settings/SharedPreferenceManager.kt @@ -119,6 +119,10 @@ class SharedPreferenceManager (private val context: Context) { return preferences.getString("shortcutWeight", "0.09")?.toFloat() } + fun areShortcutsLocked(): Boolean { + return preferences.getBoolean("lockShortcuts", false) + } + fun isBatteryEnabled(): Boolean { return preferences.getBoolean("batteryEnabled", false) } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index f5dfeee..cb28c5a 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -103,6 +103,7 @@ Vertikale Ausrichtung Verknüpfungsgröße Verknüpfungsabstand + Lock Shortcuts Gesten Linkswisch diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 72d0327..7ab7c3c 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -101,6 +101,7 @@ Pikakuvakkeiden Pystysijainti Pikakuvakkeiden koko Pikakuvakkeiden väli + Lock Shortcuts Eleet Vasen Pyyhkäisy diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa4ae56..89afd36 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -103,6 +103,7 @@ Vertical Alignment Shortcut Size Shortcut Spacing + Lock Shortcuts Gestures Swipe Left diff --git a/app/src/main/res/xml/home_preferences.xml b/app/src/main/res/xml/home_preferences.xml index 79b8041..6bc770d 100644 --- a/app/src/main/res/xml/home_preferences.xml +++ b/app/src/main/res/xml/home_preferences.xml @@ -192,6 +192,12 @@ app:key="shortcutWeight" app:title="@string/shortcut_spacing" app:useSimpleSummaryProvider="true" /> +