INTEGRATION.md

7.7 KB · raw

rendered · source

1# D7 — Password History in EntryDetailScreen — Integration23Two steps: (1) EXTRACT the shared section, (2) add a toggle + panel to4EntryDetailScreen with a `restorePassword` VM method.56D6, D7, and E6 all touch `EntryDetailScreen.kt`. The D7 insertion block below is7self-contained and anchored so it merges cleanly alongside the others.89---1011## Step 1 — EXTRACT (shared file + EntryEditScreen import)1213### 1a. New file1415Copy `app/drafts/D7/PasswordHistorySection.kt` to:1617```18app/src/main/java/com/peachpasswords/ui/vault/PasswordHistorySection.kt19```2021Package is already `com.peachpasswords.ui.vault`. It exposes three `internal`22composables — `PasswordHistorySection` (combined toggle+content, unchanged23signature used by the editor), `PasswordHistoryToggle`, and24`PasswordHistoryList` — plus the private `HistoryRow` / `HistoryAction` /25`timeSince` helpers.2627### 1b. Delete the private copy from `EntryEditScreen.kt`2829Delete the **entire** `PasswordHistorySection`, `HistoryRow`, `HistoryAction`,30and `timeSince` definitions — lines 292–393 (the block that starts with the31KDoc `/** Past-password history. ... */` and ends with the closing brace of32`timeSince`). Concretely, delete from:3334```kotlin35/**36 * Past-password history. The toggle is always present (even with no history) so37```3839through the end of:4041```kotlin42    val months = days / 3043    if (months < 12) return "${months}mo ago"44    return "${months / 12}y ago"45}46```4748Do **not** delete `TogglePill` (lines 279–290, immediately above) — it is a49separate helper used elsewhere in EntryEditScreen and is **not** part of the50history section.5152The call site in `EntryEditScreen` (lines 121–127) stays exactly as-is — the535-arg `PasswordHistorySection(history, expanded, onToggle, onRestore, onCopy)`54signature is preserved by the shared file, so behavior is identical:5556```kotlin57PasswordHistorySection(58    history = f.history,59    expanded = f.showHistory,60    onToggle = vm::toggleHistory,61    onRestore = vm::restorePassword,62    onCopy = vm::copyHistoryPassword,63)64```6566### 1c. Imports in `EntryEditScreen.kt`6768The history composables are now in the same package, so the call resolves with69**no new import**. After removing the private copy, these imports MAY become70unused and should be deleted **only if** nothing else in the file still uses71them (grep first — `FontStyle`, `Arrangement`, and `width` are commonly used by72other composables in this file, so likely keep them):7374- `androidx.compose.ui.text.font.FontStyle` — was used by the section's italic75  toggle. Keep if any other `FontStyle.Italic` remains.76- `com.peachpasswords.vault.PasswordHistoryItem` (line 54) — was the section's77  param type. Delete only if no other reference remains in the file.7879`assembleDebug` will flag any genuinely unused import; let it guide pruning.8081---8283## Step 2 — DETAIL (toggle + panel in EntryDetailScreen)8485### 2a. New imports in `EntryDetailScreen.kt`8687Add:8889```kotlin90import androidx.compose.animation.AnimatedVisibility91import com.peachpasswords.vault.VaultEntry92```9394`VaultEntry` is needed for the empty-history guard helper (or use95`e.passwordHistory.orEmpty()` inline and skip the import). The history96composables (`PasswordHistoryToggle`, `PasswordHistoryList`) are in the same97package — no import required.9899### 2b. Local expand state100101Add alongside the existing screen-level state (near `confirmingDelete`, around102line 88):103104```kotlin105var historyExpanded by remember { mutableStateOf(false) }106```107108(`remember`, `mutableStateOf`, `getValue`, `setValue` are already imported.)109110### 2c. Insertion anchor — below the password row111112In the scrollable content `Column`, the password row ends at line 224 and the113TOTP block begins at line 225. Insert the D7 block **between them**.114115Anchor (existing code — do not modify, insert immediately after the closing116`}` of the `e.password?...let { pw -> PasswordRow(...) }` block at line 224):117118```kotlin119                        onCopy = { vm.copy("password", pw) },120                    )121                }122                // <-- D7 block goes here, before:123                if (e.hasTOTP()) {124```125126D7 block to insert:127128```kotlin129                val history = e.passwordHistory.orEmpty()130                if (history.isNotEmpty()) {131                    PasswordHistoryToggle(132                        count = history.size,133                        expanded = historyExpanded,134                        onToggle = { historyExpanded = !historyExpanded },135                    )136                    AnimatedVisibility(visible = historyExpanded) {137                        Column(Modifier.padding(top = 8.dp, bottom = 6.dp)) {138                            PasswordHistoryList(139                                history = history,140                                onRestore = { oldPw -> vm.restorePassword(e.id, oldPw) },141                                onCopy = { oldPw -> vm.copy("password", oldPw) },142                            )143                        }144                    }145                }146```147148Notes:149- `Column`, `Modifier`, `padding`, `dp` are all already imported in150  EntryDetailScreen.151- `vm.copy("password", oldPw)` reuses the existing clipboard+latch helper for152  the row "copy" action (the detail VM has no separate history-copy method,153  unlike the editor VM).154- Spec wants the toggle "↺ history (N)" in Cormorant italic, t2. The shared155  `PasswordHistoryToggle` renders accent-tinted Cormorant italic 15sp (matching156  the editor's established look). If a strict t2 13sp variant is required for157  detail, that is a one-line styling tweak; current draft keeps it consistent158  with the editor for visual coherence.159160---161162## Step 3 — VM / repo method: `restorePassword`163164### 3a. No new repository method needed165166`VaultRepository.updateEntry(patch: VaultEntry)` (line 262) already:167- captures the outgoing password into `passwordHistory` (newest first, deduped,168  capped at `PASSWORD_HISTORY_MAX`) whenever `patch.password != current.password`,169- refreshes `passwordChangedAt`,170- preserves `createdAt` and bumps `modifiedAt`.171172So restore = "set password to the old value and persist" — `updateEntry` records173the swap automatically (same path the editor relies on).174175### 3b. Add to `EntryDetailViewModel.kt`176177Add this method (mirrors the existing `delete`/`copy` style; `viewModelScope`,178`launch`, and `vault` are already in scope):179180```kotlin181    /**182     * Restore a past password as the current one. updateEntry captures the183     * now-outgoing password into history, so this is a normal password swap.184     */185    fun restorePassword(entryId: String, oldPassword: String) {186        viewModelScope.launch {187            val current = vault.getEntry(entryId) ?: return@launch188            if (current.password == oldPassword) return@launch189            runCatching { vault.updateEntry(current.copy(password = oldPassword)) }190        }191    }192```193194`vault.getEntry(id)` (repo line 342) returns the live, non-deleted entry.195Passing the full `current.copy(...)` matters: `updateEntry` is a full-entry196replace, so a partial patch would clobber other fields.197198The `entryId` param matches the brief's `vm.restorePassword(entry.id, oldPw)`199call shape. (The VM already knows its own `id` via SavedStateHandle, so the200param is technically redundant — but the brief specifies the two-arg signature,201so it is kept.)202203---204205## Risks / assumptions206207- `assembleDebug` is the source of truth for which EntryEditScreen imports to208  prune after the extract — do not pre-emptively delete `FontStyle` /209  `PasswordHistoryItem` without grepping the file first.210- Toggle styling kept consistent with the editor (Cormorant italic 15sp, accent211  0.7). Brief says "t2 13sp"; treat as a cosmetic decision for the orchestrator.212- No new strings, nav routes, DI, or model changes. `passwordHistory` and213  `PasswordHistoryItem` already exist; `updateEntry` already does history capture.