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

Modern-Apps.git / weather / AGENTS.md

AGENTS.md13.6 KiBRenderedCodeRaw

AGENTS.md — weather/ (':weather')

Scoped supplement. Global rules in root AGENTS.md apply. Stay inside weather/ + allowed shared modules. Do not root-scan.

Install: ./install weather (dev by default).

  • Gradle: :weather / dir: weather/
  • Package roots present: ui, data, domain, platform, network, intents, widget, service, sync
  • Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt
  • Deps: :library:network, :library:widgets, :library:map, :library:room, :library:wearlink, :library:log, Wear Compose (material + foundation)
  • Metadata: metadata_data/weather.md (present)
  • Rust: yes / screenshotTest: yes

Overview

Purpose: Material You weather — Open-Meteo hourly/daily forecasts, air-quality/UV/pollen/humidity/pressure/wind/visibility blocks, map layers, Glance widgets, assistant intents. Key features:

  • Saved locations + device location (reverse-geocoded) with Room-cached forecasts refreshed by WeatherRefreshWorker
  • Metric blocks + graphs per location; Open-Meteo vector map tiles via the Rust core (domain/map/OmTilesNative)
  • Two Glance widgets (standard + blob); GetWeather/GetWeatherByName current-conditions and GetForecast capped multi-day/hourly assistant intents

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. Entry points + reading order: Route → MainActivity.kt → Navigation.kt → ui/HomePage.kt → platform/WeatherViewModel.kt → data/WeatherRepository.kt → network/WeatherApi.kt.

One APK, two form factors (phone + watch)

This module is the single Weather APK for phones and watches: same applicationId = "com.vayunmathur.weather" and signing on both, as the WearLink handshake requires. The manifest deliberately declares no android.hardware.type.watch feature (required=true would block phones; required=false is disallowed for this feature), plus touchscreen not-required and com.google.android.wearable.standalone=false; distribution is sideload/F-Droid, not Play's watch channel, so the APK installs on phones and watches alike. platform/FormFactor.kt reads PackageManager.FEATURE_WATCH at runtime: MainActivity (the sole launcher entry) forwards watches to ui/WearMainActivity before any phone state loads; phones get the tab UI. The Glance widget receivers are a phone-only surface and early-return on a watch.

Wear sync (Watch conduit client)

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.

  • Snapshot + watch-state sync: conduit data items (/weather/snapshot phone -> watch, /weather/watch-state watch -> phone)
  • Sync request: conduit message (/weather/request-sync), watch -> phone only
  • 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).
  • 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.
  • 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.

Watch experience (in this module)

  • 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.
  • Watch state persists in data/WearWeatherStore (wear-weather-snapshot.json).
  • 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.

Gotchas:

  • Unit system follows the device locale (platform/SystemUnits) — format in domain/, never in ui/
  • 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
  • Widgets must render from cache alone — never network on the widget path
  • 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

Key files

Root — entry + navigation

  • com/vayunmathur/weather/MainActivity.kt
  • com/vayunmathur/weather/Navigation.kt
  • com/vayunmathur/weather/Route.kt (Home / SearchLocation / Settings / WeatherMap)

data/ — cache + repository + refresh

  • com/vayunmathur/weather/data/WeatherDatabase.kt
  • com/vayunmathur/weather/data/WeatherRepository.kt
  • com/vayunmathur/weather/data/WeatherDao.kt
  • com/vayunmathur/weather/data/WeatherCache.kt
  • com/vayunmathur/weather/data/WeatherCacheStore.kt
  • com/vayunmathur/weather/data/WeatherRefreshWorker.kt
  • com/vayunmathur/weather/data/SavedLocation.kt
  • com/vayunmathur/weather/data/WeatherPrefs.kt — the app's only preferences owner (weather DataStore, SettingsDataStore): background-refresh setting + backup format for the settings page

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; in expanded the panel is permanent, so the forecast's search bar renders without a drawer toggle
  • com/vayunmathur/weather/domain/WmoCode.kt
  • com/vayunmathur/weather/domain/UnitFormat.kt
  • com/vayunmathur/weather/domain/DateTimeFormat.kt
  • com/vayunmathur/weather/domain/MetricSeries.kt
  • com/vayunmathur/weather/domain/SelectedData.kt
  • com/vayunmathur/weather/domain/SelectedDateOrTime.kt
  • com/vayunmathur/weather/domain/map/OmDomains.kt
  • com/vayunmathur/weather/domain/map/OmMapMetadata.kt
  • com/vayunmathur/weather/domain/map/OmColorize.kt
  • com/vayunmathur/weather/domain/map/OmTilesNative.kt — Rust tile bridge

network/ — static R2 reads + DTOs

  • 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
  • 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)
  • com/vayunmathur/weather/network/OpenMeteoDto.kt
  • com/vayunmathur/weather/network/GeocodingDto.kt
  • com/vayunmathur/weather/network/AirQualityDto.kt
  • com/vayunmathur/weather/network/WxBundleDto.kt / WxBundleMapper.kt — bundle format + mapping to the DTOs above

platform/ — ViewModel, location, summaries

  • com/vayunmathur/weather/platform/WeatherViewModel.kt
  • com/vayunmathur/weather/platform/WeatherUiContract.kt
  • com/vayunmathur/weather/platform/LocationProvider.kt
  • com/vayunmathur/weather/platform/ReverseGeocode.kt
  • com/vayunmathur/weather/platform/Summary.kt
  • com/vayunmathur/weather/platform/Precipitation.kt
  • com/vayunmathur/weather/platform/SystemUnits.kt
  • com/vayunmathur/weather/platform/AppBackupAgent.kt

intents/ — assistant IPC

  • com/vayunmathur/weather/intents/GetWeatherIntent.kt
  • com/vayunmathur/weather/intents/GetWeatherByNameIntent.kt
  • 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

ui/ + ui/components/ + blocks/ — home, map, locations, metric blocks

  • com/vayunmathur/weather/ui/SettingsPage.kt — settings (library SettingsPage DSL only) + stateless SettingsContent for previews
  • com/vayunmathur/weather/ui/HomePage.kt
  • com/vayunmathur/weather/ui/ForecastColumn.kt
  • com/vayunmathur/weather/ui/DeviceLocation.kt
  • com/vayunmathur/weather/ui/LocationsScreen.kt
  • com/vayunmathur/weather/ui/SearchLocationPage.kt
  • com/vayunmathur/weather/ui/SearchLocationContent.kt — stateless search-dialog body rendered by SearchLocationPage and screenshot captures
  • com/vayunmathur/weather/ui/WeatherMapPage.kt
  • com/vayunmathur/weather/ui/WeatherMapState.kt
  • com/vayunmathur/weather/ui/WeatherMapComponents.kt
  • com/vayunmathur/weather/ui/components/CurrentWeatherCard.kt
  • com/vayunmathur/weather/ui/components/HourlyCard.kt
  • com/vayunmathur/weather/ui/components/DailyCard.kt
  • com/vayunmathur/weather/ui/components/SummaryCard.kt
  • com/vayunmathur/weather/ui/components/WeatherBlocks.kt
  • com/vayunmathur/weather/ui/components/CardsHeader.kt
  • com/vayunmathur/weather/ui/components/SelectedHeader.kt
  • com/vayunmathur/weather/ui/components/MainSearchBar.kt
  • com/vayunmathur/weather/ui/components/LocationItem.kt
  • com/vayunmathur/weather/ui/components/UseDeviceLocationCard.kt
  • com/vayunmathur/weather/ui/components/MetricGraphSheet.kt
  • com/vayunmathur/weather/ui/components/WeatherIconBox.kt
  • com/vayunmathur/weather/ui/components/blocks/StatBlock.kt
  • com/vayunmathur/weather/ui/components/blocks/BlockHeader.kt
  • com/vayunmathur/weather/ui/components/blocks/AirQualityBlock.kt
  • com/vayunmathur/weather/ui/components/blocks/UvIndexBlock.kt
  • com/vayunmathur/weather/ui/components/blocks/PollenBlock.kt
  • com/vayunmathur/weather/ui/components/blocks/HumidityBlock.kt
  • com/vayunmathur/weather/ui/components/blocks/PressureBlock.kt
  • com/vayunmathur/weather/ui/components/blocks/WindBlock.kt
  • com/vayunmathur/weather/ui/components/blocks/VisibilityBlock.kt
  • com/vayunmathur/weather/ui/components/blocks/PrecipitationBlock.kt
  • com/vayunmathur/weather/ui/components/blocks/CloudCoverBlock.kt
  • com/vayunmathur/weather/ui/components/blocks/SunBlock.kt
  • com/vayunmathur/weather/ui/components/blocks/MoonBlock.kt

sync/ — wear companion sync

  • com/vayunmathur/weather/sync/WearWeatherSync.kt — phone conduit client node; snapshot publish from cached forecasts, watch-state receive, request-sync handling
  • com/vayunmathur/weather/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive into the watch store, watch-state publish, sync request

Watch experience (ui/ + platform/ + data/ + domain/)

  • com/vayunmathur/weather/ui/WearMainActivity.kt — watch entry (WearShellActivity)
  • com/vayunmathur/weather/ui/WearRoute.kt, WearLocationsScreen.kt, WearLocationScreen.kt
  • com/vayunmathur/weather/platform/FormFactor.kt — watch detection (FEATURE_WATCH)
  • com/vayunmathur/weather/platform/WearSystemUnits.kt — watch display units from regional preferences
  • com/vayunmathur/weather/data/WearWeatherStore.kt
  • com/vayunmathur/weather/domain/WearWeatherFormatting.kt

widget/ — Glance widgets (cache-fed only)

  • com/vayunmathur/weather/widget/WeatherGlanceWidget.kt — includes WeatherGlanceWidgetReceiver + WidgetWeather model (one widget, one file)
  • com/vayunmathur/weather/widget/WeatherBlobGlanceWidget.kt — includes WeatherBlobGlanceWidgetReceiver (one widget, one file)

Verify (this module only)

./gradlew :weather:compileDevKotlin
./gradlew :weather:lint
./gradlew :weather:checkMetadata
  • 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.