INTEGRATION.md
E6 — TOTP Double-Tap to Edit · Integration
Goal: double-tap (or a 14dp pencil icon) on the TOTP code in EntryDetailScreen
opens an inline editor for the 2FA secret (masked field + eye toggle + ✓/✗,
mirroring the D6 inline-edit pattern). On save it persists the new secret via
vm.updateEntry(entry.copy(totp = newValue)) and TotpBand regenerates live.
An invalid/unparseable secret shows "Invalid 2FA secret" in breach color and
blocks save.
Draft file: app/drafts/E6/TotpInlineEdit.kt — one public composable
TotpBandEditable(...) plus E6-prefixed private helpers (no name collisions with
D6's UnderlinedField / SaveCancelRow).
D6 / D7 / E6 all touch
EntryDetailScreen.kt. This block is self-contained and uses only one anchor (the existing TotpBand call site). Merge order with D6/D7 is irrelevant for E6 except for the sharedCopyButtonvisibility note below.
1. Destination
Move app/drafts/E6/TotpInlineEdit.kt →
app/src/main/java/com/peachpasswords/ui/vault/TotpInlineEdit.kt
(same package com.peachpasswords.ui.vault).
It is a separate file, so it references the existing private CopyButton from
EntryDetailScreen.kt. Make CopyButton internal (change private fun CopyButton → internal fun CopyButton) so this file can call it. No other
visibility changes are needed.
(Alternative: paste TotpBandEditable and its private helpers directly into
EntryDetailScreen.kt, in which case leave CopyButton private. The E6-prefixed
helper names already avoid collisions with the D6 helpers if D6 is also inlined.)
2. Insertion anchor — swap the TotpBand call site
In EntryDetailScreen.kt, the EntryDetailScreen composable currently renders the
read-only band here:
if (e.hasTOTP()) {
Spacer(Modifier.height(4.dp))
TotpBand(totpField = e.totp!!, copied = copiedField == "totp", onCopy = vm::copyTotp)
}
Replace the TotpBand(...) call with TotpBandEditable(...):
if (e.hasTOTP()) {
Spacer(Modifier.height(4.dp))
TotpBandEditable(
totpField = e.totp!!,
copied = copiedField == "totp",
onCopy = vm::copyTotp,
onSaveSecret = { newSecret -> vm.updateTotp(newSecret) },
)
}
The existing private TotpBand composable in EntryDetailScreen.kt becomes unused
after this swap — delete it (lines ~303–357, the @Composable private fun TotpBand(...) block) to avoid an unused-symbol lint warning. Its visual chrome is
reproduced verbatim inside TotpBandEditable's view mode.
3. New ViewModel method — EntryDetailViewModel.updateTotp
EntryDetailViewModel currently has no updateEntry/update path (only
reveal, mask, copy, copyTotp, delete). Add a method that patches just the
totp field via the existing repo updateEntry. The repo already exposes:
suspend fun updateEntry(patch: VaultEntry): VaultEntry // VaultRepository.kt:262 — full-entry replace
Add to EntryDetailViewModel (it already injects VaultRepository vault and holds
val entry: StateFlow<VaultEntry?>):
/** Persist a new 2FA secret (base32 or otpauth:// URI). Caller validates first. */
fun updateTotp(newSecret: String) {
val current = entry.value ?: return
viewModelScope.launch {
runCatching { vault.updateEntry(current.copy(totp = newSecret)) }
}
}
This satisfies the brief's vm.updateEntry(entry.copy(totp = newValue)) contract
(same effect, named for the single field). The entry StateFlow re-emits after the
repo persists, so TotpBandEditable receives the new totpField and regenerates
the code live with no further wiring.
If D6's integration already adds a generic
fun updateField(field: String, value: String)orfun updateEntry(patch: VaultEntry)to this VM, you may instead call that fromonSaveSecret(e.g.onSaveSecret = { vm.updateField("totp", it) }) and skip addingupdateTotp. Pick one; don't add both.
4. Secret validation
Validation reuses the existing generator — no new code:
TOTPGenerator.generateCode(trimmed) != null // null ⇒ empty / unparseable secret
TOTPGenerator.parse accepts both a bare base32 secret and a full
otpauth://totp/...?secret=... URI (see vault/TOTPGenerator.kt:18,40). A blank,
non-base32, or malformed value yields null, which the editor surfaces as
"Invalid 2FA secret" (breach color) and blocks the save. Valid secrets call back
through onSaveSecret.
5. New imports
None required in EntryDetailScreen.kt for the call-site swap (all referenced
symbols already imported). TotpInlineEdit.kt carries its own imports.
EntryDetailViewModel.kt already imports viewModelScope, launch, and
VaultEntry — no new imports for updateTotp.
6. Risks / assumptions
CopyButtonvisibility: the only cross-file coupling. Flip it tointernal(§1) or inline the E6 composable. D6/D7 may want the same flip — make it once.- Delete the old
TotpBand(§2) or it lints as unused. - VM method dedupe (§3): if D6 adds a generic update method, reuse it instead of
updateTotp. - Live regeneration depends on
EntryDetailViewModel.entrybeing a StateFlow backed byvault.entries(it is —EntryDetailViewModel.kt:31), so the saved secret flows back automatically. - The editor seeds the draft from the raw stored
totp(base32 or otpauth URI), i.e. the user edits/sees the secret itself, never the generated code. Masked by default; eye toggle reveals.