pre-fill name for new color themes

This commit is contained in:
Helium314 2025-03-02 12:05:49 +01:00
parent e342ff24b5
commit 72ca12d52e

View file

@ -44,6 +44,7 @@ import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.ColorType import helium314.keyboard.latin.common.ColorType
import helium314.keyboard.latin.common.Links import helium314.keyboard.latin.common.Links
import helium314.keyboard.latin.common.decodeBase36 import helium314.keyboard.latin.common.decodeBase36
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.appendLink import helium314.keyboard.latin.utils.appendLink
@ -172,6 +173,10 @@ fun ColorThemePickerDialog(
private fun AddColorRow(onDismissRequest: () -> Unit, userColors: Collection<String>, targetScreen: String, prefKey: String) { private fun AddColorRow(onDismissRequest: () -> Unit, userColors: Collection<String>, targetScreen: String, prefKey: String) {
var textValue by remember { mutableStateOf(TextFieldValue()) } var textValue by remember { mutableStateOf(TextFieldValue()) }
val prefs = LocalContext.current.prefs() val prefs = LocalContext.current.prefs()
val defaultName = KeyboardTheme.getUnusedThemeName(stringResource(R.string.theme_name_user), prefs)
val textEmpty = textValue.text.isEmpty()
val currentName = if (textEmpty) defaultName else textValue.text
val label: @Composable (() -> Unit)? = if (textEmpty) { { Text(defaultName) } } else null
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = 10.dp) modifier = Modifier.padding(start = 10.dp)
@ -181,12 +186,14 @@ private fun AddColorRow(onDismissRequest: () -> Unit, userColors: Collection<Str
value = textValue, value = textValue,
onValueChange = { textValue = it }, onValueChange = { textValue = it },
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
singleLine = true singleLine = true,
label = label
) )
EditButton(textValue.text.isNotEmpty() && textValue.text !in userColors) { EditButton(currentName.isNotBlank() && currentName !in userColors) {
onDismissRequest() onDismissRequest()
prefs.edit().putString(prefKey, textValue.text).apply() prefs.edit().putString(prefKey, currentName).apply()
SettingsDestination.navigateTo(targetScreen) KeyboardTheme.writeUserMoreColors(prefs, currentName, Defaults.PREF_USER_MORE_COLORS) // write sth so theme is stored
SettingsDestination.navigateTo(targetScreen + currentName)
KeyboardSwitcher.getInstance().setThemeNeedsReload() KeyboardSwitcher.getInstance().setThemeNeedsReload()
} }
} }