fix: show modem preset name if channel name is empty

(or "Default" if not available)
master
andrekir 2023-05-21 09:19:55 -03:00
rodzic 8643d50425
commit d58e092333
3 zmienionych plików z 10 dodań i 2 usunięć

Wyświetl plik

@ -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 = {

Wyświetl plik

@ -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) }

Wyświetl plik

@ -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(