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: the theme picker announces itself, and the theme layer has tests

Durganshu Mishra0b9c3f8b62b9
diff --git a/app/src/main/java/com/gotcha/data/SettingsRepository.kt b/app/src/main/java/com/gotcha/data/SettingsRepository.kt
index ba153f5..7e88af3 100644
--- a/app/src/main/java/com/gotcha/data/SettingsRepository.kt
+++ b/app/src/main/java/com/gotcha/data/SettingsRepository.kt
@@ -191,6 +191,28 @@ data class Settings(
}
}
+/**
+ * Which skin an install lands on when it has never chosen one.
+ *
+ * Appearance used to be two settings — a Deep Space theme plus a light/dark
+ * mode — and is now a single skin per look. Someone who had deliberately set
+ * their app light must not be handed the dark one on upgrade, which is the
+ * whole reason this exists. It runs once: [SettingsRepository] writes the
+ * result, and every later load reads that instead.
+ *
+ * @param legacyThemeMode the old `theme_mode` value, or null if never set.
+ */
+internal fun migrateSkinId(legacyThemeMode: String?): String =
+ if (legacyThemeMode == LEGACY_THEME_MODE_LIGHT) {
+ SKIN_DEEP_SPACE_LIGHT
+ } else {
+ SKIN_DEEP_SPACE_DARK
+ }
+
+internal const val SKIN_DEEP_SPACE_DARK = "deepspace"
+internal const val SKIN_DEEP_SPACE_LIGHT = "deepspace_light"
+private const val LEGACY_THEME_MODE_LIGHT = "LIGHT"
+
/** Stores credentials in EncryptedSharedPreferences (PRD R6). Never logged. */
class SettingsRepository(context: Context) {
@@ -218,19 +240,13 @@ class SettingsRepository(context: Context) {
private fun string(key: String, default: String = ""): String =
prefs.getString(key, default) ?: default
- /**
- * The chosen skin, migrating anyone who was on the old Deep Space + "Light"
- * combination. That pairing used to be two settings; it is one skin now, and
- * silently moving them to the dark one would repaint an app they had
- * deliberately set light.
- */
+ /** Reads the stored skin, running the one-shot migration if it has not run. */
private fun resolvedSkinId(): String {
val stored = prefs.getString(KEY_SKIN_ID, null)
if (stored != null) return stored
- val legacy = prefs.getString(KEY_LEGACY_THEME_MODE, null)
- val id = if (legacy == "LIGHT") SKIN_DEEP_SPACE_LIGHT else SKIN_DEEP_SPACE_DARK
- prefs.edit().putString(KEY_SKIN_ID, id).apply()
- return id
+ val migrated = migrateSkinId(prefs.getString(KEY_LEGACY_THEME_MODE, null))
+ prefs.edit().putString(KEY_SKIN_ID, migrated).apply()
+ return migrated
}
fun load(): Settings = Settings(
@@ -384,10 +400,8 @@ class SettingsRepository(context: Context) {
const val KEY_ASSISTIVE_BALL = "assistive_ball_enabled"
const val KEY_SKIN_ID = "skin_id"
- /** Only read by [resolvedSkinId]'s migration; never written any more. */
+ /** Only read by [migrateSkinId]; never written any more. */
const val KEY_LEGACY_THEME_MODE = "theme_mode"
- const val SKIN_DEEP_SPACE_DARK = "deepspace"
- const val SKIN_DEEP_SPACE_LIGHT = "deepspace_light"
const val KEY_DISABLED_SKILLS = "disabled_skills"
const val KEY_DISABLED_CONNECTORS = "disabled_connectors"
const val KEY_PROACTIVE_ENABLED = "proactive_enabled"
diff --git a/app/src/main/java/com/gotcha/ui/AppearanceScreen.kt b/app/src/main/java/com/gotcha/ui/AppearanceScreen.kt
index 8dbb271..1e4799f 100644
--- a/app/src/main/java/com/gotcha/ui/AppearanceScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/AppearanceScreen.kt
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.selection.selectable
+import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
@@ -28,6 +29,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.gotcha.data.Settings
@@ -119,7 +123,12 @@ private const val TILES_PER_ROW = 2
@Composable
private fun SkinGrid(selectedId: String, onSelect: (String) -> Unit) {
- Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
+ // Announced as one group of mutually exclusive choices rather than as six
+ // unrelated buttons.
+ Column(
+ modifier = Modifier.selectableGroup(),
+ verticalArrangement = Arrangement.spacedBy(10.dp)
+ ) {
Skins.all.chunked(TILES_PER_ROW).forEach { row ->
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
row.forEach { skin ->
@@ -152,7 +161,18 @@ private fun RowScope.SkinTile(skin: Skin, selected: Boolean, onSelect: () -> Uni
color = border,
shape = RoundedCornerShape(16.dp)
)
- .selectable(selected = selected, onClick = onSelect)
+ .selectable(
+ selected = selected,
+ // Without a role this reads as a plain button with no sense of
+ // being one of a set, and nothing announces which one is on.
+ role = Role.RadioButton,
+ onClick = onSelect
+ )
+ // The preview, the name and the brightness are one choice, not three
+ // things to swipe through.
+ .semantics(mergeDescendants = true) {
+ contentDescription = "${skin.label}, ${brightnessLabel(skin)} theme"
+ }
.testTag("appearance_skin_${skin.id}")
) {
SkinPreview(skin)
diff --git a/app/src/test/java/com/gotcha/data/SkinMigrationTest.kt b/app/src/test/java/com/gotcha/data/SkinMigrationTest.kt
new file mode 100644
index 0000000..f02a089
--- /dev/null
+++ b/app/src/test/java/com/gotcha/data/SkinMigrationTest.kt
@@ -0,0 +1,50 @@
+package com.gotcha.data
+
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+/**
+ * The appearance migration runs exactly once per install, silently, and its
+ * result is written back — so a mistake here is a mistake nobody reports and
+ * nobody can undo without finding the setting again. It is worth pinning down.
+ */
+class SkinMigrationTest {
+
+ @Test
+ fun `someone who chose Light keeps a light theme`() {
+ assertEquals(SKIN_DEEP_SPACE_LIGHT, migrateSkinId("LIGHT"))
+ }
+
+ @Test
+ fun `someone who chose Dark keeps a dark theme`() {
+ assertEquals(SKIN_DEEP_SPACE_DARK, migrateSkinId("DARK"))
+ }
+
+ /**
+ * SYSTEM was the default, and the overwhelming majority of installs are on
+ * it. Dark is the honest landing place: it is what the app looked like for
+ * most of them, and it is the skin the picker calls the original.
+ */
+ @Test
+ fun `someone who never changed it lands on the original`() {
+ assertEquals(SKIN_DEEP_SPACE_DARK, migrateSkinId("SYSTEM"))
+ assertEquals(SKIN_DEEP_SPACE_DARK, migrateSkinId(null))
+ }
+
+ /** A value from a build that no longer exists must not throw. */
+ @Test
+ fun `an unrecognised legacy value falls back rather than failing`() {
+ assertEquals(SKIN_DEEP_SPACE_DARK, migrateSkinId("AUTO_BATTERY"))
+ assertEquals(SKIN_DEEP_SPACE_DARK, migrateSkinId(""))
+ }
+
+ /** The ids it produces have to be ids the picker actually knows. */
+ @Test
+ fun `every id the migration can produce is a real skin`() {
+ val produced = listOf(null, "SYSTEM", "LIGHT", "DARK", "nonsense").map(::migrateSkinId)
+ val known = com.gotcha.ui.theme.Skins.all.map { it.id }
+ produced.forEach { id ->
+ assert(id in known) { "migration produced '$id', which is not in Skins.all" }
+ }
+ }
+}
diff --git a/app/src/test/java/com/gotcha/ui/theme/SkinTest.kt b/app/src/test/java/com/gotcha/ui/theme/SkinTest.kt
new file mode 100644
index 0000000..804f255
--- /dev/null
+++ b/app/src/test/java/com/gotcha/ui/theme/SkinTest.kt
@@ -0,0 +1,152 @@
+package com.gotcha.ui.theme
+
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.unit.dp
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertNotEquals
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+/**
+ * The skin catalogue and the rules derived from it.
+ *
+ * These are the invariants the rest of the theme layer assumes without checking:
+ * that an unknown id cannot crash the app, that a glass skin can always be made
+ * solid, and that the transparent `background` role — which is what lets a
+ * Scaffold show the wallpaper — survives exactly where it should and nowhere
+ * else.
+ */
+class SkinTest {
+
+ @Test
+ fun `an unknown id falls back to the default rather than throwing`() {
+ assertEquals(Skins.DeepSpaceDark, Skins.byId("a-skin-from-a-future-build"))
+ assertEquals(Skins.DeepSpaceDark, Skins.byId(""))
+ }
+
+ @Test
+ fun `the default id resolves to a real skin`() {
+ assertEquals(Skins.DEFAULT_ID, Skins.byId(Skins.DEFAULT_ID).id)
+ }
+
+ @Test
+ fun `ids are unique`() {
+ val ids = Skins.all.map { it.id }
+ assertEquals(ids.size, ids.toSet().size)
+ }
+
+ @Test
+ fun `only the glass skins draw a wallpaper`() {
+ Skins.all.forEach { skin ->
+ assertEquals(
+ "${skin.id}: isGlass and backdrop disagree",
+ skin.backdrop != Backdrop.NONE,
+ skin.isGlass
+ )
+ }
+ }
+
+ /**
+ * Scaffold paints its container from `background`. A glass skin has to leave
+ * that transparent or the app lays an opaque sheet over its own wallpaper —
+ * which is exactly the bug that made Orchid look like flat pink.
+ */
+ @Test
+ fun `glass skins keep a transparent background role`() {
+ Skins.all.filter { it.isGlass }.forEach { skin ->
+ assertEquals(
+ "${skin.id} must not paint over its own wallpaper",
+ Color.Transparent,
+ skin.scheme.background
+ )
+ }
+ }
+
+ @Test
+ fun `opaque skins paint their own background`() {
+ Skins.all.filterNot { it.isGlass }.forEach { skin ->
+ assertNotEquals(
+ "${skin.id} has no wallpaper, so something must paint the ground",
+ Color.Transparent,
+ skin.scheme.background
+ )
+ }
+ }
+
+ @Test
+ fun `making a skin solid removes the wallpaper and every translucent surface`() {
+ Skins.all.filter { it.isGlass }.forEach { skin ->
+ val solid = skin.opaque()
+ assertFalse("${skin.id} still reports glass", solid.isGlass)
+ assertEquals("${skin.id} kept its grain", 0f, solid.grain, 0f)
+ assertEquals("${skin.id} kept its scrim", 0f, solid.scrim, 0f)
+ assertEquals("${skin.id} background", skin.ground, solid.scheme.background)
+ listOf(
+ "surface" to solid.scheme.surface,
+ "surfaceVariant" to solid.scheme.surfaceVariant,
+ "secondaryContainer" to solid.scheme.secondaryContainer
+ ).forEach { (role, color) ->
+ assertEquals("${skin.id} $role is still see-through", 1f, color.alpha, 0.001f)
+ }
+ }
+ }
+
+ @Test
+ fun `making an already opaque skin solid changes nothing`() {
+ assertEquals(Skins.DeepSpaceDark, Skins.DeepSpaceDark.opaque())
+ assertEquals(Skins.DeepSpaceLight, Skins.DeepSpaceLight.opaque())
+ }
+
+ /**
+ * Compositing a translucent panel onto its ground must land between the two,
+ * not on either — a flatten that returns the ground has erased the panel.
+ */
+ @Test
+ fun `flattening lands between the panel and the ground`() {
+ val solid = Skins.Aura.opaque()
+ val panel = solid.scheme.surface
+ assertNotEquals(Skins.Aura.ground, panel)
+ assertTrue("panel should sit above its ground", panel.red > Skins.Aura.ground.red)
+ }
+
+ /** System-bar icons follow the skin, never the device's dark-mode flag. */
+ @Test
+ fun `light skins ask for dark system bar icons`() {
+ Skins.all.forEach { skin ->
+ assertEquals(
+ "${skin.id}",
+ skin.brightness == Brightness.LIGHT,
+ skin.darkSystemBarIcons
+ )
+ }
+ }
+
+ @Test
+ fun `the launch ground is never transparent`() {
+ Skins.all.forEach { skin ->
+ assertEquals(
+ "${skin.id} would flash a see-through window before first frame",
+ 1f,
+ skin.launchGround.alpha,
+ 0.001f
+ )
+ }
+ }
+
+ @Test
+ fun `the small radius is derived from the large one`() {
+ Skins.all.forEach { skin ->
+ assertEquals("${skin.id}", skin.corner / 2, skin.cornerSmall)
+ assertTrue("${skin.id} has no radius at all", skin.corner > 0.dp)
+ }
+ }
+
+ @Test
+ fun `only skins with a wallpaper declare frost, grain or scrim`() {
+ Skins.all.filterNot { it.isGlass }.forEach { skin ->
+ assertEquals("${skin.id} grain", 0f, skin.grain, 0f)
+ assertEquals("${skin.id} scrim", 0f, skin.scrim, 0f)
+ }
+ }
+}