notes: tag rename/delete dialogs are routes
- Commit
84686c0cfdbfadffea48a2615beea52d909cc51b- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 21:41 UTC (4 days ago)
- Parents
bf610cb
DialogsAsRoutes batch for notes (fixes a broken HEAD the dialogs sweep left behind: NotesListScreen passed onRenameClick/openRenameTag names to a TagFilterRow that took onRename/onDelete, so :notes:compileReleaseKotlin failed on a clean tree with 'No value passed for parameter onRename' — this broke ./install all). TagFilterRow now exposes onRenameClick/onDeleteClick (opening the rename/delete dialog routes), NotesUiContract gains openRenameTag/openDeleteTag/renameTag/deleteTag, the dialogs are Route destinations with content under ui/dialogs/ (DeleteTagDialog new), and captures cover them. Verified on the main tree: :notes:compileReleaseKotlin green, :notes:testDevUnitTest green.
Diff
notes/src/main/java/com/vayunmathur/notes/Navigation.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/Navigation.kt b/notes/src/main/java/com/vayunmathur/notes/Navigation.ktindex a7a1d3e9e8..01cd698882 100644--- a/notes/src/main/java/com/vayunmathur/notes/Navigation.kt+++ b/notes/src/main/java/com/vayunmathur/notes/Navigation.kt@@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.lifecycle.compose.collectAsStateWithLifecycle+import com.vayunmathur.library.util.DialogPage import com.vayunmathur.library.util.FullscreenPage import com.vayunmathur.library.util.ListDetailPage import com.vayunmathur.library.util.ListPage@@ -14,7 +15,11 @@ import com.vayunmathur.notes.platform.NotesViewModel import com.vayunmathur.notes.ui.ExternalNoteScreen import com.vayunmathur.notes.ui.InkEditorPage import com.vayunmathur.notes.ui.NotePage+import com.vayunmathur.notes.domain.tagCounts+import com.vayunmathur.notes.domain.tagKey import com.vayunmathur.notes.ui.NotesListPage+import com.vayunmathur.notes.ui.dialogs.DeleteTagDialog+import com.vayunmathur.notes.ui.dialogs.RenameTagDialog @Composable fun Navigation(notesViewModel: NotesViewModel) {@@ -39,5 +44,38 @@ fun Navigation(notesViewModel: NotesViewModel) { entry<Route.InkEditor>(metadata = FullscreenPage()) { InkEditorPage(backStack, notesViewModel, it.noteId, it.blockId) }+ entry<Route.RenameTagDialog>(metadata = DialogPage()) { route ->+ val notes by notesViewModel.notes.collectAsStateWithLifecycle()+ RenameTagDialog(+ tag = route.tag,+ existingTags = tagCounts(notes.map { it.tags }).map { it.name },+ onRename = { to ->+ // Keep the filter on the renamed tag, as the list screen did.+ val selected = notesViewModel.selectedTag.value+ if (selected != null && tagKey(selected) == tagKey(route.tag)) {+ notesViewModel.setSelectedTag(to)+ }+ notesViewModel.renameTag(route.tag, to)+ },+ onDismiss = { backStack.pop() },+ )+ }+ entry<Route.DeleteTagDialog>(metadata = DialogPage()) { route ->+ val notes by notesViewModel.notes.collectAsStateWithLifecycle()+ val count = tagCounts(notes.map { it.tags })+ .firstOrNull { tagKey(it.name) == tagKey(route.tag) }?.count ?: 0+ DeleteTagDialog(+ tag = route.tag,+ count = count,+ onConfirm = {+ val selected = notesViewModel.selectedTag.value+ if (selected != null && tagKey(selected) == tagKey(route.tag)) {+ notesViewModel.setSelectedTag(null)+ }+ notesViewModel.deleteTag(route.tag)+ },+ onDismiss = { backStack.pop() },+ )+ } } }
notes/src/main/java/com/vayunmathur/notes/Route.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/Route.kt b/notes/src/main/java/com/vayunmathur/notes/Route.ktindex 113c3f3e3f..6ff3208c16 100644--- a/notes/src/main/java/com/vayunmathur/notes/Route.kt+++ b/notes/src/main/java/com/vayunmathur/notes/Route.kt@@ -3,6 +3,8 @@ package com.vayunmathur.notes import com.vayunmathur.library.util.NavKey import kotlinx.serialization.Serializable +// SCREENSHOT COVERAGE EXCEPTION: ExternalNote: external note opens a shared/dropped file URI through the ViewModel; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: InkEditor: ink editor draws on Room-backed block state with a stylus canvas; no stateless slice for Layoutlib /** Navigation destinations for the notes app. */ @Serializable sealed interface Route: NavKey {@@ -22,4 +24,10 @@ sealed interface Route: NavKey { */ @Serializable data class InkEditor(val noteId: Long, val blockId: String): Route+ /** Rename dialog destination for the tag named [tag] (long-press on its filter chip). */+ @Serializable+ data class RenameTagDialog(val tag: String): Route+ /** Delete confirmation dialog destination for the tag named [tag]. */+ @Serializable+ data class DeleteTagDialog(val tag: String): Route }
notes/src/main/java/com/vayunmathur/notes/platform/NotesUiContract.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/platform/NotesUiContract.kt b/notes/src/main/java/com/vayunmathur/notes/platform/NotesUiContract.ktindex a4ef3106fb..d7b14c8e0d 100644--- a/notes/src/main/java/com/vayunmathur/notes/platform/NotesUiContract.kt+++ b/notes/src/main/java/com/vayunmathur/notes/platform/NotesUiContract.kt@@ -46,6 +46,12 @@ interface NotesListActions { /** Removes [tag] from every note. Never deletes a note. */ fun deleteTag(tag: String) {} + /** Opens the rename dialog destination for [tag]. */+ fun openRenameTag(tag: String) {}++ /** Opens the delete confirmation dialog destination for [tag]. */+ fun openDeleteTag(tag: String) {}+ /** The search field text changed; the ViewModel debounces and re-filters. */ fun setSearchQuery(query: String) {}
notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt b/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.ktindex 110d928570..0e926639a2 100644--- a/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt@@ -74,6 +74,8 @@ fun NotesListPage(backStack: NavBackStack<Route>, viewModel: NotesViewModel) { override fun upsertAll(notes: List<Note>) { viewModel.upsertAll(notes) } override fun renameTag(from: String, to: String) { viewModel.renameTag(from, to) } override fun deleteTag(tag: String) { viewModel.deleteTag(tag) }+ override fun openRenameTag(tag: String) { backStack.add(Route.RenameTagDialog(tag)) }+ override fun openDeleteTag(tag: String) { backStack.add(Route.DeleteTagDialog(tag)) } override fun setSearchQuery(query: String) { viewModel.setSearchQuery(query) } override fun setSelectedTag(tag: String?) { viewModel.setSelectedTag(tag) } }
notes/src/main/java/com/vayunmathur/notes/ui/components/TagFilterRow.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/components/TagFilterRow.kt b/notes/src/main/java/com/vayunmathur/notes/ui/components/TagFilterRow.ktindex 1538761ece..60d233ee5c 100644--- a/notes/src/main/java/com/vayunmathur/notes/ui/components/TagFilterRow.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/components/TagFilterRow.kt@@ -12,10 +12,8 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier-import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp-import com.vayunmathur.library.ui.ConfirmDialog import com.vayunmathur.library.ui.DropdownMenu import com.vayunmathur.library.ui.DropdownMenuItem import com.vayunmathur.library.ui.IconDelete@@ -24,7 +22,6 @@ import com.vayunmathur.library.ui.Text import com.vayunmathur.notes.R import com.vayunmathur.notes.domain.TagCount import com.vayunmathur.notes.domain.tagKey-import com.vayunmathur.notes.ui.dialogs.RenameTagDialog import com.vayunmathur.library.ui.R as UiR /**@@ -35,7 +32,7 @@ import com.vayunmathur.library.ui.R as UiR * or tapping All shows everything. [selected] is the active tag, null for All. * Long-pressing a tag chip opens a small menu: Rename (every note; merges into * an existing tag of that name) and Delete (strips the tag from every note,- * never deletes a note), each confirmed in a dialog.+ * never deletes a note), each opened as a dialog route from the list page. */ @Composable fun TagFilterRow(@@ -43,13 +40,11 @@ fun TagFilterRow( totalCount: Int, selected: String?, onSelect: (String?) -> Unit,- onRename: (from: String, to: String) -> Unit,- onDelete: (String) -> Unit,+ onRenameClick: (String) -> Unit = {},+ onDeleteClick: (String) -> Unit = {}, modifier: Modifier = Modifier, ) { var menuFor by rememberSaveable { mutableStateOf<String?>(null) }- var renaming by rememberSaveable { mutableStateOf<String?>(null) }- var deleting by rememberSaveable { mutableStateOf<String?>(null) } val selectedKey = selected?.let(::tagKey) LazyRow(@@ -80,36 +75,15 @@ fun TagFilterRow( DropdownMenuItem( text = { Text(stringResource(UiR.string.rename)) }, leadingIcon = { IconEdit() },- onClick = { menuFor = null; renaming = tag.name },+ onClick = { menuFor = null; onRenameClick(tag.name) }, ) DropdownMenuItem( text = { Text(stringResource(UiR.string.delete)) }, leadingIcon = { IconDelete() },- onClick = { menuFor = null; deleting = tag.name },+ onClick = { menuFor = null; onDeleteClick(tag.name) }, ) } } } }-- renaming?.let { from ->- RenameTagDialog(- tag = from,- existingTags = tags.map { it.name },- onRename = { to -> onRename(from, to) },- onDismiss = { renaming = null },- )- }- deleting?.let { tag ->- val count = tags.firstOrNull { tagKey(it.name) == tagKey(tag) }?.count ?: 0- ConfirmDialog(- title = stringResource(R.string.delete_tag_title, tag),- message = pluralStringResource(R.plurals.delete_tag_message, count, count),- confirmLabel = stringResource(UiR.string.delete),- dismissLabel = stringResource(UiR.string.cancel),- destructive = true,- onConfirm = { onDelete(tag) },- onDismiss = { deleting = null },- )- } }
notes/src/main/java/com/vayunmathur/notes/ui/dialogs/DeleteTagDialog.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/dialogs/DeleteTagDialog.kt b/notes/src/main/java/com/vayunmathur/notes/ui/dialogs/DeleteTagDialog.ktnew file mode 100644index 0000000000..44b8203015--- /dev/null+++ b/notes/src/main/java/com/vayunmathur/notes/ui/dialogs/DeleteTagDialog.kt@@ -0,0 +1,26 @@+package com.vayunmathur.notes.ui.dialogs++import androidx.compose.runtime.Composable+import androidx.compose.ui.res.pluralStringResource+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.ui.ConfirmDialog+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.notes.R++/**+ * The delete-tag confirmation for `Route.DeleteTagDialog`, stateless for+ * previews/tests. Deleting a tag strips it from every note; it never+ * deletes a note.+ */+@Composable+fun DeleteTagDialog(tag: String, count: Int, onConfirm: () -> Unit, onDismiss: () -> Unit) {+ ConfirmDialog(+ title = stringResource(R.string.delete_tag_title, tag),+ message = pluralStringResource(R.plurals.delete_tag_message, count, count),+ confirmLabel = stringResource(UiR.string.delete),+ dismissLabel = stringResource(UiR.string.cancel),+ destructive = true,+ onConfirm = onConfirm,+ onDismiss = onDismiss,+ )+}
notes/src/screenshotTest/kotlin/com/vayunmathur/notes/ui/MetadataPreviews.kt
diff --git a/notes/src/screenshotTest/kotlin/com/vayunmathur/notes/ui/MetadataPreviews.kt b/notes/src/screenshotTest/kotlin/com/vayunmathur/notes/ui/MetadataPreviews.ktindex 7dbb1176ad..f6e1798513 100644--- a/notes/src/screenshotTest/kotlin/com/vayunmathur/notes/ui/MetadataPreviews.kt+++ b/notes/src/screenshotTest/kotlin/com/vayunmathur/notes/ui/MetadataPreviews.kt@@ -66,7 +66,7 @@ class MetadataPreviews { ) @PreviewTest- @Preview(name = "1-notes", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "1-notes-list", device = PHONE, group = "phone", showSystemUi = true) @Composable fun Preview1Notes() { DynamicTheme(darkTheme = true) {@@ -78,7 +78,7 @@ class MetadataPreviews { } @PreviewTest- @Preview(name = "2-editor", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "2-note", device = PHONE, group = "phone", showSystemUi = true) @Composable fun Preview2Editor() { DynamicTheme(darkTheme = true) {@@ -112,7 +112,7 @@ class MetadataPreviews { } @PreviewTest- @Preview(name = "3-search", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "3-notes-list-search", device = PHONE, group = "phone", showSystemUi = true) @Composable fun Preview3Search() { DynamicTheme(darkTheme = true) {@@ -129,7 +129,7 @@ class MetadataPreviews { /** The tag filter (#913): "Work" selected, so only work notes show and reordering is paused. */ @PreviewTest- @Preview(name = "4-tags", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "4-notes-list-tags", device = PHONE, group = "phone", showSystemUi = true) @Composable fun Preview4Tags() { DynamicTheme(darkTheme = true) {@@ -143,4 +143,32 @@ class MetadataPreviews { ) } }++ @PreviewTest+ @Preview(name = "5-rename-tag-dialog", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview5RenameTagDialog() {+ DynamicTheme(darkTheme = true) {+ com.vayunmathur.notes.ui.dialogs.RenameTagDialog(+ tag = "Work",+ existingTags = listOf("Personal", "Work", "Plans"),+ onRename = {},+ onDismiss = {},+ )+ }+ }++ @PreviewTest+ @Preview(name = "6-delete-tag-dialog", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview6DeleteTagDialog() {+ DynamicTheme(darkTheme = true) {+ com.vayunmathur.notes.ui.dialogs.DeleteTagDialog(+ tag = "Work",+ count = 2,+ onConfirm = {},+ onDismiss = {},+ )+ }+ } }
notes/src/test/java/com/vayunmathur/notes/data/NoteHybridStampTest.kt
diff --git a/notes/src/test/java/com/vayunmathur/notes/data/NoteHybridStampTest.kt b/notes/src/test/java/com/vayunmathur/notes/data/NoteHybridStampTest.ktindex 2d8412581e..f6a2cc818a 100644--- a/notes/src/test/java/com/vayunmathur/notes/data/NoteHybridStampTest.kt+++ b/notes/src/test/java/com/vayunmathur/notes/data/NoteHybridStampTest.kt@@ -1,5 +1,7 @@ package com.vayunmathur.notes.data +// FIXTURE RELATIVE-TIME EXCEPTION: timestamps are seeded relative to the wall clock the code under test reads internally, so the fresh/expired/relative-time branch under test keeps its meaning; a fixed past instant would silently change that branch.+ import android.content.Context import androidx.test.core.app.ApplicationProvider import com.vayunmathur.library.util.HybridStampGenerator
notes/src/test/java/com/vayunmathur/notes/ui/NoteTagsComposeTest.kt
diff --git a/notes/src/test/java/com/vayunmathur/notes/ui/NoteTagsComposeTest.kt b/notes/src/test/java/com/vayunmathur/notes/ui/NoteTagsComposeTest.ktindex 092a445979..67cb6c3aff 100644--- a/notes/src/test/java/com/vayunmathur/notes/ui/NoteTagsComposeTest.kt+++ b/notes/src/test/java/com/vayunmathur/notes/ui/NoteTagsComposeTest.kt@@ -42,8 +42,12 @@ class NoteTagsComposeTest { private class RecordingListActions : NotesListActions { val renamed = mutableListOf<Pair<String, String>>() val deleted = mutableListOf<String>()+ val renameRequests = mutableListOf<String>()+ val deleteRequests = mutableListOf<String>() override fun renameTag(from: String, to: String) { renamed += from to to } override fun deleteTag(tag: String) { deleted += tag }+ override fun openRenameTag(tag: String) { renameRequests += tag }+ override fun openDeleteTag(tag: String) { deleteRequests += tag } } private fun notes() = listOf(@@ -188,27 +192,35 @@ class NoteTagsComposeTest { val actions = RecordingListActions() rule.setContent { NotesListScreen(NotesListUiState(notes()), actions) } + // The tag menu now requests the dialog routes; the list page pushes+ // them and the dialogs (covered by the dialog tests below) do the work. rule.onNode(hasText("Home") and hasText("1")).performTouchInput { longClick() } rule.waitForIdle() rule.onNodeWithText("Rename").performClick() rule.waitForIdle()- rule.onNodeWithText("Tag name").performTextReplacement("work")- rule.waitForIdle()- // Renaming onto an existing tag says it will merge.- rule.onNodeWithText("Merges into the existing tag \"Work\"").assertExists()- rule.onNode(hasText("Rename") and androidx.compose.ui.test.hasClickAction()).performClick()- rule.waitForIdle()- assertEquals(listOf("Home" to "work"), actions.renamed)+ assertEquals(listOf("Home"), actions.renameRequests) rule.onNode(hasText("Ideas") and hasText("1")).performTouchInput { longClick() } rule.waitForIdle() rule.onNodeWithText("Delete").performClick() rule.waitForIdle()+ assertEquals(listOf("Ideas"), actions.deleteRequests)+ }++ @Test fun deleteTagDialogConfirms() {+ var confirmed = 0+ rule.setContent {+ com.vayunmathur.library.ui.DynamicTheme {+ com.vayunmathur.notes.ui.dialogs.DeleteTagDialog(+ tag = "Ideas", count = 1,+ onConfirm = { confirmed++ }, onDismiss = {},+ )+ }+ } rule.onNodeWithText("Delete tag \"Ideas\"?").assertExists() rule.onNodeWithText("Removes the tag from 1 note. The note itself is kept.").assertExists() rule.onNode(hasText("Delete") and androidx.compose.ui.test.hasClickAction()).performClick()- rule.waitForIdle()- assertEquals(listOf("Ideas"), actions.deleted)+ assertEquals(1, confirmed) } @Test fun renameDialogWarnsAboutMergeAndConfirms() {