f2c1c32676a2

add password-history reveal/copy/restore UI to Compose edit screen with empty state; bump v2.1.13

time
2026-06-07 16:05 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
password history
parent
01a36beeebcd
3 files app/build.gradle+2 −2app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+113 −0app/src/main/java/com/peachpasswords/ui/vault/EntryEditViewModel.kt+20 −1
app/build.gradle+2 −2
@@ -16,8 +16,8 @@1616         applicationId "com.peachpasswords"1717         minSdk 261818         targetSdk 3519-        versionCode 20101220-        versionName "2.1.12"19+        versionCode 20101320+        versionName "2.1.13"2121 2222         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"2323         vectorDrawables {

view file

app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+113 −0
@@ -25,6 +25,9 @@2525 import androidx.compose.material3.Text2626 import androidx.compose.runtime.Composable2727 import androidx.compose.runtime.getValue28+import androidx.compose.runtime.mutableStateOf29+import androidx.compose.runtime.remember30+import androidx.compose.runtime.setValue2831 import androidx.compose.ui.Alignment2932 import androidx.compose.ui.Modifier3033 import androidx.compose.ui.draw.clip@@ -47,6 +50,7 @@4750 import com.peachpasswords.ui.theme.PeachRadius4851 import com.peachpasswords.ui.theme.PeachType4952 import com.peachpasswords.ui.theme.ShellBackground53+import com.peachpasswords.vault.PasswordHistoryItem5054 5155 @Composable5256 fun EntryEditScreen(@@ -103,6 +107,13 @@103107                         onNumbers = vm::setGenNumbers, onSymbols = vm::setGenSymbols,104108                         onGenerate = vm::generate,105109                     )110+                    PasswordHistorySection(111+                        history = f.history,112+                        expanded = f.showHistory,113+                        onToggle = vm::toggleHistory,114+                        onRestore = vm::restorePassword,115+                        onCopy = vm::copyHistoryPassword,116+                    )106117                     Field("2FA secret (otpauth:// or base32)", f.totp, vm::setTotp)107118                 }108119                 Field("notes", f.notes, vm::setNotes, singleLine = false)@@ -264,4 +275,106 @@264275     ) {265276         Text(label, color = if (on) accent else PeachColors.T2, fontFamily = PeachType.Mono, fontSize = 9.sp)266277     }278+}279+280+/**281+ * Past-password history. The toggle is always present (even with no history) so282+ * the affordance is discoverable — empty state explains how it fills. Rows are283+ * masked until revealed; "use" loads the value back into the editor so the284+ * normal save records the swap.285+ */286+@Composable287+private fun PasswordHistorySection(288+    history: List<PasswordHistoryItem>,289+    expanded: Boolean,290+    onToggle: () -> Unit,291+    onRestore: (String) -> Unit,292+    onCopy: (String) -> Unit,293+) {294+    val accent = LocalPeachAccent.current295+    Column(Modifier.fillMaxWidth().padding(bottom = 14.dp)) {296+        val label = if (history.isEmpty()) "↺ history" else "↺ history (${history.size})"297+        Text(298+            if (expanded) "↺ hide history" else label,299+            color = accent.copy(alpha = 0.7f),300+            fontFamily = PeachType.Mono,301+            fontSize = 11.sp,302+            modifier = Modifier.clip(RoundedCornerShape(6.dp)).clickable(onClick = onToggle).padding(vertical = 4.dp),303+        )304+        if (expanded) {305+            Spacer(Modifier.height(8.dp))306+            if (history.isEmpty()) {307+                Box(308+                    Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))309+                        .border(1.dp, accent.copy(alpha = 0.12f), RoundedCornerShape(8.dp))310+                        .background(accent.copy(alpha = 0.05f)).padding(10.dp),311+                ) {312+                    Text(313+                        "No earlier passwords yet. When you change this password, the old one is saved here so you can copy or restore it.",314+                        color = PeachColors.T2, fontFamily = PeachType.Mono, fontSize = 10.sp,315+                    )316+                }317+            } else {318+                Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {319+                    history.forEach { item -> HistoryRow(item, onRestore, onCopy) }320+                }321+            }322+        }323+    }324+}325+326+@Composable327+private fun HistoryRow(328+    item: PasswordHistoryItem,329+    onRestore: (String) -> Unit,330+    onCopy: (String) -> Unit,331+) {332+    val accent = LocalPeachAccent.current333+    var revealed by remember { mutableStateOf(false) }334+    Row(335+        Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))336+            .border(1.dp, accent.copy(alpha = 0.12f), RoundedCornerShape(8.dp))337+            .background(accent.copy(alpha = 0.06f)).padding(horizontal = 10.dp, vertical = 8.dp),338+        verticalAlignment = Alignment.CenterVertically,339+        horizontalArrangement = Arrangement.SpaceBetween,340+    ) {341+        Column(Modifier.weight(1f)) {342+            Text(343+                if (revealed) item.password else "••••••••••••",344+                color = PeachColors.T0, fontFamily = PeachType.Mono, fontSize = 12.sp, maxLines = 1,345+            )346+            Text(347+                timeSince(item.changedAt),348+                color = accent.copy(alpha = 0.55f), fontFamily = PeachType.Mono, fontSize = 8.sp,349+            )350+        }351+        Spacer(Modifier.width(6.dp))352+        HistoryAction(if (revealed) "hide" else "show") { revealed = !revealed }353+        HistoryAction("copy") { onCopy(item.password) }354+        HistoryAction("use") { onRestore(item.password) }355+    }356+}357+358+@Composable359+private fun HistoryAction(label: String, onClick: () -> Unit) {360+    Text(361+        label, color = LocalPeachAccent.current.copy(alpha = 0.7f),362+        fontFamily = PeachType.Mono, fontSize = 9.sp,363+        modifier = Modifier.clip(RoundedCornerShape(5.dp)).clickable(onClick = onClick).padding(horizontal = 5.dp, vertical = 3.dp),364+    )365+}366+367+/** Coarse "time since" label for the history list. Mirrors the browser helper. */368+private fun timeSince(whenMs: Long): String {369+    val secs = ((System.currentTimeMillis() - whenMs) / 1000).coerceAtLeast(0)370+    if (secs < 60) return "just now"371+    val mins = secs / 60372+    if (mins < 60) return "${mins}m ago"373+    val hours = mins / 60374+    if (hours < 24) return "${hours}h ago"375+    val days = hours / 24376+    if (days < 30) return "${days}d ago"377+    val months = days / 30378+    if (months < 12) return "${months}mo ago"379+    return "${months / 12}y ago"267380 }

view file

app/src/main/java/com/peachpasswords/ui/vault/EntryEditViewModel.kt+20 −1
@@ -1,12 +1,17 @@11 package com.peachpasswords.ui.vault22 3+import android.content.ClipData4+import android.content.ClipboardManager5+import android.content.Context36 import androidx.lifecycle.SavedStateHandle47 import androidx.lifecycle.ViewModel58 import androidx.lifecycle.viewModelScope69 import com.peachpasswords.vault.PasswordGenerator10+import com.peachpasswords.vault.PasswordHistoryItem711 import com.peachpasswords.vault.VaultEntry812 import com.peachpasswords.vault.VaultRepository913 import dagger.hilt.android.lifecycle.HiltViewModel14+import dagger.hilt.android.qualifiers.ApplicationContext1015 import kotlinx.coroutines.flow.MutableStateFlow1116 import kotlinx.coroutines.flow.StateFlow1217 import kotlinx.coroutines.flow.asStateFlow@@ -25,6 +30,8 @@2530     val notes: String = "",2631     val showPassword: Boolean = false,2732     val generatorOpen: Boolean = false,33+    val history: List<PasswordHistoryItem> = emptyList(),34+    val showHistory: Boolean = false,2835     val genLength: Int = 20,2936     val genUpper: Boolean = true,3037     val genLower: Boolean = true,@@ -37,6 +44,7 @@3744 @HiltViewModel3845 class EntryEditViewModel @Inject constructor(3946     private val vault: VaultRepository,47+    @ApplicationContext private val appContext: Context,4048     savedStateHandle: SavedStateHandle,4149 ) : ViewModel() {4250     private val id: String? = savedStateHandle.get<String>("id")?.takeIf { it.isNotBlank() }@@ -54,6 +62,7 @@5462                 url = it.url.orEmpty(),5563                 totp = it.totp.orEmpty(),5664                 notes = it.notes.orEmpty(),65+                history = it.passwordHistory.orEmpty(),5766             )5867         } ?: EditForm(),5968     )@@ -68,7 +77,17 @@6877     fun setTotp(v: String) = _form.update { it.copy(totp = v) }6978     fun setNotes(v: String) = _form.update { it.copy(notes = v) }7079     fun toggleShowPassword() = _form.update { it.copy(showPassword = !it.showPassword) }71-    fun toggleGenerator() = _form.update { it.copy(generatorOpen = !it.generatorOpen) }80+    fun toggleGenerator() = _form.update { it.copy(generatorOpen = !it.generatorOpen, showHistory = false) }81+    fun toggleHistory() = _form.update { it.copy(showHistory = !it.showHistory, generatorOpen = false) }82+83+    /** Restore a past password into the editor; the save flow records the swap. */84+    fun restorePassword(pw: String) =85+        _form.update { it.copy(password = pw, showPassword = true, showHistory = false) }86+87+    fun copyHistoryPassword(pw: String) {88+        val cm = appContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager89+        cm.setPrimaryClip(ClipData.newPlainText("peach", pw))90+    }7291     fun setGenLength(n: Int) = _form.update { it.copy(genLength = n) }7392     fun setGenUpper(b: Boolean) = _form.update { it.copy(genUpper = b) }7493     fun setGenLower(b: Boolean) = _form.update { it.copy(genLower = b) }

view file