1# E6 — TOTP Double-Tap to Edit · Integration23Goal: double-tap (or a 14dp pencil icon) on the TOTP code in `EntryDetailScreen`4opens an inline editor for the 2FA secret (masked field + eye toggle + ✓/✗,5mirroring the D6 inline-edit pattern). On save it persists the new secret via6`vm.updateEntry(entry.copy(totp = newValue))` and `TotpBand` regenerates live.7An invalid/unparseable secret shows **"Invalid 2FA secret"** in breach color and8blocks save.910Draft file: `app/drafts/E6/TotpInlineEdit.kt` — one public composable11`TotpBandEditable(...)` plus E6-prefixed private helpers (no name collisions with12D6's `UnderlinedField` / `SaveCancelRow`).1314> D6 / D7 / E6 all touch `EntryDetailScreen.kt`. This block is self-contained and15> uses only one anchor (the existing TotpBand call site). Merge order with D6/D7 is16> irrelevant for E6 except for the shared `CopyButton` visibility note below.1718---1920## 1. Destination2122Move `app/drafts/E6/TotpInlineEdit.kt` →23`app/src/main/java/com/peachpasswords/ui/vault/TotpInlineEdit.kt`24(same package `com.peachpasswords.ui.vault`).2526It is a separate file, so it references the existing private `CopyButton` from27`EntryDetailScreen.kt`. **Make `CopyButton` `internal`** (change `private fun28CopyButton` → `internal fun CopyButton`) so this file can call it. No other29visibility changes are needed.3031(Alternative: paste `TotpBandEditable` and its private helpers directly into32`EntryDetailScreen.kt`, in which case leave `CopyButton` private. The E6-prefixed33helper names already avoid collisions with the D6 helpers if D6 is also inlined.)3435---3637## 2. Insertion anchor — swap the TotpBand call site3839In `EntryDetailScreen.kt`, the `EntryDetailScreen` composable currently renders the40read-only band here:4142```kotlin43 if (e.hasTOTP()) {44 Spacer(Modifier.height(4.dp))45 TotpBand(totpField = e.totp!!, copied = copiedField == "totp", onCopy = vm::copyTotp)46 }47```4849Replace the `TotpBand(...)` call with `TotpBandEditable(...)`:5051```kotlin52 if (e.hasTOTP()) {53 Spacer(Modifier.height(4.dp))54 TotpBandEditable(55 totpField = e.totp!!,56 copied = copiedField == "totp",57 onCopy = vm::copyTotp,58 onSaveSecret = { newSecret -> vm.updateTotp(newSecret) },59 )60 }61```6263The existing private `TotpBand` composable in `EntryDetailScreen.kt` becomes unused64after this swap — **delete it** (lines ~303–357, the `@Composable private fun65TotpBand(...)` block) to avoid an unused-symbol lint warning. Its visual chrome is66reproduced verbatim inside `TotpBandEditable`'s view mode.6768---6970## 3. New ViewModel method — `EntryDetailViewModel.updateTotp`7172`EntryDetailViewModel` currently has **no** `updateEntry`/update path (only73`reveal`, `mask`, `copy`, `copyTotp`, `delete`). Add a method that patches just the74`totp` field via the existing repo `updateEntry`. The repo already exposes:7576```kotlin77suspend fun updateEntry(patch: VaultEntry): VaultEntry // VaultRepository.kt:262 — full-entry replace78```7980Add to `EntryDetailViewModel` (it already injects `VaultRepository vault` and holds81`val entry: StateFlow<VaultEntry?>`):8283```kotlin84 /** Persist a new 2FA secret (base32 or otpauth:// URI). Caller validates first. */85 fun updateTotp(newSecret: String) {86 val current = entry.value ?: return87 viewModelScope.launch {88 runCatching { vault.updateEntry(current.copy(totp = newSecret)) }89 }90 }91```9293This satisfies the brief's `vm.updateEntry(entry.copy(totp = newValue))` contract94(same effect, named for the single field). The `entry` StateFlow re-emits after the95repo persists, so `TotpBandEditable` receives the new `totpField` and regenerates96the code live with no further wiring.9798> If D6's integration already adds a generic `fun updateField(field: String, value:99> String)` or `fun updateEntry(patch: VaultEntry)` to this VM, you may instead call100> that from `onSaveSecret` (e.g. `onSaveSecret = { vm.updateField("totp", it) }`)101> and skip adding `updateTotp`. Pick one; don't add both.102103---104105## 4. Secret validation106107Validation reuses the existing generator — no new code:108109```kotlin110TOTPGenerator.generateCode(trimmed) != null // null ⇒ empty / unparseable secret111```112113`TOTPGenerator.parse` accepts both a bare base32 secret and a full114`otpauth://totp/...?secret=...` URI (see `vault/TOTPGenerator.kt:18,40`). A blank,115non-base32, or malformed value yields `null`, which the editor surfaces as116"Invalid 2FA secret" (breach color) and blocks the save. Valid secrets call back117through `onSaveSecret`.118119---120121## 5. New imports122123None required in `EntryDetailScreen.kt` for the call-site swap (all referenced124symbols already imported). `TotpInlineEdit.kt` carries its own imports.125126`EntryDetailViewModel.kt` already imports `viewModelScope`, `launch`, and127`VaultEntry` — no new imports for `updateTotp`.128129---130131## 6. Risks / assumptions132133- **`CopyButton` visibility**: the only cross-file coupling. Flip it to `internal`134 (§1) or inline the E6 composable. D6/D7 may want the same flip — make it once.135- **Delete the old `TotpBand`** (§2) or it lints as unused.136- **VM method dedupe** (§3): if D6 adds a generic update method, reuse it instead of137 `updateTotp`.138- Live regeneration depends on `EntryDetailViewModel.entry` being a StateFlow backed139 by `vault.entries` (it is — `EntryDetailViewModel.kt:31`), so the saved secret140 flows back automatically.141- The editor seeds the draft from the raw stored `totp` (base32 or otpauth URI),142 i.e. the user edits/sees the secret itself, never the generated code. Masked by143 default; eye toggle reveals.