INTEGRATION.md

7.7 KB · raw

rendered · source

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:

/**
 * Past-password history. The toggle is always present (even with no history) so

through the end of:

    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:

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):

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:

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):

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):

                        onCopy = { vm.copy("password", pw) },
                    )
                }
                // <-- D7 block goes here, before:
                if (e.hasTOTP()) {

D7 block to insert:

                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:


Step 3 — VM / repo method: restorePassword

3a. No new repository method needed

VaultRepository.updateEntry(patch: VaultEntry) (line 262) already:

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):

    /**
     * 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