Modern Apps git

← Modern-Apps.git

tuner: tabs are sibling routes (#nav)

Commit
a3f5686552c55693e529acf4862951c6610169ef
Author
Vayun Mathur <[email protected]>
When
2026-11-16 20:05 UTC (19 days ago)
Parents
b3f3c95
Replace the sole Route.Tuner with Route.Note and Route.Chord
sibling destinations. Navigation starts on Note, and TunerTabs now
takes the back stack and uses the route-backed TabbedPagerScaffold
(RouteTab with the same Note/Chord labels, icons and order) with
MainNavigation hosted in its content slot; both entries are
registered with SiblingPage(), so switching tabs resets the stack.

The microphone capture DisposableEffect stays at the TunerTabs host
level, above the tab entries, so switching between Note and Chord
does not stop or restart capture, and disposal of the host is still
a full stop as before.

TunerScreensTest gains a navigation test: starting on Route.Note,
clicking Chord resets the stack to exactly Route.Chord, and
clicking Note resets it back.

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

Diff

tuner/src/main/java/com/vayunmathur/tuner/Navigation.kt
diff --git a/tuner/src/main/java/com/vayunmathur/tuner/Navigation.kt b/tuner/src/main/java/com/vayunmathur/tuner/Navigation.ktindex 659025f29f..8e1b9e55cd 100644--- a/tuner/src/main/java/com/vayunmathur/tuner/Navigation.kt+++ b/tuner/src/main/java/com/vayunmathur/tuner/Navigation.kt@@ -1,17 +1,12 @@ package com.vayunmathur.tuner  import androidx.compose.runtime.Composable-import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.rememberNavBackStack import com.vayunmathur.tuner.platform.TunerViewModel import com.vayunmathur.tuner.ui.TunerTabs  @Composable fun Navigation(viewModel: TunerViewModel) {-    val backStack = rememberNavBackStack<Route>(Route.Tuner)-    MainNavigation(backStack) {-        entry<Route.Tuner> {-            TunerTabs(viewModel)-        }-    }+    val backStack = rememberNavBackStack<Route>(Route.Note)+    TunerTabs(backStack, viewModel) }
tuner/src/main/java/com/vayunmathur/tuner/Route.kt
diff --git a/tuner/src/main/java/com/vayunmathur/tuner/Route.kt b/tuner/src/main/java/com/vayunmathur/tuner/Route.ktindex b256fa9c78..00da964338 100644--- a/tuner/src/main/java/com/vayunmathur/tuner/Route.kt+++ b/tuner/src/main/java/com/vayunmathur/tuner/Route.kt@@ -6,7 +6,11 @@ import kotlinx.serialization.Serializable /** Contract for route. */ @Serializable sealed interface Route : NavKey {-    /** Singleton holding tuner state and operations. */+    /** Note tuner tab (sibling route, the start destination). */     @Serializable-    data object Tuner : Route+    data object Note : Route++    /** Chord detector tab (sibling route). */+    @Serializable+    data object Chord : Route }
tuner/src/main/java/com/vayunmathur/tuner/ui/TunerTabs.kt
diff --git a/tuner/src/main/java/com/vayunmathur/tuner/ui/TunerTabs.kt b/tuner/src/main/java/com/vayunmathur/tuner/ui/TunerTabs.ktindex fec6374271..24d6aa804e 100644--- a/tuner/src/main/java/com/vayunmathur/tuner/ui/TunerTabs.kt+++ b/tuner/src/main/java/com/vayunmathur/tuner/ui/TunerTabs.kt@@ -5,30 +5,41 @@ import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.res.stringResource import com.vayunmathur.library.ui.IconGrid import com.vayunmathur.library.ui.IconMusicNote-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.MainNavigation+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.library.util.SiblingPage import com.vayunmathur.tuner.R+import com.vayunmathur.tuner.Route import com.vayunmathur.tuner.platform.TunerViewModel  /**- * The app's two tabs.+ * The app's two tabs as sibling [Route] destinations.  *  * Capture follows the tabs being on screen: there is no control for it, because a tuner that is  * open and not listening has nothing to offer. Starting from here rather than from the activity  * is what orders it after the permission gate, which the activity's start hook sits in front of.  * After that the activity's start/stop hooks release and restore the microphone around the- * foreground. Disposal is a full stop, not a pause.+ * foreground. Disposal is a full stop, not a pause. The effect lives at this host level, so+ * switching between the Note and Chord tabs does not restart capture.  */ @Composable-fun TunerTabs(viewModel: TunerViewModel) {+fun TunerTabs(backStack: NavBackStack<Route>, viewModel: TunerViewModel) {     DisposableEffect(Unit) {         viewModel.start()         onDispose { viewModel.stop() }     }-    val tabs = listOf(-        PagerTab(stringResource(R.string.tab_note), { IconMusicNote() }) { NotePage(viewModel) },-        PagerTab(stringResource(R.string.tab_chord), { IconGrid() }) { ChordPage(viewModel) },-    )-    TabbedPagerScaffold(tabs = tabs, tabStyle = TabStyle.BottomNav)+    TabbedPagerScaffold(+        backStack = backStack,+        tabs = listOf<RouteTab<Route>>(+            RouteTab(Route.Note, stringResource(R.string.tab_note)) { IconMusicNote() },+            RouteTab(Route.Chord, stringResource(R.string.tab_chord)) { IconGrid() },+        ),+    ) {+        MainNavigation(backStack) {+            entry<Route.Note>(metadata = SiblingPage()) { NotePage(viewModel) }+            entry<Route.Chord>(metadata = SiblingPage()) { ChordPage(viewModel) }+        }+    } }
tuner/src/test/java/com/vayunmathur/tuner/ui/TunerScreensTest.kt
diff --git a/tuner/src/test/java/com/vayunmathur/tuner/ui/TunerScreensTest.kt b/tuner/src/test/java/com/vayunmathur/tuner/ui/TunerScreensTest.ktindex 8c2c4373e9..a48e2a7142 100644--- a/tuner/src/test/java/com/vayunmathur/tuner/ui/TunerScreensTest.kt+++ b/tuner/src/test/java/com/vayunmathur/tuner/ui/TunerScreensTest.kt@@ -117,6 +117,24 @@ class TunerScreensTest {         assertTrue(true)     } +    @Test+    fun tabSelectSwapsSiblingDestination() {+        val app = ApplicationProvider.getApplicationContext<android.app.Application>()+        val vm = com.vayunmathur.tuner.platform.TunerViewModel(app)+        val stack = com.vayunmathur.library.util.NavBackStack(+            arrayOf<com.vayunmathur.tuner.Route>(com.vayunmathur.tuner.Route.Note),+        )+        composeRule.setContent { TunerTabs(stack, vm) }+        composeRule.waitForIdle()+        composeRule.onNodeWithText(str(R.string.tab_chord)).performClick()+        composeRule.waitForIdle()+        // Selecting a tab resets the stack to exactly that sibling route.+        assertEquals(listOf(com.vayunmathur.tuner.Route.Chord), stack.backStack)+        composeRule.onNodeWithText(str(R.string.tab_note)).performClick()+        composeRule.waitForIdle()+        assertEquals(listOf(com.vayunmathur.tuner.Route.Note), stack.backStack)+    }+     @Test     fun chordScreenListeningPrompt() {         composeRule.setContent { ChordScreen(state(listening = true)) { } }