diff --git a/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt b/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt index d80f2ab1..6d915b11 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt @@ -89,6 +89,13 @@ internal val destinations = listOf( TopDestination("settings", "Settings", Icons.Default.Settings), ) +/** The home route remains beneath top-level navigation, so Back returns to Runs. */ +internal const val HOME_ROUTE = "runs" + +/** Returning to home clears the accumulated top-level stack; other destinations keep it. */ +internal fun topLevelPopUpToHomeInclusive(destination: String): Boolean = + destination == HOME_ROUTE + /** * Whether [route] is the current destination. Detail panes are no longer * separate routes (they are saved state inside a destination), so this is a @@ -210,14 +217,14 @@ fun PipelinesApp( is SearchTarget.Pipeline -> { pipelineSelection = PaneSelection(MasterPane.Detail, target.pipelineId, target.version) navController.navigate("pipelines") { - popUpTo("pipelines") { inclusive = false } + popUpTo(HOME_ROUTE) { inclusive = false } launchSingleTop = true } } is SearchTarget.Run -> { runSelection = PaneSelection(MasterPane.Detail, target.runId) runSearchNav = target.takeIf { it.sequence > 0 } - navController.navigate("runs") { launchSingleTop = true } + navController.navigate(HOME_ROUTE) { launchSingleTop = true } } null -> Unit } @@ -231,7 +238,7 @@ fun PipelinesApp( val openRunFromAttention: (Long) -> Unit = { runId -> vm.arrivedAtRun(runId) runSelection = PaneSelection(pane = MasterPane.Detail, itemId = runId) - navController.navigate("runs") { launchSingleTop = true } + navController.navigate(HOME_ROUTE) { launchSingleTop = true } } // A deep link (or the notification's click action) opens its run once. The @@ -274,7 +281,9 @@ fun PipelinesApp( val onNavigate: (TopDestination) -> Unit = { destination -> if (currentRoute != destination.route) { navController.navigate(destination.route) { - popUpTo("pipelines") { inclusive = destination.route == "pipelines" } + popUpTo(HOME_ROUTE) { + inclusive = topLevelPopUpToHomeInclusive(destination.route) + } launchSingleTop = true } } @@ -317,7 +326,7 @@ fun PipelinesApp( ) NavHost( navController = navController, - startDestination = "pipelines", + startDestination = HOME_ROUTE, // While the banner is visible it owns the status-bar inset, so // the inner app bars below must not apply it a second time. modifier = Modifier @@ -344,11 +353,11 @@ fun PipelinesApp( pane = MasterPane.Detail, itemId = runId, ) - navController.navigate("runs") { launchSingleTop = true } + navController.navigate(HOME_ROUTE) { launchSingleTop = true } }, ) } - composable("runs") { + composable(HOME_ROUTE) { RunsDestination( vm = vm, wide = wide, diff --git a/android/app/src/test/java/net/awan/pipelines/ui/PipelinesNavTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/PipelinesNavTest.kt index 1347a1c5..9e1cd4c8 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/PipelinesNavTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/PipelinesNavTest.kt @@ -13,6 +13,19 @@ import org.junit.Test class PipelinesNavTest { + @Test + fun runsIsTheHomeRouteForColdLaunchAndTopLevelBack() { + assertEquals("runs", HOME_ROUTE) + } + + @Test + fun returningToHomeIsTheOnlyTopLevelNavigationThatClearsHome() { + assertTrue(topLevelPopUpToHomeInclusive(HOME_ROUTE)) + assertFalse(topLevelPopUpToHomeInclusive("pipelines")) + assertFalse(topLevelPopUpToHomeInclusive("chat")) + assertFalse(topLevelPopUpToHomeInclusive("settings")) + } + @Test fun thePillDoesNotHoldTemplates() { // Templates is configuration and moved to the Settings page; the pill keeps diff --git a/docs/notes/runs-default-home.md b/docs/notes/runs-default-home.md new file mode 100644 index 00000000..b331cf59 --- /dev/null +++ b/docs/notes/runs-default-home.md @@ -0,0 +1,7 @@ +# Runs default home + +The Android app now starts at Runs. Top-level navigation and pipeline search pop up +to the Runs home route, while explicit run deep links continue to select their run. + +The shared Android navigation documentation may still describe Pipelines as the +initial destination; the `docs-fold` documentation pass should update that reference.