screentime: keep Navigation.kt to the Navigation composable
- Commit
1931ccc107013b628fa9cf7401011177b9f59016- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 03:26 UTC (17 days ago)
- Parents
c002419
PackageStructure lint now requires the app-root Navigation.kt to contain only the top-level @Composable fun Navigation(...). This module parked its app-details and wind-down entry builders in the same file, so the module failed lint. Move the two extra top-level declarations, AppDetailsEntry and WindDownEntry, unchanged in name, signature, and behavior, into a new file ui/NavigationEntries.kt in the same module. They change from private to internal so the root Navigation composable (a different package) can still call them. Navigation.kt keeps only fun Navigation(...) and imports the moved builders; no screen, route, or navigation behavior changes. Verified: ./gradlew :screentime:lintDev :screentime:testDevUnitTest - both pass.
Diff
screentime/src/main/java/com/vayunmathur/screentime/Navigation.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/Navigation.kt b/screentime/src/main/java/com/vayunmathur/screentime/Navigation.ktindex 3f818fce60..13ce959ff0 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/Navigation.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/Navigation.kt@@ -10,10 +10,10 @@ import com.vayunmathur.library.util.ListPage import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.rememberNavBackStack import com.vayunmathur.screentime.platform.ScreenTimeViewModel-import com.vayunmathur.screentime.ui.AppDetailsScreen import com.vayunmathur.screentime.ui.DashboardActions+import com.vayunmathur.screentime.ui.AppDetailsEntry import com.vayunmathur.screentime.ui.DashboardScreen-import com.vayunmathur.screentime.ui.WindDownScreen+import com.vayunmathur.screentime.ui.WindDownEntry /** Navigation host for Screen Time: the dashboard and everything it opens. */ @Composable@@ -64,44 +64,3 @@ fun Navigation( } } -/** App-details destination: opens the route's package, then wires its controls. */-@Composable-private fun AppDetailsEntry(- viewModel: ScreenTimeViewModel,- backStack: com.vayunmathur.library.util.NavBackStack<Route>,- route: Route.AppDetails,-) {- LaunchedEffect(route.packageName) {- viewModel.openDetail(route.packageName.ifBlank { null })- }- val state by viewModel.detailState.collectAsStateWithLifecycle()- AppDetailsScreen(- state = state,- onBack = { backStack.pop() },- onSetPeriod = viewModel::setPeriod,- onStep = viewModel::stepAnchor,- onTimerChange = { minutes ->- state.packageName?.let { viewModel.setTimer(it, minutes) }- },- onPausedChange = { paused ->- state.packageName?.let { viewModel.setAppPaused(it, paused) }- },- )-}--/** Wind-down destination and its schedule controls. */-@Composable-private fun WindDownEntry(viewModel: ScreenTimeViewModel) {- val state by viewModel.state.collectAsStateWithLifecycle()- WindDownScreen(- state = state,- onEnabledChange = { viewModel.setWindDown(enabled = it) },- onStartChange = { h, m -> viewModel.setWindDown(startMinute = h * 60 + m) },- onEndChange = { h, m -> viewModel.setWindDown(endMinute = h * 60 + m) },- onToggleDay = { day ->- viewModel.setWindDown(daysMask = state.windDown.daysMask xor (1 shl day))- },- onGrayscaleChange = { viewModel.setWindDown(grayscale = it) },- onDndChange = { viewModel.setWindDown(doNotDisturb = it) },- )-}
screentime/src/main/java/com/vayunmathur/screentime/ui/NavigationEntries.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/ui/NavigationEntries.kt b/screentime/src/main/java/com/vayunmathur/screentime/ui/NavigationEntries.ktnew file mode 100644index 0000000000..dc7695c8c6--- /dev/null+++ b/screentime/src/main/java/com/vayunmathur/screentime/ui/NavigationEntries.kt@@ -0,0 +1,51 @@+package com.vayunmathur.screentime.ui++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.NavBackStack+import com.vayunmathur.screentime.Route+import com.vayunmathur.screentime.platform.ScreenTimeViewModel++/** App-details destination: opens the route's package, then wires its controls. */+@Composable+internal fun AppDetailsEntry(+ viewModel: ScreenTimeViewModel,+ backStack: NavBackStack<Route>,+ route: Route.AppDetails,+) {+ LaunchedEffect(route.packageName) {+ viewModel.openDetail(route.packageName.ifBlank { null })+ }+ val state by viewModel.detailState.collectAsStateWithLifecycle()+ AppDetailsScreen(+ state = state,+ onBack = { backStack.pop() },+ onSetPeriod = viewModel::setPeriod,+ onStep = viewModel::stepAnchor,+ onTimerChange = { minutes ->+ state.packageName?.let { viewModel.setTimer(it, minutes) }+ },+ onPausedChange = { paused ->+ state.packageName?.let { viewModel.setAppPaused(it, paused) }+ },+ )+}++/** Wind-down destination and its schedule controls. */+@Composable+internal fun WindDownEntry(viewModel: ScreenTimeViewModel) {+ val state by viewModel.state.collectAsStateWithLifecycle()+ WindDownScreen(+ state = state,+ onEnabledChange = { viewModel.setWindDown(enabled = it) },+ onStartChange = { h, m -> viewModel.setWindDown(startMinute = h * 60 + m) },+ onEndChange = { h, m -> viewModel.setWindDown(endMinute = h * 60 + m) },+ onToggleDay = { day ->+ viewModel.setWindDown(daysMask = state.windDown.daysMask xor (1 shl day))+ },+ onGrayscaleChange = { viewModel.setWindDown(grayscale = it) },+ onDndChange = { viewModel.setWindDown(doNotDisturb = it) },+ )+}