mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor: move dialog into NodeKeyStatusIcon component
This commit is contained in:
parent
c02a30cff9
commit
5d3b36532f
2 changed files with 32 additions and 27 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue