# D7 — Password History in EntryDetailScreen — Integration Two steps: (1) EXTRACT the shared section, (2) add a toggle + panel to EntryDetailScreen with a `restorePassword` VM method. D6, D7, and E6 all touch `EntryDetailScreen.kt`. The D7 insertion block below is self-contained and anchored so it merges cleanly alongside the others. --- ## Step 1 — EXTRACT (shared file + EntryEditScreen import) ### 1a. New file Copy `app/drafts/D7/PasswordHistorySection.kt` to: ``` app/src/main/java/com/peachpasswords/ui/vault/PasswordHistorySection.kt ``` Package is already `com.peachpasswords.ui.vault`. It exposes three `internal` composables — `PasswordHistorySection` (combined toggle+content, unchanged signature used by the editor), `PasswordHistoryToggle`, and `PasswordHistoryList` — plus the private `HistoryRow` / `HistoryAction` / `timeSince` helpers. ### 1b. Delete the private copy from `EntryEditScreen.kt` Delete the **entire** `PasswordHistorySection`, `HistoryRow`, `HistoryAction`, and `timeSince` definitions — lines 292–393 (the block that starts with the KDoc `/** Past-password history. ... */` and ends with the closing brace of `timeSince`). Concretely, delete from: ```kotlin /** * Past-password history. The toggle is always present (even with no history) so ``` through the end of: ```kotlin val months = days / 30 if (months < 12) return "${months}mo ago" return "${months / 12}y ago" } ``` Do **not** delete `TogglePill` (lines 279–290, immediately above) — it is a separate helper used elsewhere in EntryEditScreen and is **not** part of the history section. The call site in `EntryEditScreen` (lines 121–127) stays exactly as-is — the 5-arg `PasswordHistorySection(history, expanded, onToggle, onRestore, onCopy)` signature is preserved by the shared file, so behavior is identical: ```kotlin PasswordHistorySection( history = f.history, expanded = f.showHistory, onToggle = vm::toggleHistory, onRestore = vm::restorePassword, onCopy = vm::copyHistoryPassword, ) ``` ### 1c. Imports in `EntryEditScreen.kt` The history composables are now in the same package, so the call resolves with **no new import**. After removing the private copy, these imports MAY become unused and should be deleted **only if** nothing else in the file still uses them (grep first — `FontStyle`, `Arrangement`, and `width` are commonly used by other composables in this file, so likely keep them): - `androidx.compose.ui.text.font.FontStyle` — was used by the section's italic toggle. Keep if any other `FontStyle.Italic` remains. - `com.peachpasswords.vault.PasswordHistoryItem` (line 54) — was the section's param type. Delete only if no other reference remains in the file. `assembleDebug` will flag any genuinely unused import; let it guide pruning. --- ## Step 2 — DETAIL (toggle + panel in EntryDetailScreen) ### 2a. New imports in `EntryDetailScreen.kt` Add: ```kotlin import androidx.compose.animation.AnimatedVisibility import com.peachpasswords.vault.VaultEntry ``` `VaultEntry` is needed for the empty-history guard helper (or use `e.passwordHistory.orEmpty()` inline and skip the import). The history composables (`PasswordHistoryToggle`, `PasswordHistoryList`) are in the same package — no import required. ### 2b. Local expand state Add alongside the existing screen-level state (near `confirmingDelete`, around line 88): ```kotlin var historyExpanded by remember { mutableStateOf(false) } ``` (`remember`, `mutableStateOf`, `getValue`, `setValue` are already imported.) ### 2c. Insertion anchor — below the password row In the scrollable content `Column`, the password row ends at line 224 and the TOTP block begins at line 225. Insert the D7 block **between them**. Anchor (existing code — do not modify, insert immediately after the closing `}` of the `e.password?...let { pw -> PasswordRow(...) }` block at line 224): ```kotlin onCopy = { vm.copy("password", pw) }, ) } // <-- D7 block goes here, before: if (e.hasTOTP()) { ``` D7 block to insert: ```kotlin val history = e.passwordHistory.orEmpty() if (history.isNotEmpty()) { PasswordHistoryToggle( count = history.size, expanded = historyExpanded, onToggle = { historyExpanded = !historyExpanded }, ) AnimatedVisibility(visible = historyExpanded) { Column(Modifier.padding(top = 8.dp, bottom = 6.dp)) { PasswordHistoryList( history = history, onRestore = { oldPw -> vm.restorePassword(e.id, oldPw) }, onCopy = { oldPw -> vm.copy("password", oldPw) }, ) } } } ``` Notes: - `Column`, `Modifier`, `padding`, `dp` are all already imported in EntryDetailScreen. - `vm.copy("password", oldPw)` reuses the existing clipboard+latch helper for the row "copy" action (the detail VM has no separate history-copy method, unlike the editor VM). - Spec wants the toggle "↺ history (N)" in Cormorant italic, t2. The shared `PasswordHistoryToggle` renders accent-tinted Cormorant italic 15sp (matching the editor's established look). If a strict t2 13sp variant is required for detail, that is a one-line styling tweak; current draft keeps it consistent with the editor for visual coherence. --- ## Step 3 — VM / repo method: `restorePassword` ### 3a. No new repository method needed `VaultRepository.updateEntry(patch: VaultEntry)` (line 262) already: - captures the outgoing password into `passwordHistory` (newest first, deduped, capped at `PASSWORD_HISTORY_MAX`) whenever `patch.password != current.password`, - refreshes `passwordChangedAt`, - preserves `createdAt` and bumps `modifiedAt`. So restore = "set password to the old value and persist" — `updateEntry` records the swap automatically (same path the editor relies on). ### 3b. Add to `EntryDetailViewModel.kt` Add this method (mirrors the existing `delete`/`copy` style; `viewModelScope`, `launch`, and `vault` are already in scope): ```kotlin /** * Restore a past password as the current one. updateEntry captures the * now-outgoing password into history, so this is a normal password swap. */ fun restorePassword(entryId: String, oldPassword: String) { viewModelScope.launch { val current = vault.getEntry(entryId) ?: return@launch if (current.password == oldPassword) return@launch runCatching { vault.updateEntry(current.copy(password = oldPassword)) } } } ``` `vault.getEntry(id)` (repo line 342) returns the live, non-deleted entry. Passing the full `current.copy(...)` matters: `updateEntry` is a full-entry replace, so a partial patch would clobber other fields. The `entryId` param matches the brief's `vm.restorePassword(entry.id, oldPw)` call shape. (The VM already knows its own `id` via SavedStateHandle, so the param is technically redundant — but the brief specifies the two-arg signature, so it is kept.) --- ## Risks / assumptions - `assembleDebug` is the source of truth for which EntryEditScreen imports to prune after the extract — do not pre-emptively delete `FontStyle` / `PasswordHistoryItem` without grepping the file first. - Toggle styling kept consistent with the editor (Cormorant italic 15sp, accent 0.7). Brief says "t2 13sp"; treat as a cosmetic decision for the orchestrator. - No new strings, nav routes, DI, or model changes. `passwordHistory` and `PasswordHistoryItem` already exist; `updateEntry` already does history capture.