fix #1615: Add explicit signed int editing preference (#1629)

pull/1637/head
Joshua Soberg 2025-03-02 10:20:27 -05:00 zatwierdzone przez GitHub
rodzic 5da827473a
commit d8f67e011a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 39 dodań i 2 usunięć

Wyświetl plik

@ -46,6 +46,40 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.geeksville.mesh.R
@Composable
fun SignedIntegerEditTextPreference(
title: String,
value: Int,
enabled: Boolean,
keyboardActions: KeyboardActions,
onValueChanged: (Int) -> Unit,
modifier: Modifier = Modifier,
onFocusChanged: (FocusState) -> Unit = {},
trailingIcon: (@Composable () -> Unit)? = null,
) {
var valueState by remember(value) { mutableStateOf(value.toString()) }
EditTextPreference(
title = title,
value = valueState,
enabled = enabled,
isError = valueState.toIntOrNull() == null,
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Number, imeAction = ImeAction.Done
),
keyboardActions = keyboardActions,
onValueChanged = {
valueState = it
it.toIntOrNull()?.let { int ->
onValueChanged(int)
}
},
onFocusChanged = onFocusChanged,
modifier = modifier,
trailingIcon = trailingIcon
)
}
@Composable
fun EditTextPreference(
title: String,

Wyświetl plik

@ -44,6 +44,7 @@ import com.geeksville.mesh.ui.components.EditListPreference
import com.geeksville.mesh.ui.components.EditTextPreference
import com.geeksville.mesh.ui.components.PreferenceCategory
import com.geeksville.mesh.ui.components.PreferenceFooter
import com.geeksville.mesh.ui.components.SignedIntegerEditTextPreference
import com.geeksville.mesh.ui.components.SwitchPreference
import com.geeksville.mesh.ui.radioconfig.RadioConfigViewModel
@ -171,11 +172,13 @@ fun LoRaConfigItemList(
item { Divider() }
item {
EditTextPreference(title = "TX power (dBm)",
SignedIntegerEditTextPreference(
title = "TX power (dBm)",
value = loraInput.txPower,
enabled = enabled,
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
onValueChanged = { loraInput = loraInput.copy { txPower = it } })
onValueChanged = { loraInput = loraInput.copy { txPower = it } },
)
}
item {