From d0fcb45a5593f0e56b7b37072adb651cc78d635d Mon Sep 17 00:00:00 2001 From: Ashin Walpola Date: Tue, 20 Oct 2026 17:33:38 +0200 Subject: [PATCH] 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. --- .../ui/screens/MqttTopicViewerScreen.kt | 38 +++++++++++++++---- app/src/main/res/values-de/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/hawhamburg/micr0bu/ui/screens/MqttTopicViewerScreen.kt b/app/src/main/java/com/hawhamburg/micr0bu/ui/screens/MqttTopicViewerScreen.kt index e33ed6d..9d1ac5c 100644 --- a/app/src/main/java/com/hawhamburg/micr0bu/ui/screens/MqttTopicViewerScreen.kt +++ b/app/src/main/java/com/hawhamburg/micr0bu/ui/screens/MqttTopicViewerScreen.kt @@ -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, diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 6edeb00..1aeb492 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -356,4 +356,6 @@ V2X-Log teilen Log löschen? %1$s wird dauerhaft vom Gerät entfernt. + OBU trennen? + Die V2X-Livedaten stoppen, und ein laufendes V2X-Log erhält nichts, bis du wieder verbindest. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2b0930e..877da38 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -363,4 +363,6 @@ Share V2X log Delete log? This permanently removes %1$s from the device. + Disconnect the OBU? + Live V2X data stops, and a running V2X log gets nothing, until you connect again.