24a6f5eceb7d

fix: new entry/card/note screens — PeachField underline inputs (replaces boxed Field/CardField), 9sp/t2 labels, type-specific centered title bar, full-title fade-in watermark, new-note routes to NotesMode; EntryEditScreenTest 7 tests; v2.2.6 (166 tests)

time
2026-06-10 12:39 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
new-entry peachfield accuracy
parent
e267142d8c33
6 files app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+9 −1app/src/main/java/com/peachpasswords/ui/vault/CardEditFields.kt+6 −72app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+56 −42app/src/main/java/com/peachpasswords/ui/vault/EntryEditViewModel.kt+14 −0app/src/main/java/com/peachpasswords/ui/vault/PeachField.kt+106 −0app/src/test/java/com/peachpasswords/ui/vault/EntryEditScreenTest.kt+63 −0
app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+9 −1
@@ -126,7 +126,15 @@126126             route = PeachNav.EntryEdit.ROUTE,127127             arguments = listOf(navArgument("id") { type = NavType.StringType; nullable = true }),128128         ) { backStack ->129-            EntryEditScreen(id = backStack.arguments?.getString("id"), onBack = back)129+            EntryEditScreen(130+                id = backStack.arguments?.getString("id"),131+                onBack = back,132+                onOpenNote = { noteId ->133+                    navController.navigate(PeachNav.NotesMode.of(noteId)) {134+                        popUpTo(PeachNav.EntryEdit.ROUTE) { inclusive = true }135+                    }136+                },137+            )130138         }131139 132140         composable(

view file

app/src/main/java/com/peachpasswords/ui/vault/CardEditFields.kt+6 −72
@@ -1,28 +1,15 @@11 package com.peachpasswords.ui.vault22 3-import androidx.compose.foundation.border43 import androidx.compose.foundation.clickable5-import androidx.compose.foundation.layout.Arrangement6-import androidx.compose.foundation.layout.Box7-import androidx.compose.foundation.layout.Column8-import androidx.compose.foundation.layout.Row9-import androidx.compose.foundation.layout.Spacer10-import androidx.compose.foundation.layout.fillMaxWidth11-import androidx.compose.foundation.layout.height124 import androidx.compose.foundation.layout.padding13-import androidx.compose.foundation.layout.width145 import androidx.compose.foundation.shape.RoundedCornerShape15-import androidx.compose.foundation.text.BasicTextField166 import androidx.compose.material3.Text177 import androidx.compose.runtime.Composable18-import androidx.compose.ui.Alignment198 import androidx.compose.ui.Modifier209 import androidx.compose.ui.draw.clip21-import androidx.compose.ui.graphics.SolidColor22-import androidx.compose.ui.text.TextStyle2310 import androidx.compose.ui.text.input.KeyboardType2411 import androidx.compose.ui.text.input.PasswordVisualTransformation25-import androidx.compose.foundation.text.KeyboardOptions12+import androidx.compose.ui.text.input.VisualTransformation2613 import androidx.compose.ui.unit.dp2714 import androidx.compose.ui.unit.sp2815 import com.peachpasswords.ui.theme.LocalPeachAccent@@ -55,7 +42,7 @@5542     onToggleShowCvc: () -> Unit,5643 ) {5744     // CARD NUMBER — auto-formatted, network label beside the label.58-    CardField(45+    PeachField(5946         label = "card number",6047         value = cardNumber,6148         onChange = { raw -> onCardNumber(CardFieldUtils.formatPan(raw)) },@@ -69,7 +56,7 @@6956     )7057 7158     // CARDHOLDER — Inter body, not mono.72-    CardField(59+    PeachField(7360         label = "cardholder",7461         value = cardholderName,7562         onChange = onCardholder,@@ -77,7 +64,7 @@7764     )7865 7966     // EXPIRY — auto "MM/YY".80-    CardField(67+    PeachField(8168         label = "expiry",8269         value = expiry,8370         onChange = { raw -> onExpiry(CardFieldUtils.formatExpiry(raw)) },@@ -86,12 +73,12 @@8673 8774     // CVC — masked by default, eye toggle, maxLength by network.8875     val cvcMax = CardFieldUtils.cvcMaxDigits(network)89-    CardField(76+    PeachField(9077         label = "cvc",9178         value = cvc,9279         onChange = { raw -> onCvc(raw.filter { it.isDigit() }.take(cvcMax)) },9380         keyboardType = KeyboardType.NumberPassword,94-        masked = !showCvc,81+        visualTransformation = if (showCvc) VisualTransformation.None else PasswordVisualTransformation(),9582         trailing = {9683             Text(9784                 if (showCvc) "hide" else "show",@@ -100,57 +87,4 @@10087             )10188         },10289     )103-}104-105-/**106- * Underline-style field matching EntryEditScreen's private `Field`. Duplicated107- * here (rather than reused) so this draft is a self-contained drop-in; the108- * orchestrator may instead route these through the existing `Field`/`PasswordField`109- * — see INTEGRATION.md for the cheaper wiring option.110- */111-@Composable112-private fun CardField(113-    label: String,114-    value: String,115-    onChange: (String) -> Unit,116-    mono: Boolean = true,117-    masked: Boolean = false,118-    keyboardType: KeyboardType = KeyboardType.Text,119-    labelTrailing: (@Composable () -> Unit)? = null,120-    trailing: (@Composable () -> Unit)? = null,121-) {122-    val accent = LocalPeachAccent.current123-    Column(Modifier.fillMaxWidth().padding(bottom = 14.dp)) {124-        Row(verticalAlignment = Alignment.CenterVertically) {125-            Text(label.uppercase(), color = peachColors.T1, fontFamily = PeachType.Mono, fontSize = 8.sp)126-            if (labelTrailing != null) {127-                Spacer(Modifier.width(8.dp))128-                labelTrailing()129-            }130-        }131-        Spacer(Modifier.height(6.dp))132-        Row(verticalAlignment = Alignment.CenterVertically) {133-            Box(134-                Modifier.weight(1f)135-                    .border(1.dp, peachColors.T3, RoundedCornerShape(10.dp))136-                    .padding(horizontal = 12.dp, vertical = 12.dp),137-            ) {138-                BasicTextField(139-                    value = value,140-                    onValueChange = onChange,141-                    singleLine = true,142-                    textStyle = TextStyle(143-                        color = peachColors.T0,144-                        fontFamily = if (mono) PeachType.Mono else PeachType.Body,145-                        fontSize = 13.sp,146-                    ),147-                    cursorBrush = SolidColor(accent),148-                    keyboardOptions = KeyboardOptions(keyboardType = keyboardType),149-                    visualTransformation = if (masked) PasswordVisualTransformation() else androidx.compose.ui.text.input.VisualTransformation.None,150-                    modifier = Modifier.fillMaxWidth(),151-                )152-            }153-            if (trailing != null) { Spacer(Modifier.width(8.dp)); trailing() }154-        }155-    }15690 }

view file

app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+56 −42
@@ -19,7 +19,6 @@1919 import androidx.compose.foundation.layout.width2020 import androidx.compose.foundation.rememberScrollState2121 import androidx.compose.foundation.shape.RoundedCornerShape22-import androidx.compose.foundation.text.BasicTextField2322 import androidx.compose.foundation.verticalScroll2423 import androidx.compose.material3.Slider2524 import androidx.compose.material3.SliderDefaults@@ -34,7 +33,6 @@3433 import androidx.compose.ui.draw.clip3534 import androidx.compose.ui.draw.clipToBounds3635 import androidx.compose.ui.graphics.Color37-import androidx.compose.ui.graphics.SolidColor3836 import androidx.compose.ui.text.TextStyle3937 import androidx.compose.ui.text.font.FontStyle4038 import androidx.compose.ui.text.font.FontWeight@@ -57,34 +55,45 @@5755 fun EntryEditScreen(5856     id: String?,5957     onBack: () -> Unit,58+    onOpenNote: (String) -> Unit = {},6059     vm: EntryEditViewModel = hiltViewModel(),6160 ) {6261     val f by vm.form.collectAsState()6362     val usernameSuggestions by vm.usernameSuggestions.collectAsState()6463     val accent = LocalPeachAccent.current6564 65+    // Ghost watermark fades in (0 → 0.03α over 300ms) once the title has any text.66+    val watermarkAlpha by androidx.compose.animation.core.animateFloatAsState(67+        targetValue = editGhostWatermarkTarget(f.title),68+        animationSpec = tween(300),69+        label = "edit-watermark",70+    )71+6672     ShellBackground {6773         Column(Modifier.fillMaxSize().statusBarsPadding()) {68-            Row(69-                Modifier.fillMaxWidth().height(56.dp).padding(horizontal = 18.dp),70-                verticalAlignment = Alignment.CenterVertically,71-                horizontalArrangement = Arrangement.SpaceBetween,72-            ) {73-                Text("cancel", color = peachColors.T1, fontFamily = PeachType.Mono, fontSize = 12.sp,74-                    modifier = Modifier.clip(RoundedCornerShape(8.dp)).clickable(onClick = onBack).padding(8.dp))75-                Text(if (vm.isNew) "new entry" else "edit", color = peachColors.T1,76-                    fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 16.sp)77-                Text("save", color = accent, fontFamily = PeachType.Mono, fontSize = 13.sp,78-                    modifier = Modifier.clip(RoundedCornerShape(8.dp)).clickable { vm.save(onBack) }.padding(8.dp))74+            Box(Modifier.fillMaxWidth().height(56.dp).padding(horizontal = 18.dp)) {75+                Text("cancel", color = peachColors.T2, fontFamily = PeachType.Mono, fontSize = 11.sp,76+                    modifier = Modifier.align(Alignment.CenterStart)77+                        .clip(RoundedCornerShape(8.dp)).clickable(onClick = onBack).padding(8.dp))78+                Text(editTitleBarLabel(vm.isNew, f.type), color = peachColors.T1,79+                    fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp,80+                    modifier = Modifier.align(Alignment.Center))81+                Text("save", color = accent, fontFamily = PeachType.Mono, fontSize = 11.sp,82+                    modifier = Modifier.align(Alignment.CenterEnd)83+                        .clip(RoundedCornerShape(8.dp)).clickable { vm.save(onBack) }.padding(8.dp))7984             }8085 81-            Box(Modifier.fillMaxSize()) {82-                // Ghost PeachScript watermark behind the form (matches the detail hero).83-                if (f.title.isNotBlank()) {86+            Box(Modifier.fillMaxSize().clipToBounds()) {87+                // Ghost PeachScript watermark behind the form (matches the detail hero):88+                // the full title, fading in as the user types.89+                if (watermarkAlpha > 0f) {8490                     Text(85-                        text = f.title.first().uppercase(),91+                        text = ghostWatermarkText(f.title),8692                         style = TextStyle(fontFamily = PeachType.Script, fontSize = 140.sp),87-                        color = peachColors.T0.copy(alpha = 0.03f),93+                        color = peachColors.T0.copy(alpha = watermarkAlpha),94+                        maxLines = 1,95+                        softWrap = false,96+                        overflow = androidx.compose.ui.text.style.TextOverflow.Clip,8897                         modifier = Modifier.align(Alignment.TopEnd).offset(x = (-16).dp, y = 8.dp),8998                     )9099                 }@@ -93,7 +102,12 @@93102                 ) {94103                 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {95104                     listOf("login", "note", "card").forEach { t ->96-                        EntryTypePill(t, f.type == t) { vm.setType(t) }105+                        EntryTypePill(t, f.type == t) {106+                            // A brand-new note skips the form entirely and drops straight107+                            // into the full-screen notes editor (brief Fix 6 item 7).108+                            if (shouldOpenNotesMode(vm.isNew, t)) vm.createNoteAndOpen(onOpenNote)109+                            else vm.setType(t)110+                        }97111                     }98112                 }99113                 Spacer(Modifier.height(18.dp))@@ -196,6 +210,20 @@196210     }197211 }198212 213+/** Centered title-bar label: "new entry" / "new note" / "new card", or "edit". */214+internal fun editTitleBarLabel(isNew: Boolean, type: String): String = when {215+    !isNew -> "edit"216+    type == "note" -> "new note"217+    type == "card" -> "new card"218+    else -> "new entry"219+}220+221+/** A brand-new note opens the full-screen notes editor instead of the form. */222+internal fun shouldOpenNotesMode(isNew: Boolean, type: String): Boolean = isNew && type == "note"223+224+/** Target alpha for the edit-screen ghost watermark — visible only once a title exists. */225+internal fun editGhostWatermarkTarget(title: String): Float = if (title.isNotBlank()) 0.03f else 0f226+199227 @Composable200228 private fun Field(201229     label: String,@@ -205,29 +233,15 @@205233     transformation: VisualTransformation = VisualTransformation.None,206234     trailing: (@Composable () -> Unit)? = null,207235 ) {208-    val accent = LocalPeachAccent.current209-    Column(Modifier.fillMaxWidth().padding(bottom = 14.dp)) {210-        Text(label.uppercase(), color = peachColors.T1, fontFamily = PeachType.Mono, fontSize = 8.sp)211-        Spacer(Modifier.height(6.dp))212-        Row(verticalAlignment = Alignment.CenterVertically) {213-            Box(214-                Modifier.weight(1f)215-                    .border(1.dp, peachColors.T3, RoundedCornerShape(10.dp))216-                    .padding(horizontal = 12.dp, vertical = 12.dp),217-            ) {218-                BasicTextField(219-                    value = value,220-                    onValueChange = onChange,221-                    singleLine = singleLine,222-                    textStyle = TextStyle(color = peachColors.T0, fontFamily = PeachType.Mono, fontSize = 13.sp),223-                    cursorBrush = SolidColor(accent),224-                    visualTransformation = transformation,225-                    modifier = Modifier.fillMaxWidth(),226-                )227-            }228-            if (trailing != null) { Spacer(Modifier.width(8.dp)); trailing() }229-        }230-    }236+    PeachField(237+        label = label,238+        value = value,239+        onChange = onChange,240+        singleLine = singleLine,241+        mono = true,242+        visualTransformation = transformation,243+        trailing = trailing,244+    )231245 }232246 233247 @Composable

view file

app/src/main/java/com/peachpasswords/ui/vault/EntryEditViewModel.kt+14 −0
@@ -92,6 +92,20 @@9292         MutableStateFlow(vault.getDistinctFieldValues("username").take(4)).asStateFlow()9393 9494     fun setType(t: String) = _form.update { it.copy(type = t) }95+96+    /**97+     * Create a blank NOTE entry and hand its id to [onOpen] so the caller can98+     * navigate straight into the full-screen notes editor (brief Fix 6 item 7) —99+     * a new note never shows the generic edit form.100+     */101+    fun createNoteAndOpen(onOpen: (String) -> Unit) {102+        viewModelScope.launch {103+            runCatching {104+                vault.addEntry(VaultEntry(id = "", type = "note", title = "", createdAt = 0, modifiedAt = 0))105+            }.onSuccess { onOpen(it.id) }106+                .onFailure { e -> _form.update { it.copy(error = e.message ?: "could not create note") } }107+        }108+    }95109     fun setTitle(v: String) = _form.update { it.copy(title = v, error = null) }96110     fun setUsername(v: String) = _form.update { it.copy(username = v) }97111     fun setEmail(v: String) = _form.update { it.copy(email = v) }

view file

app/src/main/java/com/peachpasswords/ui/vault/PeachField.kt+106 −0
@@ -0,0 +1,106 @@1+package com.peachpasswords.ui.vault2+3+import androidx.compose.foundation.interaction.MutableInteractionSource4+import androidx.compose.foundation.interaction.collectIsFocusedAsState5+import androidx.compose.foundation.layout.Column6+import androidx.compose.foundation.layout.Row7+import androidx.compose.foundation.layout.Spacer8+import androidx.compose.foundation.layout.fillMaxWidth9+import androidx.compose.foundation.layout.height10+import androidx.compose.foundation.layout.padding11+import androidx.compose.foundation.layout.width12+import androidx.compose.foundation.text.BasicTextField13+import androidx.compose.foundation.text.KeyboardOptions14+import androidx.compose.material3.Text15+import androidx.compose.runtime.Composable16+import androidx.compose.runtime.getValue17+import androidx.compose.runtime.remember18+import androidx.compose.ui.Alignment19+import androidx.compose.ui.Modifier20+import androidx.compose.ui.draw.drawBehind21+import androidx.compose.ui.geometry.Offset22+import androidx.compose.ui.geometry.Size23+import androidx.compose.ui.graphics.SolidColor24+import androidx.compose.ui.text.TextStyle25+import androidx.compose.ui.text.input.KeyboardType26+import androidx.compose.ui.text.input.VisualTransformation27+import androidx.compose.ui.unit.dp28+import androidx.compose.ui.unit.em29+import androidx.compose.ui.unit.sp30+import com.peachpasswords.ui.theme.LocalPeachAccent31+import com.peachpasswords.ui.theme.peachColors32+import com.peachpasswords.ui.theme.PeachType33+34+/**35+ * The Peach text field used across the entry-edit screens: a bare underline (no36+ * border box), drawn in t3 and lit to the accent while focused — matching the37+ * lock screen's credential inputs. Label is IBM Plex Mono 9sp, uppercase, t2,38+ * with 0.08em tracking.39+ *40+ * Replaces the old boxed `Field`/`CardField` primitives so every new-entry input41+ * shares one underline style (brief Fix 6).42+ */43+@Composable44+fun PeachField(45+    label: String,46+    value: String,47+    onChange: (String) -> Unit,48+    modifier: Modifier = Modifier,49+    singleLine: Boolean = true,50+    mono: Boolean = true,51+    keyboardType: KeyboardType = KeyboardType.Text,52+    visualTransformation: VisualTransformation = VisualTransformation.None,53+    labelTrailing: (@Composable () -> Unit)? = null,54+    trailing: (@Composable () -> Unit)? = null,55+) {56+    val accent = LocalPeachAccent.current57+    val interaction = remember { MutableInteractionSource() }58+    val focused by interaction.collectIsFocusedAsState()59+    val hairline = peachColors.T360+    Column(modifier.fillMaxWidth().padding(bottom = 14.dp)) {61+        Row(verticalAlignment = Alignment.CenterVertically) {62+            Text(63+                label.uppercase(),64+                color = peachColors.T2,65+                fontFamily = PeachType.Mono,66+                fontSize = 9.sp,67+                letterSpacing = 0.08.em,68+            )69+            if (labelTrailing != null) {70+                Spacer(Modifier.width(8.dp))71+                labelTrailing()72+            }73+        }74+        Spacer(Modifier.height(6.dp))75+        Row(verticalAlignment = Alignment.CenterVertically) {76+            BasicTextField(77+                value = value,78+                onValueChange = onChange,79+                singleLine = singleLine,80+                textStyle = TextStyle(81+                    color = peachColors.T0,82+                    fontFamily = if (mono) PeachType.Mono else PeachType.Body,83+                    fontSize = 13.sp,84+                ),85+                cursorBrush = SolidColor(accent),86+                interactionSource = interaction,87+                keyboardOptions = KeyboardOptions(keyboardType = keyboardType),88+                visualTransformation = visualTransformation,89+                modifier = Modifier90+                    .weight(1f)91+                    .drawBehind {92+                        drawRect(93+                            color = if (focused) accent else hairline,94+                            topLeft = Offset(0f, size.height - 1.dp.toPx()),95+                            size = Size(size.width, 1.dp.toPx()),96+                        )97+                    }98+                    .padding(vertical = 8.dp),99+            )100+            if (trailing != null) {101+                Spacer(Modifier.width(8.dp))102+                trailing()103+            }104+        }105+    }106+}

view file

app/src/test/java/com/peachpasswords/ui/vault/EntryEditScreenTest.kt+63 −0
@@ -0,0 +1,63 @@1+package com.peachpasswords.ui.vault2+3+import org.junit.Assert.assertEquals4+import org.junit.Assert.assertFalse5+import org.junit.Assert.assertTrue6+import org.junit.Test7+8+class EntryEditScreenTest {9+10+    // ── Top-bar label (cancel | <title> | save) ───────────────────────────────11+12+    @Test fun title_bar_label_is_type_specific_for_new_entries() {13+        assertEquals("new entry", editTitleBarLabel(isNew = true, type = "login"))14+        assertEquals("new note", editTitleBarLabel(isNew = true, type = "note"))15+        assertEquals("new card", editTitleBarLabel(isNew = true, type = "card"))16+    }17+18+    @Test fun title_bar_label_is_edit_for_existing_entries() {19+        assertEquals("edit", editTitleBarLabel(isNew = false, type = "login"))20+        assertEquals("edit", editTitleBarLabel(isNew = false, type = "note"))21+    }22+23+    // ── New note routes to NotesMode, not the form ────────────────────────────24+25+    @Test fun new_note_routes_to_notes_mode() {26+        assertTrue(shouldOpenNotesMode(isNew = true, type = "note"))27+        // Existing note stays in the form; new login/card stay in the form.28+        assertFalse(shouldOpenNotesMode(isNew = false, type = "note"))29+        assertFalse(shouldOpenNotesMode(isNew = true, type = "login"))30+        assertFalse(shouldOpenNotesMode(isNew = true, type = "card"))31+    }32+33+    // ── Ghost watermark fades in as the title is typed ────────────────────────34+35+    @Test fun new_entry_ghost_watermark_appears_on_title_type() {36+        assertEquals(0f, editGhostWatermarkTarget(""), 0f)37+        assertEquals(0f, editGhostWatermarkTarget("   "), 0f)38+        assertEquals(0.03f, editGhostWatermarkTarget("GitHub"), 0f)39+    }40+41+    // ── Card field formatting (CardFieldUtils, used live by setCardNumber etc.) ─42+43+    @Test fun new_card_number_auto_formats() {44+        assertEquals("4242 4242 4242 4242", CardFieldUtils.formatPan("4242424242424242"))45+        // Amex groups 4-6-5.46+        assertEquals("3782 822463 10005", CardFieldUtils.formatPan("378282246310005"))47+    }48+49+    @Test fun new_card_expiry_auto_formats_mm_yy() {50+        assertEquals("12", CardFieldUtils.formatExpiry("12"))51+        assertEquals("12/28", CardFieldUtils.formatExpiry("1228"))52+        assertEquals("12/28", CardFieldUtils.formatExpiry("122899")) // caps at 4 digits53+    }54+55+    @Test fun new_card_expiry_rejects_invalid_month() {56+        // currentYear2 = 26, currentMonth = 6 (2026-06).57+        assertFalse(CardFieldUtils.isExpiryValid("13/28", currentYear2 = 26, currentMonth = 6))58+        assertFalse(CardFieldUtils.isExpiryValid("00/28", currentYear2 = 26, currentMonth = 6))59+        assertTrue(CardFieldUtils.isExpiryValid("12/28", currentYear2 = 26, currentMonth = 6))60+        // Past year rejected.61+        assertFalse(CardFieldUtils.isExpiryValid("12/24", currentYear2 = 26, currentMonth = 6))62+    }63+}

view file