Modern Apps git

← Modern-Apps.git

flashcards: tabs are sibling routes (#nav)

Commit
e9edbfe78cd27b100b7e268f828e61d6b16fd88d
Author
Vayun Mathur <[email protected]>
When
2026-11-16 19:55 UTC (19 days ago)
Parents
3363e21
Add Route.Decks and Route.Settings as sibling destinations, delete
Route.Main, and keep Route.Stats as the single statistics route: it
is both a bottom-bar tab and the destination NoteListPage.openStats
pushes, so there is no longer a separate pager tab duplicating it.

Navigation now starts on Route.Decks and uses the route-backed
TabbedPagerScaffold (RouteTab for Decks/Stats/Settings, same labels,
icons and order) with MainNavigation hosted in its content slot.
Decks keeps its list role with ListPage() + SiblingPage(); Settings
is SiblingPage(); Stats keeps ListDetailPage() and gains
SiblingPage(), so pushing it over a note list behaves as before and
selecting it as a tab resets the stack. NoteTypeList, NoteTypeEdit,
CardList, NoteEdit and Review entries are unchanged.

Test stacks that seeded Route.Main now seed Route.Decks, and the
route serialization check now names Decks. The existing
navigationHostShowsTabs test clicks through Stats and Settings in
the bottom bar, and the page tests continue to cover deck-to-card
and note-to-editor pushes and pops.

Verified on devvm21958 (no push):
- ./gradlew :flashcards:compileDevKotlin :flashcards:testDevUnitTest — green

Diff

flashcards/src/main/java/com/vayunmathur/flashcards/MainActivity.kt
diff --git a/flashcards/src/main/java/com/vayunmathur/flashcards/MainActivity.kt b/flashcards/src/main/java/com/vayunmathur/flashcards/MainActivity.ktindex 7adba3014f..edd1ecf3d4 100644--- a/flashcards/src/main/java/com/vayunmathur/flashcards/MainActivity.kt+++ b/flashcards/src/main/java/com/vayunmathur/flashcards/MainActivity.kt@@ -1,7 +1,6 @@ package com.vayunmathur.flashcards  import androidx.activity.viewModels-import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.res.stringResource@@ -23,15 +22,14 @@ import com.vayunmathur.library.ui.IconDashboard import com.vayunmathur.library.ui.IconSettings import com.vayunmathur.library.ui.IconStyle import com.vayunmathur.library.ui.MaActivity-import com.vayunmathur.library.ui.PagerTab-import com.vayunmathur.library.ui.TabStyle+import com.vayunmathur.library.ui.RouteTab import com.vayunmathur.library.ui.TabbedPagerScaffold import com.vayunmathur.library.util.FullscreenPage import com.vayunmathur.library.util.ListDetailPage import com.vayunmathur.library.util.ListPage import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.MorphPage-import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.library.util.SiblingPage import com.vayunmathur.library.util.NavKey import com.vayunmathur.library.util.rememberNavBackStack import kotlinx.serialization.Serializable@@ -62,11 +60,19 @@ class MainActivity : MaActivity() { /** Navigation destinations for decks, notes, note types, review, and stats. */ @Serializable sealed interface Route : NavKey {-    /** The deck-list main screen. */+    /** The deck-list tab (sibling route, the start destination). */     @Serializable-    data object Main : Route+    data object Decks : Route -    /** The review-statistics screen. */+    /** The settings tab (sibling route). */+    @Serializable+    data object Settings : Route++    /**+     * The review-statistics screen: both a sibling tab and a destination+     * pushed over a deck's note list (NoteListPage.openStats) — one route+     * for both, not a tab duplicate.+     */     @Serializable     data object Stats : Route @@ -99,10 +105,19 @@ sealed interface Route : NavKey {  @Composable fun Navigation(viewModel: FlashcardsViewModel) {-    val backStack = rememberNavBackStack<Route>(Route.Main)+    val backStack = rememberNavBackStack<Route>(Route.Decks)+    TabbedPagerScaffold(+        backStack = backStack,+        tabs = listOf<RouteTab<Route>>(+            RouteTab(Route.Decks, stringResource(R.string.nav_decks)) { IconStyle() },+            RouteTab(Route.Stats, stringResource(R.string.nav_stats)) { IconDashboard() },+            RouteTab(Route.Settings, stringResource(R.string.nav_settings)) { IconSettings() },+        ),+    ) {     MainNavigation(backStack) {-        entry<Route.Main>(metadata = ListPage()) { FlashcardsTabs(backStack, viewModel) }-        entry<Route.Stats>(metadata = ListDetailPage()) { StatsPage(backStack, viewModel) }+        entry<Route.Decks>(metadata = ListPage() + SiblingPage()) { DeckListPage(backStack, viewModel) }+        entry<Route.Settings>(metadata = SiblingPage()) { SettingsPage(backStack, viewModel) }+        entry<Route.Stats>(metadata = ListDetailPage() + SiblingPage()) { StatsPage(backStack, viewModel) }         entry<Route.NoteTypeList>(metadata = ListDetailPage()) { NoteTypeListPage(backStack, viewModel) }         entry<Route.NoteTypeEdit>(metadata = ListDetailPage()) { NoteTypeEditPage(backStack, viewModel, it.noteTypeId) }         entry<Route.CardList>(metadata = ListDetailPage() + MorphPage()) {@@ -113,24 +128,6 @@ fun Navigation(viewModel: FlashcardsViewModel) {             ReviewPage(backStack, viewModel, it.deckId, it.mode, it.count, it.daysAhead, it.tags)         }     }+    } } -/**- * The three bottom-nav tabs, hosted in a swipeable pager (see [TabbedPagerScaffold]).- * NoteTypeList, NoteTypeEdit, CardList, NoteEdit and Review are pushed on top of this host- * as ordinary routes. Stats is kept as a standalone pushed route because- * NoteListPage.openStats() pushes Route.Stats via backStack.add().- */-@Composable-private fun FlashcardsTabs(-    backStack: NavBackStack<Route>,-    viewModel: FlashcardsViewModel,-) {-    val pagerState = rememberPagerState(pageCount = { 3 })-    val tabs = listOf(-        PagerTab(stringResource(R.string.nav_decks), { IconStyle() }) { DeckListPage(backStack, viewModel) },-        PagerTab(stringResource(R.string.nav_stats), { IconDashboard() }) { StatsPage(backStack, viewModel) },-        PagerTab(stringResource(R.string.nav_settings), { IconSettings() }) { SettingsPage(backStack, viewModel) },-    )-    TabbedPagerScaffold(tabs = tabs, pagerState = pagerState, tabStyle = TabStyle.BottomNav)-}
flashcards/src/test/java/com/vayunmathur/flashcards/ui/FlashcardsPagesTest.kt
diff --git a/flashcards/src/test/java/com/vayunmathur/flashcards/ui/FlashcardsPagesTest.kt b/flashcards/src/test/java/com/vayunmathur/flashcards/ui/FlashcardsPagesTest.ktindex 5361a81964..a701466e9b 100644--- a/flashcards/src/test/java/com/vayunmathur/flashcards/ui/FlashcardsPagesTest.kt+++ b/flashcards/src/test/java/com/vayunmathur/flashcards/ui/FlashcardsPagesTest.kt@@ -119,7 +119,7 @@ class FlashcardsPagesTest {         // Pin this deck to the top of the list so it is composed in the shared-database list.         vm.upsertDeckImpl(deck.copy(position = -1000.0))         await("deck pinned") { vm.decks.value.firstOrNull { it.id == deck.id }?.position == -1000.0 }-        val stack = NavBackStack<Route>(arrayOf(Route.Main))+        val stack = NavBackStack<Route>(arrayOf(Route.Decks))         rule.setContent { DynamicTheme { DeckListPage(stack, vm) } }         rule.onNodeWithText("PageDeckList").performScrollTo().assertIsDisplayed()         rule.onNodeWithText("PageDeckList").performScrollTo().performClick()@@ -129,7 +129,7 @@ class FlashcardsPagesTest {     @Test     fun deckListPagePlayPushesReview() {         deckWithNote("PageDeckPlay", "PagePlayFront")-        val stack = NavBackStack<Route>(arrayOf(Route.Main))+        val stack = NavBackStack<Route>(arrayOf(Route.Decks))         rule.setContent { DynamicTheme { DeckListPage(stack, vm) } }         rule.onAllNodesWithContentDescription("Play")[0].performClick()         assertTrue(stack.last() is Route.Review)@@ -138,7 +138,7 @@ class FlashcardsPagesTest {     @Test     fun noteListPageBindsAndNavigates() {         val deck = deckWithNote("PageNoteDeck", "PageNoteFront")-        val stack = NavBackStack<Route>(arrayOf(Route.Main, Route.CardList(deck.id)))+        val stack = NavBackStack<Route>(arrayOf(Route.Decks, Route.CardList(deck.id)))         rule.setContent { DynamicTheme { NoteListPage(stack, vm, deck.id) } }         rule.onNodeWithText("PageNoteFront").assertIsDisplayed()         rule.onNodeWithText("Study").assertIsDisplayed()@@ -155,19 +155,19 @@ class FlashcardsPagesTest {     fun noteEditPageBindsAndSaves() {         val deck = deckWithNote("PageEditDeck", "PageEditFront")         val note = runBlocking { repo.getAllNotesImpl().first { it.sortField == "PageEditFront" } }-        val stack = NavBackStack<Route>(arrayOf(Route.Main, Route.NoteEdit(deck.id, note.id)))+        val stack = NavBackStack<Route>(arrayOf(Route.Decks, Route.NoteEdit(deck.id, note.id)))         rule.setContent { DynamicTheme { NoteEditPage(stack, vm, deck.id, note.id) } }         rule.onNodeWithText("Edit card").assertIsDisplayed()         rule.onNodeWithText("PageEditDeck").assertIsDisplayed()         rule.onNodeWithContentDescription("Save").performClick()         // Saving pops the editor off the stack.         await("editor popped") { stack.backStack.size == 1 }-        assertEquals(Route.Main, stack.last())+        assertEquals(Route.Decks, stack.last())     }      @Test     fun noteTypePagesBind() {-        val stack = NavBackStack<Route>(arrayOf(Route.Main))+        val stack = NavBackStack<Route>(arrayOf(Route.Decks))         rule.setContent { DynamicTheme { NoteTypeListPage(stack, vm) } }         // "Basic" can match two semantics nodes while the list is still         // settling (the built-in row plus its substring sibling row in the@@ -184,7 +184,7 @@ class FlashcardsPagesTest {      @Test     fun noteTypeEditPageBindsExisting() {-        val stack = NavBackStack<Route>(arrayOf(Route.Main, Route.NoteTypeEdit(1L)))+        val stack = NavBackStack<Route>(arrayOf(Route.Decks, Route.NoteTypeEdit(1L)))         rule.setContent { DynamicTheme { NoteTypeEditPage(stack, vm, 1L) } }         rule.onNodeWithText("Edit note type").assertIsDisplayed()         rule.onNodeWithText("Basic").assertIsDisplayed()@@ -192,7 +192,7 @@ class FlashcardsPagesTest {      @Test     fun noteTypeEditPageBindsNew() {-        val stack = NavBackStack<Route>(arrayOf(Route.Main))+        val stack = NavBackStack<Route>(arrayOf(Route.Decks))         rule.setContent { DynamicTheme { NoteTypeEditPage(stack, vm, 0L) } }         rule.onNodeWithText("New note type").assertIsDisplayed()     }@@ -200,7 +200,7 @@ class FlashcardsPagesTest {     @Test     fun reviewPageBindsAndGrades() {         val deck = deckWithNote("PageReviewDeck", "PageReviewFront")-        val stack = NavBackStack<Route>(arrayOf(Route.Main, Route.Review(deck.id)))+        val stack = NavBackStack<Route>(arrayOf(Route.Decks, Route.Review(deck.id)))         rule.setContent { DynamicTheme { ReviewPage(stack, vm, deck.id) } }         await("review front") {             runCatching { rule.onNodeWithText("PageReviewFront").assertIsDisplayed(); true }.getOrDefault(false)@@ -215,7 +215,7 @@ class FlashcardsPagesTest {     @Test     fun reviewPageWithModeParamsStartsCramSession() {         val deck = deckWithNote("PageCramDeck", "PageCramFront")-        val stack = NavBackStack<Route>(arrayOf(Route.Main))+        val stack = NavBackStack<Route>(arrayOf(Route.Decks))         // mode 4 = CRAM         rule.setContent { DynamicTheme { ReviewPage(stack, vm, deck.id, mode = 4, count = 5, daysAhead = 2, tags = listOf("pagetag")) } }         await("cram front") {@@ -226,7 +226,7 @@ class FlashcardsPagesTest {     @Test     fun statsPageBinds() {         deckWithNote("PageStatsDeck", "PageStatsFront")-        val stack = NavBackStack<Route>(arrayOf(Route.Main))+        val stack = NavBackStack<Route>(arrayOf(Route.Decks))         rule.setContent { DynamicTheme { StatsPage(stack, vm) } }         rule.onNodeWithText("Stats").assertIsDisplayed()         rule.onNodeWithText("All decks").assertExists()@@ -237,7 +237,7 @@ class FlashcardsPagesTest {      @Test     fun settingsPageBindsAndWritesThrough() {-        val stack = NavBackStack<Route>(arrayOf(Route.Main))+        val stack = NavBackStack<Route>(arrayOf(Route.Decks))         rule.setContent { DynamicTheme { SettingsPage(stack, vm) } }         rule.onNodeWithText("Settings").assertIsDisplayed()         rule.onNodeWithText("Dark").performScrollTo().performClick()
flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsMiscTest.kt
diff --git a/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsMiscTest.kt b/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsMiscTest.ktindex 1fff5fa559..1cfc6af0db 100644--- a/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsMiscTest.kt+++ b/flashcards/src/test/java/com/vayunmathur/flashcards/util/FlashcardsMiscTest.kt@@ -158,7 +158,7 @@ class FlashcardsMiscTest {     @Test     fun routesSerializeRoundTrip() {         val json = Json { classDiscriminator = "type" }-        assertTrue(json.encodeToString(Route.serializer(), Route.Main).contains("Main") || json.encodeToString(Route.serializer(), Route.Main).isNotBlank())+        assertTrue(json.encodeToString(Route.serializer(), Route.Decks).contains("Decks") || json.encodeToString(Route.serializer(), Route.Decks).isNotBlank())         val review = Route.Review(deckId = 42, mode = 4, count = 9, daysAhead = 2, tags = listOf("a", "b"))         val encoded = json.encodeToString(Route.serializer(), review)         assertTrue(encoded.contains("42"))