mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-24 08:36:26 +00:00
make subtypeDialog survive screen rotation (but currently loses changes to settings)
This commit is contained in:
parent
93e6f88f6c
commit
cab9cc7de0
6 changed files with 33 additions and 23 deletions
|
@ -206,7 +206,7 @@ class LanguageSettingsDialog(
|
|||
infos.remove(subtype)
|
||||
//if (isCustom)
|
||||
// LayoutUtilsCustom.removeCustomLayoutFile(layoutSetName, context)
|
||||
SubtypeUtilsAdditional.removeAdditionalSubtype(prefs, subtype.subtype)
|
||||
SubtypeUtilsAdditional.removeAdditionalSubtype(context, subtype.subtype)
|
||||
SubtypeSettings.removeEnabledSubtype(context, subtype.subtype)
|
||||
reloadSetting()
|
||||
}
|
||||
|
|
|
@ -109,6 +109,10 @@ fun createDictionaryTextHtml(message: String, locale: Locale, context: Context):
|
|||
@Composable
|
||||
fun MissingDictionaryDialog(onDismissRequest: () -> Unit, locale: Locale) {
|
||||
val prefs = LocalContext.current.prefs()
|
||||
if (prefs.getBoolean(Settings.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG, Defaults.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG)) {
|
||||
onDismissRequest()
|
||||
return
|
||||
}
|
||||
val availableDicts = createDictionaryTextAnnotated(locale)
|
||||
val dictLink = "${Links.DICTIONARY_URL}/src/branch/main/dictionaries/main_$locale.dict"
|
||||
val message = stringResource(R.string.no_dictionary_message, "§repl1§", locale.toString(), "§repl2§")
|
||||
|
|
|
@ -127,7 +127,7 @@ data class SettingsSubtype(val locale: Locale, val extraValues: String) {
|
|||
|
||||
fun with(extraValueKey: String, extraValue: String?): SettingsSubtype {
|
||||
val newList = extraValues.split(",")
|
||||
.filterNot { it.startsWith("$extraValueKey=") || it == extraValueKey }
|
||||
.filterNot { it.isBlank() || it.startsWith("$extraValueKey=") || it == extraValueKey }
|
||||
val newValue = if (extraValue == null) extraValueKey else "$extraValueKey=$extraValue"
|
||||
val newValues = (newList + newValue).joinToString(",")
|
||||
return copy(extraValues = newValues)
|
||||
|
@ -135,7 +135,7 @@ data class SettingsSubtype(val locale: Locale, val extraValues: String) {
|
|||
|
||||
fun without(extraValueKey: String): SettingsSubtype {
|
||||
val newValues = extraValues.split(",")
|
||||
.filterNot { it.startsWith("$extraValueKey=") || it == extraValueKey }
|
||||
.filterNot { it.isBlank() || it.startsWith("$extraValueKey=") || it == extraValueKey }
|
||||
.joinToString(",")
|
||||
return copy(extraValues = newValues)
|
||||
}
|
||||
|
@ -174,7 +174,8 @@ data class SettingsSubtype(val locale: Locale, val extraValues: String) {
|
|||
Log.e(SettingsSubtype::class.simpleName, "unknown language, should not happen ${locale}, $languageTag, $extraValue, ${hashCode()}, $nameResId")
|
||||
}
|
||||
val filteredExtraValue = extraValue.split(",").filterNot {
|
||||
it == ExtraValue.ASCII_CAPABLE
|
||||
it.isBlank()
|
||||
|| it == ExtraValue.ASCII_CAPABLE
|
||||
|| it == ExtraValue.EMOJI_CAPABLE
|
||||
|| it == ExtraValue.IS_ADDITIONAL_SUBTYPE
|
||||
|| it.startsWith(ExtraValue.UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME)
|
||||
|
|
|
@ -58,7 +58,10 @@ object SubtypeUtilsAdditional {
|
|||
Settings.writePrefAdditionalSubtypes(prefs, newAdditionalSubtypesString)
|
||||
}
|
||||
|
||||
fun removeAdditionalSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype) {
|
||||
// todo: SettingsSubtype?
|
||||
fun removeAdditionalSubtype(context: Context, subtype: InputMethodSubtype) {
|
||||
val prefs = context.prefs()
|
||||
SubtypeSettings.removeEnabledSubtype(context, subtype)
|
||||
val oldAdditionalSubtypesString = prefs.getString(Settings.PREF_ADDITIONAL_SUBTYPES, Defaults.PREF_ADDITIONAL_SUBTYPES)!!
|
||||
val oldAdditionalSubtypes = createAdditionalSubtypes(oldAdditionalSubtypesString)
|
||||
val newAdditionalSubtypes = oldAdditionalSubtypes.filter { it != subtype }
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
package helium314.keyboard.settings.dialogs
|
||||
|
||||
import android.content.Context
|
||||
import android.view.inputmethod.InputMethodSubtype
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
|
@ -77,12 +76,10 @@ import helium314.keyboard.settings.layoutIntent
|
|||
import helium314.keyboard.settings.screens.GetIcon
|
||||
import java.util.Locale
|
||||
|
||||
// todo:
|
||||
// rotating closes the dialog
|
||||
@Composable
|
||||
fun SubtypeDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
subtype: InputMethodSubtype,
|
||||
initialSubtype: SettingsSubtype,
|
||||
onConfirmed: (SettingsSubtype) -> Unit,
|
||||
) {
|
||||
// todo: make sure the values are always correct (e.g. if using rememberSaveable and rotating)
|
||||
|
@ -91,7 +88,7 @@ fun SubtypeDialog(
|
|||
val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
|
||||
if ((b?.value ?: 0) < 0)
|
||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||
var currentSubtype by remember { mutableStateOf(subtype.toSettingsSubtype()) }
|
||||
var currentSubtype by remember { mutableStateOf(initialSubtype) }
|
||||
val availableLocalesForScript = getAvailableSecondaryLocales(ctx, currentSubtype.locale).sortedBy { it.toLanguageTag() }
|
||||
var showSecondaryLocaleDialog by remember { mutableStateOf(false) }
|
||||
var showKeyOrderDialog by remember { mutableStateOf(false) }
|
||||
|
@ -102,19 +99,22 @@ fun SubtypeDialog(
|
|||
ThreeButtonAlertDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
onConfirmed = { onConfirmed(currentSubtype) },
|
||||
neutralButtonText = if (SubtypeSettings.isAdditionalSubtype(subtype)) stringResource(R.string.delete) else null,
|
||||
neutralButtonText = if (initialSubtype.isAdditionalSubtype(prefs)) stringResource(R.string.delete) else null,
|
||||
onNeutral = {
|
||||
SubtypeUtilsAdditional.removeAdditionalSubtype(ctx, initialSubtype.toAdditionalSubtype()!!)
|
||||
SubtypeSettings.removeEnabledSubtype(ctx, initialSubtype.toAdditionalSubtype()!!)
|
||||
onDismissRequest()
|
||||
SubtypeUtilsAdditional.removeAdditionalSubtype(prefs, subtype)
|
||||
SubtypeSettings.removeEnabledSubtype(ctx, subtype)
|
||||
},
|
||||
title = { Text(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype)) },
|
||||
title = {
|
||||
val mainLayout = initialSubtype.mainLayoutName() ?: SubtypeLocaleUtils.QWERTY
|
||||
Text(SubtypeLocaleUtils.getDisplayNameInSystemLocale(mainLayout, initialSubtype.locale))
|
||||
},
|
||||
content = {
|
||||
Column(
|
||||
modifier = Modifier.verticalScroll(scrollState),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
MainLayoutRow(subtype, currentSubtype, customMainLayouts) { currentSubtype = it }
|
||||
MainLayoutRow(initialSubtype, currentSubtype, customMainLayouts) { currentSubtype = it }
|
||||
if (availableLocalesForScript.size > 1) {
|
||||
WithSmallTitle(stringResource(R.string.secondary_locale)) {
|
||||
TextButton(onClick = { showSecondaryLocaleDialog = true }) {
|
||||
|
@ -306,7 +306,7 @@ private fun PopupOrderDialog(
|
|||
|
||||
@Composable
|
||||
private fun MainLayoutRow(
|
||||
subtype: InputMethodSubtype,
|
||||
initialSubtype: SettingsSubtype,
|
||||
currentSubtype: SettingsSubtype,
|
||||
customLayouts: List<String>,
|
||||
setCurrentSubtype: (SettingsSubtype) -> Unit,
|
||||
|
@ -339,12 +339,13 @@ private fun MainLayoutRow(
|
|||
Text(SubtypeLocaleUtils.getDisplayNameInSystemLocale(it, currentSubtype.locale))
|
||||
Row (verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(painterResource(R.drawable.ic_edit), stringResource(R.string.edit_layout), Modifier.clickable { showLayoutEditDialog = it to null })
|
||||
if (it in customLayouts && subtype.mainLayoutName() != it) // don't allow current main layout
|
||||
if (it in customLayouts && initialSubtype.mainLayoutName() != it) // don't allow current main layout
|
||||
Icon(painterResource(R.drawable.ic_bin), stringResource(R.string.delete), Modifier.clickable { showLayoutDeleteDialog = true })
|
||||
}
|
||||
}
|
||||
if (showLayoutDeleteDialog) {
|
||||
val others = SubtypeSettings.getAdditionalSubtypes().filter { st -> st.mainLayoutName() == it }.any { it != subtype }
|
||||
val others = SubtypeSettings.getAdditionalSubtypes().filter { st -> st.mainLayoutName() == it }
|
||||
.any { it.toSettingsSubtype() != initialSubtype }
|
||||
ConfirmationDialog(
|
||||
onDismissRequest = { showLayoutDeleteDialog = false },
|
||||
confirmButtonText = stringResource(R.string.delete),
|
||||
|
|
|
@ -17,6 +17,7 @@ import androidx.compose.runtime.collectAsState
|
|||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
|
@ -57,7 +58,7 @@ fun LanguageScreen(
|
|||
val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
|
||||
if ((b?.value ?: 0) < 0)
|
||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||
var selectedSubtype: InputMethodSubtype? by remember { mutableStateOf(null) } // todo: rememberSaveable? maybe with SettingsSubtype?
|
||||
var selectedSubtype: String? by rememberSaveable { mutableStateOf(null) }
|
||||
val enabledSubtypes = SubtypeSettings.getEnabledSubtypes(prefs)
|
||||
SearchScreen(
|
||||
onClickBack = onClickBack,
|
||||
|
@ -82,7 +83,7 @@ fun LanguageScreen(
|
|||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { selectedSubtype = item }
|
||||
.clickable { selectedSubtype = item.toSettingsSubtype().toPref() }
|
||||
.padding(vertical = 6.dp, horizontal = 16.dp)
|
||||
) {
|
||||
var showNoDictDialog by remember { mutableStateOf(false) }
|
||||
|
@ -112,16 +113,16 @@ fun LanguageScreen(
|
|||
}
|
||||
)
|
||||
if (selectedSubtype != null) {
|
||||
val oldSubtype = selectedSubtype!!
|
||||
val oldSubtype = selectedSubtype!!.toSettingsSubtype()
|
||||
SubtypeDialog(
|
||||
onDismissRequest = {
|
||||
selectedSubtype = null
|
||||
sortedSubtypes = getSortedSubtypes(ctx)
|
||||
},
|
||||
onConfirmed = {
|
||||
SubtypeUtilsAdditional.changeAdditionalSubtype(oldSubtype.toSettingsSubtype(), it, ctx)
|
||||
SubtypeUtilsAdditional.changeAdditionalSubtype(oldSubtype, it, ctx)
|
||||
},
|
||||
subtype = oldSubtype
|
||||
initialSubtype = oldSubtype
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue