feat: expand role confirmation to include REPEATER (#1657)

* Clarify role change behavior

The role change logic was modified to show a confirmation dialog when the role is set to `ROUTER`, `ROUTER_CLIENT`, or `REPEATER`. Previously, the dialog was only displayed when setting the role to `ROUTER`.

* Implement router role confirmation dialog

- Added a confirmation dialog when changing the device role to ROUTER, ROUTER_CLIENT, or REPEATER.
- The confirmation dialog ensures users are aware of the implications of selecting a role used for infrastructure.
- Updated the logic to set the selected role only after confirmation.
- Only show dialog when changing to infrastructure roles.

* remove deprecated ROUTER_CLIENT to avoid confusion
pull/1653/head^2
James Rich 2025-03-07 14:26:57 -06:00 zatwierdzone przez GitHub
rodzic d40672df40
commit 6dfb6a56d6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 24 dodań i 15 usunięć

Wyświetl plik

@ -17,9 +17,11 @@
package com.geeksville.mesh.ui.radioconfig.components package com.geeksville.mesh.ui.radioconfig.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
@ -131,6 +133,11 @@ fun RouterRoleConfirmationDialog(
Column { Column {
Text(text = annotatedDialogText) Text(text = annotatedDialogText)
Row( Row(
modifier = Modifier
.fillMaxWidth()
.clickable(true) {
confirmed = !confirmed
},
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
Checkbox( Checkbox(
@ -168,16 +175,22 @@ fun DeviceConfigItemList(
) { ) {
val focusManager = LocalFocusManager.current val focusManager = LocalFocusManager.current
var deviceInput by rememberSaveable { mutableStateOf(deviceConfig) } var deviceInput by rememberSaveable { mutableStateOf(deviceConfig) }
var selectedRole by rememberSaveable { mutableStateOf(deviceInput.role) }
var showRouterRoleConfirmationDialog by rememberSaveable { mutableStateOf(false) } val infrastructureRoles = listOf(
if (showRouterRoleConfirmationDialog) { DeviceConfig.Role.ROUTER,
DeviceConfig.Role.REPEATER,
)
if (selectedRole != deviceInput.role) {
if (selectedRole in infrastructureRoles) {
RouterRoleConfirmationDialog( RouterRoleConfirmationDialog(
onDismiss = { showRouterRoleConfirmationDialog = false }, onDismiss = { selectedRole = deviceInput.role },
onConfirm = { onConfirm = {
showRouterRoleConfirmationDialog = false deviceInput = deviceInput.copy { role = selectedRole }
deviceInput = deviceInput.copy { role = DeviceConfig.Role.ROUTER }
} }
) )
} else {
deviceInput = deviceInput.copy { role = selectedRole }
}
} }
LazyColumn( LazyColumn(
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
@ -190,11 +203,7 @@ fun DeviceConfigItemList(
enabled = enabled, enabled = enabled,
selectedItem = deviceInput.role, selectedItem = deviceInput.role,
onItemSelected = { onItemSelected = {
if (it == DeviceConfig.Role.ROUTER && deviceInput.role != DeviceConfig.Role.ROUTER) { selectedRole = it
showRouterRoleConfirmationDialog = true
} else {
deviceInput = deviceInput.copy { role = it }
}
}, },
summary = stringResource(id = deviceInput.role.stringRes), summary = stringResource(id = deviceInput.role.stringRes),
) )