Automatically add morekeys_misc and actions based on morekeys and qwertysyms

This commit is contained in:
Aleksandras Kostarevas 2024-07-24 21:33:30 +03:00
parent db82511d92
commit 5c025bec86

View File

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