d3bba806ea47

add PanicScreen 3-step destroy-vault flow with PanicViewModel, danger/ghost buttons, DESTROY-typed confirm

time
2026-06-09 02:06 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
C5 PanicScreen
parent
cf8ceb57b72e
1 file app/src/main/java/com/peachpasswords/ui/settings/PanicScreen.kt+190 −0
app/src/main/java/com/peachpasswords/ui/settings/PanicScreen.kt+190 −0
@@ -0,0 +1,190 @@1+package com.peachpasswords.ui.settings2+3+import androidx.compose.foundation.background4+import androidx.compose.foundation.border5+import androidx.compose.foundation.clickable6+import androidx.compose.foundation.layout.Arrangement7+import androidx.compose.foundation.layout.Box8+import androidx.compose.foundation.layout.Column9+import androidx.compose.foundation.layout.Row10+import androidx.compose.foundation.layout.Spacer11+import androidx.compose.foundation.layout.fillMaxSize12+import androidx.compose.foundation.layout.fillMaxWidth13+import androidx.compose.foundation.layout.padding14+import androidx.compose.foundation.layout.size15+import androidx.compose.foundation.layout.systemBarsPadding16+import androidx.compose.foundation.layout.width17+import androidx.compose.foundation.shape.RoundedCornerShape18+import androidx.compose.foundation.text.BasicTextField19+import androidx.compose.material3.Text20+import androidx.compose.runtime.Composable21+import androidx.compose.runtime.getValue22+import androidx.compose.runtime.mutableStateOf23+import androidx.compose.runtime.remember24+import androidx.compose.runtime.setValue25+import androidx.compose.ui.Alignment26+import androidx.compose.ui.Modifier27+import androidx.compose.ui.draw.clip28+import androidx.compose.ui.graphics.Color29+import androidx.compose.ui.graphics.SolidColor30+import androidx.compose.ui.text.TextStyle31+import androidx.compose.ui.text.font.FontStyle32+import androidx.compose.ui.text.input.TextFieldValue33+import androidx.compose.ui.unit.em34+import androidx.compose.ui.unit.sp35+import androidx.compose.ui.unit.dp36+import androidx.hilt.navigation.compose.hiltViewModel37+import androidx.lifecycle.ViewModel38+import androidx.lifecycle.viewModelScope39+import com.peachpasswords.ui.theme.LocalPeachAccent40+import com.peachpasswords.ui.theme.PeachColors41+import com.peachpasswords.ui.theme.PeachType42+import com.peachpasswords.vault.VaultRepository43+import dagger.hilt.android.lifecycle.HiltViewModel44+import kotlinx.coroutines.launch45+import javax.inject.Inject46+47+@HiltViewModel48+class PanicViewModel @Inject constructor(private val vault: VaultRepository) : ViewModel() {49+    val entryCount: Int get() = vault.getEntries().size50+    fun destroy(onDone: () -> Unit) = viewModelScope.launch { vault.destroyVault(); onDone() }51+}52+53+@Composable54+fun PanicScreen(55+    onBack: () -> Unit,56+    onDestroyed: () -> Unit,57+    vm: PanicViewModel = hiltViewModel(),58+) {59+    var step by remember { mutableStateOf(1) }60+    val entryCount = remember { vm.entryCount }61+62+    // The panic flow is intentionally cold: no bloom, a flat near-black field so63+    // it reads as a dead-end rather than another lit-up screen in the app.64+    Box(modifier = Modifier.fillMaxSize().background(Color(0xFF0C0A06))) {65+        Column(66+            modifier = Modifier67+                .fillMaxSize()68+                .systemBarsPadding()69+                .padding(horizontal = 28.dp, vertical = 32.dp),70+            verticalArrangement = Arrangement.Center,71+        ) {72+            when (step) {73+                1 -> Step1(onCancel = onBack, onContinue = { step = 2 })74+                2 -> Step2(entryCount = entryCount, onBack = { step = 1 }, onContinue = { step = 3 })75+                else -> Step3(onDestroy = { vm.destroy(onDestroyed) })76+            }77+        }78+    }79+}80+81+@Composable82+private fun Step1(onCancel: () -> Unit, onContinue: () -> Unit) {83+    Headline("destroy vault", 44.sp, PeachColors.Breach)84+    Spacer(Modifier.size(20.dp))85+    Text(86+        "This will permanently delete your vault and all saved passwords from this device. This cannot be undone.",87+        color = PeachColors.T1,88+        style = PeachType.body,89+    )90+    Spacer(Modifier.size(28.dp))91+    Row(modifier = Modifier.fillMaxWidth()) {92+        GhostButton("Cancel", PeachColors.T1, onCancel)93+        Spacer(Modifier.width(12.dp))94+        DangerButton("I understand, continue", enabled = true, onClick = onContinue)95+    }96+}97+98+@Composable99+private fun Step2(entryCount: Int, onBack: () -> Unit, onContinue: () -> Unit) {100+    Headline("are you sure?", 32.sp, PeachColors.Breach)101+    Spacer(Modifier.size(18.dp))102+    Text(103+        "You will lose access to all $entryCount saved passwords.",104+        color = PeachColors.T1,105+        style = PeachType.body,106+    )107+    Spacer(Modifier.size(28.dp))108+    Row(modifier = Modifier.fillMaxWidth()) {109+        GhostButton("Go back", PeachColors.T1, onBack)110+        Spacer(Modifier.width(12.dp))111+        DangerButton("Yes, destroy it", enabled = true, onClick = onContinue)112+    }113+}114+115+@Composable116+private fun Step3(onDestroy: () -> Unit) {117+    var typed by remember { mutableStateOf(TextFieldValue("")) }118+    val accent = LocalPeachAccent.current119+    val confirmed = typed.text == "DESTROY"120+121+    Headline("type DESTROY to confirm", 28.sp, PeachColors.T0)122+    Spacer(Modifier.size(22.dp))123+    BasicTextField(124+        value = typed,125+        onValueChange = { typed = it },126+        singleLine = true,127+        textStyle = TextStyle(128+            fontFamily = PeachType.Mono,129+            fontSize = 18.sp,130+            letterSpacing = 0.18.em,131+            color = PeachColors.T0,132+        ),133+        cursorBrush = SolidColor(accent),134+        modifier = Modifier.fillMaxWidth(),135+    )136+    Spacer(Modifier.size(6.dp))137+    Box(138+        modifier = Modifier139+            .fillMaxWidth()140+            .size(1.dp)141+            .background(PeachColors.T3),142+    )143+    Spacer(Modifier.size(28.dp))144+    DangerButton("Destroy vault", enabled = confirmed, onClick = onDestroy)145+}146+147+@Composable148+private fun Headline(text: String, fontSize: androidx.compose.ui.unit.TextUnit, color: Color) {149+    Text(150+        text,151+        color = color,152+        style = TextStyle(153+            fontFamily = PeachType.Display,154+            fontStyle = FontStyle.Italic,155+            fontSize = fontSize,156+        ),157+    )158+}159+160+@Composable161+private fun GhostButton(label: String, color: Color, onClick: () -> Unit) {162+    Box(163+        modifier = Modifier164+            .clip(RoundedCornerShape(999.dp))165+            .border(1.dp, color.copy(alpha = 0.4f), RoundedCornerShape(999.dp))166+            .clickable(onClick = onClick)167+            .padding(horizontal = 18.dp, vertical = 11.dp),168+    ) {169+        Text(label, color = color, style = PeachType.sortPill.copy(fontSize = 11.sp))170+    }171+}172+173+@Composable174+private fun DangerButton(label: String, enabled: Boolean, onClick: () -> Unit) {175+    val alpha = if (enabled) 1f else 0.4f176+    Box(177+        modifier = Modifier178+            .clip(RoundedCornerShape(999.dp))179+            .background(PeachColors.BreachBg.copy(alpha = PeachColors.BreachBg.alpha * alpha))180+            .border(1.dp, PeachColors.Breach.copy(alpha = 0.55f * alpha), RoundedCornerShape(999.dp))181+            .clickable(enabled = enabled, onClick = onClick)182+            .padding(horizontal = 18.dp, vertical = 11.dp),183+    ) {184+        Text(185+            label,186+            color = PeachColors.Breach.copy(alpha = alpha),187+            style = PeachType.sortPill.copy(fontSize = 11.sp),188+        )189+    }190+}

view file