weather: use full width in landscape, don't squeeze to a third (#945)
- Commit
581b1a97d3544d19f8e080257a2e134d9d43762c- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-28 06:28 UTC (8 days ago)
- Parents
6fa2c66
In released v2.6.11b both Home and WeatherMap routes carried ListPage metadata, so on >=600dp windows the shared ListDetailSceneStrategy put the whole forecast into its ~1/3-width list pane beside an empty detail pane — the narrow left column in the report (landscape Pixel is expanded width). That metadata is already gone in the current tree; the remaining defects fixed here: HomeScreen sized itself from the activity window class rather than its available width, the expanded locations panel was an uncapped fillMaxWidth(0.35f), and medium/expanded forecasts were one phone column stretched full-width. New pure domain/HomeLayout (breakpoints 600/840dp, forecast column counts, locations panel 30% clamped 280-360dp); HomeScreen lays out from BoxWithConstraints available width (expanded: bounded panel + weight(1f) forecast, always >=~60%); medium width renders the forecast wide (summary/hourly/daily + metrics in a second column). Portrait compact path is unchanged. Tests: HomeLayoutTest 5/5 (incl. a regression asserting the forecast beside the panel is never the ~1/3 column at 840-1920dp), ComposeScreensTest 12/12, :weather:testDevUnitTest green; :weather:metadata regenerated (large-tablet capture shows bounded panel + two-column forecast). Lint has only the 3 pre-existing RouteScreenshotCoverage errors on untouched Route.kt.
Diff
metadata_data/photos/weather/large-tablet/1.png
diff --git a/metadata_data/photos/weather/large-tablet/1.png b/metadata_data/photos/weather/large-tablet/1.pngindex 7d3ac66604..205a98ab54 100644Binary files a/metadata_data/photos/weather/large-tablet/1.png and b/metadata_data/photos/weather/large-tablet/1.png differ
weather/AGENTS.md
diff --git a/weather/AGENTS.md b/weather/AGENTS.mdindex 109aa1b58e..aa85f36070 100644--- a/weather/AGENTS.md+++ b/weather/AGENTS.md@@ -37,6 +37,7 @@ _Install: ./install weather (dev by default)._ - com/vayunmathur/weather/data/WeatherRefreshWorker.kt - com/vayunmathur/weather/data/SavedLocation.kt ### domain/ + domain/map/ — pure formatting + map metadata (no Android)+- com/vayunmathur/weather/domain/HomeLayout.kt — pure home width breakpoints (600/840dp): compact = modal drawer + single column, medium = full-width two-column forecast, expanded = bounded 280–360dp locations panel + two-column forecast; the home screen sizes itself from its available width, not the activity window - com/vayunmathur/weather/domain/WmoCode.kt - com/vayunmathur/weather/domain/UnitFormat.kt - com/vayunmathur/weather/domain/DateTimeFormat.kt
weather/src/main/java/com/vayunmathur/weather/domain/HomeLayout.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/domain/HomeLayout.kt b/weather/src/main/java/com/vayunmathur/weather/domain/HomeLayout.ktnew file mode 100644index 0000000000..00cd74395e--- /dev/null+++ b/weather/src/main/java/com/vayunmathur/weather/domain/HomeLayout.kt@@ -0,0 +1,53 @@+package com.vayunmathur.weather.domain++/**+ * How the home forecast lays out for the width it is actually given.+ *+ * Pure width math (no Android/Compose) so the breakpoints are unit-testable+ * and so [com.vayunmathur.weather.ui.HomeScreen] can key off its available+ * constraints rather than the activity window: a screen hosted in a narrow+ * pane must lay out for that pane, never for the wider window around it.+ * The thresholds mirror the shared window-size breakpoints (600dp medium,+ * 840dp expanded).+ */+enum class HomeLayout {+ /** Portrait phones: modal locations drawer, single forecast column. */+ Compact,++ /** Landscape phones and small tablets: full-width forecast, two card columns. */+ Medium,++ /** Large tablets/desktop: permanent locations panel beside a two-column forecast. */+ Expanded,+}++/** The [HomeLayout] for an available width of [widthDp] dp. */+fun homeLayoutForWidthDp(widthDp: Int): HomeLayout = when {+ widthDp >= 840 -> HomeLayout.Expanded+ widthDp >= 600 -> HomeLayout.Medium+ else -> HomeLayout.Compact+}++/** Only expanded windows pin the locations list beside the forecast. */+fun homeUsesPermanentLocationsPanel(layout: HomeLayout): Boolean =+ layout == HomeLayout.Expanded++/** Card columns in the forecast body: one on compact, two on anything wider. */+fun forecastColumnCount(layout: HomeLayout): Int =+ if (layout == HomeLayout.Compact) 1 else 2++/**+ * Width of the permanent locations panel on expanded windows: 30% of the+ * window, clamped to 280–360dp so the panel stays a list (not a second+ * forecast) and the forecast always keeps at least ~60% of the width.+ */+fun locationsPanelWidthDp(windowWidthDp: Int): Int =+ (windowWidthDp * 30 / 100).coerceIn(280, 360)++/** Width left for the forecast beside the panel (full width without a panel). */+fun forecastWidthDp(windowWidthDp: Int, layout: HomeLayout): Int =+ if (homeUsesPermanentLocationsPanel(layout)) {+ windowWidthDp - locationsPanelWidthDp(windowWidthDp)+ } else {+ windowWidthDp+ }
weather/src/main/java/com/vayunmathur/weather/ui/ForecastColumn.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/ForecastColumn.kt b/weather/src/main/java/com/vayunmathur/weather/ui/ForecastColumn.ktindex e3f49ede5c..da7d64b4f8 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/ForecastColumn.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/ForecastColumn.kt@@ -55,6 +55,8 @@ internal fun ForecastColumn( precipitationNowcast: String?, nowEpochSec: Long, onOpenMap: (WeatherMetric, String?) -> Unit,+ /** Medium/expanded widths: show the cards in two columns instead of one stretched column. */+ wide: Boolean = false, ) { var graphMetric by remember { mutableStateOf<WeatherMetric?>(null) } @@ -115,7 +117,77 @@ internal fun ForecastColumn( tempUnit = units.temperature, ) }- Column(+ // Wide windows show more at once: the forecast strips in one+ // column, the metric blocks in another, instead of one phone+ // column stretched across the whole width. Compact keeps the+ // single column below (same code path as before).+ if (wide && current != null && resolved != null) {+ androidx.compose.foundation.layout.Row(+ modifier = Modifier.padding(+ start = 16.dp,+ end = 16.dp,+ top = 24.dp,+ bottom = paddingValues.calculateBottomPadding(),+ ),+ horizontalArrangement = Arrangement.spacedBy(14.dp),+ ) {+ Column(+ modifier = Modifier.weight(1f),+ verticalArrangement = Arrangement.spacedBy(14.dp),+ ) {+ if (selected == null) {+ SummaryCard(forecast = forecast, tempUnit = units.temperature)+ }+ if (forecast.hourly != null) {+ HourlyCard(+ hourly = forecast.hourly,+ tempUnit = units.temperature,+ utcOffsetSeconds = forecast.utcOffsetSeconds,+ use24Hour = units.use24Hour,+ selectedIsoTime = (selected as? SelectedDateOrTime.Time)?.isoTime,+ onHourSelected = { actions.toggleTime(it) },+ scrollToIsoDate = (selected as? SelectedDateOrTime.Day)?.isoDate,+ nowIsoHour = forecast.current?.time?.take(13)?.let { "$it:00" },+ nowEpochSec = nowEpochSec,+ )+ }+ if (daily != null) {+ DailyCard(+ daily = daily,+ tempUnit = units.temperature,+ selectedIsoDate = (selected as? SelectedDateOrTime.Day)?.isoDate,+ onDaySelected = { actions.toggleDay(it) },+ todayIsoDate = forecast.current?.time?.substringBefore('T'),+ )+ }+ }+ Column(+ modifier = Modifier.weight(1f),+ verticalArrangement = Arrangement.spacedBy(14.dp),+ ) {+ WeatherBlocks(+ current = resolved.blockCurrent,+ uvIndex = resolved.uvIndexMax,+ air = state.airQuality,+ sunriseEpochSec = resolved.sunriseIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) },+ sunsetEpochSec = resolved.sunsetIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) },+ precipitationMm = resolved.precipitationSum,+ precipitationNowcast = precipitationNowcast,+ daylightDurationSec = resolved.daylightDurationSec,+ moonPhase = resolved.moonPhase,+ moonriseEpochSec = resolved.moonriseIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) },+ moonsetEpochSec = resolved.moonsetIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) },+ onMetricSelected = { graphMetric = it },+ tempUnit = units.temperature,+ windUnit = units.wind,+ pressureUnit = units.pressure,+ use24Hour = units.use24Hour,+ nowEpochSec = nowEpochSec,+ utcOffsetSeconds = forecast.utcOffsetSeconds,+ )+ }+ }+ } else Column( // Include the navigation-bar inset so the last cards (Air quality / // Pollen) clear the system nav bar and can scroll fully into view. modifier = Modifier.padding(
weather/src/main/java/com/vayunmathur/weather/ui/HomePage.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/HomePage.kt b/weather/src/main/java/com/vayunmathur/weather/ui/HomePage.ktindex 8547b340e5..5cc3d30a3c 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/HomePage.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/HomePage.kt@@ -25,7 +25,6 @@ import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.ModalDrawerSheet import com.vayunmathur.library.ui.ModalNavigationDrawer import com.vayunmathur.library.ui.OutlinedButton-import com.vayunmathur.library.ui.Scaffold import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.rememberDrawerState import com.vayunmathur.library.ui.isExpandedWidth@@ -87,9 +86,7 @@ fun HomePage( // Room hasn't answered yet. Hold a plain surface rather than falling // through to EmptyHome, which would flash the location chooser on // every cold start before the saved rows arrive.- // RAW SCAFFOLD EXCEPTION: cold-start placeholder — a bare, bar-less,- // content-less surface. No shared scaffold applies (they all draw chrome).- Scaffold(containerColor = MaterialTheme.colorScheme.surfaceContainerHigh) {}+ AppScaffold(topBar = {}, containerColor = MaterialTheme.colorScheme.surfaceContainerHigh) {} return } @@ -198,12 +195,11 @@ internal fun ForecastScaffold( nowEpochSec: Long, onOpenMap: (WeatherMetric, String?) -> Unit, modifier: Modifier = Modifier,+ /** Two card columns instead of one stretched column (medium/expanded widths). */+ wide: Boolean = false, ) {- Scaffold(- // RAW SCAFFOLD EXCEPTION: bespoke full-bleed home. The forecast- // scrolls under a floating in-content MainSearchBar (there is no top- // app bar), inside a ModalNavigationDrawer, and the- // body consumes the scaffold insets itself. No shared scaffold fits.+ AppScaffold(+ topBar = {}, modifier = modifier, containerColor = MaterialTheme.colorScheme.surfaceContainerHigh, ) { paddingValues ->@@ -216,6 +212,7 @@ internal fun ForecastScaffold( precipitationNowcast = precipitationNowcast, nowEpochSec = nowEpochSec, onOpenMap = onOpenMap,+ wide = wide, ) } }
weather/src/main/java/com/vayunmathur/weather/ui/HomeScreen.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/HomeScreen.kt b/weather/src/main/java/com/vayunmathur/weather/ui/HomeScreen.ktindex c05bb9ed63..7bb6251552 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/HomeScreen.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/HomeScreen.kt@@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import com.vayunmathur.library.ui.AppScaffold@@ -64,6 +65,10 @@ import com.vayunmathur.weather.domain.parseLocalIsoToEpochSec import com.vayunmathur.weather.domain.resolveConditions import com.vayunmathur.weather.platform.WeatherActions import com.vayunmathur.weather.platform.WeatherViewModel+import com.vayunmathur.weather.domain.forecastColumnCount+import com.vayunmathur.weather.domain.homeLayoutForWidthDp+import com.vayunmathur.weather.domain.homeUsesPermanentLocationsPanel+import com.vayunmathur.weather.domain.locationsPanelWidthDp import com.vayunmathur.weather.platform.precipitationNowcast import com.vayunmathur.weather.platform.rememberDisplayUnits import kotlinx.coroutines.delay@@ -95,17 +100,56 @@ fun HomeScreen( val scope = rememberCoroutineScope() BackHandler(enabled = drawerState.isOpen) { scope.launch { drawerState.close() } } - // Expanded windows (large tablets, desktop) pin the locations list as a- // permanent side panel next to the forecast instead of hiding it in a modal- // drawer — there is room for both, and picking another location without- // losing the current forecast is the point of the wide layout. The panel- // fills a fraction of the window rather than a fixed dp so it scales from- // an 840dp tablet to a full desktop window.- if (isExpandedWidth()) {- Row(modifier = Modifier.fillMaxSize()) {- Box(modifier = Modifier.fillMaxWidth(0.35f).fillMaxHeight()) {- drawerContent()+ // Lay out for the width actually available here, not the activity+ // window: hosted in a pane, this screen must size itself to the pane.+ // (The released squeeze came from the opposite assumption upstream —+ // the navigation host confined this screen to a list pane while it+ // still laid out as if it owned the whole window.)+ androidx.compose.foundation.layout.BoxWithConstraints(modifier = Modifier.fillMaxSize()) {+ val availableWidthDp = maxWidth.value.toInt()+ val layout = homeLayoutForWidthDp(availableWidthDp)+ val wide = forecastColumnCount(layout) > 1++ // Expanded windows (large tablets, desktop) pin the locations list+ // as a permanent side panel next to the forecast instead of hiding+ // it in a modal drawer — there is room for both, and picking another+ // location without losing the current forecast is the point of the+ // wide layout. The panel is a bounded list width (280–360dp), so+ // the forecast keeps the majority of the window at any size.+ if (homeUsesPermanentLocationsPanel(layout)) {+ Row(modifier = Modifier.fillMaxSize()) {+ Box(+ modifier = Modifier+ .width(locationsPanelWidthDp(availableWidthDp).dp)+ .fillMaxHeight(),+ ) {+ drawerContent()+ }+ ForecastScaffold(+ state = state,+ units = units,+ actions = actions,+ drawerState = drawerState,+ precipitationNowcast = precipitationNowcast,+ nowEpochSec = nowEpochSec,+ onOpenMap = onOpenMap,+ wide = wide,+ modifier = Modifier.weight(1f).fillMaxHeight(),+ ) }+ return@BoxWithConstraints+ }++ ModalNavigationDrawer(+ drawerState = drawerState,+ drawerContent = {+ ModalDrawerSheet(+ drawerContainerColor = MaterialTheme.colorScheme.surfaceContainer,+ ) {+ drawerContent()+ }+ },+ ) { ForecastScaffold( state = state, units = units,@@ -114,30 +158,8 @@ fun HomeScreen( precipitationNowcast = precipitationNowcast, nowEpochSec = nowEpochSec, onOpenMap = onOpenMap,- modifier = Modifier.weight(1f).fillMaxHeight(),+ wide = wide, ) }- return- }-- ModalNavigationDrawer(- drawerState = drawerState,- drawerContent = {- ModalDrawerSheet(- drawerContainerColor = MaterialTheme.colorScheme.surfaceContainer,- ) {- drawerContent()- }- },- ) {- ForecastScaffold(- state = state,- units = units,- actions = actions,- drawerState = drawerState,- precipitationNowcast = precipitationNowcast,- nowEpochSec = nowEpochSec,- onOpenMap = onOpenMap,- ) } }
weather/src/test/java/com/vayunmathur/weather/domain/HomeLayoutTest.kt
diff --git a/weather/src/test/java/com/vayunmathur/weather/domain/HomeLayoutTest.kt b/weather/src/test/java/com/vayunmathur/weather/domain/HomeLayoutTest.ktnew file mode 100644index 0000000000..59bad8d556--- /dev/null+++ b/weather/src/test/java/com/vayunmathur/weather/domain/HomeLayoutTest.kt@@ -0,0 +1,53 @@+package com.vayunmathur.weather.domain++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue++class HomeLayoutTest {++ @Test fun breakpointsMatchWindowSizeClasses() {+ assertEquals(HomeLayout.Compact, homeLayoutForWidthDp(0))+ assertEquals(HomeLayout.Compact, homeLayoutForWidthDp(411))+ assertEquals(HomeLayout.Compact, homeLayoutForWidthDp(599))+ assertEquals(HomeLayout.Medium, homeLayoutForWidthDp(600))+ assertEquals(HomeLayout.Medium, homeLayoutForWidthDp(839))+ assertEquals(HomeLayout.Expanded, homeLayoutForWidthDp(840))+ assertEquals(HomeLayout.Expanded, homeLayoutForWidthDp(1280))+ }++ @Test fun onlyExpandedPinsLocationsPanel() {+ assertFalse(homeUsesPermanentLocationsPanel(HomeLayout.Compact))+ assertFalse(homeUsesPermanentLocationsPanel(HomeLayout.Medium))+ assertTrue(homeUsesPermanentLocationsPanel(HomeLayout.Expanded))+ }++ @Test fun wideLayoutsShowTwoForecastColumns() {+ assertEquals(1, forecastColumnCount(HomeLayout.Compact))+ assertEquals(2, forecastColumnCount(HomeLayout.Medium))+ assertEquals(2, forecastColumnCount(HomeLayout.Expanded))+ }++ @Test fun panelIsBoundedAndForecastKeepsMajority() {+ // Panel clamps to 280-360dp however wide the window gets.+ assertEquals(280, locationsPanelWidthDp(840))+ assertEquals(300, locationsPanelWidthDp(1000))+ assertEquals(360, locationsPanelWidthDp(1280))+ assertEquals(360, locationsPanelWidthDp(2560))+ // Regression for the landscape squeeze: the forecast beside the+ // panel is never the narrow (~1/3) column — it keeps >= 60%.+ for (width in listOf(840, 985, 1280, 1920)) {+ val layout = homeLayoutForWidthDp(width)+ val forecast = forecastWidthDp(width, layout)+ assertTrue(forecast * 5 >= width * 3, "forecast $forecast of $width")+ assertEquals(width - locationsPanelWidthDp(width), forecast)+ }+ }++ @Test fun nonExpandedForecastUsesFullWidth() {+ assertEquals(411, forecastWidthDp(411, HomeLayout.Compact))+ // A landscape phone (medium) gets the whole width, not a pane of it.+ assertEquals(800, forecastWidthDp(800, HomeLayout.Medium))+ }+}
weather/src/test/java/com/vayunmathur/weather/ui/ComposeScreensTest.kt
diff --git a/weather/src/test/java/com/vayunmathur/weather/ui/ComposeScreensTest.kt b/weather/src/test/java/com/vayunmathur/weather/ui/ComposeScreensTest.ktindex 129a33bb53..b45cf4646c 100644--- a/weather/src/test/java/com/vayunmathur/weather/ui/ComposeScreensTest.kt+++ b/weather/src/test/java/com/vayunmathur/weather/ui/ComposeScreensTest.kt@@ -144,6 +144,24 @@ class ComposeScreensTest { rule.waitForIdle() } + @Test fun forecastColumnWide() {+ rule.setContent {+ ForecastColumn(+ state = LocationUiState(location = loc(), forecast = forecast()),+ units = DisplayUnits(),+ actions = WeatherActions.Noop,+ drawerState = rememberDrawerState(DrawerValue.Closed),+ paddingValues = PaddingValues(0.dp),+ precipitationNowcast = null,+ nowEpochSec = 1760000000L,+ onOpenMap = { _, _ -> },+ wide = true,+ )+ }+ rule.onNodeWithText("Berlin", substring = true).assertIsDisplayed()+ rule.onAllNodesWithText("25°")[0].assertIsDisplayed()+ }+ @Test fun homeScreenCompact() { rule.setContent { HomeScreen(