9c3928460165

wire MainActivity theme/accent from VaultSettings (dark/light/system); make Appearance Theme a 3-way cycle; fix launch window bg per resolved theme

time
2026-06-09 13:42 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
light theme palette migration
parent
810ffe368b4a
2 files app/src/main/java/com/peachpasswords/MainActivity.kt+31 −5app/src/main/java/com/peachpasswords/ui/settings/SettingsCardBodies.kt+7 −2
app/src/main/java/com/peachpasswords/MainActivity.kt+31 −5
@@ -1,11 +1,15 @@11 package com.peachpasswords22 3+import android.content.res.Configuration34 import android.graphics.Color as AndroidColor45 import android.graphics.drawable.ColorDrawable56 import android.os.Bundle67 import android.view.WindowManager78 import androidx.activity.compose.setContent89 import androidx.activity.enableEdgeToEdge10+import androidx.compose.foundation.isSystemInDarkTheme11+import androidx.compose.runtime.collectAsState12+import androidx.compose.runtime.getValue913 import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen1014 import androidx.fragment.app.FragmentActivity1115 import dagger.hilt.android.AndroidEntryPoint@@ -14,6 +18,8 @@1418 import com.peachpasswords.ui.PeachNav1519 import com.peachpasswords.ui.onboarding.ONBOARD_KEY1620 import com.peachpasswords.ui.onboarding.ONBOARD_PREFS21+import com.peachpasswords.ui.theme.ACCENT_COLORS22+import com.peachpasswords.ui.theme.DEFAULT_ACCENT1723 import com.peachpasswords.ui.theme.PeachTheme1824 import com.peachpasswords.vault.VaultRepository1925 @@ -26,8 +32,19 @@2632         installSplashScreen()2733         super.onCreate(savedInstanceState)2834 29-        // Match the splash/window fill to --bg so launch never flashes white.30-        window.setBackgroundDrawable(ColorDrawable(AndroidColor.parseColor("#0C0A06")))35+        // Match the splash/window fill to the resolved theme's --bg so launch36+        // never flashes the wrong colour before Compose draws. Resolved from the37+        // persisted setting synchronously (system mode reads the device night mode).38+        val initialTheme = vault.settings.value.theme39+        val initialDark = when (initialTheme) {40+            "light" -> false41+            "system" -> (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) ==42+                Configuration.UI_MODE_NIGHT_YES43+            else -> true44+        }45+        window.setBackgroundDrawable(46+            ColorDrawable(AndroidColor.parseColor(if (initialDark) "#0C0A06" else "#EFEEE9")),47+        )3148 3249         enableEdgeToEdge()3350 @@ -46,9 +63,18 @@4663             if (!vault.hasVault() && !onboarded) PeachNav.Onboarding else PeachNav.Lock4764 4865         setContent {49-            // Theme/accent are wired to persisted settings in a later phase; the50-            // shell uses the dark default until SettingsViewModel lands.51-            PeachTheme {66+            val settings by vault.settings.collectAsState()67+            val darkTheme = when (settings.theme) {68+                "light" -> false69+                "system" -> isSystemInDarkTheme()70+                else -> true71+            }72+            val accent = ACCENT_COLORS[settings.accentColor] ?: DEFAULT_ACCENT73+            PeachTheme(74+                darkTheme = darkTheme,75+                accent = accent,76+                reduceMotion = settings.reduceMotion,77+            ) {5278                 PeachAppNavHost(startDestination = start)5379             }5480         }

view file

app/src/main/java/com/peachpasswords/ui/settings/SettingsCardBodies.kt+7 −2
@@ -195,9 +195,14 @@195195     SubLabel("THEME", fg, top = 0.dp)196196     RowLine(fg) {197197         Name("Theme", fg)198-        SubtleButton(if (s.theme == "dark") "Switch to light" else "Switch to dark", fg) {199-            vm.setTheme(if (s.theme == "dark") "light" else "dark")198+        // Cycle dark → light → system → dark. The button shows the current mode;199+        // tapping advances to the next.200+        val (label, next) = when (s.theme) {201+            "light" -> "Light" to "system"202+            "system" -> "System" to "dark"203+            else -> "Dark" to "light"200204         }205+        SubtleButton(label, fg) { vm.setTheme(next) }201206     }202207     SubLabel("ACCENT", fg)203208     FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {

view file