diff --git a/app/src/main/java/com/geeksville/mesh/ui/NodeItem.kt b/app/src/main/java/com/geeksville/mesh/ui/NodeItem.kt index 475e151ba..83618ff85 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/NodeItem.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/NodeItem.kt @@ -70,7 +70,6 @@ import com.geeksville.mesh.ui.components.MenuItemAction import com.geeksville.mesh.ui.components.NodeKeyStatusIcon import com.geeksville.mesh.ui.components.NodeMenu import com.geeksville.mesh.ui.components.SignalInfo -import com.geeksville.mesh.ui.components.SimpleAlertDialog import com.geeksville.mesh.ui.compose.ElevationInfo import com.geeksville.mesh.ui.compose.SatelliteCountInfo import com.geeksville.mesh.ui.preview.NodeEntityPreviewParameterProvider @@ -131,16 +130,6 @@ fun NodeItem( val (detailsShown, showDetails) = remember { mutableStateOf(expanded) } - var showEncryptionDialog by remember { mutableStateOf(false) } - if (showEncryptionDialog) { - val (title, text) = when { - thatNode.mismatchKey -> R.string.encryption_error to R.string.encryption_error_text - thatNode.hasPKC -> R.string.encryption_pkc to R.string.encryption_pkc_text - else -> R.string.encryption_psk to R.string.encryption_psk_text - } - SimpleAlertDialog(title, text) { showEncryptionDialog = false } - } - Card( modifier = Modifier .fillMaxWidth() @@ -200,7 +189,7 @@ fun NodeItem( hasPKC = thatNode.hasPKC, mismatchKey = thatNode.mismatchKey, modifier = Modifier.size(32.dp) - ) { showEncryptionDialog = true } + ) Text( modifier = Modifier.weight(1f), text = longName, diff --git a/app/src/main/java/com/geeksville/mesh/ui/components/NodeKeyStatusIcon.kt b/app/src/main/java/com/geeksville/mesh/ui/components/NodeKeyStatusIcon.kt index e407bf603..233bbc777 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/components/NodeKeyStatusIcon.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/components/NodeKeyStatusIcon.kt @@ -23,6 +23,10 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.KeyOff import androidx.compose.material.icons.filled.Lock import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.rememberVectorPainter @@ -35,25 +39,37 @@ fun NodeKeyStatusIcon( hasPKC: Boolean, mismatchKey: Boolean, modifier: Modifier = Modifier, - onClick: () -> Unit = {}, -) = IconButton( - onClick = onClick, - modifier = modifier, ) { + var showEncryptionDialog by remember { mutableStateOf(false) } + if (showEncryptionDialog) { + val (title, text) = when { + mismatchKey -> R.string.encryption_error to R.string.encryption_error_text + hasPKC -> R.string.encryption_pkc to R.string.encryption_pkc_text + else -> R.string.encryption_psk to R.string.encryption_psk_text + } + SimpleAlertDialog(title, text) { showEncryptionDialog = false } + } + val (icon, tint) = when { mismatchKey -> rememberVectorPainter(Icons.Default.KeyOff) to Color.Red hasPKC -> rememberVectorPainter(Icons.Default.Lock) to Color(color = 0xFF30C047) else -> painterResource(R.drawable.ic_lock_open_right_24) to Color(color = 0xFFFEC30A) } - Icon( - painter = icon, - contentDescription = stringResource( - id = when { - mismatchKey -> R.string.encryption_error - hasPKC -> R.string.encryption_pkc - else -> R.string.encryption_psk - } - ), - tint = tint, - ) + + IconButton( + onClick = { showEncryptionDialog = true }, + modifier = modifier, + ) { + Icon( + painter = icon, + contentDescription = stringResource( + id = when { + mismatchKey -> R.string.encryption_error + hasPKC -> R.string.encryption_pkc + else -> R.string.encryption_psk + } + ), + tint = tint, + ) + } }