news: stateless settings slices and full route captures
- Commit
f1f37acadd53279946e6a4cc455730864bd1605d- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-25 23:50 UTC (10 days ago)
- Parents
4be93b4
SettingsScreen and LocalLocationScreen now expose stateless *Content bodies (values and callbacks as parameters), so screenshot previews render the real screens from literal fixtures with no ViewModel or DataStore; selection still flows through the same callbacks into the ViewModel. MetadataPreviews adds the missing route captures (expanded feed/reader, Story, Settings, LocalLocation) so every Route leaf has a screenshot, per the RouteScreenshotCoverage convention. Verified by the pilot agent: :news:metadata renders 8 images, :news:lint and :news:testDevUnitTest green.
Diff
metadata_data/photos/news/phone/4.png
diff --git a/metadata_data/photos/news/phone/4.png b/metadata_data/photos/news/phone/4.pngnew file mode 100644index 0000000000..7a6eefc65cBinary files /dev/null and b/metadata_data/photos/news/phone/4.png differ
metadata_data/photos/news/phone/5.png
diff --git a/metadata_data/photos/news/phone/5.png b/metadata_data/photos/news/phone/5.pngnew file mode 100644index 0000000000..59c37fdacbBinary files /dev/null and b/metadata_data/photos/news/phone/5.png differ
metadata_data/photos/news/phone/6.png
diff --git a/metadata_data/photos/news/phone/6.png b/metadata_data/photos/news/phone/6.pngnew file mode 100644index 0000000000..ae8f99fcd0Binary files /dev/null and b/metadata_data/photos/news/phone/6.png differ
news/src/main/java/com/vayunmathur/news/ui/LocalLocationScreen.kt
diff --git a/news/src/main/java/com/vayunmathur/news/ui/LocalLocationScreen.kt b/news/src/main/java/com/vayunmathur/news/ui/LocalLocationScreen.ktindex 35e3028639..736de45e01 100644--- a/news/src/main/java/com/vayunmathur/news/ui/LocalLocationScreen.kt+++ b/news/src/main/java/com/vayunmathur/news/ui/LocalLocationScreen.kt@@ -35,6 +35,29 @@ import com.vayunmathur.news.platform.NewsViewModel @Composable fun LocalLocationScreen(viewModel: NewsViewModel, onBack: () -> Unit) { val current by viewModel.localLocation.collectAsState()+ LocalLocationContent(+ current = current,+ onSelect = { location ->+ viewModel.setLocalLocation(location)+ onBack()+ },+ onBack = onBack,+ )+}++/**+ * Stateless location-picker body behind [LocalLocationScreen]: the current+ * preference and the pick callback are parameters, so Compose previews+ * (src/screenshotTest) render the real screen from literal fixtures with no+ * ViewModel or DataStore. The search query stays local UI state here — the+ * *selection* is the callback, never held state in a parent.+ */+@Composable+internal fun LocalLocationContent(+ current: String?,+ onSelect: (String?) -> Unit,+ onBack: () -> Unit,+) { var query by remember { mutableStateOf("") } val trimmed = query.trim() val filtered = remember(trimmed) {@@ -73,8 +96,7 @@ fun LocalLocationScreen(viewModel: NewsViewModel, onBack: () -> Unit) { headlineContent = { Text(stringResource(R.string.local_location_current, current!!)) }, supportingContent = { Text(stringResource(R.string.local_location_clear)) }, modifier = Modifier.clickable {- viewModel.setLocalLocation(null)- onBack()+onSelect(null) }, ) }@@ -86,8 +108,7 @@ fun LocalLocationScreen(viewModel: NewsViewModel, onBack: () -> Unit) { Text(stringResource(R.string.local_location_use_typed, trimmed)) }, modifier = Modifier.clickable {- viewModel.setLocalLocation(trimmed)- onBack()+onSelect(trimmed) }, ) }@@ -102,8 +123,7 @@ fun LocalLocationScreen(viewModel: NewsViewModel, onBack: () -> Unit) { ListItem( headlineContent = { Text(region) }, modifier = Modifier.clickable {- viewModel.setLocalLocation(region)- onBack()+onSelect(region) }, ) }
news/src/main/java/com/vayunmathur/news/ui/SettingsScreen.kt
diff --git a/news/src/main/java/com/vayunmathur/news/ui/SettingsScreen.kt b/news/src/main/java/com/vayunmathur/news/ui/SettingsScreen.ktindex cb27e19591..3a728f9a96 100644--- a/news/src/main/java/com/vayunmathur/news/ui/SettingsScreen.kt+++ b/news/src/main/java/com/vayunmathur/news/ui/SettingsScreen.kt@@ -32,6 +32,24 @@ fun SettingsScreen( onOpenLocalLocation: () -> Unit, ) { val localLocation by viewModel.localLocation.collectAsState()+ SettingsContent(+ localLocation = localLocation,+ onBack = onBack,+ onOpenLocalLocation = onOpenLocalLocation,+ )+}++/**+ * Stateless settings body behind [SettingsScreen]: every value is a+ * parameter, so Compose previews (src/screenshotTest) render the real+ * screen from literal fixtures with no ViewModel or DataStore.+ */+@Composable+internal fun SettingsContent(+ localLocation: String?,+ onBack: () -> Unit,+ onOpenLocalLocation: () -> Unit,+) { AppScaffold( title = stringResource(R.string.settings_title), onNavigateBack = onBack,
news/src/screenshotTest/kotlin/com/vayunmathur/news/ui/MetadataPreviews.kt
diff --git a/news/src/screenshotTest/kotlin/com/vayunmathur/news/ui/MetadataPreviews.kt b/news/src/screenshotTest/kotlin/com/vayunmathur/news/ui/MetadataPreviews.ktindex 7d3317f646..0e53917ec9 100644--- a/news/src/screenshotTest/kotlin/com/vayunmathur/news/ui/MetadataPreviews.kt+++ b/news/src/screenshotTest/kotlin/com/vayunmathur/news/ui/MetadataPreviews.kt@@ -8,7 +8,6 @@ import com.vayunmathur.news.data.CachedArticle import com.vayunmathur.news.domain.ArticleBlock import com.vayunmathur.news.domain.ExtractedArticle import com.vayunmathur.news.domain.FeedArticle-import com.vayunmathur.news.domain.FeedSort import com.vayunmathur.news.domain.Story /** Phone-shaped, roughly 1080x2340 at xxhdpi — comfortably above the F-Droid minimum. */@@ -25,6 +24,11 @@ private const val EXPANDED = "spec:width=1280dp,height=800dp,dpi=240" * `metadata_data/photos/news/<bucket>/` dirs (`phone/` and `large-tablet/`), where the * release build picks them up. News has no wear companion, so there is no `wear/` bucket. *+ * Route coverage: every `Route` leaf has a capture here, named+ * `<number>-<route-key>` (`6-story`, `7-settings`, `8-local-location`, …);+ * `RouteScreenshotCoverageTest` reflects over `Route` and fails when one is+ * missing. See `docs/screenshot-coverage.md`.+ * * The rules that keep these honest (same as every other module's MetadataPreviews): * - Order comes from the function names (`Preview1…`, `Preview2…`), per bucket. * - Each preview needs `@PreviewTest` as well as `@Preview`, and a `group` naming the@@ -71,6 +75,27 @@ class MetadataPreviews { fun Preview5ReaderExpanded() { PreviewTheme { ReaderFixture() } }++ @PreviewTest+ @Preview(name = "6-story", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview6Story() {+ PreviewTheme { StoryFixture() }+ }++ @PreviewTest+ @Preview(name = "7-settings", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview7Settings() {+ PreviewTheme { SettingsFixture() }+ }++ @PreviewTest+ @Preview(name = "8-local-location", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview8LocalLocation() {+ PreviewTheme { LocalLocationFixture() }+ } } @Composable@@ -112,12 +137,10 @@ private fun FeedFixture() { isRefreshing = false, refreshFailed = false, categoryFilter = null,- feedSort = FeedSort.TOP, localLocation = null, searchQuery = "", onSearchQueryChange = {}, onRefresh = {},- onFeedSortChange = {}, onCategoryFilterChange = {}, onToggleBookmark = {}, onOpenSaved = {},@@ -151,6 +174,42 @@ private fun ReaderFixture() { ) } +@Composable+private fun StoryFixture() {+ val first = fixtureStories.first()+ val second = fixtureStory("s1b", "npr", "Riverfront plan wins final approval in late vote", first.oneLiner)+ val story = Story(+ id = first.id,+ representative = first.representative,+ articles = listOf(first.representative, second.representative),+ )+ StoryContent(+ story = story,+ cachedByUrl = fixtureCached,+ onOpenArticle = {},+ onToggleBookmark = {},+ onBack = {},+ )+}++@Composable+private fun SettingsFixture() {+ SettingsContent(+ localLocation = "Leeds, United Kingdom",+ onBack = {},+ onOpenLocalLocation = {},+ )+}++@Composable+private fun LocalLocationFixture() {+ LocalLocationContent(+ current = "Leeds, United Kingdom",+ onSelect = {},+ onBack = {},+ )+}+ @Composable private fun SavedFixture() { SavedContent(