1# D4 (Remainder) — Integration Guide23Two features, plus one shared-file extraction:45- **D4-a** [Copy] drain button in `GeneratorDrawer` (EntryEditScreen).6- **D4-b** Wrench → `GeneratorDrawer` as a `ModalBottomSheet` in EntryDetailScreen,7 producing a local draft password with [Copy] (drain) + [Use this password].8- **D4-0** Extract the private `CopyButton` from EntryDetailScreen to a shared file9 so both surfaces can reuse the exact spec §4.4 sheen+drain animation.1011Drafts in this folder:1213| Draft file | Destination |14|---|---|15| `CopyButton.kt` | `app/src/main/java/com/peachpasswords/ui/components/CopyButton.kt` (NEW) |16| `GeneratorDrawerWithCopy.kt` | merge into `ui/vault/EntryEditScreen.kt` (replace `GeneratorDrawer`, add `GeneratorBody`) |17| `EntryDetailGenerator.kt` | merge into `ui/vault/EntryDetailScreen.kt` (`WrenchButton`, `GeneratorSheet`) |1819All drafts already declare their final package (`com.peachpasswords.ui.components`20or `com.peachpasswords.ui.vault`), so a plain move/merge compiles.2122---2324## D4-0 — Extract CopyButton (do this FIRST)2526`CopyButton` is currently a `private @Composable` at the bottom of27`EntryDetailScreen.kt` (lines ~359–416). It is used by `FieldRow`, `PasswordRow`,28and `TotpBand` in that file.2930### Steps31321. Drop `CopyButton.kt` in at `ui/components/CopyButton.kt`. It is the identical33 body, package `com.peachpasswords.ui.components`, visibility changed34 `private` → public `fun CopyButton(...)`. The KDoc is preserved.35362. In `EntryDetailScreen.kt`, **delete** the private `CopyButton` composable37 (the whole block from its KDoc `/** Copy button with the two-effect ... */`38 through its closing brace, lines ~359–416).39403. Add the import to `EntryDetailScreen.kt` (alphabetical, beside the other41 `com.peachpasswords.ui.components.*` imports — there are already42 `CharEnterText`, `FaviconInitials`, `TOTPRing`):4344 ```kotlin45 import com.peachpasswords.ui.components.CopyButton46 ```4748 Anchor (existing imports, lines ~63–65):49 ```kotlin50 import com.peachpasswords.ui.components.CharEnterText51 import com.peachpasswords.ui.components.FaviconInitials52 import com.peachpasswords.ui.components.TOTPRing53 ```54554. After deleting the private copy, the following imports in `EntryDetailScreen.kt`56 become unused **only if** nothing else in the file uses them. `TotpBand` still57 uses `animateFloat`, `Brush`, etc., so re-check; the ones the deleted58 `CopyButton` *uniquely* relied on are `Icons.Rounded.Check`,59 `Icons.Rounded.ContentCopy` (lines 30–31). Verify with the compiler / lint and60 remove any that are now dangling. (Leave anything `TotpBand`/`PasswordRow` use.)6162No behaviour change — same composable, same call sites.6364---6566## D4-a — [Copy] drain button in the inline GeneratorDrawer6768### VM additions (EntryEditViewModel)6970The drawer's [Copy] button needs (1) a copied latch for the drain animation and71(2) a copy action. The VM already has `copyHistoryPassword` (clipboard) but no72latch. Add a `genCopied` flag to `EditForm` and a `copyGenerated()`:7374```kotlin75// in EditForm:76val genCopied: Boolean = false,77```7879```kotlin80// in EntryEditViewModel:81fun copyGenerated() {82 val pw = _form.value.password83 if (pw.isEmpty()) return84 val cm = appContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager85 cm.setPrimaryClip(ClipData.newPlainText("peach", pw))86 viewModelScope.launch {87 _form.update { it.copy(genCopied = true) }88 kotlinx.coroutines.delay(1200)89 _form.update { it.copy(genCopied = false) }90 }91}92```9394(`ClipData`, `ClipboardManager`, `Context` are already imported in95EntryEditViewModel.kt.)9697### Composable merge (EntryEditScreen.kt)98991. Replace the entire private `GeneratorDrawer` composable (lines ~225–276) with100 the `GeneratorDrawer` + `GeneratorBody` from `GeneratorDrawerWithCopy.kt`.101 - The replacement `GeneratorDrawer` is `internal` (so the detail screen could102 reuse it too, though detail uses `GeneratorBody` directly).103 - **Delete** the duplicate `private fun TogglePill` at the bottom of104 `GeneratorDrawerWithCopy.kt` and keep EntryEditScreen's existing105 `TogglePill` (lines ~278–290). They are identical except corner radius:106 the existing one uses `PeachRadius.TypeTab`; the draft uses `8.dp`. **Keep107 the existing `PeachRadius.TypeTab` version** for consistency.1081092. Add the import:110 ```kotlin111 import com.peachpasswords.ui.components.CopyButton112 ```1131143. Update the call site. Anchor (lines ~112–120):115 ```kotlin116 GeneratorDrawer(117 open = f.generatorOpen,118 length = f.genLength,119 upper = f.genUpper, lower = f.genLower, numbers = f.genNumbers, symbols = f.genSymbols,120 onLength = vm::setGenLength,121 onUpper = vm::setGenUpper, onLower = vm::setGenLower,122 onNumbers = vm::setGenNumbers, onSymbols = vm::setGenSymbols,123 onGenerate = vm::generate,124 )125 ```126 becomes:127 ```kotlin128 GeneratorDrawer(129 open = f.generatorOpen,130 length = f.genLength,131 upper = f.genUpper, lower = f.genLower, numbers = f.genNumbers, symbols = f.genSymbols,132 password = f.password,133 copied = f.genCopied,134 onLength = vm::setGenLength,135 onUpper = vm::setGenUpper, onLower = vm::setGenLower,136 onNumbers = vm::setGenNumbers, onSymbols = vm::setGenSymbols,137 onGenerate = vm::generate,138 onCopy = vm::copyGenerated,139 )140 ```141142Note: the drawer fixed height grew 188 → 234dp to fit the generate/copy row.143144---145146## D4-b — Generator in EntryDetailScreen (wrench + bottom sheet)147148### VM addition (EntryDetailViewModel)149150Add a method that applies a new password via `updateEntry`. **Password history is151captured automatically** by `VaultRepository.updateEntry` whenever the password152value changes (see `VaultRepository.kt` lines ~268–290: it records the prior153password into `passwordHistory`, capped at `PASSWORD_HISTORY_MAX`, skipping empty154and dup priors). So we only pass `entry.copy(password = newPw)` — do NOT build155history manually.156157```kotlin158fun applyGeneratedPassword(newPassword: String, onDone: () -> Unit = {}) {159 val current = entry.value ?: return160 if (newPassword.isEmpty() || newPassword == current.password) { onDone(); return }161 viewModelScope.launch {162 runCatching { vault.updateEntry(current.copy(password = newPassword)) }163 onDone()164 }165}166```167168The sheet's [Copy] uses the existing `copy(field, value)` + `copiedField` latch.169Reuse a dedicated field name, e.g. `"genDraft"`:170171```kotlin172// already exists — just call with a distinct field id:173vm.copy("genDraft", draftPassword)174// and observe: copiedField == "genDraft"175```176177No new copy method needed. (`updateEntry` is already exposed on the repo;178`viewModelScope`, `launch`, `vault` are all in scope in EntryDetailViewModel.)179180### Composable merge (EntryDetailScreen.kt)1811821. Drop `WrenchButton` and `GeneratorSheet` from `EntryDetailGenerator.kt` into183 the file (or keep them in their own file in `ui/vault/` — same package, both184 `internal`, compiles either way). `GeneratorSheet` depends on `GeneratorBody`185 (from D4-a) — ensure D4-a is merged first.1861872. Add imports to EntryDetailScreen.kt:188 ```kotlin189 import androidx.compose.runtime.mutableStateOf // already present190 import androidx.compose.runtime.remember // already present191 import androidx.compose.runtime.setValue // already present192 ```193 (All three are already imported — nothing new needed for state. `GeneratorSheet`194 carries its own `ModalBottomSheet`/`Build`/`PasswordGenerator` imports in its195 file.)1961973. Hoist sheet-open state in `EntryDetailScreen`. Anchor — beside the existing198 `confirmingDelete` state (line ~88):199 ```kotlin200 var confirmingDelete by remember { mutableStateOf(false) }201 ```202 add:203 ```kotlin204 var generatorOpen by remember { mutableStateOf(false) }205 ```2062074. Add the wrench to the password row. The password value is rendered by208 `PasswordRow` (lines ~208–224 call site, composable ~258–280). Pass an209 `onGenerate` lambda through to it and render `WrenchButton` beside `CopyButton`.210211 Call-site anchor (lines ~208–224):212 ```kotlin213 e.password?.takeIf { it.isNotBlank() }?.let { pw ->214 PasswordRow(215 value = pw,216 revealed = revealed,217 copied = copiedField == "password",218 onReveal = { ... },219 onCopy = { vm.copy("password", pw) },220 )221 }222 ```223 Add `onGenerate = { generatorOpen = true }` to the `PasswordRow(...)` call.224225 In the `PasswordRow` composable (lines ~258–280), add the param226 `onGenerate: () -> Unit` and render the wrench between the show/hide text and227 the CopyButton:228 ```kotlin229 CopyButton(copied, onCopy)230 WrenchButton(onClick = onGenerate) // <-- add this line, after CopyButton231 ```2322335. Render the sheet (anywhere inside the `EntryDetailScreen` composable body,234 e.g. just before the closing of `ShellBackground { ... }`, after the scrolling235 Column at line ~234). Guard on `generatorOpen` and a non-null entry:236 ```kotlin237 if (generatorOpen && e != null) {238 GeneratorSheet(239 copied = copiedField == "genDraft",240 onCopy = { draft -> vm.copy("genDraft", draft) },241 onUse = { draft ->242 vm.applyGeneratedPassword(draft) { generatorOpen = false }243 },244 onDismiss = { generatorOpen = false },245 )246 }247 ```248249 Note `e` is captured as `val e = entry` at line ~97 — inside the250 `ShellBackground` lambda use the same `e`/`entry` you already have in scope.251252---253254## Summary of new public/internal API the orchestrator must add255256| Where | Member | Why |257|---|---|---|258| `ui/components/CopyButton.kt` | `fun CopyButton(copied, onCopy)` (public) | shared §4.4 drain button |259| `EditForm` | `val genCopied: Boolean = false` | drain latch for inline drawer |260| `EntryEditViewModel` | `fun copyGenerated()` | clipboard + latch for drawer [Copy] |261| `EntryDetailViewModel` | `fun applyGeneratedPassword(newPassword, onDone)` | [Use this password] → updateEntry (auto history) |262| `EntryDetailViewModel` | reuse `copy("genDraft", ...)` + `copiedField=="genDraft"` | sheet [Copy] drain |263264## Risks / assumptions265266- **Icon**: `Icons.Outlined.Build` is a wrench glyph and is in267 `material-icons-extended` (already a dependency). If a closer wrench is desired,268 `Icons.Outlined.Construction` is also available.269- **History capture is repo-driven**: do NOT hand-build `PasswordHistoryItem` in270 the detail path; `updateEntry` already records the prior password on change.271 Verified in `VaultRepository.kt` lines 268–290.272- **Drawer height**: bumped to 234dp to fit the generate+copy row; tweak if the273 toggle row wraps on very small screens.274- **TogglePill duplication**: the draft ships a local `TogglePill` so it compiles275 standalone — delete it on merge and keep EntryEditScreen's existing one276 (`PeachRadius.TypeTab` radius).277- **ModalBottomSheet**: `@OptIn(ExperimentalMaterial3Api::class)` required on the278 caller (`GeneratorSheet` already annotates itself); pattern mirrors279 `AutofillEntryPickerActivity.kt`.280- No nav routes added; the sheet is in-screen state only.