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.NotificationsActive
|
||||||
import androidx.compose.material.icons.filled.VerticalAlignBottom
|
import androidx.compose.material.icons.filled.VerticalAlignBottom
|
||||||
import androidx.compose.material.icons.filled.Warning
|
import androidx.compose.material.icons.filled.Warning
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Badge
|
import androidx.compose.material3.Badge
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
@@ -46,6 +47,7 @@ import androidx.compose.material3.IconButtonDefaults
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
@@ -165,6 +167,32 @@ fun MqttTopicViewerScreen(
|
|||||||
val isConnected = effectiveState == MqttConnectionState.CONNECTED
|
val isConnected = effectiveState == MqttConnectionState.CONNECTED
|
||||||
val isConnecting = effectiveState == MqttConnectionState.CONNECTING
|
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()) {
|
Column(modifier = Modifier.fillMaxSize()) {
|
||||||
|
|
||||||
// ── Inline header — replaces the removed inner TopAppBar ──────────────
|
// ── Inline header — replaces the removed inner TopAppBar ──────────────
|
||||||
@@ -214,13 +242,9 @@ fun MqttTopicViewerScreen(
|
|||||||
Spacer(Modifier.width(2.dp))
|
Spacer(Modifier.width(2.dp))
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
// Route to whichever transport this hardware actually uses.
|
if (isConnected || isConnecting) confirmDisconnect = true
|
||||||
if (isEsp32) {
|
else if (isEsp32) viewModel.connectEsp32()
|
||||||
if (isConnected || isConnecting) viewModel.disconnectEsp32()
|
else viewModel.connect()
|
||||||
else viewModel.connectEsp32()
|
|
||||||
} else {
|
|
||||||
if (isConnected || isConnecting) viewModel.disconnect() else viewModel.connect()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
colors = IconButtonDefaults.iconButtonColors(
|
colors = IconButtonDefaults.iconButtonColors(
|
||||||
contentColor = if (isConnected) ErrorRed else ConnectedGreen,
|
contentColor = if (isConnected) ErrorRed else ConnectedGreen,
|
||||||
|
|||||||
@@ -356,4 +356,6 @@
|
|||||||
<string name="v2xlog_share_chooser">V2X-Log teilen</string>
|
<string name="v2xlog_share_chooser">V2X-Log teilen</string>
|
||||||
<string name="v2xlog_delete_title">Log löschen?</string>
|
<string name="v2xlog_delete_title">Log löschen?</string>
|
||||||
<string name="v2xlog_delete_text">%1$s wird dauerhaft vom Gerät entfernt.</string>
|
<string name="v2xlog_delete_text">%1$s wird dauerhaft vom Gerät entfernt.</string>
|
||||||
|
<string name="mqtt_disconnect_confirm_title">OBU trennen?</string>
|
||||||
|
<string name="mqtt_disconnect_confirm_text">Die V2X-Livedaten stoppen, und ein laufendes V2X-Log erhält nichts, bis du wieder verbindest.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -363,4 +363,6 @@
|
|||||||
<string name="v2xlog_share_chooser">Share V2X log</string>
|
<string name="v2xlog_share_chooser">Share V2X log</string>
|
||||||
<string name="v2xlog_delete_title">Delete log?</string>
|
<string name="v2xlog_delete_title">Delete log?</string>
|
||||||
<string name="v2xlog_delete_text">This permanently removes %1$s from the device.</string>
|
<string name="v2xlog_delete_text">This permanently removes %1$s from the device.</string>
|
||||||
|
<string name="mqtt_disconnect_confirm_title">Disconnect the OBU?</string>
|
||||||
|
<string name="mqtt_disconnect_confirm_text">Live V2X data stops, and a running V2X log gets nothing, until you connect again.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user