Skip to content
Snippets Groups Projects
Commit 5c025bec authored by Aleksandras Kostarevas's avatar Aleksandras Kostarevas
Browse files

Automatically add morekeys_misc and actions based on morekeys and qwertysyms

parent db82511d
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,36 @@ private fun getKind(moreKey: String): LongPressKey? {
}
}
val alphabet = "abcdefghijklmnopqrstuvwxyz".toSet()
private fun getBestMatchForMisc(moreKeys: List<String>): String? {
if(moreKeys.any { getKind(it) == LongPressKey.MiscLetters }) return null
return moreKeys.firstOrNull { getKind(it) == LongPressKey.LanguageKeys }?.let {
val k = it.replace("!text/morekeys_", "")
if(k.length == 1 && alphabet.contains(k[0])) {
"!text/morekeys_misc_$k"
} else {
null
}
}
}
private fun getBestMatchForAction(moreKeys: List<String>): String? {
if(moreKeys.any { getKind(it) == LongPressKey.QuickActions }) return null
return moreKeys.firstOrNull { getKind(it) == LongPressKey.Symbols }?.let {
val k = it.replace("!text/qwertysyms_", "")
if(k.length == 1 && alphabet.contains(k[0])) {
"!text/actions_$k"
} else {
null
}
}
}
val LongPressKeyLayoutSetting = SettingsKey(
stringPreferencesKey("longPressKeyOrdering"),
"${LongPressKey.Numbers.ordinal},${LongPressKey.LanguageKeys.ordinal},${LongPressKey.Symbols.ordinal},${LongPressKey.QuickActions.ordinal},${LongPressKey.MiscLetters.ordinal}"
......@@ -74,7 +104,10 @@ class LongPressKeySettings(val context: Context) {
private val currentSetting = context.getSettingBlocking(LongPressKeyLayoutSetting).toLongPressKeyLayoutItems()
fun reorderMoreKeys(moreKeys: String): String {
val keys = MoreKeySpec.splitKeySpecs(moreKeys)?.toList() ?: listOf(moreKeys)
val keys = (MoreKeySpec.splitKeySpecs(moreKeys)?.toList() ?: listOf(moreKeys)).toMutableList()
getBestMatchForMisc(keys)?.let { keys.add(it) }
getBestMatchForAction(keys)?.let { keys.add(it) }
val finalKeys = mutableListOf<String>()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment