387d4fb954ca
feat: D4 generator — extract shared CopyButton (ui/components), [Copy] drain in EntryEdit GeneratorDrawer, wrench→GeneratorSheet in EntryDetail with [Use this password] (auto history) (v2.1.33)
- time
- 2026-06-09 04:29 UTC · 5 months ago
- machine
- koh2
- agent
- claude-opus-4-8
- session
- peach remaining gaps
- parent
- d39710d35123
↓ peach-android-387d4fb9.tar.gzatlas at this save
files changed8 files
app/drafts/D4/CopyButton.kt+0 −90app/drafts/D4/EntryDetailGenerator.kt+0 −165app/src/main/java/com/peachpasswords/ui/components/CopyButton.kt+90 −0app/src/main/java/com/peachpasswords/ui/vault/EntryDetailGenerator.kt+165 −0app/src/main/java/com/peachpasswords/ui/vault/EntryDetailScreen.kt+14 −59app/src/main/java/com/peachpasswords/ui/vault/EntryDetailViewModel.kt+13 −0app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+61 −23app/src/main/java/com/peachpasswords/ui/vault/EntryEditViewModel.kt+14 −0app/drafts/D4/CopyButton.kt+0 −90
@@ -1,90 +0,0 @@1-package com.peachpasswords.ui.components2-3-import androidx.compose.animation.core.LinearEasing4-import androidx.compose.animation.core.animateFloatAsState5-import androidx.compose.animation.core.tween6-import androidx.compose.foundation.background7-import androidx.compose.foundation.clickable8-import androidx.compose.foundation.layout.Box9-import androidx.compose.foundation.layout.size10-import androidx.compose.foundation.shape.RoundedCornerShape11-import androidx.compose.material.icons.Icons12-import androidx.compose.material.icons.rounded.Check13-import androidx.compose.material.icons.rounded.ContentCopy14-import androidx.compose.material3.Icon15-import androidx.compose.runtime.Composable16-import androidx.compose.runtime.getValue17-import androidx.compose.ui.Alignment18-import androidx.compose.ui.Modifier19-import androidx.compose.ui.draw.clip20-import androidx.compose.ui.draw.drawBehind21-import androidx.compose.ui.geometry.Offset22-import androidx.compose.ui.geometry.Size23-import androidx.compose.ui.graphics.Brush24-import androidx.compose.ui.graphics.Color25-import androidx.compose.ui.unit.dp26-import com.peachpasswords.ui.theme.LocalPeachAccent27-import com.peachpasswords.ui.theme.LocalReduceMotion28-import com.peachpasswords.ui.theme.PeachColors29-30-/**31- * Copy button with the two-effect copy feedback (spec §4.4): a diagonal sheen32- * sweeps once over ~600ms and an accent drain bar fills 0→100% over 1.4s. Both33- * collapse instantly when the copied latch clears, and are skipped under34- * reduce-motion.35- *36- * Extracted from EntryDetailScreen so the generator drawer (EntryEditScreen,37- * detail bottom sheet) can reuse the identical drain animation.38- */39-@Composable40-fun CopyButton(copied: Boolean, onCopy: () -> Unit) {41- val accent = LocalPeachAccent.current42- val reduceMotion = LocalReduceMotion.current43- val animate = copied && !reduceMotion44- val drain by animateFloatAsState(45- targetValue = if (copied) 1f else 0f,46- animationSpec = if (animate) tween(1400, easing = LinearEasing) else tween(0),47- label = "copy-drain",48- )49- val sheen by animateFloatAsState(50- targetValue = if (copied) 1f else 0f,51- animationSpec = if (animate) tween(600, easing = LinearEasing) else tween(0),52- label = "copy-sheen",53- )54- Box(55- Modifier56- .size(36.dp)57- .clip(RoundedCornerShape(6.dp))58- .background(PeachColors.S2)59- .clickable(onClick = onCopy)60- .drawBehind {61- if (animate && sheen < 1f) {62- val sweepX = (sheen * 2f - 0.5f) * size.width63- val band = size.width * 0.5f64- drawRect(65- brush = Brush.linearGradient(66- colors = listOf(Color.Transparent, accent.copy(alpha = 0.35f), Color.Transparent),67- start = Offset(sweepX - band, 0f),68- end = Offset(sweepX + band, size.height),69- ),70- )71- }72- if (drain > 0f) {73- val h = 2.dp.toPx()74- drawRect(75- color = accent,76- topLeft = Offset(0f, size.height - h),77- size = Size(size.width * drain, h),78- )79- }80- },81- contentAlignment = Alignment.Center,82- ) {83- Icon(84- if (copied) Icons.Rounded.Check else Icons.Rounded.ContentCopy,85- contentDescription = "copy",86- tint = if (copied) accent else PeachColors.T1,87- modifier = Modifier.size(15.dp),88- )89- }90-}app/drafts/D4/EntryDetailGenerator.kt+0 −165
@@ -1,165 +0,0 @@1-package com.peachpasswords.ui.vault2-3-/*4- * D4 drafts — generator access from EntryDetailScreen.5- *6- * Provides:7- * - WrenchButton: a 18dp wrench icon to place beside the password copy button.8- * - GeneratorSheet: a ModalBottomSheet wrapping the shared GeneratorBody. It9- * holds LOCAL generator option + draft-password state, never auto-saves, and10- * exposes [Copy] (drain) + [Use this password] (accent). "Use this password"11- * calls onUse(draft) which the screen wires to the VM's setPassword path.12- *13- * This is a DRAFT. The orchestrator integrates per INTEGRATION.md: it must add a14- * `setPassword`/`updateEntry` method to EntryDetailViewModel (see INTEGRATION.md)15- * and a `copy(...)`-backed copied latch for the sheet's draft.16- */17-18-import androidx.compose.foundation.background19-import androidx.compose.foundation.border20-import androidx.compose.foundation.clickable21-import androidx.compose.foundation.layout.Box22-import androidx.compose.foundation.layout.Column23-import androidx.compose.foundation.layout.Spacer24-import androidx.compose.foundation.layout.fillMaxWidth25-import androidx.compose.foundation.layout.height26-import androidx.compose.foundation.layout.padding27-import androidx.compose.foundation.layout.size28-import androidx.compose.foundation.shape.CircleShape29-import androidx.compose.foundation.shape.RoundedCornerShape30-import androidx.compose.material.icons.Icons31-import androidx.compose.material.icons.outlined.Build32-import androidx.compose.material3.ExperimentalMaterial3Api33-import androidx.compose.material3.Icon34-import androidx.compose.material3.ModalBottomSheet35-import androidx.compose.material3.Text36-import androidx.compose.material3.rememberModalBottomSheetState37-import androidx.compose.runtime.Composable38-import androidx.compose.runtime.getValue39-import androidx.compose.runtime.mutableStateOf40-import androidx.compose.runtime.remember41-import androidx.compose.runtime.setValue42-import androidx.compose.ui.Alignment43-import androidx.compose.ui.Modifier44-import androidx.compose.ui.draw.clip45-import androidx.compose.ui.text.font.FontStyle46-import androidx.compose.ui.unit.dp47-import androidx.compose.ui.unit.sp48-import com.peachpasswords.ui.theme.LocalPeachAccent49-import com.peachpasswords.ui.theme.PeachColors50-import com.peachpasswords.ui.theme.PeachType51-import com.peachpasswords.vault.PasswordGenerator52-53-/** Wrench icon (spec: tint t2, 18dp) — opens the generator sheet from the detail password row. */54-@Composable55-internal fun WrenchButton(onClick: () -> Unit) {56- Icon(57- Icons.Outlined.Build,58- contentDescription = "generate password",59- tint = PeachColors.T2,60- modifier = Modifier61- .size(36.dp)62- .clip(CircleShape)63- .clickable(onClick = onClick)64- .padding(9.dp), // 36 - 2*9 = 18dp glyph65- )66-}67-68-/**69- * Generator bottom sheet for EntryDetailScreen. Local-only: generating populates70- * a draft password (never persisted). The user copies it (drain) or commits it71- * via [Use this password], which fires onUse(draft) and dismisses.72- *73- * @param copied latch for the [Copy] drain animation (driven by the screen/VM).74- * @param onCopy copy the current draft to clipboard (sets the latch).75- * @param onUse commit the draft password (VM updateEntry + history capture).76- * @param onDismiss close the sheet without committing.77- */78-@OptIn(ExperimentalMaterial3Api::class)79-@Composable80-internal fun GeneratorSheet(81- copied: Boolean,82- onCopy: (String) -> Unit,83- onUse: (String) -> Unit,84- onDismiss: () -> Unit,85-) {86- val accent = LocalPeachAccent.current87- val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)88-89- var length by remember { mutableStateOf(20) }90- var upper by remember { mutableStateOf(true) }91- var lower by remember { mutableStateOf(true) }92- var numbers by remember { mutableStateOf(true) }93- var symbols by remember { mutableStateOf(true) }94- var draft by remember { mutableStateOf("") }95-96- fun gen() {97- draft = PasswordGenerator.generate(98- PasswordGenerator.Options(99- length = length,100- includeUppercase = upper,101- includeLowercase = lower,102- includeNumbers = numbers,103- includeSymbols = symbols,104- ),105- )106- }107-108- ModalBottomSheet(109- onDismissRequest = onDismiss,110- sheetState = sheetState,111- containerColor = PeachColors.S1,112- ) {113- Column(Modifier.fillMaxWidth().padding(horizontal = 20.dp, vertical = 4.dp)) {114- Text(115- "generate password",116- color = PeachColors.T0,117- fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp,118- )119- Spacer(Modifier.height(8.dp))120-121- // Draft preview — empty until first generate.122- Box(123- Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))124- .border(1.dp, PeachColors.T3, RoundedCornerShape(10.dp))125- .padding(horizontal = 12.dp, vertical = 14.dp),126- ) {127- Text(128- text = draft.ifEmpty { "tap generate" },129- color = if (draft.isEmpty()) PeachColors.T2 else PeachColors.T0,130- fontFamily = PeachType.Mono, fontSize = 13.sp,131- )132- }133- Spacer(Modifier.height(6.dp))134-135- // Shared generator controls + [Copy] drain button on the generate row.136- GeneratorBody(137- length = length,138- upper = upper, lower = lower, numbers = numbers, symbols = symbols,139- password = draft, copied = copied,140- onLength = { length = it },141- onUpper = { upper = it }, onLower = { lower = it },142- onNumbers = { numbers = it }, onSymbols = { symbols = it },143- onGenerate = { gen() },144- onCopy = { if (draft.isNotEmpty()) onCopy(draft) },145- )146-147- // [Use this password] — accent button, commits + closes. No-op while empty.148- Box(149- Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))150- .background(if (draft.isEmpty()) accent.copy(alpha = 0.10f) else accent.copy(alpha = 0.18f))151- .border(1.dp, accent.copy(alpha = 0.5f), RoundedCornerShape(10.dp))152- .clickable(enabled = draft.isNotEmpty()) { onUse(draft) }153- .padding(vertical = 14.dp),154- contentAlignment = Alignment.Center,155- ) {156- Text(157- "use this password",158- color = if (draft.isEmpty()) accent.copy(alpha = 0.5f) else accent,159- fontFamily = PeachType.Mono, fontSize = 12.sp,160- )161- }162- Spacer(Modifier.height(20.dp))163- }164- }165-}app/src/main/java/com/peachpasswords/ui/components/CopyButton.kt+90 −0
@@ -0,0 +1,90 @@1+package com.peachpasswords.ui.components2+3+import androidx.compose.animation.core.LinearEasing4+import androidx.compose.animation.core.animateFloatAsState5+import androidx.compose.animation.core.tween6+import androidx.compose.foundation.background7+import androidx.compose.foundation.clickable8+import androidx.compose.foundation.layout.Box9+import androidx.compose.foundation.layout.size10+import androidx.compose.foundation.shape.RoundedCornerShape11+import androidx.compose.material.icons.Icons12+import androidx.compose.material.icons.rounded.Check13+import androidx.compose.material.icons.rounded.ContentCopy14+import androidx.compose.material3.Icon15+import androidx.compose.runtime.Composable16+import androidx.compose.runtime.getValue17+import androidx.compose.ui.Alignment18+import androidx.compose.ui.Modifier19+import androidx.compose.ui.draw.clip20+import androidx.compose.ui.draw.drawBehind21+import androidx.compose.ui.geometry.Offset22+import androidx.compose.ui.geometry.Size23+import androidx.compose.ui.graphics.Brush24+import androidx.compose.ui.graphics.Color25+import androidx.compose.ui.unit.dp26+import com.peachpasswords.ui.theme.LocalPeachAccent27+import com.peachpasswords.ui.theme.LocalReduceMotion28+import com.peachpasswords.ui.theme.PeachColors29+30+/**31+ * Copy button with the two-effect copy feedback (spec §4.4): a diagonal sheen32+ * sweeps once over ~600ms and an accent drain bar fills 0→100% over 1.4s. Both33+ * collapse instantly when the copied latch clears, and are skipped under34+ * reduce-motion.35+ *36+ * Extracted from EntryDetailScreen so the generator drawer (EntryEditScreen,37+ * detail bottom sheet) can reuse the identical drain animation.38+ */39+@Composable40+fun CopyButton(copied: Boolean, onCopy: () -> Unit) {41+ val accent = LocalPeachAccent.current42+ val reduceMotion = LocalReduceMotion.current43+ val animate = copied && !reduceMotion44+ val drain by animateFloatAsState(45+ targetValue = if (copied) 1f else 0f,46+ animationSpec = if (animate) tween(1400, easing = LinearEasing) else tween(0),47+ label = "copy-drain",48+ )49+ val sheen by animateFloatAsState(50+ targetValue = if (copied) 1f else 0f,51+ animationSpec = if (animate) tween(600, easing = LinearEasing) else tween(0),52+ label = "copy-sheen",53+ )54+ Box(55+ Modifier56+ .size(36.dp)57+ .clip(RoundedCornerShape(6.dp))58+ .background(PeachColors.S2)59+ .clickable(onClick = onCopy)60+ .drawBehind {61+ if (animate && sheen < 1f) {62+ val sweepX = (sheen * 2f - 0.5f) * size.width63+ val band = size.width * 0.5f64+ drawRect(65+ brush = Brush.linearGradient(66+ colors = listOf(Color.Transparent, accent.copy(alpha = 0.35f), Color.Transparent),67+ start = Offset(sweepX - band, 0f),68+ end = Offset(sweepX + band, size.height),69+ ),70+ )71+ }72+ if (drain > 0f) {73+ val h = 2.dp.toPx()74+ drawRect(75+ color = accent,76+ topLeft = Offset(0f, size.height - h),77+ size = Size(size.width * drain, h),78+ )79+ }80+ },81+ contentAlignment = Alignment.Center,82+ ) {83+ Icon(84+ if (copied) Icons.Rounded.Check else Icons.Rounded.ContentCopy,85+ contentDescription = "copy",86+ tint = if (copied) accent else PeachColors.T1,87+ modifier = Modifier.size(15.dp),88+ )89+ }90+}app/src/main/java/com/peachpasswords/ui/vault/EntryDetailGenerator.kt+165 −0
@@ -0,0 +1,165 @@1+package com.peachpasswords.ui.vault2+3+/*4+ * D4 drafts — generator access from EntryDetailScreen.5+ *6+ * Provides:7+ * - WrenchButton: a 18dp wrench icon to place beside the password copy button.8+ * - GeneratorSheet: a ModalBottomSheet wrapping the shared GeneratorBody. It9+ * holds LOCAL generator option + draft-password state, never auto-saves, and10+ * exposes [Copy] (drain) + [Use this password] (accent). "Use this password"11+ * calls onUse(draft) which the screen wires to the VM's setPassword path.12+ *13+ * This is a DRAFT. The orchestrator integrates per INTEGRATION.md: it must add a14+ * `setPassword`/`updateEntry` method to EntryDetailViewModel (see INTEGRATION.md)15+ * and a `copy(...)`-backed copied latch for the sheet's draft.16+ */17+18+import androidx.compose.foundation.background19+import androidx.compose.foundation.border20+import androidx.compose.foundation.clickable21+import androidx.compose.foundation.layout.Box22+import androidx.compose.foundation.layout.Column23+import androidx.compose.foundation.layout.Spacer24+import androidx.compose.foundation.layout.fillMaxWidth25+import androidx.compose.foundation.layout.height26+import androidx.compose.foundation.layout.padding27+import androidx.compose.foundation.layout.size28+import androidx.compose.foundation.shape.CircleShape29+import androidx.compose.foundation.shape.RoundedCornerShape30+import androidx.compose.material.icons.Icons31+import androidx.compose.material.icons.outlined.Build32+import androidx.compose.material3.ExperimentalMaterial3Api33+import androidx.compose.material3.Icon34+import androidx.compose.material3.ModalBottomSheet35+import androidx.compose.material3.Text36+import androidx.compose.material3.rememberModalBottomSheetState37+import androidx.compose.runtime.Composable38+import androidx.compose.runtime.getValue39+import androidx.compose.runtime.mutableStateOf40+import androidx.compose.runtime.remember41+import androidx.compose.runtime.setValue42+import androidx.compose.ui.Alignment43+import androidx.compose.ui.Modifier44+import androidx.compose.ui.draw.clip45+import androidx.compose.ui.text.font.FontStyle46+import androidx.compose.ui.unit.dp47+import androidx.compose.ui.unit.sp48+import com.peachpasswords.ui.theme.LocalPeachAccent49+import com.peachpasswords.ui.theme.PeachColors50+import com.peachpasswords.ui.theme.PeachType51+import com.peachpasswords.vault.PasswordGenerator52+53+/** Wrench icon (spec: tint t2, 18dp) — opens the generator sheet from the detail password row. */54+@Composable55+internal fun WrenchButton(onClick: () -> Unit) {56+ Icon(57+ Icons.Outlined.Build,58+ contentDescription = "generate password",59+ tint = PeachColors.T2,60+ modifier = Modifier61+ .size(36.dp)62+ .clip(CircleShape)63+ .clickable(onClick = onClick)64+ .padding(9.dp), // 36 - 2*9 = 18dp glyph65+ )66+}67+68+/**69+ * Generator bottom sheet for EntryDetailScreen. Local-only: generating populates70+ * a draft password (never persisted). The user copies it (drain) or commits it71+ * via [Use this password], which fires onUse(draft) and dismisses.72+ *73+ * @param copied latch for the [Copy] drain animation (driven by the screen/VM).74+ * @param onCopy copy the current draft to clipboard (sets the latch).75+ * @param onUse commit the draft password (VM updateEntry + history capture).76+ * @param onDismiss close the sheet without committing.77+ */78+@OptIn(ExperimentalMaterial3Api::class)79+@Composable80+internal fun GeneratorSheet(81+ copied: Boolean,82+ onCopy: (String) -> Unit,83+ onUse: (String) -> Unit,84+ onDismiss: () -> Unit,85+) {86+ val accent = LocalPeachAccent.current87+ val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)88+89+ var length by remember { mutableStateOf(20) }90+ var upper by remember { mutableStateOf(true) }91+ var lower by remember { mutableStateOf(true) }92+ var numbers by remember { mutableStateOf(true) }93+ var symbols by remember { mutableStateOf(true) }94+ var draft by remember { mutableStateOf("") }95+96+ fun gen() {97+ draft = PasswordGenerator.generate(98+ PasswordGenerator.Options(99+ length = length,100+ includeUppercase = upper,101+ includeLowercase = lower,102+ includeNumbers = numbers,103+ includeSymbols = symbols,104+ ),105+ )106+ }107+108+ ModalBottomSheet(109+ onDismissRequest = onDismiss,110+ sheetState = sheetState,111+ containerColor = PeachColors.S1,112+ ) {113+ Column(Modifier.fillMaxWidth().padding(horizontal = 20.dp, vertical = 4.dp)) {114+ Text(115+ "generate password",116+ color = PeachColors.T0,117+ fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp,118+ )119+ Spacer(Modifier.height(8.dp))120+121+ // Draft preview — empty until first generate.122+ Box(123+ Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))124+ .border(1.dp, PeachColors.T3, RoundedCornerShape(10.dp))125+ .padding(horizontal = 12.dp, vertical = 14.dp),126+ ) {127+ Text(128+ text = draft.ifEmpty { "tap generate" },129+ color = if (draft.isEmpty()) PeachColors.T2 else PeachColors.T0,130+ fontFamily = PeachType.Mono, fontSize = 13.sp,131+ )132+ }133+ Spacer(Modifier.height(6.dp))134+135+ // Shared generator controls + [Copy] drain button on the generate row.136+ GeneratorBody(137+ length = length,138+ upper = upper, lower = lower, numbers = numbers, symbols = symbols,139+ password = draft, copied = copied,140+ onLength = { length = it },141+ onUpper = { upper = it }, onLower = { lower = it },142+ onNumbers = { numbers = it }, onSymbols = { symbols = it },143+ onGenerate = { gen() },144+ onCopy = { if (draft.isNotEmpty()) onCopy(draft) },145+ )146+147+ // [Use this password] — accent button, commits + closes. No-op while empty.148+ Box(149+ Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))150+ .background(if (draft.isEmpty()) accent.copy(alpha = 0.10f) else accent.copy(alpha = 0.18f))151+ .border(1.dp, accent.copy(alpha = 0.5f), RoundedCornerShape(10.dp))152+ .clickable(enabled = draft.isNotEmpty()) { onUse(draft) }153+ .padding(vertical = 14.dp),154+ contentAlignment = Alignment.Center,155+ ) {156+ Text(157+ "use this password",158+ color = if (draft.isEmpty()) accent.copy(alpha = 0.5f) else accent,159+ fontFamily = PeachType.Mono, fontSize = 12.sp,160+ )161+ }162+ Spacer(Modifier.height(20.dp))163+ }164+ }165+}app/src/main/java/com/peachpasswords/ui/vault/EntryDetailScreen.kt+14 −59
@@ -61,6 +61,7 @@6161 import androidx.hilt.navigation.compose.hiltViewModel6262 import com.peachpasswords.ui.PeachNav6363 import com.peachpasswords.ui.components.CharEnterText64+import com.peachpasswords.ui.components.CopyButton6465 import com.peachpasswords.ui.components.FaviconInitials6566 import com.peachpasswords.ui.components.TOTPRing6667 import com.peachpasswords.ui.lock.Biometrics@@ -89,6 +90,7 @@8990 val context = LocalContext.current9091 val accent = LocalPeachAccent.current9192 var confirmingDelete by remember { mutableStateOf(false) }93+ var generatorOpen by remember { mutableStateOf(false) }9294 9395 // FLAG_SECURE only while this screen is shown — blocks screenshots of secrets.9496 DisposableEffect(Unit) {@@ -248,6 +250,7 @@248250 }249251 },250252 onCopy = { vm.copy("password", pw) },253+ onGenerate = { generatorOpen = true },251254 )252255 }253256 if (e.hasTOTP()) {@@ -267,6 +270,15 @@267270 268271 Spacer(Modifier.height(48.dp))269272 }273+274+ if (generatorOpen) {275+ GeneratorSheet(276+ copied = copiedField == "genDraft",277+ onCopy = { draft -> vm.copy("genDraft", draft) },278+ onUse = { draft -> vm.applyGeneratedPassword(draft) { generatorOpen = false } },279+ onDismiss = { generatorOpen = false },280+ )281+ }270282 }271283 }272284 }@@ -297,6 +309,7 @@297309 copied: Boolean,298310 onReveal: () -> Unit,299311 onCopy: () -> Unit,312+ onGenerate: () -> Unit,300313 ) {301314 val accent = LocalPeachAccent.current302315 FieldShell("password") {@@ -311,6 +324,7 @@311324 modifier = Modifier.clip(RoundedCornerShape(6.dp)).clickable(onClick = onReveal).padding(8.dp),312325 )313326 CopyButton(copied, onCopy)327+ WrenchButton(onClick = onGenerate)314328 }315329 }316330 @@ -388,65 +402,6 @@388402 Spacer(Modifier.width(8.dp))389403 CopyButton(copied, onCopy)390404 }391- }392-}393-394-/**395- * Copy button with the two-effect copy feedback (spec §4.4): a diagonal sheen396- * sweeps once over ~600ms and an accent drain bar fills 0→100% over 1.4s. Both397- * collapse instantly when the copied latch clears, and are skipped under398- * reduce-motion.399- */400-@Composable401-private fun CopyButton(copied: Boolean, onCopy: () -> Unit) {402- val accent = LocalPeachAccent.current403- val reduceMotion = LocalReduceMotion.current404- val animate = copied && !reduceMotion405- val drain by animateFloatAsState(406- targetValue = if (copied) 1f else 0f,407- animationSpec = if (animate) tween(1400, easing = LinearEasing) else tween(0),408- label = "copy-drain",409- )410- val sheen by animateFloatAsState(411- targetValue = if (copied) 1f else 0f,412- animationSpec = if (animate) tween(600, easing = LinearEasing) else tween(0),413- label = "copy-sheen",414- )415- Box(416- Modifier417- .size(36.dp)418- .clip(RoundedCornerShape(6.dp))419- .background(PeachColors.S2)420- .clickable(onClick = onCopy)421- .drawBehind {422- if (animate && sheen < 1f) {423- val sweepX = (sheen * 2f - 0.5f) * size.width424- val band = size.width * 0.5f425- drawRect(426- brush = Brush.linearGradient(427- colors = listOf(Color.Transparent, accent.copy(alpha = 0.35f), Color.Transparent),428- start = Offset(sweepX - band, 0f),429- end = Offset(sweepX + band, size.height),430- ),431- )432- }433- if (drain > 0f) {434- val h = 2.dp.toPx()435- drawRect(436- color = accent,437- topLeft = Offset(0f, size.height - h),438- size = Size(size.width * drain, h),439- )440- }441- },442- contentAlignment = Alignment.Center,443- ) {444- Icon(445- if (copied) Icons.Rounded.Check else Icons.Rounded.ContentCopy,446- contentDescription = "copy",447- tint = if (copied) accent else PeachColors.T1,448- modifier = Modifier.size(15.dp),449- )450405 }451406 }452407 app/src/main/java/com/peachpasswords/ui/vault/EntryDetailViewModel.kt+13 −0
@@ -80,6 +80,19 @@8080 copy("totp", TOTPGenerator.generateCode(totp))8181 }8282 83+ /**84+ * Apply a generated password via updateEntry — VaultRepository captures the85+ * prior password into history automatically, so we only pass the new value.86+ */87+ fun applyGeneratedPassword(newPassword: String, onDone: () -> Unit = {}) {88+ val current = entry.value ?: return89+ if (newPassword.isEmpty() || newPassword == current.password) { onDone(); return }90+ viewModelScope.launch {91+ runCatching { vault.updateEntry(current.copy(password = newPassword)) }92+ onDone()93+ }94+ }95+8396 fun delete(onDone: () -> Unit) {8497 viewModelScope.launch {8598 runCatching { vault.deleteEntry(id) }app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+61 −23
@@ -45,6 +45,7 @@4545 import androidx.compose.ui.unit.sp4646 import androidx.compose.runtime.collectAsState4747 import androidx.hilt.navigation.compose.hiltViewModel48+import com.peachpasswords.ui.components.CopyButton4849 import com.peachpasswords.ui.theme.LocalPeachAccent4950 import com.peachpasswords.ui.theme.PeachColors5051 import com.peachpasswords.ui.theme.PeachMotion@@ -120,10 +121,13 @@120121 open = f.generatorOpen,121122 length = f.genLength,122123 upper = f.genUpper, lower = f.genLower, numbers = f.genNumbers, symbols = f.genSymbols,124+ password = f.password,125+ copied = f.genCopied,123126 onLength = vm::setGenLength,124127 onUpper = vm::setGenUpper, onLower = vm::setGenLower,125128 onNumbers = vm::setGenNumbers, onSymbols = vm::setGenSymbols,126129 onGenerate = vm::generate,130+ onCopy = vm::copyGenerated,127131 )128132 PasswordHistorySection(129133 history = f.history,@@ -255,14 +259,16 @@255259 open: Boolean,256260 length: Int,257261 upper: Boolean, lower: Boolean, numbers: Boolean, symbols: Boolean,262+ password: String,263+ copied: Boolean,258264 onLength: (Int) -> Unit,259265 onUpper: (Boolean) -> Unit, onLower: (Boolean) -> Unit,260266 onNumbers: (Boolean) -> Unit, onSymbols: (Boolean) -> Unit,261267 onGenerate: () -> Unit,268+ onCopy: () -> Unit,262269 ) {263- val accent = LocalPeachAccent.current264270 val height by animateDpAsState(265- targetValue = if (open) 188.dp else 0.dp,271+ targetValue = if (open) 234.dp else 0.dp,266272 animationSpec = tween(320, easing = PeachMotion.Spring),267273 label = "gen-drawer",268274 )@@ -270,27 +276,58 @@270276 Modifier.fillMaxWidth().height(height).clipToBounds()271277 .clip(RoundedCornerShape(12.dp)).background(PeachColors.S2),272278 ) {273- Column(Modifier.fillMaxWidth().padding(16.dp)) {274- Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {275- Text("GENERATOR", color = PeachColors.T1, fontFamily = PeachType.Mono, fontSize = 8.sp)276- Text("length $length", color = accent, fontFamily = PeachType.Mono, fontSize = 9.sp)277- }278- Slider(279- value = length.toFloat(),280- onValueChange = { onLength(it.toInt()) },281- valueRange = 8f..128f,282- colors = SliderDefaults.colors(thumbColor = accent, activeTrackColor = accent,283- inactiveTrackColor = PeachColors.T3),284- )285- Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {286- TogglePill("A-Z", upper, onUpper)287- TogglePill("a-z", lower, onLower)288- TogglePill("0-9", numbers, onNumbers)289- TogglePill("!@#", symbols, onSymbols)290- }291- Spacer(Modifier.height(12.dp))279+ GeneratorBody(280+ length = length,281+ upper = upper, lower = lower, numbers = numbers, symbols = symbols,282+ password = password, copied = copied,283+ onLength = onLength,284+ onUpper = onUpper, onLower = onLower, onNumbers = onNumbers, onSymbols = onSymbols,285+ onGenerate = onGenerate, onCopy = onCopy,286+ )287+ }288+ if (open) Spacer(Modifier.height(14.dp))289+}290+291+/**292+ * Shared generator body — used by the inline drawer here and the detail293+ * ModalBottomSheet (D4). Stateless; the generate row carries the [Copy] drain.294+ */295+@Composable296+internal fun GeneratorBody(297+ length: Int,298+ upper: Boolean, lower: Boolean, numbers: Boolean, symbols: Boolean,299+ password: String,300+ copied: Boolean,301+ onLength: (Int) -> Unit,302+ onUpper: (Boolean) -> Unit, onLower: (Boolean) -> Unit,303+ onNumbers: (Boolean) -> Unit, onSymbols: (Boolean) -> Unit,304+ onGenerate: () -> Unit,305+ onCopy: () -> Unit,306+) {307+ val accent = LocalPeachAccent.current308+ Column(Modifier.fillMaxWidth().padding(16.dp)) {309+ Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {310+ Text("GENERATOR", color = PeachColors.T1, fontFamily = PeachType.Mono, fontSize = 8.sp)311+ Text("length $length", color = accent, fontFamily = PeachType.Mono, fontSize = 9.sp)312+ }313+ Slider(314+ value = length.toFloat(),315+ onValueChange = { onLength(it.toInt()) },316+ valueRange = 8f..128f,317+ colors = SliderDefaults.colors(318+ thumbColor = accent, activeTrackColor = accent, inactiveTrackColor = PeachColors.T3,319+ ),320+ )321+ Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {322+ TogglePill("A-Z", upper, onUpper)323+ TogglePill("a-z", lower, onLower)324+ TogglePill("0-9", numbers, onNumbers)325+ TogglePill("!@#", symbols, onSymbols)326+ }327+ Spacer(Modifier.height(12.dp))328+ Row(verticalAlignment = Alignment.CenterVertically) {292329 Box(293- Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))330+ Modifier.weight(1f).clip(RoundedCornerShape(10.dp))294331 .border(1.dp, accent.copy(alpha = 0.5f), RoundedCornerShape(10.dp))295332 .background(accent.copy(alpha = 0.10f))296333 .clickable(onClick = onGenerate).padding(vertical = 12.dp),@@ -298,9 +335,10 @@298335 ) {299336 Text("generate", color = accent, fontFamily = PeachType.Mono, fontSize = 12.sp)300337 }338+ Spacer(Modifier.width(8.dp))339+ CopyButton(copied = copied, onCopy = { if (password.isNotEmpty()) onCopy() })301340 }302341 }303- if (open) Spacer(Modifier.height(14.dp))304342 }305343 306344 @Composableapp/src/main/java/com/peachpasswords/ui/vault/EntryEditViewModel.kt+14 −0
@@ -38,6 +38,7 @@3838 val tags: List<String> = emptyList(),3939 val showPassword: Boolean = false,4040 val generatorOpen: Boolean = false,41+ val genCopied: Boolean = false,4142 val history: List<PasswordHistoryItem> = emptyList(),4243 val showHistory: Boolean = false,4344 val genLength: Int = 20,@@ -135,6 +136,19 @@135136 /** Restore a past password into the editor; the save flow records the swap. */136137 fun restorePassword(pw: String) =137138 _form.update { it.copy(password = pw, showPassword = true, showHistory = false) }139+140+ /** Copy the current generated/typed password to the clipboard with a drain latch. */141+ fun copyGenerated() {142+ val pw = _form.value.password143+ if (pw.isEmpty()) return144+ val cm = appContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager145+ cm.setPrimaryClip(ClipData.newPlainText("peach", pw))146+ viewModelScope.launch {147+ _form.update { it.copy(genCopied = true) }148+ kotlinx.coroutines.delay(1200)149+ _form.update { it.copy(genCopied = false) }150+ }151+ }138152 139153 fun copyHistoryPassword(pw: String) {140154 val cm = appContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager