Added a function to lock shortcuts.

This commit is contained in:
ottoptj 2024-11-20 01:30:20 +02:00
commit 5d913b120c
6 changed files with 28 additions and 14 deletions

View file

@ -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<String>?) : 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()
}
}
}
}

View file

@ -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)
}

View file

@ -103,6 +103,7 @@
<string name="vertical_alignment">Vertikale Ausrichtung</string>
<string name="shortcut_size">Verknüpfungsgröße</string>
<string name="shortcut_spacing">Verknüpfungsabstand</string>
<string name="lock_shortcuts">Lock Shortcuts</string>
<string name="gestures">Gesten</string>
<string name="swipe_left">Linkswisch</string>

View file

@ -101,6 +101,7 @@
<string name="vertical_alignment">Pikakuvakkeiden Pystysijainti</string>
<string name="shortcut_size">Pikakuvakkeiden koko</string>
<string name="shortcut_spacing">Pikakuvakkeiden väli</string>
<string name="lock_shortcuts">Lock Shortcuts</string>
<string name="gestures">Eleet</string>
<string name="swipe_left">Vasen Pyyhkäisy</string>

View file

@ -103,6 +103,7 @@
<string name="vertical_alignment">Vertical Alignment</string>
<string name="shortcut_size">Shortcut Size</string>
<string name="shortcut_spacing">Shortcut Spacing</string>
<string name="lock_shortcuts">Lock Shortcuts</string>
<string name="gestures">Gestures</string>
<string name="swipe_left">Swipe Left</string>

View file

@ -192,6 +192,12 @@
app:key="shortcutWeight"
app:title="@string/shortcut_spacing"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="false"
android:title="@string/lock_shortcuts"
app:key="lockShortcuts" />
</PreferenceCategory>
<PreferenceCategory
android:layout_width="wrap_content"