mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-21 22:59:10 +00:00
make clipboard toolbar keys customizable
This commit is contained in:
parent
edd4ae2c68
commit
2fc5286b97
9 changed files with 41 additions and 11 deletions
|
@ -169,7 +169,6 @@ __Planned features and improvements:__
|
||||||
* Clearer / more intuitive arrangement of settings
|
* Clearer / more intuitive arrangement of settings
|
||||||
* Maybe hide some less used settings by default (similar to color customization)
|
* Maybe hide some less used settings by default (similar to color customization)
|
||||||
* Customizable currency keys
|
* Customizable currency keys
|
||||||
* Customizable clipboard toolbar keys (#513, #403)
|
|
||||||
* Ability to export/import (share) custom colors
|
* Ability to export/import (share) custom colors
|
||||||
* Make use of the `.com` key in URL fields (currently only available for tablets)
|
* Make use of the `.com` key in URL fields (currently only available for tablets)
|
||||||
* With language-dependent TLDs
|
* With language-dependent TLDs
|
||||||
|
|
|
@ -24,11 +24,13 @@ import helium314.keyboard.latin.R
|
||||||
import helium314.keyboard.latin.common.ColorType
|
import helium314.keyboard.latin.common.ColorType
|
||||||
import helium314.keyboard.latin.common.Constants
|
import helium314.keyboard.latin.common.Constants
|
||||||
import helium314.keyboard.latin.settings.Settings
|
import helium314.keyboard.latin.settings.Settings
|
||||||
|
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||||
import helium314.keyboard.latin.utils.ResourceUtils
|
import helium314.keyboard.latin.utils.ResourceUtils
|
||||||
import helium314.keyboard.latin.utils.ToolbarKey
|
import helium314.keyboard.latin.utils.ToolbarKey
|
||||||
import helium314.keyboard.latin.utils.createToolbarKey
|
import helium314.keyboard.latin.utils.createToolbarKey
|
||||||
import helium314.keyboard.latin.utils.getCodeForToolbarKey
|
import helium314.keyboard.latin.utils.getCodeForToolbarKey
|
||||||
import helium314.keyboard.latin.utils.getCodeForToolbarKeyLongClick
|
import helium314.keyboard.latin.utils.getCodeForToolbarKeyLongClick
|
||||||
|
import helium314.keyboard.latin.utils.getEnabledClipboardToolbarKeys
|
||||||
|
|
||||||
class ClipboardHistoryView @JvmOverloads constructor(
|
class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
@ -70,7 +72,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
// even when state is activated, the not activated color is set
|
// even when state is activated, the not activated color is set
|
||||||
// in suggestionStripView the same thing works correctly, wtf?
|
// in suggestionStripView the same thing works correctly, wtf?
|
||||||
// need to properly fix it (and maybe undo the inverted isActivated) when adding a toggle key
|
// need to properly fix it (and maybe undo the inverted isActivated) when adding a toggle key
|
||||||
listOf(ToolbarKey.ONE_HANDED, ToolbarKey.UNDO, ToolbarKey.UP, ToolbarKey.DOWN, ToolbarKey.LEFT, ToolbarKey.RIGHT, ToolbarKey.CLEAR_CLIPBOARD, ToolbarKey.COPY, ToolbarKey.CUT, ToolbarKey.SELECT_WORD, ToolbarKey.CLOSE_HISTORY)
|
getEnabledClipboardToolbarKeys(DeviceProtectedUtils.getSharedPreferences(context))
|
||||||
.forEach { toolbarKeys.add(createToolbarKey(context, keyboardAttr, it)) }
|
.forEach { toolbarKeys.add(createToolbarKey(context, keyboardAttr, it)) }
|
||||||
keyboardAttr.recycle()
|
keyboardAttr.recycle()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX
|
||||||
import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX
|
import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX
|
||||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||||
import helium314.keyboard.latin.utils.DictionaryInfoUtils
|
import helium314.keyboard.latin.utils.DictionaryInfoUtils
|
||||||
import helium314.keyboard.latin.utils.upgradeToolbarPref
|
import helium314.keyboard.latin.utils.upgradeToolbarPrefs
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class App : Application() {
|
class App : Application() {
|
||||||
|
@ -37,7 +37,7 @@ fun checkVersionUpgrade(context: Context) {
|
||||||
val oldVersion = prefs.getInt(Settings.PREF_VERSION_CODE, 0)
|
val oldVersion = prefs.getInt(Settings.PREF_VERSION_CODE, 0)
|
||||||
if (oldVersion == BuildConfig.VERSION_CODE)
|
if (oldVersion == BuildConfig.VERSION_CODE)
|
||||||
return
|
return
|
||||||
upgradeToolbarPref(prefs)
|
upgradeToolbarPrefs(prefs)
|
||||||
// clear extracted dictionaries, in case updated version contains newer ones
|
// clear extracted dictionaries, in case updated version contains newer ones
|
||||||
DictionaryInfoUtils.getCachedDirectoryList(context)?.forEach {
|
DictionaryInfoUtils.getCachedDirectoryList(context)?.forEach {
|
||||||
if (!it.isDirectory) return@forEach
|
if (!it.isDirectory) return@forEach
|
||||||
|
|
|
@ -74,6 +74,11 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
|
||||||
R.string.toolbar_keys, (name) -> ToolbarUtilsKt.getToolbarIconByName(name, requireContext()));
|
R.string.toolbar_keys, (name) -> ToolbarUtilsKt.getToolbarIconByName(name, requireContext()));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
findPreference(Settings.PREF_CLIPBOARD_TOOLBAR_KEYS).setOnPreferenceClickListener((pref) -> {
|
||||||
|
DialogUtilsKt.reorderDialog(requireContext(), Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, ToolbarUtilsKt.getDefaultClipboardToolbarPref(),
|
||||||
|
R.string.toolbar_keys, (name) -> ToolbarUtilsKt.getToolbarIconByName(name, requireContext()));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -87,7 +92,7 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
|
||||||
if (key == null) return;
|
if (key == null) return;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case Settings.PREF_POPUP_KEYS_ORDER, Settings.PREF_SHOW_POPUP_HINTS, Settings.PREF_SHOW_NUMBER_ROW,
|
case Settings.PREF_POPUP_KEYS_ORDER, Settings.PREF_SHOW_POPUP_HINTS, Settings.PREF_SHOW_NUMBER_ROW,
|
||||||
Settings.PREF_POPUP_KEYS_LABELS_ORDER, Settings.PREF_TOOLBAR_KEYS
|
Settings.PREF_POPUP_KEYS_LABELS_ORDER, Settings.PREF_TOOLBAR_KEYS, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS
|
||||||
-> mReloadKeyboard = true;
|
-> mReloadKeyboard = true;
|
||||||
case Settings.PREF_LOCALIZED_NUMBER_ROW -> KeyboardLayoutSet.onSystemLocaleChanged();
|
case Settings.PREF_LOCALIZED_NUMBER_ROW -> KeyboardLayoutSet.onSystemLocaleChanged();
|
||||||
case Settings.PREF_SHOW_HINTS
|
case Settings.PREF_SHOW_HINTS
|
||||||
|
|
|
@ -149,6 +149,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
public static final String PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = "dont_show_missing_dict_dialog";
|
public static final String PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = "dont_show_missing_dict_dialog";
|
||||||
public static final String PREF_PINNED_TOOLBAR_KEYS = "pinned_toolbar_keys";
|
public static final String PREF_PINNED_TOOLBAR_KEYS = "pinned_toolbar_keys";
|
||||||
public static final String PREF_TOOLBAR_KEYS = "toolbar_keys";
|
public static final String PREF_TOOLBAR_KEYS = "toolbar_keys";
|
||||||
|
public static final String PREF_CLIPBOARD_TOOLBAR_KEYS = "clipboard_toolbar_keys";
|
||||||
|
|
||||||
// Emoji
|
// Emoji
|
||||||
public static final String PREF_EMOJI_RECENT_KEYS = "emoji_recent_keys";
|
public static final String PREF_EMOJI_RECENT_KEYS = "emoji_recent_keys";
|
||||||
|
|
|
@ -120,15 +120,26 @@ val defaultToolbarPref = entries.filterNot { it == CLEAR_CLIPBOARD || it == CLOS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val defaultClipboardToolbarPref by lazy {
|
||||||
|
val default = listOf(ONE_HANDED, UNDO, UP, DOWN, LEFT, RIGHT, CLEAR_CLIPBOARD, COPY, CUT, SELECT_WORD, CLOSE_HISTORY)
|
||||||
|
val others = entries.filterNot { it in default }
|
||||||
|
default.joinToString(";") { "${it.name},true" } + ";" + others.joinToString(";") { "${it.name},false" }
|
||||||
|
}
|
||||||
|
|
||||||
/** add missing keys, typically because a new key has been added */
|
/** add missing keys, typically because a new key has been added */
|
||||||
fun upgradeToolbarPref(prefs: SharedPreferences) {
|
fun upgradeToolbarPrefs(prefs: SharedPreferences) {
|
||||||
val list = prefs.getString(Settings.PREF_TOOLBAR_KEYS, defaultToolbarPref)!!.split(";").toMutableList()
|
upgradeToolbarPref(prefs, Settings.PREF_TOOLBAR_KEYS, defaultToolbarPref, "true")
|
||||||
|
upgradeToolbarPref(prefs, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, defaultClipboardToolbarPref, "false")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun upgradeToolbarPref(prefs: SharedPreferences, pref: String, default: String, defaultEnabled: String) {
|
||||||
|
val list = prefs.getString(pref, default)!!.split(";").toMutableList()
|
||||||
val splitDefault = defaultToolbarPref.split(";")
|
val splitDefault = defaultToolbarPref.split(";")
|
||||||
if (list.size == splitDefault.size) return
|
if (list.size == splitDefault.size) return
|
||||||
splitDefault.forEach { entry ->
|
splitDefault.forEach { entry ->
|
||||||
val keyWithComma = entry.substringBefore(",") + ","
|
val keyWithComma = entry.substringBefore(",") + ","
|
||||||
if (list.none { it.startsWith(keyWithComma) })
|
if (list.none { it.startsWith(keyWithComma) })
|
||||||
list.add("${keyWithComma}true")
|
list.add("${keyWithComma}$defaultEnabled")
|
||||||
}
|
}
|
||||||
// likely not needed, but better prepare for possibility of key removal
|
// likely not needed, but better prepare for possibility of key removal
|
||||||
list.removeAll {
|
list.removeAll {
|
||||||
|
@ -142,8 +153,12 @@ fun upgradeToolbarPref(prefs: SharedPreferences) {
|
||||||
prefs.edit { putString(Settings.PREF_TOOLBAR_KEYS, list.joinToString(";")) }
|
prefs.edit { putString(Settings.PREF_TOOLBAR_KEYS, list.joinToString(";")) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEnabledToolbarKeys(prefs: SharedPreferences): List<ToolbarKey> {
|
fun getEnabledToolbarKeys(prefs: SharedPreferences) = getEnabledToolbarKeys(prefs, Settings.PREF_TOOLBAR_KEYS, defaultToolbarPref)
|
||||||
val string = prefs.getString(Settings.PREF_TOOLBAR_KEYS, defaultToolbarPref)!!
|
|
||||||
|
fun getEnabledClipboardToolbarKeys(prefs: SharedPreferences) = getEnabledToolbarKeys(prefs, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, defaultClipboardToolbarPref)
|
||||||
|
|
||||||
|
private fun getEnabledToolbarKeys(prefs: SharedPreferences, pref: String, default: String): List<ToolbarKey> {
|
||||||
|
val string = prefs.getString(pref, default)!!
|
||||||
return string.split(";").mapNotNull {
|
return string.split(";").mapNotNull {
|
||||||
val split = it.split(",")
|
val split = it.split(",")
|
||||||
if (split.last() == "true") {
|
if (split.last() == "true") {
|
||||||
|
|
|
@ -28,12 +28,13 @@
|
||||||
android:id="@+id/clipboard_strip_scroll_view"
|
android:id="@+id/clipboard_strip_scroll_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
style="?attr/suggestionStripViewStyle"
|
||||||
android:scrollbarThumbHorizontal="@color/toolbar_scrollbar" >
|
android:scrollbarThumbHorizontal="@color/toolbar_scrollbar" >
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/clipboard_strip"
|
android:id="@+id/clipboard_strip"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
style="?attr/suggestionStripViewStyle" >
|
android:layout_gravity="end" >
|
||||||
<!-- empty view to move buttons to the right -->
|
<!-- empty view to move buttons to the right -->
|
||||||
<View
|
<View
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|
|
@ -249,6 +249,9 @@
|
||||||
<string name="down" tools:keep="@string/down">Down</string>
|
<string name="down" tools:keep="@string/down">Down</string>
|
||||||
<string name="undo" tools:keep="@string/undo">Undo</string>
|
<string name="undo" tools:keep="@string/undo">Undo</string>
|
||||||
<string name="redo" tools:keep="@string/redo">Redo</string>
|
<string name="redo" tools:keep="@string/redo">Redo</string>
|
||||||
|
<string name="close_history" tools:keep="@string/close_history">Close clipboard history</string>
|
||||||
|
<!-- Title of the settings to set clipboard toolbar keys -->
|
||||||
|
<string name="clipboard_toolbar_keys">Select clipboard toolbar keys</string>
|
||||||
<!-- Title of the settings to show "..." as hints for more functionality on long-press -->
|
<!-- Title of the settings to show "..." as hints for more functionality on long-press -->
|
||||||
<string name="show_popup_hints">Show functional hints</string>
|
<string name="show_popup_hints">Show functional hints</string>
|
||||||
<!-- Description of the show_popup_hints setting -->
|
<!-- Description of the show_popup_hints setting -->
|
||||||
|
|
|
@ -99,6 +99,10 @@
|
||||||
android:key="toolbar_keys"
|
android:key="toolbar_keys"
|
||||||
android:title="@string/toolbar_keys" />
|
android:title="@string/toolbar_keys" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="clipboard_toolbar_keys"
|
||||||
|
android:title="@string/clipboard_toolbar_keys" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="var_toolbar_direction"
|
android:key="var_toolbar_direction"
|
||||||
android:title="@string/var_toolbar_direction"
|
android:title="@string/var_toolbar_direction"
|
||||||
|
|
Loading…
Add table
Reference in a new issue