f9e5f1539ecc

feat: C3 VaultHealthScreen (score ring, 5 collapsible sections w/ change-password CTA, all-healthy state) + C5 wiring — Panic route, Vault→Advanced accordion (replace-from-backup, destroy vault); both built green (v2.1.21)

time
2026-06-09 02:09 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
peach gap implementation
parent
d3bba806ea47
5 files app/build.gradle+2 −2app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+15 −1app/src/main/java/com/peachpasswords/ui/PeachNav.kt+1 −0app/src/main/java/com/peachpasswords/ui/settings/SettingsCardBodies.kt+17 −0app/src/main/java/com/peachpasswords/ui/vault/VaultHealthScreen.kt+311 −0
app/build.gradle+2 −2
@@ -16,8 +16,8 @@1616         applicationId "com.peachpasswords"1717         minSdk 261818         targetSdk 3519-        versionCode 20102020-        versionName "2.1.20"19+        versionCode 20102120+        versionName "2.1.21"2121 2222         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"2323         vectorDrawables {

view file

app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+15 −1
@@ -17,7 +17,9 @@1717 import com.peachpasswords.ui.lock.LockScreen1818 import com.peachpasswords.ui.pairing.ChirpPairScreen1919 import com.peachpasswords.ui.screens.SimpleStub20+import com.peachpasswords.ui.settings.PanicScreen2021 import com.peachpasswords.ui.settings.SettingsScreen22+import com.peachpasswords.ui.vault.VaultHealthScreen2123 import com.peachpasswords.ui.theme.PeachMotion2224 import com.peachpasswords.ui.vault.EntryDetailScreen2325 import com.peachpasswords.ui.vault.EntryEditScreen@@ -95,9 +97,21 @@9597         composable(PeachNav.CodexGenerate.route) { CodexGenerateScreen(onBack = back) }9698         composable(PeachNav.CodexRestore.route) { CodexRestoreScreen(onBack = back, onRestored = back) }9799         composable(PeachNav.ChirpPair.route) { ChirpPairScreen(onBack = back) }98-        composable(PeachNav.Health.route) { SimpleStub("Vault health", back) }100+        composable(PeachNav.Health.route) {101+            VaultHealthScreen(onBack = back, onEditEntry = { nav(PeachNav.EntryEdit(it)) })102+        }99103         composable(PeachNav.Trash.route) { TrashScreen(onBack = back) }100104         composable(PeachNav.Import.route) { SimpleStub("Import", back) }101105         composable(PeachNav.Export.route) { SimpleStub("Export", back) }106+        composable(PeachNav.Panic.route) {107+            PanicScreen(108+                onBack = back,109+                onDestroyed = {110+                    navController.navigate(PeachNav.Lock.route) {111+                        popUpTo(0) { inclusive = true }112+                    }113+                },114+            )115+        }102116     }103117 }

view file

app/src/main/java/com/peachpasswords/ui/PeachNav.kt+1 −0
@@ -36,4 +36,5 @@3636     data object Trash : PeachNav("trash")3737     data object Import : PeachNav("import")3838     data object Export : PeachNav("export")39+    data object Panic : PeachNav("panic")3940 }

view file

app/src/main/java/com/peachpasswords/ui/settings/SettingsCardBodies.kt+17 −0
@@ -358,6 +358,23 @@358358         SubtleButton("open", fg) { onNavigate(PeachNav.CodexGenerate) }359359     }360360     RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }361+362+    var advancedOpen by remember { mutableStateOf(false) }363+    SubLabel("ADVANCED", fg)364+    RowLine(fg) {365+        Name("Advanced", fg)366+        SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }367+    }368+    if (advancedOpen) {369+        RowLine(fg) {370+            Name("Replace vault from backup", com.peachpasswords.ui.theme.PeachColors.SyncBusy)371+            SubtleButton("open", com.peachpasswords.ui.theme.PeachColors.SyncBusy) { onNavigate(PeachNav.Import) }372+        }373+        RowLine(fg) {374+            Name("Destroy vault", com.peachpasswords.ui.theme.PeachColors.Breach)375+            SubtleButton("destroy", com.peachpasswords.ui.theme.PeachColors.Breach) { onNavigate(PeachNav.Panic) }376+        }377+    }361378 }362379 363380 /* ────────────────────────────────  Sync  ────────────────────────────────── */

view file

app/src/main/java/com/peachpasswords/ui/vault/VaultHealthScreen.kt+311 −0
@@ -0,0 +1,311 @@1+package com.peachpasswords.ui.vault2+3+import androidx.compose.foundation.Canvas4+import androidx.compose.foundation.border5+import androidx.compose.foundation.clickable6+import androidx.compose.foundation.layout.Box7+import androidx.compose.foundation.layout.Column8+import androidx.compose.foundation.layout.Row9+import androidx.compose.foundation.layout.Spacer10+import androidx.compose.foundation.layout.fillMaxSize11+import androidx.compose.foundation.layout.fillMaxWidth12+import androidx.compose.foundation.layout.padding13+import androidx.compose.foundation.layout.size14+import androidx.compose.foundation.layout.systemBarsPadding15+import androidx.compose.foundation.layout.width16+import androidx.compose.foundation.lazy.LazyColumn17+import androidx.compose.foundation.lazy.items18+import androidx.compose.foundation.shape.RoundedCornerShape19+import androidx.compose.material.icons.Icons20+import androidx.compose.material.icons.automirrored.rounded.ArrowBack21+import androidx.compose.material3.Icon22+import androidx.compose.material3.Text23+import androidx.compose.runtime.Composable24+import androidx.compose.runtime.collectAsState25+import androidx.compose.runtime.getValue26+import androidx.compose.runtime.mutableStateMapOf27+import androidx.compose.runtime.remember28+import androidx.compose.ui.Alignment29+import androidx.compose.ui.Modifier30+import androidx.compose.ui.draw.clip31+import androidx.compose.ui.geometry.Offset32+import androidx.compose.ui.geometry.Size33+import androidx.compose.ui.graphics.Color34+import androidx.compose.ui.graphics.StrokeCap35+import androidx.compose.ui.graphics.drawscope.Stroke36+import androidx.compose.ui.text.TextStyle37+import androidx.compose.ui.text.font.FontStyle38+import androidx.compose.ui.text.style.TextAlign39+import androidx.compose.ui.unit.dp40+import androidx.compose.ui.unit.sp41+import androidx.hilt.navigation.compose.hiltViewModel42+import androidx.lifecycle.ViewModel43+import com.peachpasswords.ui.components.FaviconInitials44+import com.peachpasswords.ui.components.PeachMark45+import com.peachpasswords.ui.theme.LocalPeachAccent46+import com.peachpasswords.ui.theme.PeachColors47+import com.peachpasswords.ui.theme.PeachType48+import com.peachpasswords.ui.theme.ShellBackground49+import com.peachpasswords.vault.VaultEntry50+import com.peachpasswords.vault.VaultHealth51+import com.peachpasswords.vault.VaultRepository52+import com.peachpasswords.vault.domainKey53+import com.peachpasswords.vault.hasPasskey54+import dagger.hilt.android.lifecycle.HiltViewModel55+import kotlinx.coroutines.flow.MutableStateFlow56+import kotlinx.coroutines.flow.StateFlow57+import kotlinx.coroutines.flow.asStateFlow58+import javax.inject.Inject59+60+/** Warm amber used for the "reused" and "weak" advisory buckets. */61+private val Amber = Color(0xFFC8A840)62+63+/** Local password-age threshold for the "Old" bucket: 365 days. */64+private const val OLD_PASSWORD_MS = 365L * 24 * 60 * 60 * 100065+66+@HiltViewModel67+class VaultHealthViewModel @Inject constructor(68+    private val vault: VaultRepository,69+) : ViewModel() {70+    val entries: StateFlow<List<VaultEntry>> = vault.entries71+72+    private val _report = MutableStateFlow(VaultHealth.buildReport(vault.getEntries()))73+    val report: StateFlow<VaultHealth.VaultHealthReport> = _report.asStateFlow()74+75+    /** Re-read the live entry list and recompute the local health report. */76+    fun recompute() {77+        _report.value = VaultHealth.buildReport(vault.getEntries())78+    }79+}80+81+@Composable82+fun VaultHealthScreen(83+    onBack: () -> Unit,84+    onEditEntry: (String) -> Unit,85+    vm: VaultHealthViewModel = hiltViewModel(),86+) {87+    val accent = LocalPeachAccent.current88+    val entries by vm.entries.collectAsState()89+    val report by vm.report.collectAsState()90+91+    val byId = remember(entries) { entries.associateBy { it.id } }92+    val flags = remember(report) { report.entries.associateBy { it.entryId } }93+94+    val now = System.currentTimeMillis()95+    val breached = report.entries.filter { it.isBreach }.mapNotNull { byId[it.entryId] }96+    val reused = report.entries.filter { it.isReused }.mapNotNull { byId[it.entryId] }97+    val weak = report.entries.filter { it.isWeak }.mapNotNull { byId[it.entryId] }98+    val old = entries.filter { e ->99+        e.passwordChangedAt?.let { (now - it) > OLD_PASSWORD_MS } == true100+    }101+    val noPasskey = entries.filter { !it.hasPasskey() }102+103+    val allHealthy = breached.isEmpty() && reused.isEmpty() &&104+        weak.isEmpty() && old.isEmpty() && noPasskey.isEmpty()105+106+    val expanded = remember { mutableStateMapOf<String, Boolean>() }107+108+    ShellBackground {109+        Column(110+            modifier = Modifier111+                .fillMaxSize()112+                .systemBarsPadding()113+                .padding(horizontal = 20.dp, vertical = 16.dp),114+        ) {115+            // Top bar: back · "vault health" · "check now"116+            Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {117+                Icon(118+                    Icons.AutoMirrored.Rounded.ArrowBack,119+                    contentDescription = "back",120+                    tint = PeachColors.T0,121+                    modifier = Modifier.size(22.dp).clip(RoundedCornerShape(8.dp)).clickable(onClick = onBack),122+                )123+                Spacer(Modifier.width(14.dp))124+                Text(125+                    "vault health",126+                    color = PeachColors.T0,127+                    style = TextStyle(128+                        fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 22.sp,129+                    ),130+                )131+                Spacer(Modifier.weight(1f))132+                GhostPill("check now", accent) { vm.recompute() }133+            }134+135+            Spacer(Modifier.size(22.dp))136+137+            ScoreRing(score = report.vaultScore, accent = accent)138+139+            Spacer(Modifier.size(24.dp))140+141+            if (allHealthy) {142+                Column(143+                    modifier = Modifier.fillMaxSize(),144+                    horizontalAlignment = Alignment.CenterHorizontally,145+                ) {146+                    Spacer(Modifier.weight(1f))147+                    PeachMark(size = 60.dp)148+                    Spacer(Modifier.size(18.dp))149+                    Text(150+                        "Your vault looks healthy.",151+                        color = PeachColors.T1,152+                        textAlign = TextAlign.Center,153+                        style = TextStyle(154+                            fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 20.sp,155+                        ),156+                    )157+                    Spacer(Modifier.weight(1f))158+                }159+            } else {160+                LazyColumn(modifier = Modifier.weight(1f)) {161+                    healthSection("Breached", breached, PeachColors.Breach, expanded, onEditEntry)162+                    healthSection("Reused", reused, Amber, expanded, onEditEntry)163+                    healthSection("Weak", weak, Amber, expanded, onEditEntry)164+                    healthSection("Old", old, PeachColors.T2, expanded, onEditEntry)165+                    healthSection("No passkey", noPasskey, PeachColors.T2, expanded, onEditEntry)166+                }167+            }168+        }169+    }170+}171+172+private fun androidx.compose.foundation.lazy.LazyListScope.healthSection(173+    title: String,174+    bucket: List<VaultEntry>,175+    badgeColor: Color,176+    expanded: androidx.compose.runtime.snapshots.SnapshotStateMap<String, Boolean>,177+    onEditEntry: (String) -> Unit,178+) {179+    item(key = "header_$title") {180+        SectionHeader(181+            title = title,182+            count = bucket.size,183+            badgeColor = badgeColor,184+            expanded = expanded[title] == true,185+            onToggle = { expanded[title] = !(expanded[title] == true) },186+        )187+    }188+    if (expanded[title] == true) {189+        items(bucket, key = { "${title}_${it.id}" }) { entry ->190+            HealthEntryRow(entry = entry, onChange = { onEditEntry(entry.id) })191+        }192+    }193+}194+195+@Composable196+private fun SectionHeader(197+    title: String,198+    count: Int,199+    badgeColor: Color,200+    expanded: Boolean,201+    onToggle: () -> Unit,202+) {203+    Row(204+        verticalAlignment = Alignment.CenterVertically,205+        modifier = Modifier206+            .fillMaxWidth()207+            .clip(RoundedCornerShape(10.dp))208+            .clickable(onClick = onToggle)209+            .padding(vertical = 12.dp),210+    ) {211+        Text(212+            title,213+            color = if (expanded) PeachColors.T0 else PeachColors.T1,214+            style = TextStyle(215+                fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp,216+            ),217+        )218+        Spacer(Modifier.width(10.dp))219+        CountBadge(count, badgeColor)220+    }221+}222+223+@Composable224+private fun HealthEntryRow(entry: VaultEntry, onChange: () -> Unit) {225+    Row(226+        verticalAlignment = Alignment.CenterVertically,227+        modifier = Modifier.fillMaxWidth().padding(start = 6.dp, top = 8.dp, bottom = 8.dp),228+    ) {229+        FaviconInitials(source = entry.url ?: entry.title, size = 26.dp)230+        Spacer(Modifier.width(12.dp))231+        Column(Modifier.weight(1f)) {232+            Text(entry.title, color = PeachColors.T0, style = PeachType.entryNameList)233+            val domain = entry.domainKey()234+            if (!domain.isNullOrBlank()) {235+                Text(domain, color = PeachColors.T2, style = PeachType.tinyMono)236+            }237+        }238+        GhostPill("Change password", LocalPeachAccent.current, onChange)239+    }240+}241+242+@Composable243+private fun ScoreRing(score: Int, accent: Color) {244+    Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {245+        Box(contentAlignment = Alignment.Center) {246+            Canvas(modifier = Modifier.size(100.dp)) {247+                val stroke = 8.dp.toPx()248+                val inset = stroke / 2f249+                val arcSize = Size(size.width - stroke, size.height - stroke)250+                val topLeft = Offset(inset, inset)251+                drawArc(252+                    color = PeachColors.T3,253+                    startAngle = -90f,254+                    sweepAngle = 360f,255+                    useCenter = false,256+                    topLeft = topLeft,257+                    size = arcSize,258+                    style = Stroke(width = stroke, cap = StrokeCap.Round),259+                )260+                drawArc(261+                    color = accent,262+                    startAngle = -90f,263+                    sweepAngle = (score.coerceIn(0, 100) / 100f) * 360f,264+                    useCenter = false,265+                    topLeft = topLeft,266+                    size = arcSize,267+                    style = Stroke(width = stroke, cap = StrokeCap.Round),268+                )269+            }270+            Column(horizontalAlignment = Alignment.CenterHorizontally) {271+                Text(272+                    score.toString(),273+                    color = PeachColors.T0,274+                    style = TextStyle(275+                        fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 44.sp,276+                    ),277+                )278+                Text(279+                    "vault score",280+                    color = PeachColors.T2,281+                    style = PeachType.labelMono.copy(fontSize = 9.sp),282+                )283+            }284+        }285+    }286+}287+288+@Composable289+private fun CountBadge(count: Int, color: Color) {290+    Box(291+        modifier = Modifier292+            .clip(RoundedCornerShape(999.dp))293+            .border(1.dp, color.copy(alpha = 0.4f), RoundedCornerShape(999.dp))294+            .padding(horizontal = 9.dp, vertical = 3.dp),295+    ) {296+        Text(count.toString(), color = color, style = PeachType.sortPill.copy(fontSize = 10.sp))297+    }298+}299+300+@Composable301+private fun GhostPill(label: String, color: Color, onClick: () -> Unit) {302+    Box(303+        modifier = Modifier304+            .clip(RoundedCornerShape(999.dp))305+            .border(1.dp, color.copy(alpha = 0.4f), RoundedCornerShape(999.dp))306+            .clickable(onClick = onClick)307+            .padding(horizontal = 12.dp, vertical = 5.dp),308+    ) {309+        Text(label, color = color, style = PeachType.sortPill.copy(fontSize = 10.sp))310+    }311+}

view file