fix: show modem preset name if channel name is empty

(or "Default" if not available)
This commit is contained in:
andrekir 2023-05-21 09:19:55 -03:00
parent 8643d50425
commit d58e092333
3 changed files with 10 additions and 2 deletions

View file

@ -107,6 +107,7 @@ fun ChannelSettingsItemList(
@Composable
fun ChannelSettingsItemList(
settingsList: List<ChannelSettings>,
modemPresetName: String = "Default",
maxChannels: Int = 8,
enabled: Boolean,
focusManager: FocusManager,
@ -125,6 +126,7 @@ fun ChannelSettingsItemList(
channelSettings = with(settingsListInput) {
if (size > index) get(index) else channelSettings { }
},
modemPresetName = modemPresetName,
onAddClick = {
if (settingsListInput.size > index) settingsListInput[index] = it
else settingsListInput.add(it)
@ -147,7 +149,7 @@ fun ChannelSettingsItemList(
itemsIndexed(settingsListInput) { index, channel ->
ChannelCard(
index = index,
title = channel.name,
title = channel.name.ifEmpty { modemPresetName },
enabled = enabled,
onEditClick = { showEditChannelDialog = index },
onDeleteClick = { settingsListInput.removeAt(index) }

View file

@ -48,6 +48,7 @@ fun EditChannelDialog(
onAddClick: (ChannelProtos.ChannelSettings) -> Unit,
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
modemPresetName: String = "Default",
) {
val base64Flags = Base64.URL_SAFE + Base64.NO_WRAP
fun encodeToString(input: ByteString) =
@ -73,9 +74,10 @@ fun EditChannelDialog(
text = {
AppCompatTheme {
Column(modifier.fillMaxWidth()) {
var isFocused by remember { mutableStateOf(false) }
EditTextPreference(
title = stringResource(R.string.channel_name),
value = nameInput,
value = if (isFocused) nameInput else nameInput.ifEmpty { modemPresetName },
maxSize = 11, // name max_size:12
enabled = true,
isError = false,
@ -84,6 +86,7 @@ fun EditChannelDialog(
),
keyboardActions = KeyboardActions(onDone = { }),
onValueChanged = { nameInput = it },
onFocusChanged = { isFocused = it.isFocused },
)
OutlinedTextField(