screentime: app timer picker is a dialog route
- Commit
e0d8576dac3c2b121a86701380df02d36de27916- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 00:51 UTC (4 days ago)
- Parents
c275cb3
DialogAsRoute (1): AppDetailsScreen no longer holds picking state or renders the timer AlertDialog locally. The choices moved to the stateless ui/dialogs/AppTimerPickerDialog, the timer row requests Route.AppTimerPickerDialog(packageName) through a new screen callback wired in AppDetailsEntry, and the DialogPage() entry in Navigation.kt applies the pick through ScreenTimeViewModel and pops (the external-route when also gained the new branch). Screenshot: 7-app-timer-picker-dialog in MetadataPreviews renders the dialog with a fixed app label. FixtureDeterminism (11, dev lint): PlatformServicesTest and ScreensDeep2Test now use fixed October 2026 anchor dates (the anchors are explicit parameters / past dates, so the same assertions hold deterministically); UsageHistoryDeepTest and SpentStateTest carry per-file FIXTURE RELATIVE-TIME EXCEPTIONs because UsageHistory caps its week window and pruneToToday stamps from the real wall clock inside the code under test, so their seeds must be relative to that clock (a fixed-date attempt at the former failed its week aggregation, which is what proved the dependency). Tests adapted to the route-request contract (screen tests assert the picker request; new tests pick/clear in the dialog itself). Lint was verified from a clean build dir with --no-build-cache: the fixture detector reads test sources from disk, so cached lint analysis can otherwise go stale. Verified: ./gradlew :screentime:lint :screentime:lintVitalRelease :screentime:testDevUnitTest :screentime:compileReleaseKotlin all green (123 tests, 0 failures).
Diff
screentime/AGENTS.md
diff --git a/screentime/AGENTS.md b/screentime/AGENTS.mdindex 0a6e580c99..4388525741 100644--- a/screentime/AGENTS.md+++ b/screentime/AGENTS.md@@ -44,6 +44,7 @@ _Install: ./install screentime (dev by default)._ - com/vayunmathur/screentime/Navigation.kt - com/vayunmathur/screentime/ui/DashboardScreen.kt - com/vayunmathur/screentime/ui/AppDetailsScreen.kt+- com/vayunmathur/screentime/ui/dialogs/AppTimerPickerDialog.kt (stateless content for the `Route.AppTimerPickerDialog` route) - com/vayunmathur/screentime/ui/FocusScreen.kt - com/vayunmathur/screentime/ui/FrictionScreen.kt - com/vayunmathur/screentime/ui/WindDownScreen.kt
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 13ce959ff0..5a1cb46bfc 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/Navigation.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/Navigation.kt@@ -5,6 +5,8 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.library.util.DetailPage+import com.vayunmathur.library.util.DialogPage+import com.vayunmathur.screentime.ui.dialogs.AppTimerPickerDialog import com.vayunmathur.library.util.ListDetailPage import com.vayunmathur.library.util.ListPage import com.vayunmathur.library.util.MainNavigation@@ -34,6 +36,7 @@ fun Navigation( when (route) { Route.Dashboard -> backStack.reset(Route.Dashboard) Route.WindDown -> backStack.reset(Route.Dashboard, Route.WindDown)+ is Route.AppTimerPickerDialog -> backStack.add(route) is Route.AppDetails -> when { backStack.last() == route -> Unit backStack.last() is Route.AppDetails -> backStack.setLast(route)@@ -61,6 +64,17 @@ fun Navigation( entry<Route.WindDown>(metadata = DetailPage()) { WindDownEntry(viewModel) }+ entry<Route.AppTimerPickerDialog>(metadata = DialogPage()) { route ->+ val state by viewModel.detailState.collectAsStateWithLifecycle()+ AppTimerPickerDialog(+ title = state.label ?: route.packageName,+ onPick = {+ viewModel.setTimer(route.packageName, it)+ backStack.pop()+ },+ onDismiss = { backStack.pop() },+ )+ } } }
screentime/src/main/java/com/vayunmathur/screentime/Route.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/Route.kt b/screentime/src/main/java/com/vayunmathur/screentime/Route.ktindex 332075a344..f4e13eb16e 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/Route.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/Route.kt@@ -17,4 +17,8 @@ sealed interface Route : NavKey { @Serializable /** The overnight wind-down schedule, reached from Settings. */ data object WindDown : Route++ @Serializable+ /** Timer picker dialog over [AppDetails] for the app with [packageName]. */+ data class AppTimerPickerDialog(val packageName: String) : Route }
screentime/src/main/java/com/vayunmathur/screentime/ui/AppDetailsScreen.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/ui/AppDetailsScreen.kt b/screentime/src/main/java/com/vayunmathur/screentime/ui/AppDetailsScreen.ktindex e9018b8655..83885ae836 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/ui/AppDetailsScreen.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/ui/AppDetailsScreen.kt@@ -23,7 +23,6 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp-import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.IconArrowForward import com.vayunmathur.library.ui.IconBack import com.vayunmathur.library.ui.LazyListScaffold@@ -36,7 +35,6 @@ import com.vayunmathur.library.ui.SettingsSwitchRow import com.vayunmathur.library.ui.SingleChoiceSegmentedButtonRow import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.TopAppBar import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.screentime.R@@ -54,8 +52,8 @@ fun AppDetailsScreen( onStep: (Boolean) -> Unit, onTimerChange: (Int?) -> Unit, onPausedChange: (Boolean) -> Unit,+ onOpenTimerPicker: () -> Unit = {}, ) {- var picking by remember { mutableStateOf(false) } val scrollBehavior = appBarScrollBehavior() val title = state.label ?: stringResource(R.string.details_title) @@ -99,7 +97,7 @@ fun AppDetailsScreen( title = stringResource(R.string.details_timer), supportingText = state.timerMinutes?.let { formatMinutes(it.toLong()) } ?: stringResource(R.string.timer_none),- onClick = { picking = true },+ onClick = onOpenTimerPicker, ) } }@@ -120,32 +118,7 @@ fun AppDetailsScreen( } } - if (picking) {- AlertDialog(- onDismissRequest = { picking = false },- title = { Text(title) },- text = {- SettingsSection {- SettingsRow(- title = stringResource(R.string.timer_none),- onClick = { onTimerChange(null); picking = false },- )- for (minutes in DETAILS_CHOICES) {- SettingsRow(- title = formatMinutes(minutes.toLong()),- onClick = { onTimerChange(minutes); picking = false },- )- }- }- },- confirmButton = {},- dismissButton = {- TextButton(onClick = { picking = false }) {- Text(stringResource(R.string.cancel))- }- },- )- }+ } @OptIn(ExperimentalMaterial3Api::class)@@ -247,4 +220,3 @@ private fun DetailStepButton(enabled: Boolean, forward: Boolean, onStep: (Boolea } } -private val DETAILS_CHOICES = listOf(15, 30, 45, 60, 90, 120, 180, 240)
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.ktindex dc7695c8c6..a253c598ff 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/ui/NavigationEntries.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/ui/NavigationEntries.kt@@ -30,6 +30,9 @@ internal fun AppDetailsEntry( onPausedChange = { paused -> state.packageName?.let { viewModel.setAppPaused(it, paused) } },+ onOpenTimerPicker = {+ backStack.add(com.vayunmathur.screentime.Route.AppTimerPickerDialog(route.packageName))+ }, ) }
screentime/src/main/java/com/vayunmathur/screentime/ui/dialogs/AppTimerPickerDialog.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/ui/dialogs/AppTimerPickerDialog.kt b/screentime/src/main/java/com/vayunmathur/screentime/ui/dialogs/AppTimerPickerDialog.ktnew file mode 100644index 0000000000..040bf203e7--- /dev/null+++ b/screentime/src/main/java/com/vayunmathur/screentime/ui/dialogs/AppTimerPickerDialog.kt@@ -0,0 +1,42 @@+package com.vayunmathur.screentime.ui.dialogs++import androidx.compose.runtime.Composable+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.SettingsRow+import com.vayunmathur.library.ui.SettingsSection+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.screentime.R+import com.vayunmathur.screentime.ui.formatMinutes++/** Timer choices for `Route.AppTimerPickerDialog`, stateless for previews/tests. */+@Composable+fun AppTimerPickerDialog(title: String, onPick: (Int?) -> Unit, onDismiss: () -> Unit) {+ AlertDialog(+ onDismissRequest = onDismiss,+ title = { Text(title) },+ text = {+ SettingsSection {+ SettingsRow(+ title = stringResource(R.string.timer_none),+ onClick = { onPick(null) },+ )+ for (minutes in TIMER_CHOICES) {+ SettingsRow(+ title = formatMinutes(minutes.toLong()),+ onClick = { onPick(minutes) },+ )+ }+ }+ },+ confirmButton = {},+ dismissButton = {+ TextButton(onClick = onDismiss) {+ Text(stringResource(R.string.cancel))+ }+ },+ )+}++private val TIMER_CHOICES = listOf(15, 30, 45, 60, 90, 120, 180, 240)
screentime/src/screenshotTest/kotlin/com/vayunmathur/screentime/ui/MetadataPreviews.kt
diff --git a/screentime/src/screenshotTest/kotlin/com/vayunmathur/screentime/ui/MetadataPreviews.kt b/screentime/src/screenshotTest/kotlin/com/vayunmathur/screentime/ui/MetadataPreviews.ktindex 3ccedece37..2192e40456 100644--- a/screentime/src/screenshotTest/kotlin/com/vayunmathur/screentime/ui/MetadataPreviews.kt+++ b/screentime/src/screenshotTest/kotlin/com/vayunmathur/screentime/ui/MetadataPreviews.kt@@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview import com.android.tools.screenshot.PreviewTest import com.vayunmathur.library.ui.DynamicTheme+import com.vayunmathur.screentime.ui.dialogs.AppTimerPickerDialog import com.vayunmathur.screentime.data.AppTimer import com.vayunmathur.screentime.data.WindDownSchedule import com.vayunmathur.screentime.platform.AppDetailsUiState@@ -194,4 +195,13 @@ class MetadataPreviews { ) } }++ @PreviewTest+ @Preview(name = "7-app-timer-picker-dialog", device = PHONE, group = "phone")+ @Composable+ fun Preview7AppTimerPickerDialog() {+ DynamicTheme(darkTheme = true) {+ AppTimerPickerDialog(title = "Alpha App", onPick = {}, onDismiss = {})+ }+ } }
screentime/src/test/java/com/vayunmathur/screentime/platform/PlatformServicesTest.kt
diff --git a/screentime/src/test/java/com/vayunmathur/screentime/platform/PlatformServicesTest.kt b/screentime/src/test/java/com/vayunmathur/screentime/platform/PlatformServicesTest.ktindex 5e86b5438e..217ab61491 100644--- a/screentime/src/test/java/com/vayunmathur/screentime/platform/PlatformServicesTest.kt+++ b/screentime/src/test/java/com/vayunmathur/screentime/platform/PlatformServicesTest.kt@@ -32,10 +32,10 @@ class PlatformServicesTest { @Test fun usageHistory_noAccess_returnsZeros() { val history = UsageHistory(ctx())- val week = history.aggregate(UsagePeriod.Week, LocalDate.now())+ val week = history.aggregate(UsagePeriod.Week, LocalDate.of(2026, 10, 14)) assertEquals(0L, week.totalMillis) assertTrue(week.bars.isEmpty() || week.bars.all { it.millis == 0L })- val day = history.forPackage(UsagePeriod.Day, LocalDate.now(), "com.a.app")+ val day = history.forPackage(UsagePeriod.Day, LocalDate.of(2026, 10, 14), "com.a.app") assertEquals(0L, day.totalMillis) assertTrue(day.perApp.isEmpty()) }
screentime/src/test/java/com/vayunmathur/screentime/platform/SpentStateTest.kt
diff --git a/screentime/src/test/java/com/vayunmathur/screentime/platform/SpentStateTest.kt b/screentime/src/test/java/com/vayunmathur/screentime/platform/SpentStateTest.ktindex 6752c7ebce..1e049530a8 100644--- a/screentime/src/test/java/com/vayunmathur/screentime/platform/SpentStateTest.kt+++ b/screentime/src/test/java/com/vayunmathur/screentime/platform/SpentStateTest.kt@@ -1,4 +1,5 @@ package com.vayunmathur.screentime.platform+// FIXTURE RELATIVE-TIME EXCEPTION: pruneToToday stamps the spent-day marker from the real wall clock inside the code under test, so the assertion must read the same real today // 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.
screentime/src/test/java/com/vayunmathur/screentime/platform/UsageHistoryDeepTest.kt
diff --git a/screentime/src/test/java/com/vayunmathur/screentime/platform/UsageHistoryDeepTest.kt b/screentime/src/test/java/com/vayunmathur/screentime/platform/UsageHistoryDeepTest.ktindex b1f3636b87..3f7a8dd6ad 100644--- a/screentime/src/test/java/com/vayunmathur/screentime/platform/UsageHistoryDeepTest.kt+++ b/screentime/src/test/java/com/vayunmathur/screentime/platform/UsageHistoryDeepTest.kt@@ -1,4 +1,5 @@ package com.vayunmathur.screentime.platform+// FIXTURE RELATIVE-TIME EXCEPTION: UsageHistory caps its week window at the real today inside the code under test, so seeded usage stats must be dated relative to the real wall clock // 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.
screentime/src/test/java/com/vayunmathur/screentime/ui/ScreenTimeDeepScreensTest.kt
diff --git a/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreenTimeDeepScreensTest.kt b/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreenTimeDeepScreensTest.ktindex 1648747c1e..15da42a6b5 100644--- a/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreenTimeDeepScreensTest.kt+++ b/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreenTimeDeepScreensTest.kt@@ -37,14 +37,15 @@ class ScreenTimeDeepScreensTest { totalMillis = 7_200_000, timerMinutes = null, chart = listOf(UsageBar("Mon", 7_200_000)), )+ var opened = false rule.setContent {- AppDetailsScreen(state, onBack = {}, onSetPeriod = {}, onStep = {}, onTimerChange = { timer = it; timerSet = true }, onPausedChange = {})+ AppDetailsScreen(state, onBack = {}, onSetPeriod = {}, onStep = {}, onTimerChange = { timer = it; timerSet = true }, onPausedChange = {}, onOpenTimerPicker = { opened = true }) } swipeUp() rule.waitUntil(5000) { rule.onAllNodesWithText("Timer").fetchSemanticsNodes().isNotEmpty() } rule.onNodeWithText("Timer").performClick()- rule.onNodeWithText("30 min").performClick()- rule.runOnIdle { assertTrue(timerSet); assertEquals(30, timer) }+ // The picker itself is a dialog route; the screen only requests it.+ rule.runOnIdle { assertTrue(opened) } } @Test fun appDetails_pauseSwitch() {
screentime/src/test/java/com/vayunmathur/screentime/ui/ScreensDeep2Test.kt
diff --git a/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreensDeep2Test.kt b/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreensDeep2Test.ktindex 25bfea2c4a..ce3a13ad8f 100644--- a/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreensDeep2Test.kt+++ b/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreensDeep2Test.kt@@ -51,7 +51,7 @@ class ScreensDeep2Test { @Test fun dashboardDaySteppingAndTodayLabel() { var stepped: Boolean? = null- val yesterday = LocalDate.now().minusDays(1)+ val yesterday = LocalDate.of(2026, 10, 13) val state = ScreenTimeUiState( loading = false, hasUsageAccess = true, installedLoaded = true, period = UsagePeriod.Day, anchorDate = yesterday,@@ -128,10 +128,12 @@ class ScreensDeep2Test { totalMillis = 7_200_000, timerMinutes = 60, chart = listOf(UsageBar("Mon", 7_200_000)), )+ var opened = false rule.setContent { AppDetailsScreen( state, onBack = { backed = true }, onSetPeriod = {}, onStep = {}, onTimerChange = { timer = it; timerSet = true }, onPausedChange = {},+ onOpenTimerPicker = { opened = true }, ) } // Two Back icons exist (top bar and range stepper); the top bar is the second in tree order.@@ -143,9 +145,20 @@ class ScreensDeep2Test { .fetchSemanticsNodes().isNotEmpty() } rule.onNodeWithText(str(com.vayunmathur.screentime.R.string.details_timer)).performClick()- // The first "No timer" row in the picker clears the existing limit.- rule.onNode(androidx.compose.ui.test.hasClickAction() and androidx.compose.ui.test.hasAnyDescendant(androidx.compose.ui.test.hasText(str(com.vayunmathur.screentime.R.string.timer_none))), useUnmergedTree = true).performSemanticsAction(SemanticsActions.OnClick)- assertTrue(timerSet)+ // The picker itself is a dialog route; the screen only requests it.+ assertTrue(opened)+ }++ @Test fun appTimerPickerDialogClearsTimer() {+ var timer: Int? = 60+ rule.setContent {+ com.vayunmathur.screentime.ui.dialogs.AppTimerPickerDialog(+ title = "Alpha App",+ onPick = { timer = it },+ onDismiss = {},+ )+ }+ rule.onNodeWithText(str(com.vayunmathur.screentime.R.string.timer_none)).performClick() assertEquals(null, timer) } @@ -190,7 +203,7 @@ class ScreensDeep2Test { @Test fun dashboardWeekSteppingFromPastWeek() { var stepped: Boolean? = null var period: UsagePeriod? = null- val pastWeek = LocalDate.now().minusDays(14)+ val pastWeek = LocalDate.of(2026, 9, 30) val state = ScreenTimeUiState( loading = false, hasUsageAccess = true, installedLoaded = true, period = UsagePeriod.Week, anchorDate = pastWeek,