Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / weather / AGENTS.md

AGENTS.md13.6 KiBRenderedCodeRaw
1# AGENTS.md — weather/ (':weather')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `weather/` + allowed shared modules. Do not root-scan.
4
5_Install: ./install weather (dev by default)._
6- Gradle: :weather / dir: weather/
7- Package roots present: ui, data, domain, platform, network, intents, widget, service, sync
8- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt
9- Deps: :library:network, :library:widgets, :library:map, :library:room, :library:wearlink, :library:log, Wear Compose (material + foundation)
10- Metadata: metadata_data/weather.md (present)
11- Rust: yes / screenshotTest: yes
12
13## Overview
14**Purpose:** Material You weather — Open-Meteo hourly/daily forecasts, air-quality/UV/pollen/humidity/pressure/wind/visibility blocks, map layers, Glance widgets, assistant intents.
15**Key features:**
16- Saved locations + device location (reverse-geocoded) with Room-cached forecasts refreshed by `WeatherRefreshWorker`
17- Metric blocks + graphs per location; Open-Meteo vector map tiles via the Rust core (`domain/map/OmTilesNative`)
18- Two Glance widgets (standard + blob); `GetWeather`/`GetWeatherByName` current-conditions and `GetForecast` capped multi-day/hourly assistant intents
19**Architecture / data-flow:** `ui/` home/map/locations → `platform/WeatherViewModel` (+ `WeatherUiContract`) → `data/WeatherRepository` over Room + `network/WeatherApi`; all weather reads come from the static R2 packs (`network/WxStatic`: `run.wxp`/`hist/<day>.wxp`/`geo.wxp` + `latest.json` manifest on `static.maproj.org/wx/v1/`), computed on device by `domain/wx/`; the map samples the same run tiles (no `.om`/`data_spatial` read); place search is the on-device `places.db.br` catalogue; `domain/` holds pure unit/metric/WMO formatting + map metadata; widgets read the same repository snapshot.
20**Entry points + reading order:** `Route` → `MainActivity.kt` → `Navigation.kt` → `ui/HomePage.kt` → `platform/WeatherViewModel.kt` → `data/WeatherRepository.kt` → `network/WeatherApi.kt`.
21
22## One APK, two form factors (phone + watch)
23This module is the single Weather APK for phones and watches: same
24`applicationId = "com.vayunmathur.weather"` and signing on both, as the
25WearLink handshake requires. The manifest deliberately declares no
26`android.hardware.type.watch` feature (required=true would block
27phones; required=false is disallowed for this feature), plus
28touchscreen not-required and
29`com.google.android.wearable.standalone=false`; distribution is
30sideload/F-Droid, not Play's watch channel, so the APK installs on
31phones and watches alike. `platform/FormFactor.kt`
32reads `PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the
33sole launcher entry) forwards watches to `ui/WearMainActivity` before
34any phone state loads; phones get the tab UI. The Glance widget
35receivers are a phone-only surface and early-return on a watch.
36
37## Wear sync (Watch conduit client)
38**Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.weather.WearWeatherProtocol`; the golden-JSON tests in this module pin the shared code's wire format.
39- Snapshot + watch-state sync: conduit data items (`/weather/snapshot` phone -> watch, `/weather/watch-state` watch -> phone)
40- Sync request: conduit message (`/weather/request-sync`), watch -> phone only
41- **Transport: Watch conduit client** — phone side `sync/WearWeatherSync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `weather`); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so neither entry activity prompts for Bluetooth. With the Watch app absent the node reports `NotInstalled`/`Unavailable` and the sync stays idle; snapshots republish on conduit `Connected` and on forecast refresh. The watch renders the locally stored snapshot offline and holds no network path of its own. Protocol values stay Celsius / km/h; rendering converts to the watch's system regional preferences (`platform/WearSystemUnits`, formatting in `domain/WearWeatherFormatting`).
42- **Push triggers:** the publish also runs on the phone Watch app's scheduled sync-trigger intent (`sync/ConduitSyncTriggerReceiver`, exported only under the `CONDUIT` signature permission, invoking `WearWeatherSync.syncNow()` — no UI, no prompt). Data arriving while the receiving process is dead lands in the conduit host's persistent store and replays on registration.
43- **Open on phone:** the watch request (`/<appId>/open-on-phone` conduit message; camera: `OPEN_ON_PHONE` op) is handled live by the sync message listener when this app is registered, and otherwise the phone conduit host broadcasts `OpenOnPhoneContract.ACTION` (package-addressed, `CONDUIT` signature permission) to `sync/OpenOnPhoneReceiver`, which launches the main activity as a new task — no phone process needs to be running first.
44
45## Watch experience (in this module)
46- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over locations (`ui/WearLocationsScreen`) and one location's current/hourly/daily detail (`ui/WearLocationScreen`); snapshots arrive automatically over the conduit, with no manual sync action.
47- Watch state persists in `data/WearWeatherStore` (`wear-weather-snapshot.json`).
48- Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:weather:metadata` into `metadata_data/photos/weather/wear/`; phone shots use the `phone` bucket.
49**Gotchas:**
50- Unit system follows the device locale (`platform/SystemUnits`) — format in `domain/`, never in `ui/`
51- Map shading is sampled on device from the R2 run tiles in `network/WxStatic`; the Rust `.om` bridge (`domain/map/OmTilesNative`) is not on the read path
52- Widgets must render from cache alone — never network on the widget path
53- Map `valid_times` are UTC; the graph sheet's selected hour is a naive location-local ISO string and is converted with the forecast's IANA zone (`localIsoToUtcIso`, zone overload) before seeding the map's time index — all epoch↔local-ISO conversion goes through the bundle's `tz` zone so the offset in force at each instant applies across DST transitions; the fetch-time `utcOffsetSeconds` is only the fallback when the zone id does not resolve
54
55## Key files
56### Root — entry + navigation
57- com/vayunmathur/weather/MainActivity.kt
58- com/vayunmathur/weather/Navigation.kt
59- com/vayunmathur/weather/Route.kt (`Home` / `SearchLocation` / `Settings` / `WeatherMap`)
60### data/ — cache + repository + refresh
61- com/vayunmathur/weather/data/WeatherDatabase.kt
62- com/vayunmathur/weather/data/WeatherRepository.kt
63- com/vayunmathur/weather/data/WeatherDao.kt
64- com/vayunmathur/weather/data/WeatherCache.kt
65- com/vayunmathur/weather/data/WeatherCacheStore.kt
66- com/vayunmathur/weather/data/WeatherRefreshWorker.kt
67- com/vayunmathur/weather/data/SavedLocation.kt
68- com/vayunmathur/weather/data/WeatherPrefs.kt — the app's only preferences owner (`weather` DataStore, `SettingsDataStore`): background-refresh setting + backup format for the settings page
69### domain/ + domain/map/ — pure formatting + map metadata (no Android)
70- 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; in expanded the panel is permanent, so the forecast's search bar renders without a drawer toggle
71- com/vayunmathur/weather/domain/WmoCode.kt
72- com/vayunmathur/weather/domain/UnitFormat.kt
73- com/vayunmathur/weather/domain/DateTimeFormat.kt
74- com/vayunmathur/weather/domain/MetricSeries.kt
75- com/vayunmathur/weather/domain/SelectedData.kt
76- com/vayunmathur/weather/domain/SelectedDateOrTime.kt
77- com/vayunmathur/weather/domain/map/OmDomains.kt
78- com/vayunmathur/weather/domain/map/OmMapMetadata.kt
79- com/vayunmathur/weather/domain/map/OmColorize.kt
80- com/vayunmathur/weather/domain/map/OmTilesNative.kt — Rust tile bridge
81### network/ — static R2 reads + DTOs
82- com/vayunmathur/weather/network/WeatherApi.kt — one entry point: bundles/temperatures/time zone via `WxStatic`, place search via the on-device catalogue; the only origin read left is the flagged `WxStatic.NotCovered` (no land tile, e.g. open ocean) bundle fallback to `api.maproj.org/wx/v1`, which stays up for older clients
83- com/vayunmathur/weather/network/WxStatic.kt — R2 pack reader (Range + disk cache, run `next_check` staleness), manifest (`latest.json` `generated_at`), geo-block time zone, search-row temperatures, and map metadata/region sampling from the run tiles (nearest 0.125° cell; the old `.om` path bilinearly interpolated the same grid)
84- com/vayunmathur/weather/network/OpenMeteoDto.kt
85- com/vayunmathur/weather/network/GeocodingDto.kt
86- com/vayunmathur/weather/network/AirQualityDto.kt
87- com/vayunmathur/weather/network/WxBundleDto.kt / WxBundleMapper.kt — bundle format + mapping to the DTOs above
88### platform/ — ViewModel, location, summaries
89- com/vayunmathur/weather/platform/WeatherViewModel.kt
90- com/vayunmathur/weather/platform/WeatherUiContract.kt
91- com/vayunmathur/weather/platform/LocationProvider.kt
92- com/vayunmathur/weather/platform/ReverseGeocode.kt
93- com/vayunmathur/weather/platform/Summary.kt
94- com/vayunmathur/weather/platform/Precipitation.kt
95- com/vayunmathur/weather/platform/SystemUnits.kt
96- com/vayunmathur/weather/platform/AppBackupAgent.kt
97### intents/ — assistant IPC
98- com/vayunmathur/weather/intents/GetWeatherIntent.kt
99- com/vayunmathur/weather/intents/GetWeatherByNameIntent.kt
100- com/vayunmathur/weather/intents/GetForecastIntent.kt — validated `WeatherForecastQuery` contract: named place resolves saved places first, then the catalogue (or an explicit coordinate pair); returns at most 5 days + 12 hourly summary entries, never raw series
101### ui/ + ui/components/ + blocks/ — home, map, locations, metric blocks
102- com/vayunmathur/weather/ui/SettingsPage.kt — settings (library `SettingsPage` DSL only) + stateless `SettingsContent` for previews
103- com/vayunmathur/weather/ui/HomePage.kt
104- com/vayunmathur/weather/ui/ForecastColumn.kt
105- com/vayunmathur/weather/ui/DeviceLocation.kt
106- com/vayunmathur/weather/ui/LocationsScreen.kt
107- com/vayunmathur/weather/ui/SearchLocationPage.kt
108- com/vayunmathur/weather/ui/SearchLocationContent.kt — stateless search-dialog body rendered by SearchLocationPage and screenshot captures
109- com/vayunmathur/weather/ui/WeatherMapPage.kt
110- com/vayunmathur/weather/ui/WeatherMapState.kt
111- com/vayunmathur/weather/ui/WeatherMapComponents.kt
112- com/vayunmathur/weather/ui/components/CurrentWeatherCard.kt
113- com/vayunmathur/weather/ui/components/HourlyCard.kt
114- com/vayunmathur/weather/ui/components/DailyCard.kt
115- com/vayunmathur/weather/ui/components/SummaryCard.kt
116- com/vayunmathur/weather/ui/components/WeatherBlocks.kt
117- com/vayunmathur/weather/ui/components/CardsHeader.kt
118- com/vayunmathur/weather/ui/components/SelectedHeader.kt
119- com/vayunmathur/weather/ui/components/MainSearchBar.kt
120- com/vayunmathur/weather/ui/components/LocationItem.kt
121- com/vayunmathur/weather/ui/components/UseDeviceLocationCard.kt
122- com/vayunmathur/weather/ui/components/MetricGraphSheet.kt
123- com/vayunmathur/weather/ui/components/WeatherIconBox.kt
124- com/vayunmathur/weather/ui/components/blocks/StatBlock.kt
125- com/vayunmathur/weather/ui/components/blocks/BlockHeader.kt
126- com/vayunmathur/weather/ui/components/blocks/AirQualityBlock.kt
127- com/vayunmathur/weather/ui/components/blocks/UvIndexBlock.kt
128- com/vayunmathur/weather/ui/components/blocks/PollenBlock.kt
129- com/vayunmathur/weather/ui/components/blocks/HumidityBlock.kt
130- com/vayunmathur/weather/ui/components/blocks/PressureBlock.kt
131- com/vayunmathur/weather/ui/components/blocks/WindBlock.kt
132- com/vayunmathur/weather/ui/components/blocks/VisibilityBlock.kt
133- com/vayunmathur/weather/ui/components/blocks/PrecipitationBlock.kt
134- com/vayunmathur/weather/ui/components/blocks/CloudCoverBlock.kt
135- com/vayunmathur/weather/ui/components/blocks/SunBlock.kt
136- com/vayunmathur/weather/ui/components/blocks/MoonBlock.kt
137### sync/ — wear companion sync
138- com/vayunmathur/weather/sync/WearWeatherSync.kt — phone conduit client node; snapshot publish from cached forecasts, watch-state receive, request-sync handling
139- com/vayunmathur/weather/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive into the watch store, watch-state publish, sync request
140### Watch experience (ui/ + platform/ + data/ + domain/)
141- com/vayunmathur/weather/ui/WearMainActivity.kt — watch entry (WearShellActivity)
142- com/vayunmathur/weather/ui/WearRoute.kt, WearLocationsScreen.kt, WearLocationScreen.kt
143- com/vayunmathur/weather/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)
144- com/vayunmathur/weather/platform/WearSystemUnits.kt — watch display units from regional preferences
145- com/vayunmathur/weather/data/WearWeatherStore.kt
146- com/vayunmathur/weather/domain/WearWeatherFormatting.kt
147### widget/ — Glance widgets (cache-fed only)
148- com/vayunmathur/weather/widget/WeatherGlanceWidget.kt — includes `WeatherGlanceWidgetReceiver` + `WidgetWeather` model (one widget, one file)
149- com/vayunmathur/weather/widget/WeatherBlobGlanceWidget.kt — includes `WeatherBlobGlanceWidgetReceiver` (one widget, one file)
150
151## Verify (this module only)
152```
153./gradlew :weather:compileDevKotlin
154./gradlew :weather:lint
155./gradlew :weather:checkMetadata
156```
157- Wear Tile: `service/WeatherTileService` (a `MaTileService` in `:library:weartiles`) renders the primary location's current temperature/condition from `WearWeatherStore`; the store requests a tile update on every new snapshot, plus 15-minute freshness. Tap opens `WearMainActivity`.