Skip to content

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: implement collapsible connector cards with persistent enable switches for improved UI organization closes #20

Rishabh Bajpaie69fe2dfa84d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bcb78e6..06c56e8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,20 @@ All notable changes to Gotcha are documented here.
## [Unreleased]
+### Added — Collapsible Connectors cards (#20)
+
+- **Connector cards collapse by default.** The Connectors screen now shows one
+ compact row per connector — title, live status line, and (once connected) the
+ enable switch — with the setup steps, credential fields and buttons hidden
+ until the row is tapped. Each card expands independently via a rotating
+ chevron on its header.
+- **Enable switch stays reachable.** Toggling a connector on/off no longer
+ requires expanding its card; the switch lives on the always-visible header
+ once connected. The expanded body keeps the explanatory copy and Disconnect.
+- **Connect affordance hint.** A disconnected connector's status reads
+ "Not connected — tap to set up" so it is clear the header opens the setup.
+ "Reconnect needed" OAuth states keep their fuller message.
+
### Added — Scaled Samosa credit display (#19)
- **Remaining credit shown, never the raw value.** The AI Config and Speech
diff --git a/app/src/main/java/com/gotcha/ui/ConnectorCards.kt b/app/src/main/java/com/gotcha/ui/ConnectorCards.kt
index 20b7762..40a63db 100644
--- a/app/src/main/java/com/gotcha/ui/ConnectorCards.kt
+++ b/app/src/main/java/com/gotcha/ui/ConnectorCards.kt
@@ -1,11 +1,18 @@
package com.gotcha.ui
+import androidx.compose.animation.AnimatedVisibility
+import androidx.compose.animation.core.animateFloatAsState
+import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material3.Button
+import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
@@ -21,6 +28,10 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
@@ -37,20 +48,58 @@ import kotlinx.coroutines.launch
* [OAuthConnectorCard] — client credentials plus the loopback consent flow and
* its paste-URL fallback, for BYO-OAuth connectors (Google, Microsoft).
*
+ * Both cards are **collapsed by default**: a compact header row shows the
+ * title, the live status line and (once connected) the enable switch, and the
+ * body — blurb, setup steps, fields and buttons — only appears when the header
+ * is tapped. Each card expands independently.
+ *
* Connectors own their own credential storage, so these talk to the connector
* objects directly — there is nothing for SettingsRepository to persist.
*/
-/** Title + live status line + explanatory blurb and numbered setup steps. */
+/**
+ * The always-visible header row of a connector card: title, live status line,
+ * the enable switch (kept reachable without expanding), and a chevron that
+ * rotates to point up when the body is expanded. Tapping anywhere except the
+ * switch toggles the body.
+ */
@Composable
-private fun CardHeader(title: String, status: String, blurb: String?, steps: List<String>) {
- Text(title, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Medium)
- Text(status, style = MaterialTheme.typography.bodyMedium)
- if (blurb != null) Text(blurb, style = MaterialTheme.typography.bodySmall)
- if (steps.isNotEmpty()) {
- Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
- steps.forEach { Text(it, style = MaterialTheme.typography.bodySmall) }
+private fun ConnectorHeader(
+ title: String,
+ status: String,
+ expanded: Boolean,
+ onToggle: () -> Unit,
+ showSwitch: Boolean,
+ enabled: Boolean,
+ onEnabledChange: (Boolean) -> Unit,
+ headerTestTag: String
+) {
+ val rotation by animateFloatAsState(if (expanded) 180f else 0f)
+ Row(
+ verticalAlignment = Alignment.CenterVertically,
+ modifier = Modifier
+ .fillMaxWidth()
+ .clickable(onClick = onToggle)
+ .padding(vertical = 4.dp)
+ .testTag(headerTestTag)
+ ) {
+ Column(modifier = Modifier.weight(1f)) {
+ Text(title, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Medium)
+ Text(status, style = MaterialTheme.typography.bodySmall)
}
+ if (showSwitch) {
+ Switch(
+ checked = enabled,
+ onCheckedChange = onEnabledChange,
+ modifier = Modifier.semantics { contentDescription = "Enable $title" }
+ )
+ }
+ Icon(
+ imageVector = Icons.Filled.KeyboardArrowDown,
+ contentDescription = if (expanded) "Collapse $title" else "Expand $title",
+ tint = MaterialTheme.colorScheme.onSurfaceVariant,
+ modifier = Modifier.graphicsLayer { rotationZ = rotation }
+ )
}
}
@@ -58,9 +107,17 @@ private fun CardHeader(title: String, status: String, blurb: String?, steps: Lis
* The enable/disable switch, shown only once a connector is connected. Distinct
* from Disconnect: switching off keeps the credentials (re-enabling needs no
* re-auth) but withholds the connector's tools and skills from the assistant.
+ *
+ * [showSwitch] lets the expanded body keep the explanatory copy without
+ * duplicating the switch itself — the switch already lives in the always-visible
+ * header row so it stays reachable while the card is collapsed.
*/
@Composable
-private fun EnabledRow(enabled: Boolean, onEnabledChange: (Boolean) -> Unit) {
+private fun EnabledRow(
+ enabled: Boolean,
+ onEnabledChange: (Boolean) -> Unit,
+ showSwitch: Boolean = true
+) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
@@ -77,10 +134,17 @@ private fun EnabledRow(enabled: Boolean, onEnabledChange: (Boolean) -> Unit) {
style = MaterialTheme.typography.bodySmall
)
}
- Switch(checked = enabled, onCheckedChange = onEnabledChange)
+ if (showSwitch) Switch(checked = enabled, onCheckedChange = onEnabledChange)
}
}
+/**
+ * The status line a collapsed card shows for a connector that has no saved
+ * credentials yet — the "tap to set up" affordance hint.
+ */
+private fun disconnectedHint(status: String): String =
+ if (status == "Not connected") "Not connected — tap to set up" else status
+
@Composable
fun TokenConnectorCard(
title: String,
@@ -98,59 +162,86 @@ fun TokenConnectorCard(
steps: List<String> = emptyList(),
canConnect: () -> Boolean = { fields.all { it.value.isNotBlank() } },
/** Rendered between the fields and the Connect button (e.g. the Gmail preset shortcut). */
- belowFields: @Composable () -> Unit = {}
+ belowFields: @Composable () -> Unit = {},
+ /** Test tag for the always-visible header row. */
+ headerTestTag: String = "connector_header_$title"
) {
val scope = rememberCoroutineScope()
// Bumped after connect/disconnect so statusLine() is re-read.
var refreshTick by remember { mutableStateOf(0) }
var busy by remember { mutableStateOf(false) }
var status by remember { mutableStateOf("") }
+ var expanded by remember { mutableStateOf(false) }
+
+ val connected = isConnected()
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
- key(refreshTick) { CardHeader(title, statusLine(), blurb, steps) }
+ key(refreshTick) {
+ ConnectorHeader(
+ title = title,
+ status = if (connected) statusLine() else disconnectedHint(statusLine()),
+ expanded = expanded,
+ onToggle = { expanded = !expanded },
+ showSwitch = connected && onEnabledChange != null,
+ enabled = enabled,
+ onEnabledChange = { onEnabledChange?.invoke(it) },
+ headerTestTag = headerTestTag
+ )
+ }
- if (!isConnected()) {
- fields.forEach { field ->
- OutlinedTextField(
- value = field.value,
- onValueChange = { field.value = it },
- label = { Text(field.label) },
- singleLine = true,
- visualTransformation = if (field.secret) {
- PasswordVisualTransformation()
- } else {
- androidx.compose.ui.text.input.VisualTransformation.None
- },
- keyboardOptions = KeyboardOptions(keyboardType = field.keyboard),
- modifier = Modifier.fillMaxWidth()
- )
- }
- belowFields()
- Button(
- onClick = {
- busy = true
- scope.launch {
- status = onConnect()
- busy = false
- refreshTick++
+ if (status.isNotBlank()) Text(status, style = MaterialTheme.typography.bodySmall)
+
+ AnimatedVisibility(visible = expanded) {
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ if (!connected) {
+ if (blurb != null) Text(blurb, style = MaterialTheme.typography.bodySmall)
+ if (steps.isNotEmpty()) {
+ Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
+ steps.forEach { Text(it, style = MaterialTheme.typography.bodySmall) }
+ }
}
- },
- enabled = !busy && canConnect(),
- modifier = Modifier.fillMaxWidth()
- ) { Text(if (busy) "Connecting…" else "Connect") }
- } else {
- if (onEnabledChange != null) EnabledRow(enabled, onEnabledChange)
- OutlinedButton(
- onClick = {
- onDisconnect()
- fields.filter { it.secret }.forEach { it.value = "" }
- status = "Disconnected."
- refreshTick++
- },
- modifier = Modifier.fillMaxWidth()
- ) { Text("Disconnect") }
+ fields.forEach { field ->
+ OutlinedTextField(
+ value = field.value,
+ onValueChange = { field.value = it },
+ label = { Text(field.label) },
+ singleLine = true,
+ visualTransformation = if (field.secret) {
+ PasswordVisualTransformation()
+ } else {
+ androidx.compose.ui.text.input.VisualTransformation.None
+ },
+ keyboardOptions = KeyboardOptions(keyboardType = field.keyboard),
+ modifier = Modifier.fillMaxWidth()
+ )
+ }
+ belowFields()
+ Button(
+ onClick = {
+ busy = true
+ scope.launch {
+ status = onConnect()
+ busy = false
+ refreshTick++
+ }
+ },
+ enabled = !busy && canConnect(),
+ modifier = Modifier.fillMaxWidth()
+ ) { Text(if (busy) "Connecting…" else "Connect") }
+ } else {
+ if (onEnabledChange != null) EnabledRow(enabled, onEnabledChange, showSwitch = false)
+ OutlinedButton(
+ onClick = {
+ onDisconnect()
+ fields.filter { it.secret }.forEach { it.value = "" }
+ status = "Disconnected."
+ refreshTick++
+ },
+ modifier = Modifier.fillMaxWidth()
+ ) { Text("Disconnect") }
+ }
+ }
}
- if (status.isNotBlank()) Text(status, style = MaterialTheme.typography.bodySmall)
}
}
@@ -171,7 +262,9 @@ fun OAuthConnectorCard(
onEnabledChange: ((Boolean) -> Unit)? = null,
blurb: String? = null,
steps: List<String> = emptyList(),
- extraFields: @Composable () -> Unit = {}
+ extraFields: @Composable () -> Unit = {},
+ /** Test tag for the always-visible header row. */
+ headerTestTag: String = "connector_header_$title"
) {
val scope = rememberCoroutineScope()
var refreshTick by remember { mutableStateOf(0) }
@@ -181,6 +274,7 @@ fun OAuthConnectorCard(
var showPasteFallback by remember { mutableStateOf(false) }
var busy by remember { mutableStateOf(false) }
var status by remember { mutableStateOf("") }
+ var expanded by remember { mutableStateOf(false) }
val usesSecret = initialClientSecret != null
fun apply(outcome: OAuthConnectFlow.Outcome) {
@@ -192,86 +286,110 @@ fun OAuthConnectorCard(
refreshTick++
}
- Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
- key(refreshTick) { CardHeader(title, statusLine(), blurb, steps) }
+ val connected = isConnected()
- if (!isConnected() || needsReconnect()) {
- OutlinedTextField(
- value = clientId,
- onValueChange = { clientId = it },
- label = { Text("Client ID") },
- singleLine = true,
- modifier = Modifier.fillMaxWidth()
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ key(refreshTick) {
+ ConnectorHeader(
+ title = title,
+ status = if (connected) statusLine() else disconnectedHint(statusLine()),
+ expanded = expanded,
+ onToggle = { expanded = !expanded },
+ showSwitch = connected && onEnabledChange != null,
+ enabled = enabled,
+ onEnabledChange = { onEnabledChange?.invoke(it) },
+ headerTestTag = headerTestTag
)
- if (usesSecret) {
- OutlinedTextField(
- value = clientSecret,
- onValueChange = { clientSecret = it },
- label = { Text("Client secret") },
- singleLine = true,
- visualTransformation = PasswordVisualTransformation(),
- modifier = Modifier.fillMaxWidth()
- )
- }
- extraFields()
- Button(
- onClick = {
- busy = true
- status = "Opening sign-in…"
- scope.launch {
- apply(flow.connect(clientId, clientSecret.takeIf { usesSecret }))
+ }
+
+ if (status.isNotBlank()) Text(status, style = MaterialTheme.typography.bodySmall)
+
+ AnimatedVisibility(visible = expanded) {
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ if (!connected || needsReconnect()) {
+ if (blurb != null) Text(blurb, style = MaterialTheme.typography.bodySmall)
+ if (steps.isNotEmpty()) {
+ Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
+ steps.forEach { Text(it, style = MaterialTheme.typography.bodySmall) }
+ }
}
- },
- enabled = !busy && clientId.isNotBlank() && (!usesSecret || clientSecret.isNotBlank()),
- modifier = Modifier.fillMaxWidth()
- ) { Text(if (busy) "Waiting for sign-in…" else "Connect") }
+ OutlinedTextField(
+ value = clientId,
+ onValueChange = { clientId = it },
+ label = { Text("Client ID") },
+ singleLine = true,
+ modifier = Modifier.fillMaxWidth()
+ )
+ if (usesSecret) {
+ OutlinedTextField(
+ value = clientSecret,
+ onValueChange = { clientSecret = it },
+ label = { Text("Client secret") },
+ singleLine = true,
+ visualTransformation = PasswordVisualTransformation(),
+ modifier = Modifier.fillMaxWidth()
+ )
+ }
+ extraFields()
+ Button(
+ onClick = {
+ busy = true
+ status = "Opening sign-in…"
+ scope.launch {
+ apply(flow.connect(clientId, clientSecret.takeIf { usesSecret }))
+ }
+ },
+ enabled = !busy && clientId.isNotBlank() && (!usesSecret || clientSecret.isNotBlank()),
+ modifier = Modifier.fillMaxWidth()
+ ) { Text(if (busy) "Waiting for sign-in…" else "Connect") }
- TextButton(onClick = { showPasteFallback = !showPasteFallback }) {
- Text(
+ TextButton(onClick = { showPasteFallback = !showPasteFallback }) {
+ Text(
+ if (showPasteFallback) {
+ "Hide paste-URL fallback"
+ } else {
+ "Browser didn't return? Paste redirect URL"
+ }
+ )
+ }
if (showPasteFallback) {
- "Hide paste-URL fallback"
- } else {
- "Browser didn't return? Paste redirect URL"
+ OutlinedTextField(
+ value = pastedUrl,
+ onValueChange = { pastedUrl = it },
+ label = { Text("Pasted redirect URL") },
+ singleLine = true,
+ modifier = Modifier.fillMaxWidth()
+ )
+ Button(
+ onClick = {
+ busy = true
+ scope.launch {
+ apply(
+ flow.connectWithPastedUrl(
+ clientId,
+ clientSecret.takeIf { usesSecret },
+ pastedUrl
+ )
+ )
+ }
+ },
+ enabled = !busy && pastedUrl.isNotBlank(),
+ modifier = Modifier.fillMaxWidth()
+ ) { Text("Finish sign-in with pasted URL") }
}
- )
- }
- if (showPasteFallback) {
- OutlinedTextField(
- value = pastedUrl,
- onValueChange = { pastedUrl = it },
- label = { Text("Pasted redirect URL") },
- singleLine = true,
- modifier = Modifier.fillMaxWidth()
- )
- Button(
- onClick = {
- busy = true
- scope.launch {
- apply(
- flow.connectWithPastedUrl(
- clientId,
- clientSecret.takeIf { usesSecret },
- pastedUrl
- )
- )
- }
- },
- enabled = !busy && pastedUrl.isNotBlank(),
- modifier = Modifier.fillMaxWidth()
- ) { Text("Finish sign-in with pasted URL") }
+ } else {
+ if (onEnabledChange != null) EnabledRow(enabled, onEnabledChange, showSwitch = false)
+ OutlinedButton(
+ onClick = {
+ onDisconnect()
+ clientSecret = ""
+ status = "Disconnected."
+ refreshTick++
+ },
+ modifier = Modifier.fillMaxWidth()
+ ) { Text("Disconnect") }
+ }
}
- } else {
- if (onEnabledChange != null) EnabledRow(enabled, onEnabledChange)
- OutlinedButton(
- onClick = {
- onDisconnect()
- clientSecret = ""
- status = "Disconnected."
- refreshTick++
- },
- modifier = Modifier.fillMaxWidth()
- ) { Text("Disconnect") }
}
- if (status.isNotBlank()) Text(status, style = MaterialTheme.typography.bodySmall)
}
}
diff --git a/app/src/main/java/com/gotcha/ui/ConnectorsSection.kt b/app/src/main/java/com/gotcha/ui/ConnectorsSection.kt
index cf9c54a..1d64ab8 100644
--- a/app/src/main/java/com/gotcha/ui/ConnectorsSection.kt
+++ b/app/src/main/java/com/gotcha/ui/ConnectorsSection.kt
@@ -81,6 +81,7 @@ private fun NotionCard(
statusLine = notion::statusLine,
isConnected = notion::isConnected,
fields = listOf(token),
+ headerTestTag = "connector_header_notion",
blurb = "Search, read and write Notion pages using an internal integration in your own " +
"workspace — no OAuth app to register.",
steps = listOf(
@@ -117,6 +118,7 @@ private fun ImapCard(
statusLine = imap::statusLine,
isConnected = imap::isConnected,
fields = fields,
+ headerTestTag = "connector_header_imap",
steps = listOf(
"Needs an app password, not your regular password. Requires " +
"2-Step Verification to be enabled first.",
@@ -189,6 +191,7 @@ private fun GoogleCard(
initialClientId = google.credentials()?.clientId ?: "",
initialClientSecret = google.credentials()?.clientSecret ?: "",
flow = flow,
+ headerTestTag = "connector_header_google",
onDisconnect = google::disconnect,
enabled = enabled,
onEnabledChange = onEnabledChange,
@@ -250,6 +253,7 @@ private fun MicrosoftCard(
// Public client — PKCE only, so there is no secret to paste.
initialClientSecret = null,
flow = flow,
+ headerTestTag = "connector_header_microsoft",
onDisconnect = microsoft::disconnect,
enabled = enabled,
onEnabledChange = onEnabledChange,