ed2b2847cc79

refactor: extract PasswordHistorySection (+toggle/list) to shared ui/vault/PasswordHistorySection.kt; EntryEdit imports it (v2.1.34)

time
2026-06-09 04:31 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
peach remaining gaps
parent
387d4fb954ca
3 files app/drafts/D7/PasswordHistorySection.kt+0 −168app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+2 −103app/src/main/java/com/peachpasswords/ui/vault/PasswordHistorySection.kt+168 −0
app/drafts/D7/PasswordHistorySection.kt+0 −168
@@ -1,168 +0,0 @@1-package com.peachpasswords.ui.vault2-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.fillMaxWidth12-import androidx.compose.foundation.layout.height13-import androidx.compose.foundation.layout.padding14-import androidx.compose.foundation.layout.width15-import androidx.compose.foundation.shape.RoundedCornerShape16-import androidx.compose.material3.Text17-import androidx.compose.runtime.Composable18-import androidx.compose.runtime.getValue19-import androidx.compose.runtime.mutableStateOf20-import androidx.compose.runtime.remember21-import androidx.compose.runtime.setValue22-import androidx.compose.ui.Alignment23-import androidx.compose.ui.Modifier24-import androidx.compose.ui.draw.clip25-import androidx.compose.ui.text.font.FontStyle26-import androidx.compose.ui.unit.dp27-import androidx.compose.ui.unit.sp28-import com.peachpasswords.ui.theme.LocalPeachAccent29-import com.peachpasswords.ui.theme.PeachColors30-import com.peachpasswords.ui.theme.PeachType31-import com.peachpasswords.vault.PasswordHistoryItem32-33-/**34- * Shared past-password history UI, extracted from EntryEditScreen so both the35- * editor and EntryDetailScreen render the same rows. Behavior is unchanged from36- * the original private copy.37- *38- * - [PasswordHistorySection] is the original combined toggle + content block used39- *   by EntryEditScreen (toggle always present so the affordance is discoverable;40- *   empty state explains how it fills).41- * - [PasswordHistoryToggle] + [PasswordHistoryList] split the same pieces apart so42- *   EntryDetailScreen can drive expand/collapse with AnimatedVisibility itself.43- *44- * Rows are masked until revealed; "use" hands the value to [onRestore].45- */46-@Composable47-internal fun PasswordHistorySection(48-    history: List<PasswordHistoryItem>,49-    expanded: Boolean,50-    onToggle: () -> Unit,51-    onRestore: (String) -> Unit,52-    onCopy: (String) -> Unit,53-) {54-    Column(Modifier.fillMaxWidth().padding(bottom = 14.dp)) {55-        PasswordHistoryToggle(count = history.size, expanded = expanded, onToggle = onToggle)56-        if (expanded) {57-            Spacer(Modifier.height(8.dp))58-            PasswordHistoryList(history = history, onRestore = onRestore, onCopy = onCopy)59-        }60-    }61-}62-63-/**64- * The "↺ history (N)" affordance — Cormorant italic, accent-tinted. Shows a bare65- * "↺ history" when empty and "↺ hide history" when [expanded].66- */67-@Composable68-internal fun PasswordHistoryToggle(69-    count: Int,70-    expanded: Boolean,71-    onToggle: () -> Unit,72-) {73-    val accent = LocalPeachAccent.current74-    val label = if (count == 0) "↺ history" else "↺ history ($count)"75-    Text(76-        if (expanded) "↺ hide history" else label,77-        color = accent.copy(alpha = 0.7f),78-        fontFamily = PeachType.Display,79-        fontStyle = FontStyle.Italic,80-        fontSize = 15.sp,81-        modifier = Modifier.clip(RoundedCornerShape(6.dp)).clickable(onClick = onToggle).padding(vertical = 4.dp),82-    )83-}84-85-/**86- * The expanded body: either the empty-state explainer or the list of past87- * passwords. Caller owns the expand/collapse (and any AnimatedVisibility wrap).88- */89-@Composable90-internal fun PasswordHistoryList(91-    history: List<PasswordHistoryItem>,92-    onRestore: (String) -> Unit,93-    onCopy: (String) -> Unit,94-) {95-    val accent = LocalPeachAccent.current96-    if (history.isEmpty()) {97-        Box(98-            Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))99-                .border(1.dp, accent.copy(alpha = 0.12f), RoundedCornerShape(8.dp))100-                .background(accent.copy(alpha = 0.05f)).padding(10.dp),101-        ) {102-            Text(103-                "No earlier passwords yet. When you change this password, the old one is saved here so you can copy or restore it.",104-                color = PeachColors.T2, fontFamily = PeachType.Mono, fontSize = 10.sp,105-            )106-        }107-    } else {108-        Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {109-            history.forEach { item -> HistoryRow(item, onRestore, onCopy) }110-        }111-    }112-}113-114-@Composable115-private fun HistoryRow(116-    item: PasswordHistoryItem,117-    onRestore: (String) -> Unit,118-    onCopy: (String) -> Unit,119-) {120-    val accent = LocalPeachAccent.current121-    var revealed by remember { mutableStateOf(false) }122-    Row(123-        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))124-            .border(1.dp, accent.copy(alpha = 0.12f), RoundedCornerShape(8.dp))125-            .background(accent.copy(alpha = 0.06f)).padding(horizontal = 10.dp, vertical = 8.dp),126-        verticalAlignment = Alignment.CenterVertically,127-        horizontalArrangement = Arrangement.SpaceBetween,128-    ) {129-        Column(Modifier.weight(1f)) {130-            Text(131-                if (revealed) item.password else "••••••••••••",132-                color = PeachColors.T0, fontFamily = PeachType.Mono, fontSize = 12.sp, maxLines = 1,133-            )134-            Text(135-                timeSince(item.changedAt),136-                color = accent.copy(alpha = 0.55f), fontFamily = PeachType.Mono, fontSize = 8.sp,137-            )138-        }139-        Spacer(Modifier.width(6.dp))140-        HistoryAction(if (revealed) "hide" else "show") { revealed = !revealed }141-        HistoryAction("copy") { onCopy(item.password) }142-        HistoryAction("use") { onRestore(item.password) }143-    }144-}145-146-@Composable147-private fun HistoryAction(label: String, onClick: () -> Unit) {148-    Text(149-        label, color = LocalPeachAccent.current.copy(alpha = 0.7f),150-        fontFamily = PeachType.Mono, fontSize = 9.sp,151-        modifier = Modifier.clip(RoundedCornerShape(5.dp)).clickable(onClick = onClick).padding(horizontal = 5.dp, vertical = 3.dp),152-    )153-}154-155-/** Coarse "time since" label for the history list. Mirrors the browser helper. */156-private fun timeSince(whenMs: Long): String {157-    val secs = ((System.currentTimeMillis() - whenMs) / 1000).coerceAtLeast(0)158-    if (secs < 60) return "just now"159-    val mins = secs / 60160-    if (mins < 60) return "${mins}m ago"161-    val hours = mins / 60162-    if (hours < 24) return "${hours}h ago"163-    val days = hours / 24164-    if (days < 30) return "${days}d ago"165-    val months = days / 30166-    if (months < 12) return "${months}mo ago"167-    return "${months / 12}y ago"168-}

view file at the parent

app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+2 −103
@@ -52,7 +52,6 @@5252 import com.peachpasswords.ui.theme.PeachRadius5353 import com.peachpasswords.ui.theme.PeachType5454 import com.peachpasswords.ui.theme.ShellBackground55-import com.peachpasswords.vault.PasswordHistoryItem5655 5756 @Composable5857 fun EntryEditScreen(@@ -355,105 +354,5 @@355354     }356355 }357356 358-/**359- * Past-password history. The toggle is always present (even with no history) so360- * the affordance is discoverable — empty state explains how it fills. Rows are361- * masked until revealed; "use" loads the value back into the editor so the362- * normal save records the swap.363- */364-@Composable365-private fun PasswordHistorySection(366-    history: List<PasswordHistoryItem>,367-    expanded: Boolean,368-    onToggle: () -> Unit,369-    onRestore: (String) -> Unit,370-    onCopy: (String) -> Unit,371-) {372-    val accent = LocalPeachAccent.current373-    Column(Modifier.fillMaxWidth().padding(bottom = 14.dp)) {374-        val label = if (history.isEmpty()) "↺ history" else "↺ history (${history.size})"375-        Text(376-            if (expanded) "↺ hide history" else label,377-            color = accent.copy(alpha = 0.7f),378-            fontFamily = PeachType.Display,379-            fontStyle = FontStyle.Italic,380-            fontSize = 15.sp,381-            modifier = Modifier.clip(RoundedCornerShape(6.dp)).clickable(onClick = onToggle).padding(vertical = 4.dp),382-        )383-        if (expanded) {384-            Spacer(Modifier.height(8.dp))385-            if (history.isEmpty()) {386-                Box(387-                    Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))388-                        .border(1.dp, accent.copy(alpha = 0.12f), RoundedCornerShape(8.dp))389-                        .background(accent.copy(alpha = 0.05f)).padding(10.dp),390-                ) {391-                    Text(392-                        "No earlier passwords yet. When you change this password, the old one is saved here so you can copy or restore it.",393-                        color = PeachColors.T2, fontFamily = PeachType.Mono, fontSize = 10.sp,394-                    )395-                }396-            } else {397-                Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {398-                    history.forEach { item -> HistoryRow(item, onRestore, onCopy) }399-                }400-            }401-        }402-    }403-}404-405-@Composable406-private fun HistoryRow(407-    item: PasswordHistoryItem,408-    onRestore: (String) -> Unit,409-    onCopy: (String) -> Unit,410-) {411-    val accent = LocalPeachAccent.current412-    var revealed by remember { mutableStateOf(false) }413-    Row(414-        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))415-            .border(1.dp, accent.copy(alpha = 0.12f), RoundedCornerShape(8.dp))416-            .background(accent.copy(alpha = 0.06f)).padding(horizontal = 10.dp, vertical = 8.dp),417-        verticalAlignment = Alignment.CenterVertically,418-        horizontalArrangement = Arrangement.SpaceBetween,419-    ) {420-        Column(Modifier.weight(1f)) {421-            Text(422-                if (revealed) item.password else "••••••••••••",423-                color = PeachColors.T0, fontFamily = PeachType.Mono, fontSize = 12.sp, maxLines = 1,424-            )425-            Text(426-                timeSince(item.changedAt),427-                color = accent.copy(alpha = 0.55f), fontFamily = PeachType.Mono, fontSize = 8.sp,428-            )429-        }430-        Spacer(Modifier.width(6.dp))431-        HistoryAction(if (revealed) "hide" else "show") { revealed = !revealed }432-        HistoryAction("copy") { onCopy(item.password) }433-        HistoryAction("use") { onRestore(item.password) }434-    }435-}436-437-@Composable438-private fun HistoryAction(label: String, onClick: () -> Unit) {439-    Text(440-        label, color = LocalPeachAccent.current.copy(alpha = 0.7f),441-        fontFamily = PeachType.Mono, fontSize = 9.sp,442-        modifier = Modifier.clip(RoundedCornerShape(5.dp)).clickable(onClick = onClick).padding(horizontal = 5.dp, vertical = 3.dp),443-    )444-}445-446-/** Coarse "time since" label for the history list. Mirrors the browser helper. */447-private fun timeSince(whenMs: Long): String {448-    val secs = ((System.currentTimeMillis() - whenMs) / 1000).coerceAtLeast(0)449-    if (secs < 60) return "just now"450-    val mins = secs / 60451-    if (mins < 60) return "${mins}m ago"452-    val hours = mins / 60453-    if (hours < 24) return "${hours}h ago"454-    val days = hours / 24455-    if (days < 30) return "${days}d ago"456-    val months = days / 30457-    if (months < 12) return "${months}mo ago"458-    return "${months / 12}y ago"459-}357+// PasswordHistorySection / HistoryRow / HistoryAction / timeSince were extracted358+// to ui/vault/PasswordHistorySection.kt (D7) so EntryDetailScreen can reuse them.

view file

app/src/main/java/com/peachpasswords/ui/vault/PasswordHistorySection.kt+168 −0
@@ -0,0 +1,168 @@1+package com.peachpasswords.ui.vault2+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.fillMaxWidth12+import androidx.compose.foundation.layout.height13+import androidx.compose.foundation.layout.padding14+import androidx.compose.foundation.layout.width15+import androidx.compose.foundation.shape.RoundedCornerShape16+import androidx.compose.material3.Text17+import androidx.compose.runtime.Composable18+import androidx.compose.runtime.getValue19+import androidx.compose.runtime.mutableStateOf20+import androidx.compose.runtime.remember21+import androidx.compose.runtime.setValue22+import androidx.compose.ui.Alignment23+import androidx.compose.ui.Modifier24+import androidx.compose.ui.draw.clip25+import androidx.compose.ui.text.font.FontStyle26+import androidx.compose.ui.unit.dp27+import androidx.compose.ui.unit.sp28+import com.peachpasswords.ui.theme.LocalPeachAccent29+import com.peachpasswords.ui.theme.PeachColors30+import com.peachpasswords.ui.theme.PeachType31+import com.peachpasswords.vault.PasswordHistoryItem32+33+/**34+ * Shared past-password history UI, extracted from EntryEditScreen so both the35+ * editor and EntryDetailScreen render the same rows. Behavior is unchanged from36+ * the original private copy.37+ *38+ * - [PasswordHistorySection] is the original combined toggle + content block used39+ *   by EntryEditScreen (toggle always present so the affordance is discoverable;40+ *   empty state explains how it fills).41+ * - [PasswordHistoryToggle] + [PasswordHistoryList] split the same pieces apart so42+ *   EntryDetailScreen can drive expand/collapse with AnimatedVisibility itself.43+ *44+ * Rows are masked until revealed; "use" hands the value to [onRestore].45+ */46+@Composable47+internal fun PasswordHistorySection(48+    history: List<PasswordHistoryItem>,49+    expanded: Boolean,50+    onToggle: () -> Unit,51+    onRestore: (String) -> Unit,52+    onCopy: (String) -> Unit,53+) {54+    Column(Modifier.fillMaxWidth().padding(bottom = 14.dp)) {55+        PasswordHistoryToggle(count = history.size, expanded = expanded, onToggle = onToggle)56+        if (expanded) {57+            Spacer(Modifier.height(8.dp))58+            PasswordHistoryList(history = history, onRestore = onRestore, onCopy = onCopy)59+        }60+    }61+}62+63+/**64+ * The "↺ history (N)" affordance — Cormorant italic, accent-tinted. Shows a bare65+ * "↺ history" when empty and "↺ hide history" when [expanded].66+ */67+@Composable68+internal fun PasswordHistoryToggle(69+    count: Int,70+    expanded: Boolean,71+    onToggle: () -> Unit,72+) {73+    val accent = LocalPeachAccent.current74+    val label = if (count == 0) "↺ history" else "↺ history ($count)"75+    Text(76+        if (expanded) "↺ hide history" else label,77+        color = accent.copy(alpha = 0.7f),78+        fontFamily = PeachType.Display,79+        fontStyle = FontStyle.Italic,80+        fontSize = 15.sp,81+        modifier = Modifier.clip(RoundedCornerShape(6.dp)).clickable(onClick = onToggle).padding(vertical = 4.dp),82+    )83+}84+85+/**86+ * The expanded body: either the empty-state explainer or the list of past87+ * passwords. Caller owns the expand/collapse (and any AnimatedVisibility wrap).88+ */89+@Composable90+internal fun PasswordHistoryList(91+    history: List<PasswordHistoryItem>,92+    onRestore: (String) -> Unit,93+    onCopy: (String) -> Unit,94+) {95+    val accent = LocalPeachAccent.current96+    if (history.isEmpty()) {97+        Box(98+            Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))99+                .border(1.dp, accent.copy(alpha = 0.12f), RoundedCornerShape(8.dp))100+                .background(accent.copy(alpha = 0.05f)).padding(10.dp),101+        ) {102+            Text(103+                "No earlier passwords yet. When you change this password, the old one is saved here so you can copy or restore it.",104+                color = PeachColors.T2, fontFamily = PeachType.Mono, fontSize = 10.sp,105+            )106+        }107+    } else {108+        Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {109+            history.forEach { item -> HistoryRow(item, onRestore, onCopy) }110+        }111+    }112+}113+114+@Composable115+private fun HistoryRow(116+    item: PasswordHistoryItem,117+    onRestore: (String) -> Unit,118+    onCopy: (String) -> Unit,119+) {120+    val accent = LocalPeachAccent.current121+    var revealed by remember { mutableStateOf(false) }122+    Row(123+        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))124+            .border(1.dp, accent.copy(alpha = 0.12f), RoundedCornerShape(8.dp))125+            .background(accent.copy(alpha = 0.06f)).padding(horizontal = 10.dp, vertical = 8.dp),126+        verticalAlignment = Alignment.CenterVertically,127+        horizontalArrangement = Arrangement.SpaceBetween,128+    ) {129+        Column(Modifier.weight(1f)) {130+            Text(131+                if (revealed) item.password else "••••••••••••",132+                color = PeachColors.T0, fontFamily = PeachType.Mono, fontSize = 12.sp, maxLines = 1,133+            )134+            Text(135+                timeSince(item.changedAt),136+                color = accent.copy(alpha = 0.55f), fontFamily = PeachType.Mono, fontSize = 8.sp,137+            )138+        }139+        Spacer(Modifier.width(6.dp))140+        HistoryAction(if (revealed) "hide" else "show") { revealed = !revealed }141+        HistoryAction("copy") { onCopy(item.password) }142+        HistoryAction("use") { onRestore(item.password) }143+    }144+}145+146+@Composable147+private fun HistoryAction(label: String, onClick: () -> Unit) {148+    Text(149+        label, color = LocalPeachAccent.current.copy(alpha = 0.7f),150+        fontFamily = PeachType.Mono, fontSize = 9.sp,151+        modifier = Modifier.clip(RoundedCornerShape(5.dp)).clickable(onClick = onClick).padding(horizontal = 5.dp, vertical = 3.dp),152+    )153+}154+155+/** Coarse "time since" label for the history list. Mirrors the browser helper. */156+private fun timeSince(whenMs: Long): String {157+    val secs = ((System.currentTimeMillis() - whenMs) / 1000).coerceAtLeast(0)158+    if (secs < 60) return "just now"159+    val mins = secs / 60160+    if (mins < 60) return "${mins}m ago"161+    val hours = mins / 60162+    if (hours < 24) return "${hours}h ago"163+    val days = hours / 24164+    if (days < 30) return "${days}d ago"165+    val months = days / 30166+    if (months < 12) return "${months}mo ago"167+    return "${months / 12}y ago"168+}

view file