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(settings): search opens the page on the matched field (#92)

Durganshub6e4071853ba
diff --git a/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt b/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt
index 0d5639d..0e440f2 100644
--- a/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt
+++ b/app/src/androidTest/java/com/gotcha/SettingsFlowTest.kt
@@ -1,5 +1,9 @@
package com.gotcha
+import androidx.compose.ui.test.SemanticsMatcher
+import androidx.compose.ui.test.assert
+import androidx.compose.ui.test.assertCountEquals
+import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createEmptyComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
@@ -11,6 +15,7 @@ import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.gotcha.data.SettingsRepository
import com.gotcha.i18n.Language
+import com.gotcha.ui.SettingsHighlighted
import com.gotcha.testutil.TestSeed
import org.junit.After
import org.junit.Assert.assertEquals
@@ -253,4 +258,78 @@ class SettingsFlowTest {
composeRule.waitForIdle()
composeRule.onNodeWithText("Max tool rounds").performScrollTo().assertExists()
}
+
+ @Test
+ fun settingsSearch_opensOnTheMatchedFieldInsideACollapsedSection() {
+ val context = ApplicationProvider.getApplicationContext<android.content.Context>()
+ TestSeed.seedUnconfigured(context)
+
+ scenario = ActivityScenario.launch(MainActivity::class.java)
+ composeRule.waitForIdle()
+
+ composeRule.onNodeWithTag("settings_back").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("settings_back").performClick()
+ composeRule.waitForIdle()
+
+ // The result says where it will land, down to the field.
+ composeRule.onNodeWithTag("settings_search").performTextReplacement("max tool rounds")
+ composeRule.waitForIdle()
+ composeRule.onNodeWithText("AI › AI Configuration › Max tool rounds").assertExists()
+
+ // Hold the clock, so the highlight can be caught before it fades.
+ composeRule.mainClock.autoAdvance = false
+ composeRule.onNodeWithTag("settings_ai_config_row").performClick()
+ composeRule.mainClock.advanceTimeBy(HIGHLIGHT_CHECK_MS)
+
+ // Advanced opened by itself, and the field is on screen and marked —
+ // no performScrollTo: the page did the scrolling.
+ composeRule.onNodeWithTag("settings_max_tool_rounds")
+ .assertIsDisplayed()
+ .assert(SemanticsMatcher.expectValue(SettingsHighlighted, true))
+
+ // The tint fades and the highlight is spent; the field stays where it is.
+ composeRule.mainClock.autoAdvance = true
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("settings_max_tool_rounds")
+ .assert(SemanticsMatcher.keyNotDefined(SettingsHighlighted))
+
+ // Back to the hub and in again is an ordinary visit: nothing highlighted,
+ // and Advanced folded as it always starts.
+ composeRule.onNodeWithTag("settings_back").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("settings_ai_config_row").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("settings_max_tool_rounds").assertDoesNotExist()
+ }
+
+ @Test
+ fun settingsSearch_aPagesOwnTitleOpensItWithNothingHighlighted() {
+ val context = ApplicationProvider.getApplicationContext<android.content.Context>()
+ TestSeed.seedUnconfigured(context)
+
+ scenario = ActivityScenario.launch(MainActivity::class.java)
+ composeRule.waitForIdle()
+
+ composeRule.onNodeWithTag("settings_back").performClick()
+ composeRule.waitForIdle()
+ composeRule.onNodeWithTag("settings_back").performClick()
+ composeRule.waitForIdle()
+
+ composeRule.onNodeWithTag("settings_search").performTextReplacement("AI Configuration")
+ composeRule.waitForIdle()
+ composeRule.mainClock.autoAdvance = false
+ composeRule.onNodeWithTag("settings_ai_config_row").performClick()
+ composeRule.mainClock.advanceTimeBy(HIGHLIGHT_CHECK_MS)
+
+ composeRule.onNodeWithTag("settings_model").assertExists()
+ composeRule.onNodeWithTag("settings_max_tool_rounds").assertDoesNotExist()
+ composeRule.onAllNodes(SemanticsMatcher.keyIsDefined(SettingsHighlighted)).assertCountEquals(0)
+ composeRule.mainClock.autoAdvance = true
+ }
+
+ private companion object {
+ /** Long enough for the page to open and scroll, well short of the fade. */
+ const val HIGHLIGHT_CHECK_MS = 700L
+ }
}
diff --git a/app/src/main/assets/app/about-gotcha.md b/app/src/main/assets/app/about-gotcha.md
index f81542c..ab28d2b 100644
--- a/app/src/main/assets/app/about-gotcha.md
+++ b/app/src/main/assets/app/about-gotcha.md
@@ -83,6 +83,12 @@ Everything below is reached from **Settings** in the navigation drawer.
Two more rows sit on the Settings list itself: **Feature Tour**, which replays
the guided setup one step at a time, and **Send Feedback**.
+A search field sits above the Settings list. Typing a control's everyday name
+("max tool rounds", "otp", "wake word") lists the pages that hold it; where the
+words name one control, tapping the result opens its page scrolled to that
+control and briefly highlighted, opening a folded "Advanced settings" section
+if needed.
+
**Connectors are not in Settings.** They live in the navigation drawer next to
Settings, on their own Connectors screen.
diff --git a/app/src/main/java/com/gotcha/MainActivity.kt b/app/src/main/java/com/gotcha/MainActivity.kt
index b8eed2a..05e0dde 100644
--- a/app/src/main/java/com/gotcha/MainActivity.kt
+++ b/app/src/main/java/com/gotcha/MainActivity.kt
@@ -722,6 +722,12 @@ class MainActivity : ComponentActivity() {
var settingsPage by rememberSaveable {
mutableStateOf(if (unconfigured) SettingsPage.AI_CONFIG else null)
}
+ // The field a settings search result opened settingsPage on. Only that
+ // tap sets it; every other way of changing page clears it, so it can't
+ // outlive the visit it was meant for. Deliberately not saveable: after a
+ // rotation the page is back where it was, and a replayed highlight would
+ // point at something the user has already been shown.
+ var settingsHighlight by remember { mutableStateOf<String?>(null) }
var assistiveBallOn by remember { mutableStateOf(initial.assistiveBallEnabled) }
var showFeedbackSheet by remember { mutableStateOf(false) }
var showReferralInviteDialog by remember { mutableStateOf(false) }
@@ -735,6 +741,7 @@ class MainActivity : ComponentActivity() {
val (route, page) = routeForTourPlace(place)
currentRoute = route
settingsPage = page
+ settingsHighlight = null
scope.launch {
if (place == TourPlace.CHAT_DRAWER) drawerState.open() else drawerState.close()
}
@@ -979,7 +986,16 @@ class MainActivity : ComponentActivity() {
onStartTour = { startTour() },
onSendFeedback = { showFeedbackSheet = true },
page = settingsPage,
- onPageChange = { settingsPage = it }
+ onPageChange = {
+ settingsPage = it
+ settingsHighlight = null
+ },
+ highlightField = settingsHighlight,
+ onHighlightConsumed = { settingsHighlight = null },
+ onOpenSearchResult = { page, field ->
+ settingsPage = page
+ settingsHighlight = field
+ }
)
}
Route.INBOX -> {
diff --git a/app/src/main/java/com/gotcha/ui/AiConfigScreen.kt b/app/src/main/java/com/gotcha/ui/AiConfigScreen.kt
index 23b5207..7feb631 100644
--- a/app/src/main/java/com/gotcha/ui/AiConfigScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/AiConfigScreen.kt
@@ -187,6 +187,7 @@ fun AiConfigScreen(
modifier = Modifier
.fillMaxWidth()
.menuAnchor()
+ .settingsField("settings_llm_provider")
.tourAnchor(TourAnchor.AI_PROVIDER)
)
SkinExposedDropdownMenu(
@@ -288,14 +289,14 @@ fun AiConfigScreen(
Text(if (showKey) "Hide" else "Show")
}
},
- modifier = Modifier.fillMaxWidth().testTag("settings_api_key")
+ modifier = Modifier.fillMaxWidth().settingsField("settings_api_key")
)
OutlinedTextField(
value = baseUrl,
onValueChange = { baseUrl = it },
label = { Text("Base URL (OpenAI-compatible)") },
singleLine = true,
- modifier = Modifier.fillMaxWidth().testTag("settings_base_url")
+ modifier = Modifier.fillMaxWidth().settingsField("settings_base_url")
)
}
ExposedDropdownMenuBox(
@@ -312,7 +313,7 @@ fun AiConfigScreen(
label = { Text("Main model") },
placeholder = { Text("(select model)") },
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = modelExpanded) },
- modifier = Modifier.fillMaxWidth().menuAnchor().testTag("settings_model")
+ modifier = Modifier.fillMaxWidth().menuAnchor().settingsField("settings_model")
)
SkinExposedDropdownMenu(
expanded = modelExpanded,
@@ -351,7 +352,7 @@ fun AiConfigScreen(
// Collapsed by default. The fields' state lives at the top of this
// composable and `applyAiConfig` reads it either way, so folding the
// section away never drops an edit or changes what Save writes.
- SettingsAdvancedSection(testTag = "settings_ai_advanced") {
+ SettingsAdvancedSection(testTag = AI_ADVANCED_SECTION) {
ExposedDropdownMenuBox(
expanded = subAgentModelExpanded,
onExpandedChange = {
@@ -454,7 +455,7 @@ fun AiConfigScreen(
label = { Text("Max tool rounds") },
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
- modifier = Modifier.fillMaxWidth()
+ modifier = Modifier.fillMaxWidth().settingsField("settings_max_tool_rounds")
)
OutlinedTextField(
value = maxRepeatedToolCalls,
@@ -494,7 +495,7 @@ fun AiConfigScreen(
label = { Text("API Timeout (seconds, 0 for infinite)") },
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
- modifier = Modifier.fillMaxWidth()
+ modifier = Modifier.fillMaxWidth().settingsField("settings_api_timeout")
)
OutlinedButton(
onClick = {
diff --git a/app/src/main/java/com/gotcha/ui/AssistiveBallScreen.kt b/app/src/main/java/com/gotcha/ui/AssistiveBallScreen.kt
index 37ccc1e..9f890e3 100644
--- a/app/src/main/java/com/gotcha/ui/AssistiveBallScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/AssistiveBallScreen.kt
@@ -187,7 +187,7 @@ fun AssistiveBallScreen(
valueRange = 0f..1f,
modifier = Modifier
.fillMaxWidth()
- .testTag("settings_wake_word_sensitivity")
+ .settingsField("settings_wake_word_sensitivity")
.semantics {
contentDescription = "Wake word sensitivity ${(wakeWordSensitivity * 100).toInt()} percent"
}
diff --git a/app/src/main/java/com/gotcha/ui/LanguageScreen.kt b/app/src/main/java/com/gotcha/ui/LanguageScreen.kt
index 61140fd..7f9ad3b 100644
--- a/app/src/main/java/com/gotcha/ui/LanguageScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/LanguageScreen.kt
@@ -115,7 +115,7 @@ fun LanguageScreen(
onClick = { openLanguageSettings(localContext) },
modifier = Modifier
.fillMaxWidth()
- .testTag("settings_open_app_locale")
+ .settingsField("settings_open_app_locale")
) { Text("Open Android language settings") }
HorizontalDivider(thickness = 1.dp)
@@ -148,7 +148,7 @@ fun LanguageScreen(
modifier = Modifier
.fillMaxWidth()
.menuAnchor()
- .testTag("settings_voice_language")
+ .settingsField("settings_voice_language")
)
SkinExposedDropdownMenu(
expanded = voiceExpanded,
@@ -262,7 +262,7 @@ fun LanguageScreen(
modifier = Modifier
.fillMaxWidth()
.menuAnchor()
- .testTag("settings_reply_language")
+ .settingsField("settings_reply_language")
)
SkinExposedDropdownMenu(
expanded = replyExpanded,
diff --git a/app/src/main/java/com/gotcha/ui/PersonalInfoScreen.kt b/app/src/main/java/com/gotcha/ui/PersonalInfoScreen.kt
index b36848e..dcf37fd 100644
--- a/app/src/main/java/com/gotcha/ui/PersonalInfoScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/PersonalInfoScreen.kt
@@ -98,7 +98,7 @@ fun PersonalInfoScreen(
singleLine = true,
modifier = Modifier
.fillMaxWidth()
- .testTag("settings_user_name")
+ .settingsField("settings_user_name")
.tourAnchor(TourAnchor.PERSONAL_NAME)
)
OutlinedTextField(
@@ -158,7 +158,7 @@ fun PersonalInfoScreen(
minLines = 3,
modifier = Modifier
.fillMaxWidth()
- .testTag("settings_user_response_style")
+ .settingsField("settings_user_response_style")
)
ExposedDropdownMenuBox(
@@ -176,6 +176,7 @@ fun PersonalInfoScreen(
modifier = Modifier
.fillMaxWidth()
.menuAnchor()
+ .settingsField("settings_user_currency")
)
SkinExposedDropdownMenu(
expanded = currencyExpanded,
diff --git a/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt b/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt
index 46e7cf6..a44f70f 100644
--- a/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/ProactiveScreen.kt
@@ -50,18 +50,21 @@ fun ProactiveScreen(
label = "Master Proactive Offers",
checked = proactiveEnabled,
onCheckedChange = { proactiveEnabled = it },
- isLarge = true
+ isLarge = true,
+ switchTestTag = "settings_proactive_enabled"
)
if (proactiveEnabled) {
SettingsToggleRow(
label = "Scan Screen Content",
checked = proactiveScanScreen,
- onCheckedChange = { proactiveScanScreen = it }
+ onCheckedChange = { proactiveScanScreen = it },
+ switchTestTag = "settings_proactive_scan_screen"
)
SettingsToggleRow(
label = "Scan Clipboard",
checked = proactiveScanClipboard,
- onCheckedChange = { proactiveScanClipboard = it }
+ onCheckedChange = { proactiveScanClipboard = it },
+ switchTestTag = "settings_proactive_scan_clipboard"
)
SettingsToggleRow(
label = "Scan Notifications",
@@ -71,7 +74,8 @@ fun ProactiveScreen(
SettingsToggleRow(
label = "Detect OTP / Codes",
checked = proactiveOtpEnabled,
- onCheckedChange = { proactiveOtpEnabled = it }
+ onCheckedChange = { proactiveOtpEnabled = it },
+ switchTestTag = "settings_proactive_otp"
)
SettingsToggleRow(
label = "Auto-Copy OTP to Clipboard",
diff --git a/app/src/main/java/com/gotcha/ui/SettingsCommon.kt b/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
index d483555..94a40b2 100644
--- a/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
+++ b/app/src/main/java/com/gotcha/ui/SettingsCommon.kt
@@ -3,8 +3,11 @@ package com.gotcha.ui
import android.content.Intent
import android.net.Uri
import androidx.compose.animation.AnimatedVisibility
+import androidx.compose.animation.core.Animatable
+import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
+import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -15,6 +18,8 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.relocation.BringIntoViewRequester
+import androidx.compose.foundation.relocation.bringIntoViewRequester
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
@@ -36,16 +41,22 @@ import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.Stable
+import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
+import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.drawBehind
+import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.semantics.SemanticsPropertyKey
+import androidx.compose.ui.semantics.SemanticsPropertyReceiver
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
@@ -761,6 +772,67 @@ fun SamosaAuthSection(
}
}
+/**
+ * The field a settings search result asked the open page to point at (#92),
+ * and how the page says it has done so. [SettingsScreen] provides it; each
+ * field opts in through [settingsField] or [settingsHighlight], so no page
+ * needs a parameter for it.
+ */
+@Stable
+class SettingsHighlight(val field: SettingsField?, val onConsumed: () -> Unit)
+
+val LocalSettingsHighlight = compositionLocalOf { SettingsHighlight(field = null, onConsumed = {}) }
+
+/** Set on a field while a search result is pointing at it — what tests read. */
+val SettingsHighlighted = SemanticsPropertyKey<Boolean>("SettingsHighlighted")
+var SemanticsPropertyReceiver.settingsHighlighted by SettingsHighlighted
+
+private const val HIGHLIGHT_FADE_MS = 1_500
+private const val HIGHLIGHT_ALPHA = 0.24f
+private val HighlightCorner = 8.dp
+
+/**
+ * Makes this node a place a settings search can land: when [tag] is the
+ * highlighted field, it scrolls into view and wears a tint that fades out, then
+ * the highlight is consumed so Back or a rotation can't replay it. Does not tag
+ * the node — see [settingsField] for the usual case.
+ */
+@OptIn(ExperimentalFoundationApi::class)
+@Composable
+fun Modifier.settingsHighlight(tag: String): Modifier {
+ val highlight = LocalSettingsHighlight.current
+ val isTarget = highlight.field?.testTag == tag
+ val requester = remember { BringIntoViewRequester() }
+ val tint = remember { Animatable(0f) }
+ if (isTarget) {
+ LaunchedEffect(highlight) {
+ tint.snapTo(1f)
+ // A frame first, so the field has been laid out — it may sit in a
+ // section that opened in this same composition.
+ withFrameNanos { }
+ requester.bringIntoView()
+ tint.animateTo(0f, tween(HIGHLIGHT_FADE_MS))
+ highlight.onConsumed()
+ }
+ }
+ val color = MaterialTheme.colorScheme.primary
+ return this
+ .bringIntoViewRequester(requester)
+ .semantics { if (isTarget) settingsHighlighted = true }
+ .drawBehind {
+ if (tint.value > 0f) {
+ drawRoundRect(
+ color = color.copy(alpha = HIGHLIGHT_ALPHA * tint.value),
+ cornerRadius = CornerRadius(HighlightCorner.toPx())
+ )
+ }
+ }
+}
+
+/** Tags a settings control and makes it a search landing spot, under one name. */
+@Composable
+fun Modifier.settingsField(tag: String): Modifier = testTag(tag).settingsHighlight(tag)
+
/**
* A collapsed-by-default disclosure for the knobs a page has but most people
* never touch — model overrides, loop limits, timeouts. Keeps them one tap away
@@ -775,6 +847,11 @@ fun SamosaAuthSection(
* a trip to Android Settings doesn't fold the section back up mid-edit. The
* fields inside stay hoisted in the calling screen, so collapsing the section
* never discards what was typed into it.
+ *
+ * A search result pointing at a field inside opens the section on arrival — the
+ * field isn't composed while folded, so there would be nothing to scroll to.
+ * It starts open rather than animating open, so the scroll lands on where the
+ * field will stay, not where it is halfway through the expansion.
*/
@Composable
fun SettingsAdvancedSection(
@@ -782,7 +859,8 @@ fun SettingsAdvancedSection(
title: String = "Advanced settings",
content: @Composable ColumnScope.() -> Unit
) {
- var expanded by rememberSaveable { mutableStateOf(false) }
+ val holdsHighlight = LocalSettingsHighlight.current.field?.section == testTag
+ var expanded by rememberSaveable { mutableStateOf(holdsHighlight) }
Row(
modifier = Modifier
@@ -821,6 +899,9 @@ fun SettingsAdvancedSection(
* for the same reason — it is what a UiAutomator/Maestro flow, which cannot see
* test tags, has to aim at.
*
+ * [switchTestTag] is also the name a settings search result uses for the row;
+ * the whole row is what scrolls into view and tints (see [settingsHighlight]).
+ *
* [enabled] disables the `Switch` (greyed out, no tap effect) for a row whose
* action depends on a prerequisite the user has not met yet; the caller should
* also explain the prerequisite nearby.
@@ -837,7 +918,10 @@ fun SettingsToggleRow(
modifier: Modifier = Modifier
) {
Row(
- modifier = modifier.fillMaxWidth(),
+ modifier = modifier
+ .fillMaxWidth()
+ // The tint covers the label as well as the switch it names.
+ .then(if (switchTestTag != null) Modifier.settingsHighlight(switchTestTag) else Modifier),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
diff --git a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
index 9e6b3b3..8b247a7 100644
--- a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
@@ -17,8 +17,12 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.DisposableEffect
+import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
@@ -32,6 +36,7 @@ import com.gotcha.data.Settings
import com.gotcha.i18n.Language
import com.gotcha.ui.tour.TourAnchor
import com.gotcha.ui.tour.tourAnchor
+import kotlinx.coroutines.delay
/**
* Settings, shaped like the system Settings app: a home list of categories, each
@@ -43,6 +48,9 @@ import com.gotcha.ui.tour.tourAnchor
*
* Every page saves through [onSave]'s mutator, writing only the fields it owns.
*/
+/** How long a search highlight waits for its field before lapsing unshown. */
+private const val HIGHLIGHT_LAPSE_MS = 3_000L
+
@Composable
fun SettingsScreen(
/** Reads the persisted settings. Each page calls it on entry, so a page always
@@ -115,7 +123,17 @@ fun SettingsScreen(
* able to walk them to the next one.
*/
page: SettingsPage? = null,
- onPageChange: (SettingsPage?) -> Unit = {}
+ onPageChange: (SettingsPage?) -> Unit = {},
+ /**
+ * The [SettingsField.testTag] a search result opened [page] on, or null.
+ * Hoisted beside [page] because both change in the one tap; cleared through
+ * [onHighlightConsumed] once the page has shown it, and by the host on any
+ * other page change, so Back never returns to a stale highlight.
+ */
+ highlightField: String? = null,
+ onHighlightConsumed: () -> Unit = {},
+ /** Opens a page from a search result, pointed at the field the query named. */
+ onOpenSearchResult: (SettingsPage, String?) -> Unit = { target, _ -> onPageChange(target) }
) {
// Back leaves the sub-page for whatever it hangs off — its hub if it has one,
// the home list otherwise. Only the list itself exits Settings.
@@ -123,102 +141,123 @@ fun SettingsScreen(
if (page != null) BackHandler(onBack = backToHome)
- when (page) {
- SettingsPage.APPEARANCE -> AppearanceScreen(
- load = load,
- onSave = onSave,
- onBack = backToHome,
- onApply = onAppearanceChange
- )
- SettingsPage.PERSONAL_INFO -> PersonalInfoScreen(
- load = load,
- onSave = onSave,
- onBack = backToHome,
- onOpenLanguage = { onPageChange(SettingsPage.LANGUAGE) }
- )
- SettingsPage.LANGUAGE -> LanguageScreen(
- load = load,
- onSave = onSave,
- onBack = backToHome,
- onTestVoice = onTestVoice
- )
- SettingsPage.AI -> AiHubScreen(
- onBack = backToHome,
- onOpenPage = onPageChange
- )
- SettingsPage.AI_CONFIG -> AiConfigScreen(
- load = load,
- onSave = onSave,
- onBack = backToHome,
- onTestConnection = onTestConnection,
- onRefreshChatModels = onRefreshChatModels,
- onSamosaSignIn = onSamosaSignIn,
- onSamosaSignOut = onSamosaSignOut,
- onFetchSamosaProfile = onFetchSamosaProfile,
- onClaimReferral = onClaimReferral,
- onClearLlmCache = onClearLlmCache,
- onClearDebugScreenshots = onClearDebugScreenshots
- )
- SettingsPage.SPEECH -> SpeechScreen(
- load = load,
- onSave = onSave,
- onBack = backToHome,
- onRefreshAudioModels = onRefreshAudioModels,
- onSamosaSignIn = onSamosaSignIn,
- onSamosaSignOut = onSamosaSignOut,
- onFetchSamosaProfile = onFetchSamosaProfile,
- onClaimReferral = onClaimReferral
- )
- SettingsPage.PERMISSIONS -> PermissionsScreen(
- packageName = packageName,
- onBack = backToHome,
- onOpenTermuxSetup = { onPageChange(SettingsPage.TERMUX) }
- )
- SettingsPage.TERMUX -> TermuxSetupScreen(onBack = backToHome)
- SettingsPage.SKILLS -> SkillsScreen(
- load = load,
- onSave = onSave,
- onBack = backToHome
- )
- SettingsPage.PROACTIVE -> ProactiveScreen(
- load = load,
- onSave = onSave,
- onBack = backToHome
- )
- SettingsPage.ASSISTIVE_BALL -> AssistiveBallScreen(
- load = load,
- onSave = onSave,
- enabled = assistiveBallEnabled,
- onToggle = onToggleAssistiveBall,
- onBack = backToHome
- )
- SettingsPage.NOTIFICATIONS -> NotificationsScreen(
- load = load,
- onSave = onSave,
- onBack = backToHome,
- onSyncServerMessages = onSyncServerMessages
- )
- SettingsPage.ABOUT -> AboutScreen(
- onBack = backToHome,
- onOpenPage = onPageChange
- )
- SettingsPage.ABOUT_SAMOSA -> AboutSamosaScreen(
- context = androidx.compose.ui.platform.LocalContext.current,
- onBack = backToHome
- )
- SettingsPage.LEGAL -> LegalScreen(
- context = androidx.compose.ui.platform.LocalContext.current,
- load = load,
- onSave = onSave,
- onBack = backToHome
- )
- null -> SettingsHome(
- onBack = onBack,
- onOpenPage = onPageChange,
- onStartTour = onStartTour,
- onSendFeedback = onSendFeedback
+ // A field the page never shows — the OTP switch while proactive offers are
+ // off, the API key while Samosa is the provider — has nothing to consume the
+ // highlight, so it lapses on its own rather than waiting for a later visit.
+ LaunchedEffect(page, highlightField) {
+ if (highlightField != null) {
+ delay(HIGHLIGHT_LAPSE_MS)
+ onHighlightConsumed()
+ }
+ }
+ // Leaving Settings altogether ends the visit the highlight belonged to.
+ DisposableEffect(Unit) { onDispose { onHighlightConsumed() } }
+ val highlight = remember(page, highlightField) {
+ SettingsHighlight(
+ field = page?.let { p -> highlightField?.let { settingsFieldFor(p, it) } },
+ onConsumed = onHighlightConsumed
)
}
+
+ CompositionLocalProvider(LocalSettingsHighlight provides highlight) {
+ when (page) {
+ SettingsPage.APPEARANCE -> AppearanceScreen(
+ load = load,
+ onSave = onSave,
+ onBack = backToHome,
+ onApply = onAppearanceChange
+ )
+ SettingsPage.PERSONAL_INFO -> PersonalInfoScreen(
+ load = load,
+ onSave = onSave,
+ onBack = backToHome,
+ onOpenLanguage = { onPageChange(SettingsPage.LANGUAGE) }
+ )
+ SettingsPage.LANGUAGE -> LanguageScreen(
+ load = load,
+ onSave = onSave,
+ onBack = backToHome,
+ onTestVoice = onTestVoice
+ )
+ SettingsPage.AI -> AiHubScreen(
+ onBack = backToHome,
+ onOpenPage = onPageChange
+ )
+ SettingsPage.AI_CONFIG -> AiConfigScreen(
+ load = load,
+ onSave = onSave,
+ onBack = backToHome,
+ onTestConnection = onTestConnection,
+ onRefreshChatModels = onRefreshChatModels,
+ onSamosaSignIn = onSamosaSignIn,
+ onSamosaSignOut = onSamosaSignOut,
+ onFetchSamosaProfile = onFetchSamosaProfile,
+ onClaimReferral = onClaimReferral,
+ onClearLlmCache = onClearLlmCache,
+ onClearDebugScreenshots = onClearDebugScreenshots
+ )
+ SettingsPage.SPEECH -> SpeechScreen(
+ load = load,
+ onSave = onSave,
+ onBack = backToHome,
+ onRefreshAudioModels = onRefreshAudioModels,
+ onSamosaSignIn = onSamosaSignIn,
+ onSamosaSignOut = onSamosaSignOut,
+ onFetchSamosaProfile = onFetchSamosaProfile,
+ onClaimReferral = onClaimReferral
+ )
+ SettingsPage.PERMISSIONS -> PermissionsScreen(
+ packageName = packageName,
+ onBack = backToHome,
+ onOpenTermuxSetup = { onPageChange(SettingsPage.TERMUX) }
+ )
+ SettingsPage.TERMUX -> TermuxSetupScreen(onBack = backToHome)
+ SettingsPage.SKILLS -> SkillsScreen(
+ load = load,
+ onSave = onSave,
+ onBack = backToHome
+ )
+ SettingsPage.PROACTIVE -> ProactiveScreen(
+ load = load,
+ onSave = onSave,
+ onBack = backToHome
+ )
+ SettingsPage.ASSISTIVE_BALL -> AssistiveBallScreen(
+ load = load,
+ onSave = onSave,
+ enabled = assistiveBallEnabled,
+ onToggle = onToggleAssistiveBall,
+ onBack = backToHome
+ )
+ SettingsPage.NOTIFICATIONS -> NotificationsScreen(
+ load = load,
+ onSave = onSave,
+ onBack = backToHome,
+ onSyncServerMessages = onSyncServerMessages
+ )
+ SettingsPage.ABOUT -> AboutScreen(
+ onBack = backToHome,
+ onOpenPage = onPageChange
+ )
+ SettingsPage.ABOUT_SAMOSA -> AboutSamosaScreen(
+ context = androidx.compose.ui.platform.LocalContext.current,
+ onBack = backToHome
+ )
+ SettingsPage.LEGAL -> LegalScreen(
+ context = androidx.compose.ui.platform.LocalContext.current,
+ load = load,
+ onSave = onSave,
+ onBack = backToHome
+ )
+ null -> SettingsHome(
+ onBack = onBack,
+ onOpenPage = onPageChange,
+ onOpenSearchResult = onOpenSearchResult,
+ onStartTour = onStartTour,
+ onSendFeedback = onSendFeedback
+ )
+ }
+ }
}
/**
@@ -234,6 +273,7 @@ fun SettingsScreen(
private fun SettingsHome(
onBack: () -> Unit,
onOpenPage: (SettingsPage) -> Unit,
+ onOpenSearchResult: (SettingsPage, String?) -> Unit,
onStartTour: () -> Unit,
onSendFeedback: () -> Unit
) {
@@ -246,6 +286,10 @@ private fun SettingsHome(
query = ""
onOpenPage(page)
}
+ val openResult = { result: SettingsSearchResult ->
+ query = ""
+ onOpenSearchResult(result.page, result.field?.testTag)
+ }
SettingsScaffold(
title = "Settings",
@@ -260,7 +304,7 @@ private fun SettingsHome(
onSendFeedback = onSendFeedback
)
} else {
- SettingsSearchResults(query = query, onOpenPage = openPage)
+ SettingsSearchResults(query = query, onOpenResult = openResult)
}
}
}
@@ -323,10 +367,11 @@ private fun ColumnScope.SettingsHomeRows(
* Pages matching the query. Rows keep their home-list [SettingsPage.testTag] so
* a result is the same row by every name the tour and the tests know it by; a
* nested page shows its hub in the label instead of a tour anchor it would be
- * spotlighting in the wrong place.
+ * spotlighting in the wrong place, and a result that named one control ends
+ * its label with that control — which is where the page will open.
*/
@Composable
-private fun SettingsSearchResults(query: String, onOpenPage: (SettingsPage) -> Unit) {
+private fun SettingsSearchResults(query: String, onOpenResult: (SettingsSearchResult) -> Unit) {
val results = filterSettings(query)
if (results.isEmpty()) {
Text(
@@ -344,9 +389,9 @@ private fun SettingsSearchResults(query: String, onOpenPage: (SettingsPage) -> U
HorizontalDivider(thickness = 1.dp)
SettingsNavRow(
page = result.page,
- onClick = { onOpenPage(result.page) },
+ onClick = { onOpenResult(result) },
modifier = Modifier.testTag(result.page.testTag),
- title = result.breadcrumb
+ title = result.label
)
}
}
diff --git a/app/src/main/java/com/gotcha/ui/SettingsSearchEntry.kt b/app/src/main/java/com/gotcha/ui/SettingsSearchEntry.kt
index 0730ff1..64aefdd 100644
--- a/app/src/main/java/com/gotcha/ui/SettingsSearchEntry.kt
+++ b/app/src/main/java/com/gotcha/ui/SettingsSearchEntry.kt
@@ -6,16 +6,40 @@ package com.gotcha.ui
* A page's own title and summary are only half of what people type: nobody
* looks for "Assistive Ball and Wake Word" by its title — they type "wake
* word", "api key" or "read aloud", naming a *control* somewhere inside a page.
- * [keywordsFor] carries those aliases, so the index answers for fields that have
- * no row of their own on the home list.
+ * [entryFor] carries those aliases, so the index answers for fields that have
+ * no row of their own on the home list — and, where the alias names one field,
+ * says which, so the page can open on it rather than at the top.
*
* Kept free of Compose so the matching is a plain unit test.
*/
-/** One searchable settings page: the page itself plus the words that find it. */
+/**
+ * One control a search can land on, not just the page it sits in.
+ *
+ * [testTag] is the control's tag on its page: the page scrolls it into view and
+ * tints it briefly (see [settingsHighlight]). [section] is the tag of the
+ * [SettingsAdvancedSection] it is folded inside, if any — the section has to
+ * open before the field exists to scroll to.
+ */
+data class SettingsField(
+ val testTag: String,
+ val label: String,
+ val keywords: List<String> = emptyList(),
+ val section: String? = null
+) {
+ private val haystack: String = (listOf(label) + keywords).joinToString(" ").lowercase()
+
+ internal fun matches(token: String): Boolean = haystack.contains(token)
+}
+
+/**
+ * One searchable settings page: the page itself, the words that find it as a
+ * whole, and the [fields] inside it that a query can point at more precisely.
+ */
data class SettingsSearchEntry(
val page: SettingsPage,
- val keywords: List<String>
+ val keywords: List<String>,
+ val fields: List<SettingsField> = emptyList()
) {
/**
* How the result names itself. A page inside a hub says which hub it is in —
@@ -27,115 +51,201 @@ data class SettingsSearchEntry(
/** Everything this entry matches against, lowercased once at construction. */
private val haystack: String =
- (listOf(page.title, page.summary) + keywords).joinToString(" ").lowercase()
+ (listOf(page.title, page.summary) + keywords + fields.flatMap { listOf(it.label) + it.keywords })
+ .joinToString(" ")
+ .lowercase()
+
+ private val titleWords: Set<String> = wordsOf(page.title)
internal fun matches(token: String): Boolean = haystack.contains(token)
+
+ /**
+ * The field [tokens] name, or null when they name the page itself.
+ *
+ * A query spelling out the page's whole title asks for the page, so it
+ * highlights nothing even when a field would also match ("language" is
+ * not a request for the App language row). Part of a title is fair game:
+ * "wake word" is half of "Assistive Ball and Wake Word" and still means the
+ * switch. Otherwise the first field matching every token wins, in page
+ * order; words spread across the page's aliases and a field find the page
+ * but no one field.
+ */
+ internal fun fieldFor(tokens: List<String>): SettingsField? {
+ if (wordsOf(tokens.joinToString(" ")).containsAll(titleWords)) return null
+ return fields.firstOrNull { field -> tokens.all { field.matches(it) } }
+ }
+}
+
+/** Lowercase words of [text], punctuation dropped: "Speech (TTS / STT)" → speech, tts, stt. */
+private fun wordsOf(text: String): Set<String> =
+ text.lowercase().split(Regex("[^\\p{L}\\p{N}]+")).filter { it.isNotEmpty() }.toSet()
+
+/** A page a query found, and the control inside it the query named, if any. */
+data class SettingsSearchResult(
+ val entry: SettingsSearchEntry,
+ val field: SettingsField?
+) {
+ val page: SettingsPage get() = entry.page
+
+ /** The breadcrumb, carried one step further down when a field matched. */
+ val label: String
+ get() = this.field?.let { "${entry.breadcrumb} › ${it.label}" } ?: entry.breadcrumb
}
/**
- * Keyword lists read as prose here — one comma-separated blob per page — because
+ * Keyword lists read as prose here — one comma-separated blob each — because
* a quoted-string list of forty aliases is a wall nobody rereads.
*/
private fun words(csv: String): List<String> =
csv.split(',').map { it.trim() }.filter { it.isNotEmpty() }
+/** Short form for the index below: tag, label, then the aliases as prose. */
+private fun field(testTag: String, label: String, csv: String = "", section: String? = null) =
+ SettingsField(testTag, label, words(csv), section)
+
/**
- * Aliases for the controls a page owns, in the words people actually type.
+ * Aliases for a page and for the controls it owns, in the words people actually
+ * type. A word that names one control belongs to that control's [field], so a
+ * result can open the page on it; what names the page as a whole ("privacy",
+ * "assistant") stays with the page.
*
* Exhaustive on purpose: a new [SettingsPage] fails to compile here rather than
- * shipping a page that search can't find. An empty list is a fine answer when
- * the title and summary already say everything.
+ * shipping a page that search can't find. No aliases and no fields is a fine
+ * answer when the title and summary already say everything.
*/
-@Suppress("CyclomaticComplexMethod")
-private fun keywordsFor(page: SettingsPage): List<String> = when (page) {
- SettingsPage.PERSONAL_INFO -> words(
- """
- name, currency, reply style, tone, about me, profile
- """
+@Suppress("CyclomaticComplexMethod", "LongMethod")
+private fun entryFor(page: SettingsPage): SettingsSearchEntry = when (page) {
+ SettingsPage.PERSONAL_INFO -> SettingsSearchEntry(
+ page,
+ words("about me, profile"),
+ listOf(
+ field("settings_user_name", "Name"),
+ field("settings_user_response_style", "Reply style", "tone"),
+ field("settings_user_currency", "Preferred currency")
+ )
)
- SettingsPage.LANGUAGE -> words(
- """
- app language, voice language, reply language, translate, locale
- """
+ SettingsPage.LANGUAGE -> SettingsSearchEntry(
+ page,
+ words("translate, locale"),
+ listOf(
+ field("settings_open_app_locale", "App language"),
+ field("settings_voice_language", "Voice language"),
+ field("settings_reply_language", "AI reply language")
+ )
)
- SettingsPage.AI -> words(
- """
- assistant, llm, brain, provider
- """
+ SettingsPage.AI -> SettingsSearchEntry(
+ page,
+ words("assistant, llm, brain, provider")
)
- SettingsPage.AI_CONFIG -> words(
- """
- api key, base url, endpoint, model, provider, max tool rounds,
- agent limits, timeout, samosa sign in, sign in, login, credits, openai,
- temperature
- """
+ SettingsPage.AI_CONFIG -> SettingsSearchEntry(
+ page,
+ words("samosa sign in, sign in, login, credits, temperature"),
+ listOf(
+ field("settings_llm_provider", "LLM provider", "provider, openai, samosa"),
+ field("settings_api_key", "API key"),
+ field("settings_base_url", "Base URL", "endpoint"),
+ field("settings_model", "Main model", "model"),
+ field(
+ "settings_max_tool_rounds",
+ "Max tool rounds",
+ "agent limits",
+ section = AI_ADVANCED_SECTION
+ ),
+ field("settings_api_timeout", "API timeout", "timeout", section = AI_ADVANCED_SECTION)
+ )
)
- SettingsPage.SPEECH -> words(
- """
- tts, stt, voice, transcription, transcribe, read aloud, read replies,
- speak, microphone, kokoro, whisper
- """
+ SettingsPage.SPEECH -> SettingsSearchEntry(
+ page,
+ words("voice, speak, microphone, kokoro, whisper"),
+ listOf(
+ field("settings_tts_provider", "TTS provider", "tts, text to speech"),
+ field(
+ "settings_stt_provider",
+ "STT provider",
+ "stt, transcription, transcribe, speech to text"
+ ),
+ field("settings_auto_read_replies", "Auto-read replies aloud", "read aloud, read replies")
+ )
)
- SettingsPage.PERMISSIONS -> words(
- """
- accessibility, notification access, device admin, root, health connect,
- camera, location, contacts, sms, storage, display over other apps,
- overlay, grant, allow
- """
+ SettingsPage.PERMISSIONS -> SettingsSearchEntry(
+ page,
+ words(
+ """
+ accessibility, notification access, device admin, root, health connect,
+ camera, location, contacts, sms, storage, display over other apps,
+ overlay, grant, allow
+ """
+ )
)
- SettingsPage.TERMUX -> words(
- """
- linux, shell, command, terminal, ffmpeg, package, bash
- """
+ SettingsPage.TERMUX -> SettingsSearchEntry(
+ page,
+ words("linux, shell, command, terminal, ffmpeg, package, bash")
)
- SettingsPage.SKILLS -> words(
- """
- plugin, skill, community, import, mcp
- """
+ SettingsPage.SKILLS -> SettingsSearchEntry(
+ page,
+ words("plugin, skill, community, import, mcp")
)
- SettingsPage.PROACTIVE -> words(
- """
- otp, screen scanning, offers, suggestions, clipboard, privacy
- """
+ SettingsPage.PROACTIVE -> SettingsSearchEntry(
+ page,
+ words("privacy"),
+ listOf(
+ field("settings_proactive_enabled", "Proactive offers", "offers, suggestions"),
+ field("settings_proactive_scan_screen", "Scan screen content", "screen scanning"),
+ field("settings_proactive_scan_clipboard", "Scan clipboard", "clipboard"),
+ field("settings_proactive_otp", "Detect OTP / codes", "otp")
+ )
)
- SettingsPage.ASSISTIVE_BALL -> words(
- """
- wake word, hey gotcha, floating ball, bubble, overlay, hands free,
- hands-free, always listening, sensitivity
- """
+ SettingsPage.ASSISTIVE_BALL -> SettingsSearchEntry(
+ page,
+ words("overlay, hands free, hands-free"),
+ listOf(
+ field("settings_assistive_ball", "Show assistive ball", "floating ball, bubble"),
+ field("settings_wake_word", "Wake word: Hey Gotcha", "always listening"),
+ field("settings_wake_word_sensitivity", "Wake word sensitivity", "sensitivity")
+ )
)
- SettingsPage.APPEARANCE -> words(
- """
- theme, dark mode, light mode, wallpaper, skin, font, colors
- """
+ SettingsPage.APPEARANCE -> SettingsSearchEntry(
+ page,
+ words("theme, dark mode, light mode, wallpaper, skin, font, colors")
)
- SettingsPage.NOTIFICATIONS -> words(
- """
- alerts, sound, vibrate, server messages, announcements, sync,
- daily tip, tips, suggestions, ideas, reminder, reminders, unfinished, routine,
- inactivity, quiet hours, do not disturb, history, inbox, privacy
- """
+ SettingsPage.NOTIFICATIONS -> SettingsSearchEntry(
+ page,
+ words(
+ """
+ alerts, daily tip, tips, suggestions, ideas, reminder, reminders, unfinished,
+ routine, inactivity, quiet hours, do not disturb, history, inbox, privacy
+ """
+ ),
+ listOf(
+ field("settings_notify_vibration", "Vibration", "vibrate"),
+ field("settings_notify_chime", "Chime", "sound"),
+ field("settings_task_finished_enabled", "Notify when a task finishes"),
+ field("settings_server_messages_enabled", "Server messages", "announcements, sync")
+ )
)
- SettingsPage.ABOUT -> words(
- """
- version, contact, support, company, samosa
- """
+ SettingsPage.ABOUT -> SettingsSearchEntry(
+ page,
+ words("version, contact, support, company, samosa")
)
- SettingsPage.ABOUT_SAMOSA -> words(
- """
- mission, products, pricing, developers, samosa ai
- """
+ SettingsPage.ABOUT_SAMOSA -> SettingsSearchEntry(
+ page,
+ words("mission, products, pricing, developers, samosa ai")
)
- SettingsPage.LEGAL -> words(
- """
- terms, privacy policy, disclaimer, data retention, licence, license
- """
+ SettingsPage.LEGAL -> SettingsSearchEntry(
+ page,
+ words("terms, privacy policy, disclaimer, data retention, licence, license")
)
}
+/** The tag of AI Configuration's collapsed "Advanced settings" section. */
+internal const val AI_ADVANCED_SECTION = "settings_ai_advanced"
+
/** Every settings page, in home-list declaration order. */
-val settingsSearchIndex: List<SettingsSearchEntry> =
- SettingsPage.entries.map { SettingsSearchEntry(it, keywordsFor(it)) }
+val settingsSearchIndex: List<SettingsSearchEntry> = SettingsPage.entries.map(::entryFor)
+
+/** The field tagged [testTag] on [page], or null if the index has none. */
+fun settingsFieldFor(page: SettingsPage, testTag: String): SettingsField? =
+ settingsSearchIndex.first { it.page == page }.fields.firstOrNull { it.testTag == testTag }
/**
* Pages matching [query], case-insensitively, over title, summary and keywords.
@@ -145,8 +255,10 @@ val settingsSearchIndex: List<SettingsSearchEntry> =
* extra word narrows rather than widens the result. A blank query matches
* nothing: the caller shows the normal, unfiltered list instead.
*/
-fun filterSettings(query: String): List<SettingsSearchEntry> {
+fun filterSettings(query: String): List<SettingsSearchResult> {
val tokens = query.lowercase().split(' ', '\t', '\n').filter { it.isNotBlank() }
if (tokens.isEmpty()) return emptyList()
- return settingsSearchIndex.filter { entry -> tokens.all { entry.matches(it) } }
+ return settingsSearchIndex
+ .filter { entry -> tokens.all { entry.matches(it) } }
+ .map { entry -> SettingsSearchResult(entry, entry.fieldFor(tokens)) }
}
diff --git a/app/src/main/java/com/gotcha/ui/SpeechScreen.kt b/app/src/main/java/com/gotcha/ui/SpeechScreen.kt
index 35f4053..404ec8d 100644
--- a/app/src/main/java/com/gotcha/ui/SpeechScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/SpeechScreen.kt
@@ -2,8 +2,6 @@ package com.gotcha.ui
import android.widget.Toast
import androidx.compose.foundation.clickable
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Button
import androidx.compose.material3.DropdownMenuItem
@@ -12,7 +10,6 @@ import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.material3.ExposedDropdownMenuDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
-import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
@@ -22,7 +19,6 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
-import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
@@ -267,7 +263,7 @@ fun SpeechScreen(
expanded = ttsProviderExpanded
)
},
- modifier = Modifier.fillMaxWidth().menuAnchor()
+ modifier = Modifier.fillMaxWidth().menuAnchor().settingsField("settings_tts_provider")
)
SkinExposedDropdownMenu(
expanded = ttsProviderExpanded,
@@ -421,7 +417,7 @@ fun SpeechScreen(
expanded = sttProviderExpanded
)
},
- modifier = Modifier.fillMaxWidth().menuAnchor()
+ modifier = Modifier.fillMaxWidth().menuAnchor().settingsField("settings_stt_provider")
)
SkinExposedDropdownMenu(
expanded = sttProviderExpanded,
@@ -534,14 +530,13 @@ fun SpeechScreen(
}
AudioProvider.ANDROID, AudioProvider.NONE -> Unit
}
- Row(
- modifier = Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.SpaceBetween,
- verticalAlignment = Alignment.CenterVertically
- ) {
- Text("Auto-read replies aloud", style = MaterialTheme.typography.bodyLarge)
- Switch(checked = autoReadReplies, onCheckedChange = { autoReadReplies = it })
- }
+ SettingsToggleRow(
+ label = "Auto-read replies aloud",
+ checked = autoReadReplies,
+ onCheckedChange = { autoReadReplies = it },
+ isLarge = true,
+ switchTestTag = "settings_auto_read_replies"
+ )
Button(
onClick = {
onSave { applySpeech(it) }
diff --git a/app/src/test/java/com/gotcha/ui/SettingsSearchEntryTest.kt b/app/src/test/java/com/gotcha/ui/SettingsSearchEntryTest.kt
index ee7f15b..9562fab 100644
--- a/app/src/test/java/com/gotcha/ui/SettingsSearchEntryTest.kt
+++ b/app/src/test/java/com/gotcha/ui/SettingsSearchEntryTest.kt
@@ -1,6 +1,7 @@
package com.gotcha.ui
import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
@@ -82,4 +83,53 @@ class SettingsSearchEntryTest {
val termux = settingsSearchIndex.first { it.page == SettingsPage.TERMUX }
assertEquals(SettingsPage.TERMUX.title, termux.breadcrumb)
}
+
+ private fun fieldFor(query: String, page: SettingsPage) =
+ filterSettings(query).first { it.page == page }.field
+
+ @Test
+ fun aQueryNamingAControlPointsAtThatControl() {
+ val maxRounds = fieldFor("max tool rounds", SettingsPage.AI_CONFIG)
+ assertEquals("settings_max_tool_rounds", maxRounds?.testTag)
+ // It sits in the collapsed Advanced block, which has to open for it.
+ assertEquals(AI_ADVANCED_SECTION, maxRounds?.section)
+
+ assertEquals("settings_proactive_otp", fieldFor("otp", SettingsPage.PROACTIVE)?.testTag)
+ assertEquals("settings_wake_word", fieldFor("wake word", SettingsPage.ASSISTIVE_BALL)?.testTag)
+ assertEquals("settings_auto_read_replies", fieldFor("read aloud", SettingsPage.SPEECH)?.testTag)
+ }
+
+ @Test
+ fun aPagesOwnTitleHighlightsNothing() {
+ SettingsPage.entries.forEach { page ->
+ assertNull("${page.title} highlights a field", fieldFor(page.title, page))
+ }
+ }
+
+ @Test
+ fun aPageLevelAliasHighlightsNothing() {
+ assertNull(fieldFor("privacy", SettingsPage.PROACTIVE))
+ assertNull(fieldFor("accessibility", SettingsPage.PERMISSIONS))
+ }
+
+ @Test
+ fun aFieldResultNamesTheFieldInItsLabel() {
+ val result = filterSettings("max tool rounds").first { it.page == SettingsPage.AI_CONFIG }
+ assertEquals("AI › AI Configuration › Max tool rounds", result.label)
+ }
+
+ @Test
+ fun fieldTagsAreUniqueAcrossTheIndex() {
+ val tags = settingsSearchIndex.flatMap { entry -> entry.fields.map { it.testTag } }
+ assertEquals(tags.size, tags.toSet().size)
+ }
+
+ @Test
+ fun fieldsAreFoundByTheirPageAndTag() {
+ assertEquals(
+ "Max tool rounds",
+ settingsFieldFor(SettingsPage.AI_CONFIG, "settings_max_tool_rounds")?.label
+ )
+ assertNull(settingsFieldFor(SettingsPage.SPEECH, "settings_max_tool_rounds"))
+ }
}