feat(#2060): Enforce valid names for UserConfig (#2063)

This commit is contained in:
James Rich 2025-06-09 17:46:22 +00:00 committed by GitHub
parent f5b34d6408
commit 4767e48fe2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View file

@ -69,7 +69,6 @@ fun PreferenceFooter(
modifier = modifier
.height(48.dp)
.weight(1f),
enabled = enabled,
onClick = onNegativeClicked,
) {
Text(

View file

@ -82,6 +82,9 @@ fun UserConfigItemList(
var userInput by rememberSaveable { mutableStateOf(userConfig) }
val firmwareVersion = DeviceVersion(metadata?.firmwareVersion ?: "")
val validLongName = userInput.longName.isNotBlank()
val validShortName = userInput.shortName.isNotBlank()
val validNames = validLongName && validShortName
LazyColumn(
modifier = Modifier.fillMaxSize()
) {
@ -102,7 +105,7 @@ fun UserConfigItemList(
value = userInput.longName,
maxSize = 39, // long_name max_size:40
enabled = enabled,
isError = userInput.longName.isEmpty(),
isError = !validLongName,
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Text, imeAction = ImeAction.Done
),
@ -119,7 +122,7 @@ fun UserConfigItemList(
value = userInput.shortName,
maxSize = 4, // short_name max_size:5
enabled = enabled,
isError = userInput.shortName.isEmpty(),
isError = !validShortName,
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Text, imeAction = ImeAction.Done
),
@ -165,7 +168,7 @@ fun UserConfigItemList(
item {
PreferenceFooter(
enabled = enabled && userInput != userConfig,
enabled = enabled && userInput != userConfig && validNames,
onCancelClicked = {
focusManager.clearFocus()
userInput = userConfig