From 6dfb6a56d65b1f2715b1b7a364bd9f3d6eb59bbc Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Fri, 7 Mar 2025 14:26:57 -0600 Subject: [PATCH] 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 --- .../components/DeviceConfigItemList.kt | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/DeviceConfigItemList.kt b/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/DeviceConfigItemList.kt index 9b08ae7f0..ae5bbcca9 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/DeviceConfigItemList.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/DeviceConfigItemList.kt @@ -17,9 +17,11 @@ package com.geeksville.mesh.ui.radioconfig.components +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions @@ -131,6 +133,11 @@ fun RouterRoleConfirmationDialog( Column { Text(text = annotatedDialogText) Row( + modifier = Modifier + .fillMaxWidth() + .clickable(true) { + confirmed = !confirmed + }, verticalAlignment = Alignment.CenterVertically ) { Checkbox( @@ -168,16 +175,22 @@ fun DeviceConfigItemList( ) { val focusManager = LocalFocusManager.current var deviceInput by rememberSaveable { mutableStateOf(deviceConfig) } - - var showRouterRoleConfirmationDialog by rememberSaveable { mutableStateOf(false) } - if (showRouterRoleConfirmationDialog) { - RouterRoleConfirmationDialog( - onDismiss = { showRouterRoleConfirmationDialog = false }, - onConfirm = { - showRouterRoleConfirmationDialog = false - deviceInput = deviceInput.copy { role = DeviceConfig.Role.ROUTER } - } - ) + var selectedRole by rememberSaveable { mutableStateOf(deviceInput.role) } + val infrastructureRoles = listOf( + DeviceConfig.Role.ROUTER, + DeviceConfig.Role.REPEATER, + ) + if (selectedRole != deviceInput.role) { + if (selectedRole in infrastructureRoles) { + RouterRoleConfirmationDialog( + onDismiss = { selectedRole = deviceInput.role }, + onConfirm = { + deviceInput = deviceInput.copy { role = selectedRole } + } + ) + } else { + deviceInput = deviceInput.copy { role = selectedRole } + } } LazyColumn( modifier = Modifier.fillMaxSize() @@ -190,11 +203,7 @@ fun DeviceConfigItemList( enabled = enabled, selectedItem = deviceInput.role, onItemSelected = { - if (it == DeviceConfig.Role.ROUTER && deviceInput.role != DeviceConfig.Role.ROUTER) { - showRouterRoleConfirmationDialog = true - } else { - deviceInput = deviceInput.copy { role = it } - } + selectedRole = it }, summary = stringResource(id = deviceInput.role.stringRes), )