Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
feat(settings): add transient overlay for connection test feedback
Durganshu Mishrac31cbbc9e705
diff --git a/RUNNING.md b/RUNNING.mdindex 806efbb..c64626c 100644--- a/RUNNING.md+++ b/RUNNING.md@@ -103,8 +103,9 @@ The app calls `POST {baseUrl}chat/completions`, so the Base URL must be the part> need to enable cleartext traffic (see Troubleshooting).### Verify the connection-1. Tap **Test connection**. It sends a cheap "ping" request and shows- `✓ Connected: …` on success or the error on failure.+1. Tap **Test connection**. It sends a cheap "ping" request and shows a centred+ overlay — `Testing connection…` while it runs, then `✓ Connected: …` on+ success or the error on failure, which fades out after ~2.5 s.2. Tap **Save**. Then **← Back** to reach the chat screen. Chat input staysdisabled until a key is saved.diff --git a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt b/app/src/main/java/com/gotcha/ui/SettingsScreen.ktindex d80fdb1..8b86178 100644--- a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt+++ b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt@@ -1,8 +1,11 @@package com.gotcha.uiimport androidx.compose.animation.AnimatedVisibility+import androidx.compose.animation.fadeIn+import androidx.compose.animation.fadeOutimport androidx.compose.foundation.clickableimport androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.fillMaxSize@@ -24,6 +27,7 @@ import androidx.compose.material3.Scaffoldimport androidx.compose.material3.SegmentedButtonimport androidx.compose.material3.SegmentedButtonDefaultsimport androidx.compose.material3.SingleChoiceSegmentedButtonRow+import androidx.compose.material3.Surfaceimport androidx.compose.material3.Switchimport androidx.compose.material3.Textimport androidx.compose.material3.TextButton@@ -42,14 +46,25 @@ import androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.text.input.KeyboardTypeimport androidx.compose.ui.text.input.PasswordVisualTransformationimport androidx.compose.ui.text.input.VisualTransformation+import androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.unit.dpimport com.gotcha.audio.AudioModelimport com.gotcha.audio.AudioProviderimport com.gotcha.data.LlmProviderimport com.gotcha.data.Settingsimport com.gotcha.data.ThemeMode+import kotlinx.coroutines.delayimport kotlinx.coroutines.launch+/**+ * A transient message shown as a centred overlay on top of the settings content.+ * [sticky] messages stay until replaced (used while an operation is still running).+ */+private data class SettingsOverlay(val text: String, val sticky: Boolean = false)++/** How long a non-sticky overlay message stays on screen. */+private const val OVERLAY_DURATION_MS = 2500L+@OptIn(ExperimentalMaterial3Api::class)@Composablefun SettingsScreen(@@ -120,6 +135,7 @@ fun SettingsScreen(var showTtsKey by remember { mutableStateOf(false) }var showSttKey by remember { mutableStateOf(false) }var status by remember { mutableStateOf<String?>(null) }+ var overlay by remember { mutableStateOf<SettingsOverlay?>(null) }var testing by remember { mutableStateOf(false) }var refreshingModels by remember { mutableStateOf(false) }var refreshingChatModels by remember { mutableStateOf(false) }@@ -219,6 +235,17 @@ fun SettingsScreen(}}+ // Auto-dismiss transient overlay messages. Each assignment creates a new+ // SettingsOverlay instance, so repeating the same text restarts the timer.+ LaunchedEffect(overlay) {+ overlay?.let {+ if (!it.sticky) {+ delay(OVERLAY_DURATION_MS)+ overlay = null+ }+ }+ }+Scaffold(topBar = {TopAppBar(@@ -227,10 +254,10 @@ fun SettingsScreen()}) { padding ->+ Box(modifier = Modifier.fillMaxSize().padding(padding)) {Column(modifier = Modifier.fillMaxSize()- .padding(padding).padding(16.dp).verticalScroll(rememberScrollState()),verticalArrangement = Arrangement.spacedBy(12.dp)@@ -559,12 +586,17 @@ fun SettingsScreen(OutlinedButton(onClick = {testing = true- status = "Testing connection…"+ // Sticky while the request is in flight, then the result+ // replaces it and fades out on its own.+ overlay = SettingsOverlay("Testing connection…", sticky = true)+ status = nullscope.launch {val result = onTestConnection(currentSettings())- status = result.fold(- onSuccess = { "✓ Connected: $it" },- onFailure = { "✗ Connection failed: ${it.message}" }+ overlay = SettingsOverlay(+ result.fold(+ onSuccess = { "✓ Connected: $it" },+ onFailure = { "✗ Connection failed: ${it.message}" }+ ))testing = false}@@ -1109,6 +1141,42 @@ fun SettingsScreen(style = MaterialTheme.typography.bodySmall)}++ OverlayMessage(message = overlay, modifier = Modifier.align(Alignment.Center))+ } // Box+ }+}++/**+ * Centred, non-interactive toast-style overlay used for transient feedback+ * (e.g. connection test progress and result).+ */+@Composable+private fun OverlayMessage(message: SettingsOverlay?, modifier: Modifier = Modifier) {+ // Keep the last text around so it stays readable through the fade-out.+ var lastText by remember { mutableStateOf("") }+ message?.let { lastText = it.text }+ AnimatedVisibility(+ visible = message != null,+ enter = fadeIn(),+ exit = fadeOut(),+ modifier = modifier+ ) {+ Surface(+ shape = MaterialTheme.shapes.medium,+ color = MaterialTheme.colorScheme.inverseSurface,+ contentColor = MaterialTheme.colorScheme.inverseOnSurface,+ tonalElevation = 6.dp,+ shadowElevation = 6.dp,+ modifier = Modifier.padding(32.dp).testTag("settings_overlay")+ ) {+ Text(+ text = lastText,+ style = MaterialTheme.typography.bodyLarge,+ textAlign = TextAlign.Center,+ modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp)+ )+ }}}