From d58e092333cd91337b468e88da1bc3519299ad67 Mon Sep 17 00:00:00 2001 From: andrekir Date: Sun, 21 May 2023 09:19:55 -0300 Subject: [PATCH] fix: show modem preset name if channel name is empty (or "Default" if not available) --- app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt | 3 +++ .../mesh/ui/components/config/ChannelSettingsItemList.kt | 4 +++- .../mesh/ui/components/config/EditChannelDialog.kt | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt index f78c8564..f4382711 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt @@ -126,6 +126,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) { val primaryChannel = ChannelSet(channelSet).primaryChannel val channelUrl = ChannelSet(channelSet).getChannelUrl() + val modemPresetName = Channel(Channel.default.settings, channelSet.loraConfig).name val barcodeLauncher = rememberLauncherForActivityResult(ScanContract()) { result -> if (result.contents != null) { @@ -244,6 +245,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) { channelSettings = with(channelSet) { if (settingsCount > index) getSettings(index) else channelSettings { } }, + modemPresetName = modemPresetName, onAddClick = { with(channelSet) { if (settingsCount > index) channelSet = copy { settings[index] = it } @@ -258,6 +260,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) { var showChannelEditor by remember { mutableStateOf(false) } if (showChannelEditor) ChannelSettingsItemList( settingsList = channelSet.settingsList, + modemPresetName = modemPresetName, enabled = enabled, focusManager = focusManager, onNegativeClicked = { diff --git a/app/src/main/java/com/geeksville/mesh/ui/components/config/ChannelSettingsItemList.kt b/app/src/main/java/com/geeksville/mesh/ui/components/config/ChannelSettingsItemList.kt index 0635bfb6..24a739e3 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/components/config/ChannelSettingsItemList.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/components/config/ChannelSettingsItemList.kt @@ -107,6 +107,7 @@ fun ChannelSettingsItemList( @Composable fun ChannelSettingsItemList( settingsList: List, + 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) } diff --git a/app/src/main/java/com/geeksville/mesh/ui/components/config/EditChannelDialog.kt b/app/src/main/java/com/geeksville/mesh/ui/components/config/EditChannelDialog.kt index 25dffe42..be65708e 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/components/config/EditChannelDialog.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/components/config/EditChannelDialog.kt @@ -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(