kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
* Add confirmation dialog for changing to router role Introduced a confirmation dialog that will be shown when changing the device role to "router". The confirmation dialog includes links to the "Device Role Documentation" and "Choosing The Right Device Role" blog post. The user must check a checkbox to confirm. * Update router role handling Modified the handling of the router role in `DeviceConfigItemList.kt` to avoid returning prematurely from the `onItemSelected` lambda. This ensures that the role is updated properly when a user selects the "ROUTER" role. * removes konami code check, remove testing code * Refactor router role confirmation text - Moves the router role confirmation text to strings.xml. - Updates to use `AnnotatedString.fromHtml` instead of `buildAnnotatedString` and `withLink`. - Changes from hard-coded strings to string resources.pull/1643/head
rodzic
888688176c
commit
2859bed416
|
@ -17,19 +17,31 @@
|
|||
|
||||
package com.geeksville.mesh.ui.radioconfig.components
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.AlertDialog
|
||||
import androidx.compose.material.Checkbox
|
||||
import androidx.compose.material.Divider
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.TextLinkStyles
|
||||
import androidx.compose.ui.text.fromHtml
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
|
@ -97,6 +109,57 @@ fun DeviceConfigScreen(
|
|||
)
|
||||
}
|
||||
|
||||
@Suppress("LongMethod")
|
||||
@Composable
|
||||
fun RouterRoleConfirmationDialog(
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: () -> Unit,
|
||||
) {
|
||||
val dialogTitle = stringResource(R.string.are_you_sure)
|
||||
val annotatedDialogText = AnnotatedString.fromHtml(
|
||||
htmlString = stringResource(R.string.router_role_confirmation_text),
|
||||
linkStyles = TextLinkStyles(style = SpanStyle(color = Color.Blue))
|
||||
)
|
||||
|
||||
var confirmed by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
AlertDialog(
|
||||
title = {
|
||||
Text(text = dialogTitle)
|
||||
},
|
||||
text = {
|
||||
Column {
|
||||
Text(text = annotatedDialogText)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Checkbox(
|
||||
checked = confirmed,
|
||||
onCheckedChange = { confirmed = it }
|
||||
)
|
||||
Text(stringResource(R.string.i_know_what_i_m_doing))
|
||||
}
|
||||
}
|
||||
},
|
||||
onDismissRequest = onDismiss,
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = onConfirm,
|
||||
enabled = confirmed
|
||||
) {
|
||||
Text(stringResource(R.string.accept))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(
|
||||
onClick = onDismiss
|
||||
) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DeviceConfigItemList(
|
||||
deviceConfig: DeviceConfig,
|
||||
|
@ -106,6 +169,16 @@ 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 }
|
||||
}
|
||||
)
|
||||
}
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
|
@ -116,7 +189,13 @@ fun DeviceConfigItemList(
|
|||
title = "Role",
|
||||
enabled = enabled,
|
||||
selectedItem = deviceInput.role,
|
||||
onItemSelected = { deviceInput = deviceInput.copy { role = it } },
|
||||
onItemSelected = {
|
||||
if (it == DeviceConfig.Role.ROUTER && deviceInput.role != DeviceConfig.Role.ROUTER) {
|
||||
showRouterRoleConfirmationDialog = true
|
||||
} else {
|
||||
deviceInput = deviceInput.copy { role = it }
|
||||
}
|
||||
},
|
||||
summary = stringResource(id = deviceInput.role.stringRes),
|
||||
)
|
||||
Divider()
|
||||
|
|
|
@ -328,4 +328,7 @@
|
|||
<string name="channel_3">Channel 3</string>
|
||||
<string name="current">Current</string>
|
||||
<string name="voltage">Voltage</string>
|
||||
<string name="are_you_sure">Are you sure?</string>
|
||||
<string name="router_role_confirmation_text"><![CDATA[I have read the <a href="https://meshtastic.org/docs/configuration/radio/device/#roles">Device Role Documentation</a> and the blog post about <a href="http://meshtastic.org/blog/choosing-the-right-device-role">Choosing The Right Device Role</a>.]]></string>
|
||||
<string name="i_know_what_i_m_doing">I know what I\'m doing.</string>
|
||||
</resources>
|
||||
|
|
Ładowanie…
Reference in New Issue