Ask before disconnecting the OBU on the V2X screen
The disconnect icon sits next to the map button and dropped the ESP32-C5 or CiT One link on a single tap. It now opens a standard confirmation dialog first. Connecting still needs no confirmation. Checked on a Pixel 9 Pro (ESP32 path): Cancel, Back and rotation keep the link and the dialog; confirming disconnects.
This commit is contained in:
@@ -33,6 +33,7 @@ import androidx.compose.material.icons.filled.Map
|
||||
import androidx.compose.material.icons.filled.NotificationsActive
|
||||
import androidx.compose.material.icons.filled.VerticalAlignBottom
|
||||
import androidx.compose.material.icons.filled.Warning
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Badge
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
@@ -46,6 +47,7 @@ import androidx.compose.material3.IconButtonDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
@@ -165,6 +167,32 @@ fun MqttTopicViewerScreen(
|
||||
val isConnected = effectiveState == MqttConnectionState.CONNECTED
|
||||
val isConnecting = effectiveState == MqttConnectionState.CONNECTING
|
||||
|
||||
// Disconnecting drops live V2X data and any running log until the OBU is connected again, and
|
||||
// the icon sits next to the map button, so a stray tap must not do it. Connecting needs no
|
||||
// confirmation: it cannot lose anything.
|
||||
var confirmDisconnect by rememberSaveable { mutableStateOf(false) }
|
||||
if (confirmDisconnect) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { confirmDisconnect = false },
|
||||
title = { Text(stringResource(R.string.mqtt_disconnect_confirm_title)) },
|
||||
text = { Text(stringResource(R.string.mqtt_disconnect_confirm_text)) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
confirmDisconnect = false
|
||||
// Route to whichever transport this hardware actually uses.
|
||||
if (isEsp32) viewModel.disconnectEsp32() else viewModel.disconnect()
|
||||
}) {
|
||||
Text(stringResource(R.string.mqtt_disconnect), color = MaterialTheme.colorScheme.error)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { confirmDisconnect = false }) {
|
||||
Text(stringResource(R.string.log_cancel))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
|
||||
// ── Inline header — replaces the removed inner TopAppBar ──────────────
|
||||
@@ -214,13 +242,9 @@ fun MqttTopicViewerScreen(
|
||||
Spacer(Modifier.width(2.dp))
|
||||
IconButton(
|
||||
onClick = {
|
||||
// Route to whichever transport this hardware actually uses.
|
||||
if (isEsp32) {
|
||||
if (isConnected || isConnecting) viewModel.disconnectEsp32()
|
||||
else viewModel.connectEsp32()
|
||||
} else {
|
||||
if (isConnected || isConnecting) viewModel.disconnect() else viewModel.connect()
|
||||
}
|
||||
if (isConnected || isConnecting) confirmDisconnect = true
|
||||
else if (isEsp32) viewModel.connectEsp32()
|
||||
else viewModel.connect()
|
||||
},
|
||||
colors = IconButtonDefaults.iconButtonColors(
|
||||
contentColor = if (isConnected) ErrorRed else ConnectedGreen,
|
||||
|
||||
Reference in New Issue
Block a user