mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-01 12:22:17 +00:00
determine whether to show shift key for scripts without uppercase
This commit is contained in:
parent
48fbe86dcc
commit
27e2a6f584
4 changed files with 32 additions and 7 deletions
|
@ -80,7 +80,7 @@ object SubtypeSettings {
|
|||
val subtype = enabledSubtypes.firstOrNull { it.toSettingsSubtype() == selectedSubtype }
|
||||
if (subtype != null) {
|
||||
return subtype
|
||||
} else {
|
||||
} else if (enabledSubtypes.isNotEmpty()) {
|
||||
Log.w(TAG, "selected subtype $selectedSubtype / ${prefs.getString(Settings.PREF_SELECTED_SUBTYPE, Defaults.PREF_SELECTED_SUBTYPE)} not found")
|
||||
}
|
||||
if (enabledSubtypes.isNotEmpty())
|
||||
|
|
|
@ -125,7 +125,7 @@ data class SettingsSubtype(val locale: Locale, val extraValues: String) {
|
|||
|
||||
fun layoutName(type: LayoutType) = LayoutType.getLayoutMap(getExtraValueOf(KEYBOARD_LAYOUT_SET) ?: "")[type]
|
||||
|
||||
fun with(extraValueKey: String, extraValue: String?): SettingsSubtype {
|
||||
fun with(extraValueKey: String, extraValue: String? = null): SettingsSubtype {
|
||||
val newList = extraValues.split(",")
|
||||
.filterNot { it.isBlank() || it.startsWith("$extraValueKey=") || it == extraValueKey }
|
||||
val newValue = if (extraValue == null) extraValueKey else "$extraValueKey=$extraValue"
|
||||
|
@ -142,7 +142,9 @@ data class SettingsSubtype(val locale: Locale, val extraValues: String) {
|
|||
|
||||
fun getExtraValueOf(extraValueKey: String): String? = extraValues.getExtraValueOf(extraValueKey)
|
||||
|
||||
fun withLayout(type: LayoutType, name: String): SettingsSubtype {
|
||||
fun hasExtraValueOf(extraValueKey: String): Boolean = extraValues.hasExtraValueOf(extraValueKey)
|
||||
|
||||
fun withLayout(type: LayoutType, name: String): SettingsSubtype {
|
||||
val map = LayoutType.getLayoutMap(getExtraValueOf(KEYBOARD_LAYOUT_SET) ?: "")
|
||||
map[type] = name
|
||||
return with(KEYBOARD_LAYOUT_SET, map.toExtraValue())
|
||||
|
@ -166,6 +168,9 @@ data class SettingsSubtype(val locale: Locale, val extraValues: String) {
|
|||
fun String.getExtraValueOf(extraValueKey: String) = split(",")
|
||||
.firstOrNull { it.startsWith("$extraValueKey=") }?.substringAfter("$extraValueKey=")
|
||||
|
||||
fun String.hasExtraValueOf(extraValueKey: String) = split(",")
|
||||
.any { it.startsWith("$extraValueKey=") || it == extraValueKey }
|
||||
|
||||
/** Creates a SettingsSubtype from the given InputMethodSubtype.
|
||||
* Will strip some extra values that are set when creating the InputMethodSubtype from SettingsSubtype */
|
||||
fun InputMethodSubtype.toSettingsSubtype(): SettingsSubtype {
|
||||
|
|
|
@ -21,6 +21,7 @@ import androidx.compose.material3.Switch
|
|||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
|
@ -55,7 +56,7 @@ import helium314.keyboard.latin.utils.LayoutType.Companion.displayNameId
|
|||
import helium314.keyboard.latin.utils.LayoutUtils
|
||||
import helium314.keyboard.latin.utils.LayoutUtilsCustom
|
||||
import helium314.keyboard.latin.utils.Log
|
||||
import helium314.keyboard.latin.utils.ScriptUtils.SCRIPT_LATIN
|
||||
import helium314.keyboard.latin.utils.ScriptUtils
|
||||
import helium314.keyboard.latin.utils.ScriptUtils.script
|
||||
import helium314.keyboard.latin.utils.SettingsSubtype
|
||||
import helium314.keyboard.latin.utils.SettingsSubtype.Companion.toSettingsSubtype
|
||||
|
@ -90,6 +91,25 @@ fun SubtypeDialog(
|
|||
var currentSubtypeString by rememberSaveable { mutableStateOf(initialSubtype.toPref()) }
|
||||
val currentSubtype = currentSubtypeString.toSettingsSubtype()
|
||||
fun setCurrentSubtype(subtype: SettingsSubtype) { currentSubtypeString = subtype.toPref() }
|
||||
LaunchedEffect(currentSubtypeString) {
|
||||
if (ScriptUtils.scriptSupportsUppercase(currentSubtype.locale)) return@LaunchedEffect
|
||||
// update the noShiftKey extra value
|
||||
val mainLayout = currentSubtype.mainLayoutName()
|
||||
val noShiftKey = if (mainLayout != null && LayoutUtilsCustom.isCustomLayout(mainLayout)) {
|
||||
// determine from layout
|
||||
val content = LayoutUtilsCustom.getLayoutFile(mainLayout, LayoutType.MAIN, ctx).readText()
|
||||
!content.contains("\"shift_state_selector\"")
|
||||
} else {
|
||||
// determine from subtype with same layout
|
||||
SubtypeSettings.getResourceSubtypesForLocale(currentSubtype.locale)
|
||||
.firstOrNull { it.mainLayoutName() == mainLayout }
|
||||
?.containsExtraValueKey(ExtraValue.NO_SHIFT_KEY) ?: false
|
||||
}
|
||||
if (!noShiftKey && currentSubtype.hasExtraValueOf(ExtraValue.NO_SHIFT_KEY))
|
||||
setCurrentSubtype(currentSubtype.without(ExtraValue.NO_SHIFT_KEY))
|
||||
else if (noShiftKey && !currentSubtype.hasExtraValueOf(ExtraValue.NO_SHIFT_KEY))
|
||||
setCurrentSubtype(currentSubtype.with(ExtraValue.NO_SHIFT_KEY))
|
||||
}
|
||||
|
||||
val availableLocalesForScript = getAvailableSecondaryLocales(ctx, currentSubtype.locale).sortedBy { it.toLanguageTag() }
|
||||
var showSecondaryLocaleDialog by remember { mutableStateOf(false) }
|
||||
|
@ -141,7 +161,7 @@ fun SubtypeDialog(
|
|||
setCurrentSubtype(currentSubtype.without(ExtraValue.HINT_ORDER))
|
||||
}
|
||||
}
|
||||
if (currentSubtype.locale.script() == SCRIPT_LATIN) {
|
||||
if (currentSubtype.locale.script() == ScriptUtils.SCRIPT_LATIN) {
|
||||
WithSmallTitle(stringResource(R.string.show_popup_keys_title)) {
|
||||
val explicitValue = currentSubtype.getExtraValueOf(ExtraValue.MORE_POPUPS)
|
||||
val value = explicitValue ?: prefs.getString(Settings.PREF_MORE_POPUP_KEYS, Defaults.PREF_MORE_POPUP_KEYS)!!
|
||||
|
@ -155,7 +175,7 @@ fun SubtypeDialog(
|
|||
}
|
||||
}
|
||||
if (hasLocalizedNumberRow(currentSubtype.locale, ctx)) {
|
||||
Row {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
val checked = currentSubtype.getExtraValueOf(ExtraValue.LOCALIZED_NUMBER_ROW)?.toBoolean()
|
||||
Text(stringResource(R.string.localized_number_row), Modifier.weight(1f))
|
||||
Switch(
|
||||
|
|
|
@ -1003,6 +1003,6 @@ New dictionary:
|
|||
<string name="customize_icons_reset_message">Really reset all customized icons?</string>
|
||||
<!-- Confirmation message when deleting a something (currently used for custom colors) -->
|
||||
<string name="delete_confirmation">Really delete %s?</string>
|
||||
<!-- Message when chosen name is invalid (empty or already taked) -->
|
||||
<!-- Message when chosen name is invalid (empty or already taken) -->
|
||||
<string name="name_invalid">Invalid name</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue