Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
963a5e0e86 | ||
|
|
a1a56d9b50 | ||
|
|
a134b8f46f | ||
|
|
79e6031823 | ||
|
|
0c42d8570b | ||
|
|
8eb9544189 | ||
|
|
27bf4e88f4 | ||
|
|
c61b03b48f | ||
|
|
054c76d093 | ||
|
|
c446798403 | ||
|
|
c1c76252f1 | ||
|
|
c0bf0f6042 | ||
|
|
1d8c3f8f5f | ||
|
|
c5c1483544 | ||
|
|
a9f2f69398 | ||
|
|
b359249c59 |
No files matched your search
@@ -0,0 +1,3 @@
|
||||
.giteatoken
|
||||
*.jks
|
||||
keystore.properties
|
||||
@@ -0,0 +1,114 @@
|
||||
# NoGooleApps
|
||||
|
||||
**Everyday Android apps without Google.** Privacy-friendly rebuilds of the standard Google apps, for people who want the polish of the originals without Play Services, tracking or an account. Made with GrapheneOS, CalyxOS, /e/OS and LineageOS in mind, and works the same on any stock Android phone.
|
||||
|
||||
> Not affiliated with, endorsed by or connected to Google. These are independent, clean-room rebuilds: no Google code, assets, icons, fonts or text are used.
|
||||
|
||||
## Apps
|
||||
|
||||
| App | Replaces | Status | Install |
|
||||
| --- | --- | --- | --- |
|
||||
| **Wetter** (`wetter/`) | Google Weather / Pixel Weather | alpha, in daily testing | [Obtainium](https://apps.obtainium.imranr.dev/redirect?r=obtainium://app/%7B%22id%22%3A%22app.wetter%22%2C%22url%22%3A%22https%3A%2F%2Fgit.mrblake.cc%2FMrBlake%2FNoGooleApps%22%2C%22author%22%3A%22MrBlake%22%2C%22name%22%3A%22Wetter%22%2C%22overrideSource%22%3A%22Codeberg%22%2C%22preferredApkIndex%22%3A0%2C%22additionalSettings%22%3A%22%7B%5C%22appId%5C%22%3A%5C%22app.wetter%5C%22%2C%5C%22includePrereleases%5C%22%3Atrue%2C%5C%22fallbackToOlderReleases%5C%22%3Atrue%2C%5C%22filterReleaseTitlesByRegEx%5C%22%3A%5C%22%5EWetter%20%5C%22%2C%5C%22apkFilterRegEx%5C%22%3A%5C%22%5Ewetter-.%2A%5C%5C%5C%5C.apk%24%5C%22%2C%5C%22autoApkFilterByArch%5C%22%3Afalse%2C%5C%22verifyLatestTag%5C%22%3Afalse%2C%5C%22releaseTitleAsVersion%5C%22%3Afalse%7D%22%7D) · F-Droid: not yet |
|
||||
|
||||
More apps will follow, one folder each. Each one goes through the same pipeline (see [How these apps are made](#how-these-apps-are-made)).
|
||||
|
||||
### Wetter
|
||||
|
||||
A weather app with the look and feel of Pixel Weather: an animated sky that changes with the conditions, a large hero temperature, hourly and 10-day forecasts, and shaped Material 3 Expressive detail tiles (wind, sun, UV, air quality, visibility, humidity, pressure, pollen).
|
||||
|
||||
- **No Google Play Services.** Location uses the platform's own providers (including the AOSP fused provider), so it works on GrapheneOS without sandboxed Play.
|
||||
- **No account, no tracking, no analytics.** Everything stays on the device. Coordinates are rounded to two decimals (about 1 km) before they reach the weather service.
|
||||
- **Open data sources only:** [Open-Meteo](https://open-meteo.com) for forecasts, 15-minute precipitation, air quality, pollen and place search (CC BY 4.0), and [Nominatim / OpenStreetMap](https://nominatim.org) for naming your current location.
|
||||
- **Features today:** current location and saved cities (swipe between them), search with a full preview before saving, precipitation-in-the-next-hours card, a rule-based daily summary, day detail view, units and theme settings, light and dark mode.
|
||||
- **Five home-screen widgets:** a weather card that grows from 3×2 to 4×5 (hourly panel, then a daily list), a pill, a tilted pill, a one-line bar with a cookie badge, and a classic card. Each one can be customised when added or later: location, system/light/dark, colours (wallpaper Material You, current weather, or five fixed palettes, all WCAG AA checked) and background opacity from 100 % down to fully transparent.
|
||||
- **Coming next:** severe weather alerts (DWD / MeteoAlarm), precipitation radar map, card reordering, notifications.
|
||||
|
||||
Requires Android 10 (API 29) or newer.
|
||||
|
||||
## Install with Obtainium
|
||||
|
||||
[Obtainium](https://github.com/ImranR98/Obtainium) installs and updates apps straight from this repository's releases, with no store in between.
|
||||
|
||||
### Wetter
|
||||
|
||||
[<img src="https://raw.githubusercontent.com/ImranR98/Obtainium/main/assets/graphics/badge_obtainium.png" alt="Get it on Obtainium" height="54">](https://apps.obtainium.imranr.dev/redirect?r=obtainium://app/%7B%22id%22%3A%22app.wetter%22%2C%22url%22%3A%22https%3A%2F%2Fgit.mrblake.cc%2FMrBlake%2FNoGooleApps%22%2C%22author%22%3A%22MrBlake%22%2C%22name%22%3A%22Wetter%22%2C%22overrideSource%22%3A%22Codeberg%22%2C%22preferredApkIndex%22%3A0%2C%22additionalSettings%22%3A%22%7B%5C%22appId%5C%22%3A%5C%22app.wetter%5C%22%2C%5C%22includePrereleases%5C%22%3Atrue%2C%5C%22fallbackToOlderReleases%5C%22%3Atrue%2C%5C%22filterReleaseTitlesByRegEx%5C%22%3A%5C%22%5EWetter%20%5C%22%2C%5C%22apkFilterRegEx%5C%22%3A%5C%22%5Ewetter-.%2A%5C%5C%5C%5C.apk%24%5C%22%2C%5C%22autoApkFilterByArch%5C%22%3Afalse%2C%5C%22verifyLatestTag%5C%22%3Afalse%2C%5C%22releaseTitleAsVersion%5C%22%3Afalse%7D%22%7D)
|
||||
|
||||
Open the button on your phone with Obtainium installed and confirm the import. The link carries the complete configuration, so nothing has to be set by hand:
|
||||
|
||||
| setting | value | why |
|
||||
| --- | --- | --- |
|
||||
| Source | `https://git.mrblake.cc/MrBlake/NoGooleApps` | this repository (note the spelling: **NoGooleApps**) |
|
||||
| Override source | Forgejo (Codeberg) | the repository runs on a self-hosted Gitea, which Obtainium does not detect on its own; Gitea speaks the same release API |
|
||||
| Filter release titles | `^Wetter ` | several apps share this repository; only weather releases count |
|
||||
| Filter APKs | `^wetter-.*\.apk$` | picks the weather APK from the release assets |
|
||||
|
||||
If the button does not open Obtainium (some browsers block links to apps; the page then shows a button to tap, or enable "open links in apps" in the browser), paste this link into the phone's browser address bar, or add the app by hand with the settings above:
|
||||
|
||||
```
|
||||
obtainium://app/%7B%22id%22%3A%22app.wetter%22%2C%22url%22%3A%22https%3A%2F%2Fgit.mrblake.cc%2FMrBlake%2FNoGooleApps%22%2C%22author%22%3A%22MrBlake%22%2C%22name%22%3A%22Wetter%22%2C%22overrideSource%22%3A%22Codeberg%22%2C%22preferredApkIndex%22%3A0%2C%22additionalSettings%22%3A%22%7B%5C%22appId%5C%22%3A%5C%22app.wetter%5C%22%2C%5C%22includePrereleases%5C%22%3Atrue%2C%5C%22fallbackToOlderReleases%5C%22%3Atrue%2C%5C%22filterReleaseTitlesByRegEx%5C%22%3A%5C%22%5EWetter%20%5C%22%2C%5C%22apkFilterRegEx%5C%22%3A%5C%22%5Ewetter-.%2A%5C%5C%5C%5C.apk%24%5C%22%2C%5C%22autoApkFilterByArch%5C%22%3Afalse%2C%5C%22verifyLatestTag%5C%22%3Afalse%2C%5C%22releaseTitleAsVersion%5C%22%3Afalse%7D%22%7D
|
||||
```
|
||||
|
||||
**Releases.** Every app is published as a release titled `<App> <version>` (for example `Wetter 0.1.0`, tag `wetter-v0.1.0`) with one asset named `<app>-<version>.apk`. Obtainium shows *"no matching version"* until the first release of an app exists.
|
||||
|
||||
**F-Droid:** not available yet. The apps contain no proprietary libraries, so an F-Droid build is planned (either the main repository or a self-hosted F-Droid repo).
|
||||
|
||||
## How these apps are made
|
||||
|
||||
### The Replica pipeline
|
||||
|
||||
Every app is rebuilt with **[Replica](https://github.com/Jakeschincariol/replica-skill)**, an open set of eleven Claude Code skills by Jake Schincariol for cloning an app's *functionality and UX patterns* clean-room style. Each skill writes files the next one reads, and everything is kept in [`replica/`](replica/):
|
||||
|
||||
| Step | Skill | What it produced for Wetter |
|
||||
| --- | --- | --- |
|
||||
| 1 | `replica-recon` | [Recon map](replica/recon.md) built from public sources (help center, reviews, store listing): 15 screens, 9 user flows, components, inferred data model, [feature matrix](replica/features.csv) |
|
||||
| 2 | `replica-architect` | [Architecture](replica/architecture.md) and [schema](replica/schema.sql): native Kotlin, offline-first, no server, public APIs only |
|
||||
| 3 | `replica-design` | [Design tokens](replica/design/tokens.json) and [component specs](replica/design/components.md), WCAG AA contrast checked (70 colour pairs), generated into Compose code |
|
||||
| 4 | `replica-build` | The app itself, screen by screen, with a [build log](replica/build-log.md) and [screenshots](replica/clone-screens/) rendered from a real API response |
|
||||
| next | `replica-test`, `replica-diff`, `replica-entrepreneur`, `replica-brand`, `replica-launch`, `replica-deploy`, `replica-backend` | QA, parity scoring against the original, reading real user reviews for improvements, naming and branding, store listing, release |
|
||||
|
||||
The rules Replica enforces, and that this project follows:
|
||||
|
||||
- **Public sources and our own devices only.** No decompiling, no private APIs, no reading the original's code or network traffic.
|
||||
- **Everything written fresh.** Code, icons, weather glyphs, the animated sky and every label are made from scratch. Reference screenshots of the originals live in `replica/screens/` for layout comparison only and never ship.
|
||||
- **What cannot be cloned is left out on purpose:** Google's own forecast models, Gemini summaries, Calendar/Gmail-based insights and account sync. Open alternatives replace them where it makes sense.
|
||||
|
||||
### Built with AI, steered by a human
|
||||
|
||||
The code, the design system and this README were written by **Claude Opus 5.5** (Anthropic's model, ID `claude-opus-5-5`) running in **Claude Code**, working through the Replica skills step by step. The human side of the project (that's [@MrBlake](https://git.mrblake.cc/MrBlake)) sets direction, supplies reference screenshots, tests every build on a real Pixel phone and reports what feels wrong. Issues found that way, like stutter during scrolling or slow location, are measured on the device and fixed. A typical loop:
|
||||
|
||||
1. A skill produces its document or code; the human reviews it.
|
||||
2. The app is built and rendered to screenshots on the JVM (Roborazzi), and the screenshots are checked against the reference.
|
||||
3. The release build is installed on the phone over adb and used for real; frame timings (`dumpsys gfxinfo`) and logs guide the fixes.
|
||||
|
||||
Each commit says what changed and carries a `Co-Authored-By` line for the AI.
|
||||
|
||||
## Building from source
|
||||
|
||||
Requirements: JDK 17 or newer and the Android SDK (platform 36).
|
||||
|
||||
```bash
|
||||
cd wetter
|
||||
./gradlew :app:assembleRelease # APK in app/build/outputs/apk/release/
|
||||
./gradlew :app:testDebugUnitTest # unit + screenshot tests
|
||||
./gradlew :app:recordRoborazziDebug # re-render replica/clone-screens/
|
||||
```
|
||||
|
||||
Local release builds are signed with the debug key so they install over each other. Published releases will use a dedicated signing key.
|
||||
|
||||
## Repository layout
|
||||
|
||||
```
|
||||
replica/ recon, architecture, design system, build log, screenshots
|
||||
wetter/ the weather app (Kotlin, Jetpack Compose, Glance widgets, Room, WorkManager)
|
||||
```
|
||||
|
||||
## Credits
|
||||
|
||||
- Weather data: [Open-Meteo.com](https://open-meteo.com), CC BY 4.0
|
||||
- Place names: © [OpenStreetMap](https://www.openstreetmap.org/copyright) contributors, via Nominatim
|
||||
- UI icons: [Material Symbols](https://fonts.google.com/icons), Apache 2.0
|
||||
- Method: [Replica](https://github.com/Jakeschincariol/replica-skill) by Jake Schincariol
|
||||
|
||||
## License
|
||||
|
||||
Not chosen yet. Until a license file is added, all rights are reserved by the author.
|
||||
@@ -12,7 +12,8 @@ Stack as in architecture.md. App in `wetter/`. Screenshots are rendered on the J
|
||||
| S15 Preview | 2026-10-17 | done | – | – |
|
||||
| S04 Day detail | 2026-10-17 | done | – | tiles need day-specific values (noon), not today's |
|
||||
| S08/S09 Settings | 2026-10-17 | done | notification settings (no notifications yet) | – |
|
||||
| S12 Widgets | 2026-10-17 | partial | config activity (pick a location), 4×4 and 4×1 types, dynamic-colour style; **no screenshot** (Glance does not render in Robolectric), only verified to compile | widgets cannot draw shaders → the scene is pre-rendered to a bitmap |
|
||||
| S12 Widgets | 2026-10-17 | done | – | Glance 1.1 could not render outside the launcher; upgraded to 1.2 for compose() and picker previews, checked on the phone via a debug gallery |
|
||||
| S12 Widgets (first pass) | 2026-10-17 | superseded | config activity (pick a location), 4×4 and 4×1 types, dynamic-colour style; **no screenshot** (Glance does not render in Robolectric), only verified to compile | widgets cannot draw shaders → the scene is pre-rendered to a bitmap |
|
||||
| S05, S06, S10, S11, S13 | – | not started | card detail, radar map, reordering, alert detail, notifications | – |
|
||||
|
||||
Not yet verified on a real device: location without Play Services, network on device, widgets on the launcher, WorkManager timing.
|
||||
|
Before Width: | Height: | Size: 904 KiB After Width: | Height: | Size: 907 KiB |
|
Before Width: | Height: | Size: 893 KiB After Width: | Height: | Size: 895 KiB |
|
Before Width: | Height: | Size: 794 KiB After Width: | Height: | Size: 800 KiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 843 KiB After Width: | Height: | Size: 846 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 976 KiB After Width: | Height: | Size: 978 KiB |
|
Before Width: | Height: | Size: 1.9 MiB After Width: | Height: | Size: 1.9 MiB |
|
After Width: | Height: | Size: 152 KiB |
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 148 KiB |
|
Before Width: | Height: | Size: 887 KiB After Width: | Height: | Size: 890 KiB |
@@ -114,6 +114,78 @@ object WColor {
|
||||
val aqiBar6 = Color(0xFF8E24AA)
|
||||
val uvDotLow = Color(0xFF5CCF8A)
|
||||
val uvDotOff = Color(0xFF6B5A52)
|
||||
val widgetOceanLightBg = Color(0xFFCCE4F0)
|
||||
val widgetOceanLightOn = Color(0xFF0F2733)
|
||||
val widgetOceanLightAccent = Color(0xFF20546F)
|
||||
val widgetOceanLightPanel = Color(0xFFF9FAFB)
|
||||
val widgetOceanLightOnpanel = Color(0xFF192124)
|
||||
val widgetOceanLightBadge = Color(0xFFA8D1E6)
|
||||
val widgetOceanLightOnbadge = Color(0xFF0F2733)
|
||||
val widgetOceanDarkBg = Color(0xFF194257)
|
||||
val widgetOceanDarkOn = Color(0xFFDBECF5)
|
||||
val widgetOceanDarkAccent = Color(0xFFB0D5E8)
|
||||
val widgetOceanDarkPanel = Color(0xFF0E1315)
|
||||
val widgetOceanDarkOnpanel = Color(0xFFE7ECEF)
|
||||
val widgetOceanDarkBadge = Color(0xFF1F516B)
|
||||
val widgetOceanDarkOnbadge = Color(0xFFDFEEF6)
|
||||
val widgetForestLightBg = Color(0xFFD2E9DA)
|
||||
val widgetForestLightOn = Color(0xFF162D1D)
|
||||
val widgetForestLightAccent = Color(0xFF2E603F)
|
||||
val widgetForestLightPanel = Color(0xFFF9FBFA)
|
||||
val widgetForestLightOnpanel = Color(0xFF1B221D)
|
||||
val widgetForestLightBadge = Color(0xFFB3DBC0)
|
||||
val widgetForestLightOnbadge = Color(0xFF162D1D)
|
||||
val widgetForestDarkBg = Color(0xFF244C32)
|
||||
val widgetForestDarkOn = Color(0xFFE0F0E5)
|
||||
val widgetForestDarkAccent = Color(0xFFBADEC6)
|
||||
val widgetForestDarkPanel = Color(0xFF101411)
|
||||
val widgetForestDarkOnpanel = Color(0xFFE8EDEA)
|
||||
val widgetForestDarkBadge = Color(0xFF2D5D3D)
|
||||
val widgetForestDarkOnbadge = Color(0xFFE3F2E8)
|
||||
val widgetSunLightBg = Color(0xFFF7E4C5)
|
||||
val widgetSunLightOn = Color(0xFF3A2808)
|
||||
val widgetSunLightAccent = Color(0xFF7D5612)
|
||||
val widgetSunLightPanel = Color(0xFFFBFAF9)
|
||||
val widgetSunLightOnpanel = Color(0xFF272117)
|
||||
val widgetSunLightBadge = Color(0xFFF1D29D)
|
||||
val widgetSunLightOnbadge = Color(0xFF3A2808)
|
||||
val widgetSunDarkBg = Color(0xFF62430E)
|
||||
val widgetSunDarkOn = Color(0xFFF9EDD7)
|
||||
val widgetSunDarkAccent = Color(0xFFF2D6A6)
|
||||
val widgetSunDarkPanel = Color(0xFF17130D)
|
||||
val widgetSunDarkOnpanel = Color(0xFFF0ECE5)
|
||||
val widgetSunDarkBadge = Color(0xFF785311)
|
||||
val widgetSunDarkOnbadge = Color(0xFFFAEFDB)
|
||||
val widgetLavenderLightBg = Color(0xFFDBCFED)
|
||||
val widgetLavenderLightOn = Color(0xFF1F1230)
|
||||
val widgetLavenderLightAccent = Color(0xFF422768)
|
||||
val widgetLavenderLightPanel = Color(0xFFFAF9FB)
|
||||
val widgetLavenderLightOnpanel = Color(0xFF1E1A23)
|
||||
val widgetLavenderLightBadge = Color(0xFFC3AEE0)
|
||||
val widgetLavenderLightOnbadge = Color(0xFF1F1230)
|
||||
val widgetLavenderDarkBg = Color(0xFF341F51)
|
||||
val widgetLavenderDarkOn = Color(0xFFE6DEF2)
|
||||
val widgetLavenderDarkAccent = Color(0xFFC8B5E3)
|
||||
val widgetLavenderDarkPanel = Color(0xFF110F15)
|
||||
val widgetLavenderDarkOnpanel = Color(0xFFEAE7EE)
|
||||
val widgetLavenderDarkBadge = Color(0xFF402664)
|
||||
val widgetLavenderDarkOnbadge = Color(0xFFE9E1F4)
|
||||
val widgetGraphiteLightBg = Color(0xFFDBDDE1)
|
||||
val widgetGraphiteLightOn = Color(0xFF1E2124)
|
||||
val widgetGraphiteLightAccent = Color(0xFF42464D)
|
||||
val widgetGraphiteLightPanel = Color(0xFFFAFAFA)
|
||||
val widgetGraphiteLightOnpanel = Color(0xFF1E1E1F)
|
||||
val widgetGraphiteLightBadge = Color(0xFFC2C6CB)
|
||||
val widgetGraphiteLightOnbadge = Color(0xFF1E2124)
|
||||
val widgetGraphiteDarkBg = Color(0xFF34373D)
|
||||
val widgetGraphiteDarkOn = Color(0xFFE6E8EA)
|
||||
val widgetGraphiteDarkAccent = Color(0xFFC8CBD0)
|
||||
val widgetGraphiteDarkPanel = Color(0xFF111212)
|
||||
val widgetGraphiteDarkOnpanel = Color(0xFFEAEBEB)
|
||||
val widgetGraphiteDarkBadge = Color(0xFF3F444A)
|
||||
val widgetGraphiteDarkOnbadge = Color(0xFFE9EAEC)
|
||||
val darkAccentContainer = Color(0xFF244A80)
|
||||
val darkOnAccentContainer = Color(0xFFD6E3FF)
|
||||
}
|
||||
|
||||
object WType {
|
||||
|
||||
|
After Width: | Height: | Size: 18 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 108 108" width="432" height="432">
|
||||
<defs><linearGradient id="g" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#4E9BE6"/><stop offset="1" stop-color="#BFE3F7"/></linearGradient>
|
||||
<clipPath id="c"><circle cx="54" cy="54" r="54"/></clipPath></defs>
|
||||
<g clip-path="url(#c)"><rect width="108" height="108" fill="url(#g)"/>
|
||||
<path d="M0.00,108.00 L0.00,77.13 L2.00,76.77 L4.00,76.47 L6.00,76.25 L8.00,76.09 L10.00,76.01 L12.00,76.01 L14.00,76.09 L16.00,76.24 L18.00,76.46 L20.00,76.76 L22.00,77.11 L24.00,77.53 L26.00,77.99 L28.00,78.49 L30.00,79.02 L32.00,79.57 L34.00,80.13 L36.00,80.68 L38.00,81.23 L40.00,81.74 L42.00,82.23 L44.00,82.67 L46.00,83.06 L48.00,83.39 L50.00,83.65 L52.00,83.84 L54.00,83.96 L56.00,84.00 L58.00,83.96 L60.00,83.85 L62.00,83.66 L64.00,83.40 L66.00,83.07 L68.00,82.68 L70.00,82.25 L72.00,81.76 L74.00,81.25 L76.00,80.71 L78.00,80.15 L80.00,79.59 L82.00,79.04 L84.00,78.51 L86.00,78.01 L88.00,77.55 L90.00,77.13 L92.00,76.77 L94.00,76.47 L96.00,76.25 L98.00,76.09 L100.00,76.01 L102.00,76.01 L104.00,76.09 L106.00,76.24 L108.00,76.46 L108.00,108.00 Z" fill="#8EC2EC"/><path d="M0.00,108.00 L0.00,85.97 L2.00,86.20 L4.00,86.44 L6.00,86.69 L8.00,86.96 L10.00,87.23 L12.00,87.52 L14.00,87.81 L16.00,88.10 L18.00,88.38 L20.00,88.67 L22.00,88.95 L24.00,89.22 L26.00,89.48 L28.00,89.72 L30.00,89.95 L32.00,90.16 L34.00,90.35 L36.00,90.52 L38.00,90.67 L40.00,90.79 L42.00,90.88 L44.00,90.95 L46.00,90.99 L48.00,91.00 L50.00,90.98 L52.00,90.94 L54.00,90.87 L56.00,90.77 L58.00,90.65 L60.00,90.50 L62.00,90.32 L64.00,90.13 L66.00,89.92 L68.00,89.69 L70.00,89.44 L72.00,89.18 L74.00,88.91 L76.00,88.63 L78.00,88.34 L80.00,88.05 L82.00,87.76 L84.00,87.47 L86.00,87.19 L88.00,86.92 L90.00,86.65 L92.00,86.40 L94.00,86.16 L96.00,85.94 L98.00,85.74 L100.00,85.56 L102.00,85.40 L104.00,85.27 L106.00,85.16 L108.00,85.08 L108.00,108.00 Z" fill="#A9D3F2"/>
|
||||
<path d="M78.41,44.00 L78.32,44.76 L78.08,45.49 L77.70,46.20 L77.25,46.87 L76.77,47.50 L76.32,48.10 L75.94,48.71 L75.65,49.33 L75.47,49.99 L75.37,50.70 L75.33,51.46 L75.29,52.25 L75.21,53.05 L75.04,53.83 L74.76,54.55 L74.33,55.19 L73.78,55.71 L73.12,56.12 L72.38,56.42 L71.61,56.64 L70.83,56.81 L70.10,56.99 L69.41,57.21 L68.80,57.50 L68.23,57.89 L67.70,58.37 L67.18,58.92 L66.64,59.50 L66.07,60.07 L65.44,60.56 L64.75,60.93 L64.02,61.14 L63.26,61.19 L62.49,61.08 L61.73,60.83 L61.00,60.50 L60.30,60.14 L59.62,59.80 L58.96,59.53 L58.29,59.36 L57.61,59.29 L56.90,59.32 L56.14,59.41 L55.36,59.50 L54.55,59.56 L53.76,59.54 L52.99,59.38 L52.30,59.08 L51.68,58.62 L51.17,58.04 L50.74,57.37 L50.39,56.64 L50.09,55.91 L49.79,55.21 L49.45,54.58 L49.06,54.02 L48.57,53.53 L48.01,53.10 L47.38,52.68 L46.71,52.25 L46.06,51.78 L45.46,51.24 L44.98,50.64 L44.64,49.95 L44.46,49.21 L44.44,48.44 L44.55,47.65 L44.75,46.87 L44.99,46.11 L45.20,45.38 L45.35,44.68 L45.41,44.00 L45.35,43.32 L45.20,42.62 L44.99,41.89 L44.75,41.13 L44.55,40.35 L44.44,39.56 L44.46,38.79 L44.64,38.05 L44.98,37.36 L45.46,36.76 L46.06,36.22 L46.71,35.75 L47.38,35.32 L48.01,34.90 L48.57,34.47 L49.06,33.98 L49.45,33.42 L49.79,32.79 L50.09,32.09 L50.39,31.36 L50.74,30.63 L51.17,29.96 L51.68,29.38 L52.30,28.92 L52.99,28.62 L53.76,28.46 L54.55,28.44 L55.36,28.50 L56.14,28.59 L56.90,28.68 L57.61,28.71 L58.29,28.64 L58.96,28.47 L59.62,28.20 L60.30,27.86 L61.00,27.50 L61.73,27.17 L62.49,26.92 L63.26,26.81 L64.02,26.86 L64.75,27.07 L65.44,27.44 L66.07,27.93 L66.64,28.50 L67.18,29.08 L67.70,29.63 L68.23,30.11 L68.80,30.50 L69.41,30.79 L70.10,31.01 L70.83,31.19 L71.61,31.36 L72.38,31.58 L73.12,31.88 L73.78,32.29 L74.33,32.81 L74.76,33.45 L75.04,34.17 L75.21,34.95 L75.29,35.75 L75.33,36.54 L75.37,37.30 L75.47,38.01 L75.65,38.67 L75.94,39.29 L76.32,39.90 L76.77,40.50 L77.25,41.13 L77.70,41.80 L78.08,42.51 L78.32,43.24 Z" fill="#FFB02E"/><circle cx="61" cy="44" r="10" fill="#FF9A1F" opacity=".35"/>
|
||||
<path d="M38,74 h30 a9,9 0 0 0 0,-18 a12,12 0 0 0 -22.5,-3.5 a10,10 0 0 0 -7.5,21.5 z" fill="#D5DEE8" transform="translate(0,2.5)"/><path d="M38,74 h30 a9,9 0 0 0 0,-18 a12,12 0 0 0 -22.5,-3.5 a10,10 0 0 0 -7.5,21.5 z" fill="#FFFFFF"/></g></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
@@ -106,7 +106,79 @@
|
||||
"aqi-bar-5": "#e53935",
|
||||
"aqi-bar-6": "#8e24aa",
|
||||
"uv-dot-low": "#5ccf8a",
|
||||
"uv-dot-off": "#6b5a52"
|
||||
"uv-dot-off": "#6b5a52",
|
||||
"widget-ocean-light-bg": "#cce4f0",
|
||||
"widget-ocean-light-on": "#0f2733",
|
||||
"widget-ocean-light-accent": "#20546f",
|
||||
"widget-ocean-light-panel": "#f9fafb",
|
||||
"widget-ocean-light-onpanel": "#192124",
|
||||
"widget-ocean-light-badge": "#a8d1e6",
|
||||
"widget-ocean-light-onbadge": "#0f2733",
|
||||
"widget-ocean-dark-bg": "#194257",
|
||||
"widget-ocean-dark-on": "#dbecf5",
|
||||
"widget-ocean-dark-accent": "#b0d5e8",
|
||||
"widget-ocean-dark-panel": "#0e1315",
|
||||
"widget-ocean-dark-onpanel": "#e7ecef",
|
||||
"widget-ocean-dark-badge": "#1f516b",
|
||||
"widget-ocean-dark-onbadge": "#dfeef6",
|
||||
"widget-forest-light-bg": "#d2e9da",
|
||||
"widget-forest-light-on": "#162d1d",
|
||||
"widget-forest-light-accent": "#2e603f",
|
||||
"widget-forest-light-panel": "#f9fbfa",
|
||||
"widget-forest-light-onpanel": "#1b221d",
|
||||
"widget-forest-light-badge": "#b3dbc0",
|
||||
"widget-forest-light-onbadge": "#162d1d",
|
||||
"widget-forest-dark-bg": "#244c32",
|
||||
"widget-forest-dark-on": "#e0f0e5",
|
||||
"widget-forest-dark-accent": "#badec6",
|
||||
"widget-forest-dark-panel": "#101411",
|
||||
"widget-forest-dark-onpanel": "#e8edea",
|
||||
"widget-forest-dark-badge": "#2d5d3d",
|
||||
"widget-forest-dark-onbadge": "#e3f2e8",
|
||||
"widget-sun-light-bg": "#f7e4c5",
|
||||
"widget-sun-light-on": "#3a2808",
|
||||
"widget-sun-light-accent": "#7d5612",
|
||||
"widget-sun-light-panel": "#fbfaf9",
|
||||
"widget-sun-light-onpanel": "#272117",
|
||||
"widget-sun-light-badge": "#f1d29d",
|
||||
"widget-sun-light-onbadge": "#3a2808",
|
||||
"widget-sun-dark-bg": "#62430e",
|
||||
"widget-sun-dark-on": "#f9edd7",
|
||||
"widget-sun-dark-accent": "#f2d6a6",
|
||||
"widget-sun-dark-panel": "#17130d",
|
||||
"widget-sun-dark-onpanel": "#f0ece5",
|
||||
"widget-sun-dark-badge": "#785311",
|
||||
"widget-sun-dark-onbadge": "#faefdb",
|
||||
"widget-lavender-light-bg": "#dbcfed",
|
||||
"widget-lavender-light-on": "#1f1230",
|
||||
"widget-lavender-light-accent": "#422768",
|
||||
"widget-lavender-light-panel": "#faf9fb",
|
||||
"widget-lavender-light-onpanel": "#1e1a23",
|
||||
"widget-lavender-light-badge": "#c3aee0",
|
||||
"widget-lavender-light-onbadge": "#1f1230",
|
||||
"widget-lavender-dark-bg": "#341f51",
|
||||
"widget-lavender-dark-on": "#e6def2",
|
||||
"widget-lavender-dark-accent": "#c8b5e3",
|
||||
"widget-lavender-dark-panel": "#110f15",
|
||||
"widget-lavender-dark-onpanel": "#eae7ee",
|
||||
"widget-lavender-dark-badge": "#402664",
|
||||
"widget-lavender-dark-onbadge": "#e9e1f4",
|
||||
"widget-graphite-light-bg": "#dbdde1",
|
||||
"widget-graphite-light-on": "#1e2124",
|
||||
"widget-graphite-light-accent": "#42464d",
|
||||
"widget-graphite-light-panel": "#fafafa",
|
||||
"widget-graphite-light-onpanel": "#1e1e1f",
|
||||
"widget-graphite-light-badge": "#c2c6cb",
|
||||
"widget-graphite-light-onbadge": "#1e2124",
|
||||
"widget-graphite-dark-bg": "#34373d",
|
||||
"widget-graphite-dark-on": "#e6e8ea",
|
||||
"widget-graphite-dark-accent": "#c8cbd0",
|
||||
"widget-graphite-dark-panel": "#111212",
|
||||
"widget-graphite-dark-onpanel": "#eaebeb",
|
||||
"widget-graphite-dark-badge": "#3f444a",
|
||||
"widget-graphite-dark-onbadge": "#e9eaec",
|
||||
"dark-accent-container": "#244a80",
|
||||
"dark-on-accent-container": "#d6e3ff"
|
||||
},
|
||||
"pairs": [
|
||||
[
|
||||
@@ -396,6 +468,170 @@
|
||||
"nowcast-dot",
|
||||
"card",
|
||||
"ui"
|
||||
],
|
||||
[
|
||||
"widget-ocean-light-on",
|
||||
"widget-ocean-light-bg"
|
||||
],
|
||||
[
|
||||
"widget-ocean-light-accent",
|
||||
"widget-ocean-light-bg"
|
||||
],
|
||||
[
|
||||
"widget-ocean-light-onpanel",
|
||||
"widget-ocean-light-panel"
|
||||
],
|
||||
[
|
||||
"widget-ocean-light-onbadge",
|
||||
"widget-ocean-light-badge"
|
||||
],
|
||||
[
|
||||
"widget-ocean-dark-on",
|
||||
"widget-ocean-dark-bg"
|
||||
],
|
||||
[
|
||||
"widget-ocean-dark-accent",
|
||||
"widget-ocean-dark-bg"
|
||||
],
|
||||
[
|
||||
"widget-ocean-dark-onpanel",
|
||||
"widget-ocean-dark-panel"
|
||||
],
|
||||
[
|
||||
"widget-ocean-dark-onbadge",
|
||||
"widget-ocean-dark-badge"
|
||||
],
|
||||
[
|
||||
"widget-forest-light-on",
|
||||
"widget-forest-light-bg"
|
||||
],
|
||||
[
|
||||
"widget-forest-light-accent",
|
||||
"widget-forest-light-bg"
|
||||
],
|
||||
[
|
||||
"widget-forest-light-onpanel",
|
||||
"widget-forest-light-panel"
|
||||
],
|
||||
[
|
||||
"widget-forest-light-onbadge",
|
||||
"widget-forest-light-badge"
|
||||
],
|
||||
[
|
||||
"widget-forest-dark-on",
|
||||
"widget-forest-dark-bg"
|
||||
],
|
||||
[
|
||||
"widget-forest-dark-accent",
|
||||
"widget-forest-dark-bg"
|
||||
],
|
||||
[
|
||||
"widget-forest-dark-onpanel",
|
||||
"widget-forest-dark-panel"
|
||||
],
|
||||
[
|
||||
"widget-forest-dark-onbadge",
|
||||
"widget-forest-dark-badge"
|
||||
],
|
||||
[
|
||||
"widget-sun-light-on",
|
||||
"widget-sun-light-bg"
|
||||
],
|
||||
[
|
||||
"widget-sun-light-accent",
|
||||
"widget-sun-light-bg"
|
||||
],
|
||||
[
|
||||
"widget-sun-light-onpanel",
|
||||
"widget-sun-light-panel"
|
||||
],
|
||||
[
|
||||
"widget-sun-light-onbadge",
|
||||
"widget-sun-light-badge"
|
||||
],
|
||||
[
|
||||
"widget-sun-dark-on",
|
||||
"widget-sun-dark-bg"
|
||||
],
|
||||
[
|
||||
"widget-sun-dark-accent",
|
||||
"widget-sun-dark-bg"
|
||||
],
|
||||
[
|
||||
"widget-sun-dark-onpanel",
|
||||
"widget-sun-dark-panel"
|
||||
],
|
||||
[
|
||||
"widget-sun-dark-onbadge",
|
||||
"widget-sun-dark-badge"
|
||||
],
|
||||
[
|
||||
"widget-lavender-light-on",
|
||||
"widget-lavender-light-bg"
|
||||
],
|
||||
[
|
||||
"widget-lavender-light-accent",
|
||||
"widget-lavender-light-bg"
|
||||
],
|
||||
[
|
||||
"widget-lavender-light-onpanel",
|
||||
"widget-lavender-light-panel"
|
||||
],
|
||||
[
|
||||
"widget-lavender-light-onbadge",
|
||||
"widget-lavender-light-badge"
|
||||
],
|
||||
[
|
||||
"widget-lavender-dark-on",
|
||||
"widget-lavender-dark-bg"
|
||||
],
|
||||
[
|
||||
"widget-lavender-dark-accent",
|
||||
"widget-lavender-dark-bg"
|
||||
],
|
||||
[
|
||||
"widget-lavender-dark-onpanel",
|
||||
"widget-lavender-dark-panel"
|
||||
],
|
||||
[
|
||||
"widget-lavender-dark-onbadge",
|
||||
"widget-lavender-dark-badge"
|
||||
],
|
||||
[
|
||||
"widget-graphite-light-on",
|
||||
"widget-graphite-light-bg"
|
||||
],
|
||||
[
|
||||
"widget-graphite-light-accent",
|
||||
"widget-graphite-light-bg"
|
||||
],
|
||||
[
|
||||
"widget-graphite-light-onpanel",
|
||||
"widget-graphite-light-panel"
|
||||
],
|
||||
[
|
||||
"widget-graphite-light-onbadge",
|
||||
"widget-graphite-light-badge"
|
||||
],
|
||||
[
|
||||
"widget-graphite-dark-on",
|
||||
"widget-graphite-dark-bg"
|
||||
],
|
||||
[
|
||||
"widget-graphite-dark-accent",
|
||||
"widget-graphite-dark-bg"
|
||||
],
|
||||
[
|
||||
"widget-graphite-dark-onpanel",
|
||||
"widget-graphite-dark-panel"
|
||||
],
|
||||
[
|
||||
"widget-graphite-dark-onbadge",
|
||||
"widget-graphite-dark-badge"
|
||||
],
|
||||
[
|
||||
"dark-on-accent-container",
|
||||
"dark-accent-container"
|
||||
]
|
||||
],
|
||||
"font": {
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
feature,area,priority,original,clone,notes
|
||||
Current conditions hero (temp feels-like high/low condition),home,must,yes,yes,
|
||||
Condition-based animated background,home,must,yes,yes,original artwork not reusable; draw own
|
||||
Hourly forecast strip (24h+),home,must,yes,yes,fixed position
|
||||
10-day forecast list,home,must,yes,yes,
|
||||
Daily detail view (tap a day),home,should,yes,yes,guess: exists in original
|
||||
Precipitation card with chance and amount,cards,must,yes,yes,
|
||||
Wind card (speed direction gusts),cards,must,yes,yes,
|
||||
UV index card,cards,must,yes,yes,
|
||||
Humidity / dew point card,cards,must,yes,yes,
|
||||
Pressure card,cards,should,yes,yes,
|
||||
Visibility card,cards,should,yes,yes,
|
||||
Sunrise / sunset card,cards,must,yes,yes,
|
||||
Air quality (AQI) card,cards,should,yes,yes,Open-Meteo air-quality API (CAMS)
|
||||
Pollen card,cards,could,yes,yes,Open-Meteo pollen (Europe only)
|
||||
Drag to reorder cards,customize,should,yes,no,
|
||||
Card order saved per city,customize,could,yes,no,
|
||||
Location search by name or postal code,locations,must,yes,yes,Open-Meteo geocoding
|
||||
Current location via GPS,locations,must,yes,yes,no Google Play Services; use platform LocationManager
|
||||
Saved locations list,locations,must,yes,yes,
|
||||
Swipe to delete a location,locations,must,yes,yes,
|
||||
Swipe/pager between saved cities,locations,should,yes,yes,
|
||||
Temperature unit (default C F),settings,must,yes,yes,
|
||||
Units for precipitation wind pressure visibility,settings,should,yes,yes,
|
||||
Theme setting (system light dark),settings,should,yes,yes,
|
||||
Precipitation map with 6h nowcast and timeline scrubber,map,should,yes,no,RainViewer or DWD radar tiles + OSM base map
|
||||
Pan and zoom map,map,should,yes,no,
|
||||
Severe weather alerts banner on top,alerts,must,yes,no,DWD / MeteoAlarm feeds
|
||||
Severe weather notification,notifications,should,yes,no,background worker
|
||||
Evening tomorrow-forecast notification,notifications,could,yes,no,
|
||||
Precipitation-starting notification per city,notifications,could,yes,no,needs minute nowcast
|
||||
Homescreen widget,widgets,must,yes,partial,"2 of 5 widget types (Now 2x1/2x2, Forecast 4x2/4x3); no config activity yet"
|
||||
AI weather brief summary,ai,could,yes,partial,"template-based text or local LLM; no Gemini; rule-based brief, no LLM"
|
||||
Weather vibrations on animations,polish,could,yes,no,
|
||||
Tablet two-column layout,layout,could,yes,partial,content capped at 720dp and centred; no true two-pane
|
||||
Sync saved locations across devices via Google account,sync,could,yes,skip,no Google account by design
|
||||
Personal insights from Calendar and Gmail,ai,could,yes,skip,needs Google data access; against project goal
|
||||
Google nowcasting / MetNet models,data,could,yes,skip,proprietary model; use public forecast data
|
||||
At a Glance integration,widgets,could,yes,skip,Pixel launcher system feature
|
||||
Widget sizes small medium large with hourly/daily,widgets,must,yes,partial,Glance; resizable; small/medium/wide/tall done; 4x4 full and 4x1 glance missing
|
||||
Widget dynamic Material You colours and condition background,widgets,should,yes,partial,condition background only; dynamic colour style missing
|
||||
Widget tap opens city / refresh on schedule,widgets,must,yes,yes,
|
||||
Nowcast card (precip starting with 15-min dot chart),cards,should,yes,yes,Open-Meteo minutely_15
|
||||
Location preview with Save,locations,should,yes,yes,S15
|
||||
feature,area,priority,original,clone,notes
|
||||
Current conditions hero (temp feels-like high/low condition),home,must,yes,yes,
|
||||
Condition-based animated background,home,must,yes,yes,original artwork not reusable; draw own
|
||||
Hourly forecast strip (24h+),home,must,yes,yes,fixed position
|
||||
10-day forecast list,home,must,yes,yes,
|
||||
Daily detail view (tap a day),home,should,yes,yes,guess: exists in original
|
||||
Precipitation card with chance and amount,cards,must,yes,yes,
|
||||
Wind card (speed direction gusts),cards,must,yes,yes,
|
||||
UV index card,cards,must,yes,yes,
|
||||
Humidity / dew point card,cards,must,yes,yes,
|
||||
Pressure card,cards,should,yes,yes,
|
||||
Visibility card,cards,should,yes,yes,
|
||||
Sunrise / sunset card,cards,must,yes,yes,
|
||||
Air quality (AQI) card,cards,should,yes,yes,Open-Meteo air-quality API (CAMS)
|
||||
Pollen card,cards,could,yes,yes,Open-Meteo pollen (Europe only)
|
||||
Drag to reorder cards,customize,should,yes,no,
|
||||
Card order saved per city,customize,could,yes,no,
|
||||
Location search by name or postal code,locations,must,yes,yes,Open-Meteo geocoding
|
||||
Current location via GPS,locations,must,yes,yes,no Google Play Services; use platform LocationManager
|
||||
Saved locations list,locations,must,yes,yes,
|
||||
Swipe to delete a location,locations,must,yes,yes,
|
||||
Swipe/pager between saved cities,locations,should,yes,yes,
|
||||
Temperature unit (default C F),settings,must,yes,yes,
|
||||
Units for precipitation wind pressure visibility,settings,should,yes,yes,
|
||||
Theme setting (system light dark),settings,should,yes,yes,
|
||||
Precipitation map with 6h nowcast and timeline scrubber,map,should,yes,no,RainViewer or DWD radar tiles + OSM base map
|
||||
Pan and zoom map,map,should,yes,no,
|
||||
Severe weather alerts banner on top,alerts,must,yes,no,DWD / MeteoAlarm feeds
|
||||
Severe weather notification,notifications,should,yes,no,background worker
|
||||
Evening tomorrow-forecast notification,notifications,could,yes,no,
|
||||
Precipitation-starting notification per city,notifications,could,yes,no,needs minute nowcast
|
||||
Homescreen widget,widgets,must,yes,yes,5 widget types with config screen
|
||||
AI weather brief summary,ai,could,yes,partial,"template-based text or local LLM; no Gemini; rule-based brief, no LLM"
|
||||
Weather vibrations on animations,polish,could,yes,no,
|
||||
Tablet two-column layout,layout,could,yes,partial,content capped at 720dp and centred; no true two-pane
|
||||
Sync saved locations across devices via Google account,sync,could,yes,skip,no Google account by design
|
||||
Personal insights from Calendar and Gmail,ai,could,yes,skip,needs Google data access; against project goal
|
||||
Google nowcasting / MetNet models,data,could,yes,skip,proprietary model; use public forecast data
|
||||
At a Glance integration,widgets,could,yes,skip,Pixel launcher system feature
|
||||
Widget sizes small medium large with hourly/daily,widgets,must,yes,yes,Glance
|
||||
Widget dynamic Material You colours and condition background,widgets,should,yes,yes,condition background only
|
||||
Widget tap opens city / refresh on schedule,widgets,must,yes,yes,
|
||||
Nowcast card (precip starting with 15-min dot chart),cards,should,yes,yes,Open-Meteo minutely_15
|
||||
Location preview with Save,locations,should,yes,yes,S15
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import java.util.Properties
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
@@ -19,9 +21,25 @@ android {
|
||||
versionName = "0.1.0"
|
||||
}
|
||||
|
||||
// Release key lives outside the repo; without it, release builds fall back to the debug key (local only).
|
||||
val keyProps = Properties().apply {
|
||||
val f = file(System.getProperty("user.home") + "/.android/nogoogleapps-release.properties")
|
||||
if (f.exists()) f.inputStream().use { load(it) }
|
||||
}
|
||||
signingConfigs {
|
||||
if (keyProps.isNotEmpty()) create("release") {
|
||||
storeFile = file(keyProps.getProperty("storeFile"))
|
||||
storePassword = keyProps.getProperty("storePassword")
|
||||
keyAlias = keyProps.getProperty("keyAlias")
|
||||
keyPassword = keyProps.getProperty("keyPassword")
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
isShrinkResources = true
|
||||
signingConfig = signingConfigs.findByName("release") ?: signingConfigs.getByName("debug")
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
@@ -58,8 +76,8 @@ dependencies {
|
||||
ksp("androidx.room:room-compiler:2.7.0")
|
||||
implementation("androidx.datastore:datastore-preferences:1.1.7")
|
||||
implementation("androidx.work:work-runtime-ktx:2.11.0")
|
||||
implementation("androidx.glance:glance-appwidget:1.1.1")
|
||||
implementation("androidx.glance:glance-material3:1.1.1")
|
||||
implementation("androidx.glance:glance-appwidget:1.2.0")
|
||||
implementation("androidx.glance:glance-material3:1.2.0")
|
||||
|
||||
implementation("com.squareup.okhttp3:okhttp:4.12.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 2,
|
||||
"identityHash": "9c1a9b09f0d46a98d95c13ff8fe1ff17",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "locations",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `admin` TEXT, `country_code` TEXT NOT NULL, `lat` REAL NOT NULL, `lon` REAL NOT NULL, `timezone` TEXT NOT NULL, `is_current` INTEGER NOT NULL, `sort_order` INTEGER NOT NULL, `created_at` INTEGER NOT NULL, `updated_at` INTEGER NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "admin",
|
||||
"columnName": "admin",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "countryCode",
|
||||
"columnName": "country_code",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "lat",
|
||||
"columnName": "lat",
|
||||
"affinity": "REAL",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "lon",
|
||||
"columnName": "lon",
|
||||
"affinity": "REAL",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "timezone",
|
||||
"columnName": "timezone",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isCurrent",
|
||||
"columnName": "is_current",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "sortOrder",
|
||||
"columnName": "sort_order",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "createdAt",
|
||||
"columnName": "created_at",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "updatedAt",
|
||||
"columnName": "updated_at",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_locations_sort_order",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"sort_order"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_locations_sort_order` ON `${TABLE_NAME}` (`sort_order`)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "forecast_cache",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`location_id` INTEGER NOT NULL, `fetched_at` INTEGER NOT NULL, `forecast_json` TEXT NOT NULL, `air_json` TEXT, PRIMARY KEY(`location_id`), FOREIGN KEY(`location_id`) REFERENCES `locations`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "locationId",
|
||||
"columnName": "location_id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "fetchedAt",
|
||||
"columnName": "fetched_at",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "forecastJson",
|
||||
"columnName": "forecast_json",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "airJson",
|
||||
"columnName": "air_json",
|
||||
"affinity": "TEXT"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"location_id"
|
||||
]
|
||||
},
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "locations",
|
||||
"onDelete": "CASCADE",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"location_id"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "widget_config",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`app_widget_id` INTEGER NOT NULL, `location_id` INTEGER, `style` TEXT NOT NULL, `theme` TEXT NOT NULL, `opacity` INTEGER NOT NULL, PRIMARY KEY(`app_widget_id`), FOREIGN KEY(`location_id`) REFERENCES `locations`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "appWidgetId",
|
||||
"columnName": "app_widget_id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "locationId",
|
||||
"columnName": "location_id",
|
||||
"affinity": "INTEGER"
|
||||
},
|
||||
{
|
||||
"fieldPath": "style",
|
||||
"columnName": "style",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "theme",
|
||||
"columnName": "theme",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "opacity",
|
||||
"columnName": "opacity",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"app_widget_id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_widget_config_location_id",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"location_id"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_widget_config_location_id` ON `${TABLE_NAME}` (`location_id`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": [
|
||||
{
|
||||
"table": "locations",
|
||||
"onDelete": "SET NULL",
|
||||
"onUpdate": "NO ACTION",
|
||||
"columns": [
|
||||
"location_id"
|
||||
],
|
||||
"referencedColumns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '9c1a9b09f0d46a98d95c13ff8fe1ff17')"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application>
|
||||
<activity android:name=".WidgetGalleryActivity" android:exported="true" android:theme="@android:style/Theme.Material.NoActionBar" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,65 @@
|
||||
package app.wetter
|
||||
|
||||
import android.app.Activity
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ScrollView
|
||||
import androidx.compose.ui.unit.DpSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.glance.appwidget.GlanceAppWidget
|
||||
import androidx.glance.appwidget.compose
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import app.wetter.data.Graph
|
||||
import app.wetter.widget.BarWidget
|
||||
import app.wetter.widget.ClassicWidget
|
||||
import app.wetter.widget.PillWidget
|
||||
import app.wetter.widget.TiltWidget
|
||||
import app.wetter.widget.WeatherCardWidget
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* Debug only: renders every widget at its sizes with real data, so they can be checked
|
||||
* with `adb shell am start -n app.wetter/.WidgetGalleryActivity` and a screenshot.
|
||||
*/
|
||||
class WidgetGalleryActivity : androidx.activity.ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
Graph.init(this)
|
||||
val page = intent.getIntExtra("page", 0)
|
||||
val column = LinearLayout(this).apply { orientation = LinearLayout.VERTICAL; setPadding(px(16), px(48), px(16), px(48)) }
|
||||
setContentView(ScrollView(this).apply { setBackgroundColor(Color.rgb(96, 120, 128)); addView(column) })
|
||||
|
||||
val pages: List<List<Pair<GlanceAppWidget, DpSize>>> = listOf(
|
||||
listOf(
|
||||
WeatherCardWidget() to DpSize(360.dp, 260.dp),
|
||||
PillWidget() to DpSize(360.dp, 150.dp),
|
||||
WeatherCardWidget() to DpSize(260.dp, 150.dp),
|
||||
),
|
||||
listOf(
|
||||
WeatherCardWidget() to DpSize(360.dp, 520.dp),
|
||||
BarWidget() to DpSize(360.dp, 90.dp),
|
||||
),
|
||||
listOf(
|
||||
TiltWidget() to DpSize(180.dp, 180.dp),
|
||||
ClassicWidget() to DpSize(360.dp, 170.dp),
|
||||
ClassicWidget() to DpSize(170.dp, 170.dp),
|
||||
PillWidget() to DpSize(170.dp, 64.dp),
|
||||
),
|
||||
)
|
||||
lifecycleScope.launch {
|
||||
for ((widget, size) in pages[page.coerceIn(0, pages.lastIndex)]) {
|
||||
val views = widget.compose(this@WidgetGalleryActivity, size = size)
|
||||
val frame = FrameLayout(this@WidgetGalleryActivity)
|
||||
frame.addView(views.apply(this@WidgetGalleryActivity, frame))
|
||||
column.addView(frame, LinearLayout.LayoutParams(px(size.width.value), px(size.height.value)).apply { bottomMargin = px(20) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun px(dp: Float) = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.displayMetrics).toInt()
|
||||
private fun px(dp: Int) = px(dp.toFloat())
|
||||
}
|
||||
@@ -9,7 +9,8 @@
|
||||
<application
|
||||
android:name=".WetterApp"
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:roundIcon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@android:style/Theme.Material.NoActionBar">
|
||||
@@ -24,13 +25,29 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver android:name=".widget.NowWidgetReceiver" android:exported="true" android:label="@string/widget_now_name">
|
||||
<activity android:name=".widget.WidgetConfigActivity" android:exported="true" android:excludeFromRecents="true" android:taskAffinity="">
|
||||
<intent-filter><action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /></intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver android:name=".widget.WeatherCardReceiver" android:exported="true" android:label="@string/widget_card_name">
|
||||
<intent-filter><action android:name="android.appwidget.action.APPWIDGET_UPDATE" /></intent-filter>
|
||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_now" />
|
||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_card" />
|
||||
</receiver>
|
||||
<receiver android:name=".widget.ForecastWidgetReceiver" android:exported="true" android:label="@string/widget_forecast_name">
|
||||
<receiver android:name=".widget.PillReceiver" android:exported="true" android:label="@string/widget_pill_name">
|
||||
<intent-filter><action android:name="android.appwidget.action.APPWIDGET_UPDATE" /></intent-filter>
|
||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_forecast" />
|
||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_pill" />
|
||||
</receiver>
|
||||
<receiver android:name=".widget.TiltReceiver" android:exported="true" android:label="@string/widget_tilt_name">
|
||||
<intent-filter><action android:name="android.appwidget.action.APPWIDGET_UPDATE" /></intent-filter>
|
||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_tilt" />
|
||||
</receiver>
|
||||
<receiver android:name=".widget.BarReceiver" android:exported="true" android:label="@string/widget_bar_name">
|
||||
<intent-filter><action android:name="android.appwidget.action.APPWIDGET_UPDATE" /></intent-filter>
|
||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_bar" />
|
||||
</receiver>
|
||||
<receiver android:name=".widget.ClassicReceiver" android:exported="true" android:label="@string/widget_classic_name">
|
||||
<intent-filter><action android:name="android.appwidget.action.APPWIDGET_UPDATE" /></intent-filter>
|
||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_classic" />
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -51,7 +51,10 @@ data class WidgetConfigEntity(
|
||||
@PrimaryKey @androidx.room.ColumnInfo(name = "app_widget_id") val appWidgetId: Int,
|
||||
/** null = follow the current location */
|
||||
@androidx.room.ColumnInfo(name = "location_id") val locationId: Long?,
|
||||
val style: String = "auto",
|
||||
/** palette key, see WidgetStyle */
|
||||
val style: String = "wallpaper",
|
||||
val theme: String = "system",
|
||||
val opacity: Int = 100,
|
||||
)
|
||||
|
||||
@Dao
|
||||
@@ -107,7 +110,7 @@ interface WeatherDao {
|
||||
|
||||
@Database(
|
||||
entities = [LocationEntity::class, ForecastCacheEntity::class, WidgetConfigEntity::class],
|
||||
version = 1,
|
||||
version = 2,
|
||||
exportSchema = true,
|
||||
)
|
||||
abstract class WeatherDb : RoomDatabase() {
|
||||
@@ -115,6 +118,14 @@ abstract class WeatherDb : RoomDatabase() {
|
||||
|
||||
companion object {
|
||||
fun create(context: Context) =
|
||||
Room.databaseBuilder(context, WeatherDb::class.java, "weather.db").build()
|
||||
Room.databaseBuilder(context, WeatherDb::class.java, "weather.db").addMigrations(MIGRATION_1_2).build()
|
||||
|
||||
private val MIGRATION_1_2 = object : androidx.room.migration.Migration(1, 2) {
|
||||
override fun migrate(db: androidx.sqlite.db.SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE widget_config ADD COLUMN theme TEXT NOT NULL DEFAULT 'system'")
|
||||
db.execSQL("ALTER TABLE widget_config ADD COLUMN opacity INTEGER NOT NULL DEFAULT 100")
|
||||
db.execSQL("UPDATE widget_config SET style = 'wallpaper' WHERE style = 'auto'")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,9 @@ class DeviceLocation(private val context: Context) {
|
||||
@SuppressLint("MissingPermission")
|
||||
suspend fun get(): Location? {
|
||||
if (!hasPermission()) return null
|
||||
val providers = listOf(LocationManager.NETWORK_PROVIDER, LocationManager.GPS_PROVIDER, LocationManager.PASSIVE_PROVIDER)
|
||||
// FUSED_PROVIDER is the AOSP one (API 31+), it works without Play Services
|
||||
val fused = if (android.os.Build.VERSION.SDK_INT >= 31) listOf(LocationManager.FUSED_PROVIDER) else emptyList()
|
||||
val providers = (fused + listOf(LocationManager.NETWORK_PROVIDER, LocationManager.GPS_PROVIDER, LocationManager.PASSIVE_PROVIDER))
|
||||
.filter { runCatching { manager.isProviderEnabled(it) }.getOrDefault(false) }
|
||||
val lastKnown = providers.mapNotNull { runCatching { manager.getLastKnownLocation(it) }.getOrNull() }
|
||||
.maxByOrNull { it.time }
|
||||
@@ -44,7 +46,7 @@ class DeviceLocation(private val context: Context) {
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val FRESH_MS = 15 * 60 * 1000L
|
||||
const val TIMEOUT_MS = 12_000L
|
||||
const val FRESH_MS = 60 * 60 * 1000L
|
||||
const val TIMEOUT_MS = 8_000L
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import java.io.IOException
|
||||
import kotlinx.coroutines.delay
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
@@ -154,12 +155,24 @@ class OpenMeteo(private val http: OkHttpClient = defaultClient()) {
|
||||
return Air(c.int("european_aqi"), c.num("pm2_5"), c.num("pm10"), pollen)
|
||||
}
|
||||
|
||||
/** Open-Meteo answers 429/5xx ("service is overloaded") now and then; retry those twice with backoff. */
|
||||
private suspend fun get(url: String): String = withContext(Dispatchers.IO) {
|
||||
val request = Request.Builder().url(url).header("User-Agent", USER_AGENT).build()
|
||||
http.newCall(request).execute().use { response ->
|
||||
if (!response.isSuccessful) throw IOException("HTTP ${response.code}")
|
||||
response.body?.string() ?: throw IOException("empty body")
|
||||
var attempt = 0
|
||||
while (true) {
|
||||
val result = runCatching {
|
||||
http.newCall(request).execute().use { response ->
|
||||
if (!response.isSuccessful) throw HttpException(response.code)
|
||||
response.body?.string() ?: throw IOException("empty body")
|
||||
}
|
||||
}
|
||||
val error = result.exceptionOrNull() ?: return@withContext result.getOrThrow()
|
||||
val retryable = error is IOException && (error !is HttpException || error.code == 429 || error.code >= 500)
|
||||
if (!retryable || attempt >= 2) throw error
|
||||
delay(600L * (attempt + 1) * (attempt + 1))
|
||||
attempt++
|
||||
}
|
||||
@Suppress("UNREACHABLE_CODE") error("unreachable")
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -189,3 +202,5 @@ private fun JsonObject.int(key: String) = num(key)?.toInt()
|
||||
private fun JsonObject.arr(key: String): JsonArray = this[key]?.jsonArray ?: JsonArray(emptyList())
|
||||
private fun JsonObject.numAt(key: String, i: Int) = arr(key).getOrNull(i)?.takeUnless { it is JsonNull }?.jsonPrimitive?.doubleOrNull
|
||||
private fun JsonObject.intAt(key: String, i: Int) = numAt(key, i)?.toInt() ?: arr(key).getOrNull(i)?.takeUnless { it is JsonNull }?.jsonPrimitive?.intOrNull
|
||||
|
||||
class HttpException(val code: Int) : IOException("HTTP $code")
|
||||
@@ -1,6 +1,10 @@
|
||||
package app.wetter.data
|
||||
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
@@ -18,6 +22,15 @@ class WeatherRepository(
|
||||
private val device: DeviceLocation,
|
||||
) {
|
||||
private val currentLock = Mutex()
|
||||
private val inFlight = ConcurrentHashMap<Long, CompletableDeferred<RefreshResult>>()
|
||||
private val previews = ConcurrentHashMap<Place, Pair<String, String?>>()
|
||||
|
||||
/** Forecast and air quality at the same time; air is optional. */
|
||||
private suspend fun fetch(lat: Double, lon: Double): Pair<String, String?> = coroutineScope {
|
||||
val air = async { runCatching { api.airJson(lat, lon) }.getOrNull() }
|
||||
val forecast = async { api.forecastJson(lat, lon) }
|
||||
forecast.await() to air.await()
|
||||
}
|
||||
|
||||
val locations: Flow<List<LocationEntity>> = dao.locations()
|
||||
|
||||
@@ -36,17 +49,23 @@ class WeatherRepository(
|
||||
suspend fun refresh(location: LocationEntity, force: Boolean = false): RefreshResult {
|
||||
val cached = dao.forecastOnce(location.id)
|
||||
if (!force && cached != null && System.currentTimeMillis() - cached.fetchedAt < STALE_MS) return RefreshResult.Skipped
|
||||
return runCatching {
|
||||
val forecast = api.forecastJson(location.lat, location.lon)
|
||||
val air = runCatching { api.airJson(location.lat, location.lon) }.getOrNull()
|
||||
// a second caller for the same location waits for the running request instead of starting one
|
||||
val mine = CompletableDeferred<RefreshResult>()
|
||||
inFlight.putIfAbsent(location.id, mine)?.let { return it.await() }
|
||||
val result = runCatching {
|
||||
val (forecast, air) = fetch(location.lat, location.lon)
|
||||
dao.putForecast(ForecastCacheEntity(location.id, System.currentTimeMillis(), forecast, air))
|
||||
RefreshResult.Ok
|
||||
}.getOrElse { RefreshResult.Failed(it) }
|
||||
inFlight.remove(location.id)
|
||||
mine.complete(result)
|
||||
return result
|
||||
}
|
||||
|
||||
suspend fun refreshAll(force: Boolean = false) {
|
||||
updateCurrentLocation()
|
||||
dao.locationsOnce().forEach { refresh(it, force) }
|
||||
suspend fun refreshAll(force: Boolean = false) = coroutineScope {
|
||||
val saved = dao.locationsOnce().filter { !it.isCurrent }.map { async { refresh(it, force) } }
|
||||
updateCurrentLocation()?.let { refresh(it, force) }
|
||||
saved.forEach { it.await() }
|
||||
}
|
||||
|
||||
/** Device position -> the single is_current row. Returns null without permission or fix. */
|
||||
@@ -77,9 +96,9 @@ class WeatherRepository(
|
||||
|
||||
/** Full forecast for a place that is not saved yet (S15). */
|
||||
suspend fun preview(place: Place): Forecast {
|
||||
val forecast = api.forecastJson(place.lat, place.lon)
|
||||
val air = runCatching { api.airJson(place.lat, place.lon) }.getOrNull()
|
||||
return api.parse(forecast, air, System.currentTimeMillis())
|
||||
val raw = fetch(place.lat, place.lon)
|
||||
previews[place] = raw
|
||||
return api.parse(raw.first, raw.second, System.currentTimeMillis())
|
||||
}
|
||||
|
||||
suspend fun save(place: Place): Long {
|
||||
@@ -93,7 +112,10 @@ class WeatherRepository(
|
||||
lat = place.lat, lon = place.lon, timezone = place.timezone, sortOrder = dao.nextSortOrder(),
|
||||
)
|
||||
)
|
||||
dao.location(id)?.let { refresh(it, force = true) }
|
||||
// the preview already loaded this forecast: store it instead of fetching again
|
||||
val raw = previews.remove(place)
|
||||
if (raw != null) dao.putForecast(ForecastCacheEntity(id, System.currentTimeMillis(), raw.first, raw.second))
|
||||
else dao.location(id)?.let { refresh(it, force = true) }
|
||||
return id
|
||||
}
|
||||
|
||||
@@ -105,8 +127,9 @@ class WeatherRepository(
|
||||
return config?.locationId?.let { dao.location(it) } ?: dao.currentLocation() ?: dao.locationsOnce().firstOrNull()
|
||||
}
|
||||
|
||||
suspend fun setWidgetLocation(appWidgetId: Int, locationId: Long?) =
|
||||
dao.putWidget(WidgetConfigEntity(appWidgetId, locationId))
|
||||
suspend fun widgetConfig(appWidgetId: Int): WidgetConfigEntity? = dao.widget(appWidgetId)
|
||||
|
||||
suspend fun saveWidgetConfig(config: WidgetConfigEntity) = dao.putWidget(config)
|
||||
|
||||
suspend fun deleteWidget(appWidgetId: Int) = dao.deleteWidget(appWidgetId)
|
||||
|
||||
|
||||
@@ -139,7 +139,8 @@ fun WindTile(cur: Current, units: Units, modifier: Modifier) {
|
||||
val title = stringResource(R.string.card_wind)
|
||||
Tile(title, Icons.Outlined.Air, CircleShape, "$title $value ${units.windUnit}, ${stringResource(R.string.wind_from, from)}", modifier, centered = true) {
|
||||
// the blob points where the wind blows to
|
||||
Box(Modifier.fillMaxSize(.78f).align(Alignment.Center).clip(WShapes.triangle(cur.windDir + 180f + 90f)).background(c.fillSecondary))
|
||||
val blob = androidx.compose.runtime.remember(cur.windDir) { WShapes.triangle(cur.windDir + 180f + 90f) }
|
||||
Box(Modifier.fillMaxSize(.78f).align(Alignment.Center).clip(blob).background(c.fillSecondary))
|
||||
Column(Modifier.align(Alignment.Center), horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Spacer(Modifier.height(WSpace.s12))
|
||||
ValueText(value, units.windUnit, c.onFillSecondary)
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
package app.wetter.ui.components
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.selection.selectableGroup
|
||||
import androidx.compose.foundation.selection.toggleable
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Check
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.SwitchDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.heading
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.wetter.ui.theme.WSpace
|
||||
import app.wetter.ui.theme.WType
|
||||
|
||||
/*
|
||||
* Settings in the style of current Pixel system settings: grouped tiles with large outer
|
||||
* corners and small inner ones, 2dp gaps, tonal icon circles, values as summaries,
|
||||
* choices in dialogs.
|
||||
*/
|
||||
|
||||
private val Outer = 24.dp
|
||||
private val Inner = 4.dp
|
||||
|
||||
private fun tileShape(index: Int, count: Int): Shape = when {
|
||||
count == 1 -> RoundedCornerShape(Outer)
|
||||
index == 0 -> RoundedCornerShape(topStart = Outer, topEnd = Outer, bottomStart = Inner, bottomEnd = Inner)
|
||||
index == count - 1 -> RoundedCornerShape(topStart = Inner, topEnd = Inner, bottomStart = Outer, bottomEnd = Outer)
|
||||
else -> RoundedCornerShape(Inner)
|
||||
}
|
||||
|
||||
class GroupScope internal constructor() {
|
||||
internal val items = mutableListOf<@Composable (Shape) -> Unit>()
|
||||
fun item(content: @Composable (Shape) -> Unit) { items += content }
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsGroup(title: String? = null, modifier: Modifier = Modifier, content: GroupScope.() -> Unit) {
|
||||
val scope = GroupScope().apply(content)
|
||||
Column(modifier.padding(horizontal = WSpace.s16)) {
|
||||
if (title != null) {
|
||||
Text(
|
||||
title, style = WType.label.copy(fontSize = WType.bodySm.fontSize), color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(start = WSpace.s16, top = WSpace.s24, bottom = WSpace.s8).semantics { heading() },
|
||||
)
|
||||
} else Spacer(Modifier.padding(top = WSpace.s16))
|
||||
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||
scope.items.forEachIndexed { i, item -> item(tileShape(i, scope.items.size)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Tile(shape: Shape, modifier: Modifier = Modifier, content: @Composable () -> Unit) {
|
||||
Box(
|
||||
modifier.fillMaxWidth().clip(shape).background(MaterialTheme.colorScheme.surfaceContainerLowest).heightIn(min = 72.dp),
|
||||
contentAlignment = Alignment.CenterStart,
|
||||
) { content() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RowContent(icon: ImageVector?, title: String, summary: String?, trailing: (@Composable () -> Unit)?) {
|
||||
Row(Modifier.fillMaxWidth().padding(horizontal = WSpace.s16, vertical = WSpace.s16), verticalAlignment = Alignment.CenterVertically) {
|
||||
if (icon != null) {
|
||||
Box(Modifier.size(40.dp).clip(CircleShape).background(MaterialTheme.colorScheme.primaryContainer), contentAlignment = Alignment.Center) {
|
||||
Icon(icon, null, tint = MaterialTheme.colorScheme.onPrimaryContainer, modifier = Modifier.size(22.dp))
|
||||
}
|
||||
Spacer(Modifier.width(WSpace.s16))
|
||||
}
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(title, style = WType.body, color = MaterialTheme.colorScheme.onSurface)
|
||||
if (summary != null) Text(summary, style = WType.bodySm, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
if (trailing != null) { Spacer(Modifier.width(WSpace.s12)); trailing() }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsItem(shape: Shape, title: String, summary: String? = null, icon: ImageVector? = null, onClick: (() -> Unit)? = null, trailing: (@Composable () -> Unit)? = null) {
|
||||
Tile(shape, if (onClick != null) Modifier.clip(shape).clickable(onClick = onClick) else Modifier) { RowContent(icon, title, summary, trailing) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsSwitch(shape: Shape, title: String, checked: Boolean, onChange: (Boolean) -> Unit, summary: String? = null, icon: ImageVector? = null) {
|
||||
Tile(shape, Modifier.clip(shape).toggleable(checked, role = Role.Switch, onValueChange = onChange)) {
|
||||
RowContent(icon, title, summary) {
|
||||
Switch(
|
||||
checked, onCheckedChange = null,
|
||||
thumbContent = if (checked) { { Icon(Icons.Rounded.Check, null, Modifier.size(SwitchDefaults.IconSize)) } } else null,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A tile whose value is picked from a list in a dialog, like Pixel's radio settings. */
|
||||
@Composable
|
||||
fun <T> SettingsChoice(shape: Shape, title: String, options: List<T>, selected: T, label: (T) -> String, onPick: (T) -> Unit, icon: ImageVector? = null) {
|
||||
var open by remember { mutableStateOf(false) }
|
||||
SettingsItem(shape, title, label(selected), icon, onClick = { open = true })
|
||||
if (open) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { open = false },
|
||||
title = { Text(title) },
|
||||
text = {
|
||||
Column(Modifier.selectableGroup()) {
|
||||
options.forEach { o ->
|
||||
Row(
|
||||
Modifier.fillMaxWidth().clip(RoundedCornerShape(12.dp))
|
||||
.selectable(o == selected, role = Role.RadioButton) { onPick(o); open = false }
|
||||
.padding(vertical = WSpace.s12, horizontal = WSpace.s4),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
RadioButton(o == selected, onClick = null)
|
||||
Spacer(Modifier.width(WSpace.s16))
|
||||
Text(label(o), style = WType.body)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = { TextButton(onClick = { open = false }) { Text(androidx.compose.ui.res.stringResource(android.R.string.cancel)) } },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Free content inside a group tile (swatches, sliders). */
|
||||
@Composable
|
||||
fun SettingsCustom(shape: Shape, content: @Composable ColumnScope.() -> Unit) {
|
||||
Tile(shape) { Column(Modifier.fillMaxWidth().padding(WSpace.s16), content = content) }
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
package app.wetter.ui.scene
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.LinearEasing
|
||||
import androidx.compose.animation.core.infiniteRepeatable
|
||||
import androidx.compose.animation.core.rememberInfiniteTransition
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.withFrameNanos
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -51,19 +50,22 @@ data class SceneSpec(val condition: Condition, val isDay: Boolean, val intensity
|
||||
* [animate] false draws one still frame (battery saver, reduced motion, setting off).
|
||||
*/
|
||||
@Composable
|
||||
fun WeatherScene(spec: SceneSpec, modifier: Modifier = Modifier, animate: Boolean = true, scroll: Float = 0f) {
|
||||
fun WeatherScene(spec: SceneSpec, modifier: Modifier = Modifier, animate: Boolean = true, scroll: () -> Float = { 0f }) {
|
||||
val top by animateColorAsState(spec.top, tween(600), label = "top")
|
||||
val bottom by animateColorAsState(spec.bottom, tween(600), label = "bottom")
|
||||
val t = if (animate) {
|
||||
val transition = rememberInfiniteTransition(label = "scene")
|
||||
val v by transition.animateFloat(0f, 1f, infiniteRepeatable(tween(60_000, easing = LinearEasing)), label = "t")
|
||||
v
|
||||
} else 0.2f
|
||||
// Read only inside the draw lambda: a new frame redraws the canvas, it never recomposes.
|
||||
val time = remember { mutableFloatStateOf(0.2f) }
|
||||
if (animate) {
|
||||
LaunchedEffect(Unit) {
|
||||
val start = withFrameNanos { it }
|
||||
while (true) withFrameNanos { time.floatValue = ((it - start) / 60e9f + 0.2f) % 1f }
|
||||
}
|
||||
}
|
||||
val particles = remember(spec.condition) { Particles.make(spec.condition) }
|
||||
|
||||
Canvas(modifier.fillMaxSize()) {
|
||||
drawRect(Brush.verticalGradient(listOf(top, bottom)))
|
||||
drawSceneLayers(spec, t, scroll, particles)
|
||||
drawSceneLayers(spec, time.floatValue, scroll(), particles)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,14 +139,17 @@ fun DrawScope.drawSceneLayers(spec: SceneSpec, t: Float, scroll: Float, particle
|
||||
}
|
||||
}
|
||||
|
||||
private val hillPath = Path()
|
||||
|
||||
private fun DrawScope.drawHill(color: Color, baseY: Float, amp: Float, wavelength: Float, phase: Float) {
|
||||
val w = size.width
|
||||
val path = Path().apply {
|
||||
val path = hillPath.apply {
|
||||
rewind()
|
||||
moveTo(0f, size.height)
|
||||
var x = 0f
|
||||
while (x <= w + 8f) {
|
||||
lineTo(x, baseY - amp * sin(x / wavelength * 2 * PI.toFloat() + phase * .2f))
|
||||
x += 8f
|
||||
x += 16f
|
||||
}
|
||||
lineTo(w, size.height)
|
||||
close()
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package app.wetter.ui.screens
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.wetter.R
|
||||
import app.wetter.data.Fmt
|
||||
import app.wetter.data.Graph
|
||||
import app.wetter.data.Settings
|
||||
import app.wetter.data.Units
|
||||
import app.wetter.data.conditionOf
|
||||
import app.wetter.ui.components.DailyCapsules
|
||||
import app.wetter.ui.components.HourlyStrip
|
||||
import app.wetter.ui.components.conditionLabel
|
||||
import app.wetter.ui.scene.WeatherIcon
|
||||
import app.wetter.ui.theme.WSpace
|
||||
import app.wetter.ui.theme.WType
|
||||
import java.time.LocalDate
|
||||
|
||||
/** S04: one day, picked from the capsule row. */
|
||||
@Composable
|
||||
fun DayScreen(locationId: Long, initialDate: LocalDate, settings: Settings, onBack: () -> Unit) {
|
||||
val forecast by remember(locationId) { Graph.repo.forecast(locationId) }.collectAsState(initial = null)
|
||||
val location by produceState<app.wetter.data.LocationEntity?>(null, locationId) { value = Graph.repo.location(locationId) }
|
||||
val f = forecast ?: return
|
||||
DayContent(f, location?.name?.ifBlank { null }, initialDate, settings, onBack)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DayContent(f: app.wetter.data.Forecast, placeName: String?, initialDate: LocalDate, settings: Settings, onBack: () -> Unit) {
|
||||
var date by rememberSaveable { mutableStateOf(initialDate.toEpochDay()) }
|
||||
val units = remember(settings) { Units(settings) }
|
||||
val day = f.daily.firstOrNull { it.date.toEpochDay() == date } ?: f.daily.first()
|
||||
val cond = conditionOf(day.code)
|
||||
val onBg = MaterialTheme.colorScheme.onBackground
|
||||
|
||||
Box(Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background)) {
|
||||
LazyColumn(
|
||||
Modifier.fillMaxSize(),
|
||||
contentPadding = PaddingValues(bottom = WSpace.s32),
|
||||
verticalArrangement = Arrangement.spacedBy(WSpace.s16),
|
||||
) {
|
||||
item {
|
||||
Row(Modifier.statusBarsPadding().height(64.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Rounded.ArrowBack, stringResource(R.string.back), tint = onBg) }
|
||||
Text(stringResource(R.string.daily), style = WType.headline, color = onBg)
|
||||
}
|
||||
}
|
||||
item { DailyCapsules(f.daily, units, selected = day.date, asSection = false) { date = it.date.toEpochDay() } }
|
||||
item {
|
||||
Column(Modifier.padding(horizontal = WSpace.s24)) {
|
||||
Text(Fmt.longDate(day.date), style = WType.bodySm, color = onBg)
|
||||
Text(placeName ?: stringResource(R.string.current_location), style = WType.headline, color = onBg)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text("${units.temp(day.tMax)}/${units.temp(day.tMin)}", style = WType.dayRange, color = onBg)
|
||||
Spacer(Modifier.width(WSpace.s8))
|
||||
WeatherIcon(cond, true, 56.dp)
|
||||
}
|
||||
Text(stringResource(conditionLabel(cond, true)), style = WType.body, color = onBg)
|
||||
}
|
||||
}
|
||||
item {
|
||||
val hours = if (day.date == f.now.toLocalDate()) f.upcomingHours(24).filter { it.time.toLocalDate() == day.date } else f.hoursOf(day.date)
|
||||
HourlyStrip(hours, units, Modifier.padding(horizontal = WSpace.s16).widthIn(max = 720.dp), markNow = day.date == f.now.toLocalDate())
|
||||
}
|
||||
item {
|
||||
// the day's own values for the tiles that make sense per day
|
||||
val dayHours = f.hoursOf(day.date)
|
||||
val noon = dayHours.getOrNull(12)
|
||||
val cur = if (day.date == f.now.toLocalDate() || noon == null) f.current else f.current.copy(
|
||||
temp = noon.temp, code = noon.code, isDay = true, humidity = noon.humidity, windSpeed = noon.windSpeed, uv = day.uvMax,
|
||||
)
|
||||
app.wetter.ui.components.DetailGrid(
|
||||
cur, day, if (day.date == f.now.toLocalDate()) f.air else null, units,
|
||||
if (day.date == f.now.toLocalDate()) f.now else day.date.atTime(12, 0),
|
||||
Modifier.padding(horizontal = WSpace.s16).navigationBarsPadding().widthIn(max = 720.dp).fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,320 @@
|
||||
package app.wetter.ui.screens
|
||||
|
||||
import android.Manifest
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.FormatListBulleted
|
||||
import androidx.compose.material.icons.rounded.LocationOn
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.wetter.R
|
||||
import app.wetter.data.Forecast
|
||||
import app.wetter.data.Graph
|
||||
import app.wetter.data.LocationEntity
|
||||
import app.wetter.data.RefreshResult
|
||||
import app.wetter.data.Settings
|
||||
import app.wetter.data.Units
|
||||
import app.wetter.data.WeatherRepository
|
||||
import app.wetter.data.conditionOf
|
||||
import app.wetter.data.intensityOf
|
||||
import app.wetter.ui.components.BriefCard
|
||||
import app.wetter.ui.components.DailyCapsules
|
||||
import app.wetter.ui.components.DetailGrid
|
||||
import app.wetter.ui.components.HeroBlock
|
||||
import app.wetter.ui.components.HourlyStrip
|
||||
import app.wetter.ui.components.NowcastCard
|
||||
import app.wetter.ui.components.StatusChip
|
||||
import app.wetter.ui.components.buildBrief
|
||||
import app.wetter.ui.components.minutesAgo
|
||||
import app.wetter.ui.scene.SceneSpec
|
||||
import app.wetter.ui.scene.WeatherScene
|
||||
import app.wetter.ui.theme.LocalWeatherColors
|
||||
import app.wetter.ui.theme.WColor
|
||||
import app.wetter.ui.theme.WSpace
|
||||
import app.wetter.ui.theme.WType
|
||||
import kotlinx.coroutines.launch
|
||||
import java.time.LocalDate
|
||||
|
||||
/** S01: one page per saved location, swipe between them. */
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
settings: Settings,
|
||||
initialLocationId: Long?,
|
||||
animate: Boolean,
|
||||
onOpenLocations: () -> Unit,
|
||||
onOpenSettings: () -> Unit,
|
||||
onOpenDay: (Long, LocalDate) -> Unit,
|
||||
) {
|
||||
val repo = Graph.repo
|
||||
val locations by repo.locations.collectAsState(initial = null)
|
||||
val context = LocalContext.current
|
||||
var permissionAsked by remember { mutableStateOf(Graph.device.hasPermission()) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
|
||||
permissionAsked = true
|
||||
scope.launch { repo.updateCurrentLocation()?.let { repo.refresh(it, force = true) } }
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) { repo.refreshAll() }
|
||||
|
||||
val list = locations
|
||||
when {
|
||||
list == null -> Box(Modifier.fillMaxSize().background(WColor.sceneClearDayBottom))
|
||||
list.isEmpty() -> PermissionPrompt(
|
||||
onAllow = { launcher.launch(arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.POST_NOTIFICATIONS)) },
|
||||
onSearch = onOpenLocations,
|
||||
asked = permissionAsked && !Graph.device.hasPermission(),
|
||||
)
|
||||
else -> {
|
||||
val start = list.indexOfFirst { it.id == initialLocationId }.coerceAtLeast(0)
|
||||
val pager = rememberPagerState(initialPage = start) { list.size }
|
||||
LaunchedEffect(initialLocationId, list.size) {
|
||||
val i = list.indexOfFirst { it.id == initialLocationId }
|
||||
if (i >= 0 && i != pager.currentPage) pager.scrollToPage(i)
|
||||
}
|
||||
HorizontalPager(pager, Modifier.fillMaxSize(), key = { list[it].id }) { page ->
|
||||
LocationPage(
|
||||
location = list[page],
|
||||
settings = settings,
|
||||
animate = animate && page == pager.currentPage,
|
||||
pageCount = list.size,
|
||||
page = page,
|
||||
onOpenLocations = onOpenLocations,
|
||||
onOpenSettings = onOpenSettings,
|
||||
onOpenDay = { onOpenDay(list[page].id, it) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun LocationPage(
|
||||
location: LocationEntity,
|
||||
settings: Settings,
|
||||
animate: Boolean,
|
||||
pageCount: Int,
|
||||
page: Int,
|
||||
onOpenLocations: () -> Unit,
|
||||
onOpenSettings: () -> Unit,
|
||||
onOpenDay: (LocalDate) -> Unit,
|
||||
) {
|
||||
val repo = Graph.repo
|
||||
val forecast by remember(location.id) { repo.forecast(location.id) }.collectAsState(initial = null)
|
||||
var refreshing by remember { mutableStateOf(false) }
|
||||
var error by remember { mutableStateOf<Throwable?>(null) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val refresh: (Boolean) -> Unit = { force ->
|
||||
scope.launch {
|
||||
refreshing = force
|
||||
error = (repo.refresh(location, force) as? RefreshResult.Failed)?.error
|
||||
refreshing = false
|
||||
}
|
||||
}
|
||||
LaunchedEffect(location.id) { refresh(false) }
|
||||
|
||||
val f = forecast
|
||||
val name = location.name.ifBlank { stringResource(R.string.current_location) }
|
||||
ForecastPage(
|
||||
title = name,
|
||||
isCurrent = location.isCurrent,
|
||||
forecast = f,
|
||||
settings = settings,
|
||||
animate = animate,
|
||||
refreshing = refreshing,
|
||||
error = error,
|
||||
onRefresh = { refresh(true) },
|
||||
navigation = {
|
||||
IconButton(onClick = onOpenLocations) { Icon(Icons.Rounded.FormatListBulleted, stringResource(R.string.open_locations)) }
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = onOpenSettings) { Icon(Icons.Rounded.Settings, stringResource(R.string.settings)) }
|
||||
},
|
||||
pageIndicator = { if (pageCount > 1) PageDots(pageCount, page, it) },
|
||||
onOpenDay = onOpenDay,
|
||||
)
|
||||
}
|
||||
|
||||
/** Shared by S01 and the unsaved preview S15. */
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ForecastPage(
|
||||
title: String,
|
||||
isCurrent: Boolean,
|
||||
forecast: Forecast?,
|
||||
settings: Settings,
|
||||
animate: Boolean,
|
||||
refreshing: Boolean,
|
||||
error: Throwable?,
|
||||
onRefresh: () -> Unit,
|
||||
navigation: @Composable () -> Unit,
|
||||
actions: @Composable () -> Unit,
|
||||
pageIndicator: @Composable (Color) -> Unit = {},
|
||||
onOpenDay: ((LocalDate) -> Unit)? = null,
|
||||
) {
|
||||
val units = remember(settings) { Units(settings) }
|
||||
val res = LocalContext.current.resources
|
||||
val spec = forecast?.let { SceneSpec(conditionOf(it.current.code), it.current.isDay, intensityOf(it.current.code)) }
|
||||
?: SceneSpec(app.wetter.data.Condition.CLOUDY, true)
|
||||
val listState = rememberLazyListState()
|
||||
val fg = spec.onScene
|
||||
val failed = error != null
|
||||
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
WeatherScene(spec, animate = animate && settings.animations, scroll = {
|
||||
if (listState.firstVisibleItemIndex == 0) listState.firstVisibleItemScrollOffset.toFloat() else 2000f
|
||||
})
|
||||
PullToRefreshBox(isRefreshing = refreshing, onRefresh = onRefresh, modifier = Modifier.fillMaxSize()) {
|
||||
LazyColumn(
|
||||
state = listState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentPadding = PaddingValues(start = WSpace.s16, end = WSpace.s16, bottom = WSpace.s32),
|
||||
verticalArrangement = Arrangement.spacedBy(WSpace.s12),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
item(key = "bar") {
|
||||
Row(Modifier.fillMaxWidth().statusBarsPadding().height(64.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
androidx.compose.runtime.CompositionLocalProvider(androidx.compose.material3.LocalContentColor provides fg) {
|
||||
navigation()
|
||||
Row(Modifier.weight(1f), horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
|
||||
if (isCurrent) Icon(Icons.Rounded.LocationOn, null, Modifier.size(18.dp), tint = fg)
|
||||
Text(title, style = WType.headline, color = fg, maxLines = 1, overflow = TextOverflow.Ellipsis, textAlign = TextAlign.Center)
|
||||
}
|
||||
actions()
|
||||
}
|
||||
}
|
||||
}
|
||||
if (forecast == null) {
|
||||
item(key = "loading") {
|
||||
Column(Modifier.padding(top = 120.dp), horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
if (failed) {
|
||||
Text(stringResource(errorText(error)), color = fg, style = WType.body, textAlign = TextAlign.Center)
|
||||
TextButton(onClick = onRefresh) { Text(stringResource(R.string.retry), color = fg) }
|
||||
} else CircularProgressIndicator(color = fg)
|
||||
}
|
||||
}
|
||||
return@LazyColumn
|
||||
}
|
||||
item(key = "hero") {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
HeroBlock(title, forecast, units, fg, Modifier.widthIn(max = 560.dp))
|
||||
pageIndicator(fg)
|
||||
val age = minutesAgo(forecast.fetchedAt)
|
||||
if (failed || age >= 60) {
|
||||
StatusChip(
|
||||
when {
|
||||
failed -> stringResource(R.string.offline)
|
||||
age >= 120 -> stringResource(R.string.updated_hours, age / 60)
|
||||
else -> stringResource(R.string.updated_ago, age)
|
||||
},
|
||||
fg,
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.height(WSpace.s16))
|
||||
}
|
||||
}
|
||||
val max = Modifier.widthIn(max = 720.dp)
|
||||
if (settings.brief) item(key = "brief") { BriefCard(remember(forecast, settings) { buildBrief(res, forecast, units) }, max) }
|
||||
item(key = "nowcast") { NowcastCard(forecast.minutely, forecast, max) }
|
||||
item(key = "hourly") { HourlyStrip(forecast.upcomingHours(25), units, max) }
|
||||
item(key = "daily") { DailyCapsules(forecast.daily, units, max) { d -> onOpenDay?.invoke(d.date) } }
|
||||
item(key = "details") {
|
||||
DetailGrid(forecast.current, forecast.today, forecast.air, units, forecast.now, max.navigationBarsPadding())
|
||||
}
|
||||
item(key = "attribution") {
|
||||
Text(stringResource(R.string.attribution), style = WType.labelSm, color = fg.copy(alpha = .8f), textAlign = TextAlign.Center, modifier = Modifier.padding(top = WSpace.s16))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PageDots(count: Int, current: Int, color: Color) {
|
||||
Row(Modifier.padding(top = WSpace.s4), horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
repeat(count) { i ->
|
||||
Box(
|
||||
Modifier.height(8.dp).width(if (i == current) 20.dp else 8.dp).clip(RoundedCornerShape(4.dp))
|
||||
.background(color.copy(alpha = if (i == current) .9f else .35f))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PermissionPrompt(onAllow: () -> Unit, onSearch: () -> Unit, asked: Boolean) {
|
||||
val spec = SceneSpec(app.wetter.data.Condition.PARTLY_CLOUDY, true)
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
WeatherScene(spec)
|
||||
Column(
|
||||
Modifier.align(Alignment.Center).padding(WSpace.s32).clip(RoundedCornerShape(28.dp)).background(LocalWeatherColors.current.card).padding(WSpace.s24),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
app.wetter.ui.scene.WeatherIcon(app.wetter.data.Condition.PARTLY_CLOUDY, true, 72.dp)
|
||||
Spacer(Modifier.height(WSpace.s16))
|
||||
Text(stringResource(R.string.perm_title), style = WType.headline, color = LocalWeatherColors.current.onCard, textAlign = TextAlign.Center)
|
||||
Spacer(Modifier.height(WSpace.s8))
|
||||
Text(stringResource(R.string.perm_body), style = WType.bodySm, color = LocalWeatherColors.current.onCardMuted, textAlign = TextAlign.Center)
|
||||
Spacer(Modifier.height(WSpace.s24))
|
||||
if (!asked) Button(onClick = onAllow) { Text(stringResource(R.string.perm_allow)) }
|
||||
FilledTonalButton(onClick = onSearch) { Text(stringResource(R.string.perm_search)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@androidx.annotation.StringRes
|
||||
private fun errorText(error: Throwable?): Int = when {
|
||||
error is app.wetter.data.HttpException && (error.code == 429 || error.code >= 500) -> R.string.loading_error_busy
|
||||
error is java.net.UnknownHostException || error is java.net.ConnectException || error is java.net.SocketTimeoutException -> R.string.loading_error_offline
|
||||
else -> R.string.loading_error
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
package app.wetter.ui.screens
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
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.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
|
||||
import androidx.compose.material.icons.rounded.Close
|
||||
import androidx.compose.material.icons.rounded.Delete
|
||||
import androidx.compose.material.icons.rounded.LocationOn
|
||||
import androidx.compose.material.icons.rounded.Search
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.SnackbarResult
|
||||
import androidx.compose.material3.SwipeToDismissBox
|
||||
import androidx.compose.material3.SwipeToDismissBoxValue
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.rememberSwipeToDismissBoxState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.CustomAccessibilityAction
|
||||
import androidx.compose.ui.semantics.customActions
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.wetter.R
|
||||
import app.wetter.data.Graph
|
||||
import app.wetter.data.LocationEntity
|
||||
import app.wetter.data.Place
|
||||
import app.wetter.data.Settings
|
||||
import app.wetter.data.Units
|
||||
import app.wetter.data.conditionOf
|
||||
import app.wetter.ui.components.conditionLabel
|
||||
import app.wetter.ui.scene.SceneSpec
|
||||
import app.wetter.ui.scene.WeatherIcon
|
||||
import app.wetter.ui.theme.WRadius
|
||||
import app.wetter.ui.theme.WSpace
|
||||
import app.wetter.ui.theme.WType
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
private sealed interface SearchState {
|
||||
data object Idle : SearchState
|
||||
data object Loading : SearchState
|
||||
data class Results(val places: List<Place>) : SearchState
|
||||
data object Error : SearchState
|
||||
}
|
||||
|
||||
/** S02 saved locations + S03 search in one screen: typing swaps the list for results. */
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LocationsScreen(settings: Settings, onBack: () -> Unit, onOpen: (Long) -> Unit, onPreview: (Place) -> Unit) {
|
||||
val repo = Graph.repo
|
||||
val locations by repo.locations.collectAsState(initial = emptyList())
|
||||
var query by rememberSaveable { mutableStateOf("") }
|
||||
var state by remember { mutableStateOf<SearchState>(SearchState.Idle) }
|
||||
var attempt by remember { mutableStateOf(0) }
|
||||
val snackbar = remember { SnackbarHostState() }
|
||||
val scope = rememberCoroutineScope()
|
||||
val units = remember(settings) { Units(settings) }
|
||||
val deletedText = stringResource(R.string.deleted, "%s")
|
||||
val undoText = stringResource(R.string.undo)
|
||||
|
||||
LaunchedEffect(query, attempt) {
|
||||
if (query.trim().length < 2) { state = SearchState.Idle; return@LaunchedEffect }
|
||||
delay(300)
|
||||
state = SearchState.Loading
|
||||
state = runCatching { SearchState.Results(repo.search(query)) }.getOrElse { SearchState.Error }
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(R.string.locations)) },
|
||||
navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Rounded.ArrowBack, stringResource(R.string.back)) } },
|
||||
)
|
||||
},
|
||||
snackbarHost = { SnackbarHost(snackbar) },
|
||||
) { pad ->
|
||||
Column(Modifier.padding(pad).fillMaxSize()) {
|
||||
OutlinedTextField(
|
||||
value = query,
|
||||
onValueChange = { query = it },
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = WSpace.s16),
|
||||
placeholder = { Text(stringResource(R.string.search_hint)) },
|
||||
leadingIcon = { Icon(Icons.Rounded.Search, null) },
|
||||
trailingIcon = {
|
||||
if (query.isNotEmpty()) IconButton(onClick = { query = "" }) { Icon(Icons.Rounded.Close, null) }
|
||||
},
|
||||
singleLine = true,
|
||||
shape = RoundedCornerShape(WRadius.pill),
|
||||
)
|
||||
if (state == SearchState.Loading) LinearProgressIndicator(Modifier.fillMaxWidth().padding(horizontal = WSpace.s32, vertical = WSpace.s4))
|
||||
else Spacer(Modifier.height(WSpace.s12))
|
||||
|
||||
when (val s = state) {
|
||||
is SearchState.Results -> if (s.places.isEmpty()) {
|
||||
Text(stringResource(R.string.search_empty), Modifier.padding(WSpace.s24), style = WType.body)
|
||||
} else LazyColumn(contentPadding = PaddingValues(bottom = WSpace.s24)) {
|
||||
items(s.places, key = { "${it.lat},${it.lon}" }) { p ->
|
||||
Column(
|
||||
Modifier.fillMaxWidth().clickable { onPreview(p) }.padding(horizontal = WSpace.s24, vertical = WSpace.s12)
|
||||
) {
|
||||
Text(p.name, style = WType.body)
|
||||
Text(listOfNotNull(p.admin, p.countryCode).joinToString(", "), style = WType.bodySm, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
}
|
||||
SearchState.Error -> Column(Modifier.padding(WSpace.s24)) {
|
||||
Text(stringResource(R.string.search_error), style = WType.body)
|
||||
TextButton(onClick = { attempt++ }) { Text(stringResource(R.string.retry)) }
|
||||
}
|
||||
else -> LazyColumn(
|
||||
contentPadding = PaddingValues(start = WSpace.s16, end = WSpace.s16, bottom = WSpace.s24),
|
||||
verticalArrangement = Arrangement.spacedBy(WSpace.s8),
|
||||
) {
|
||||
items(locations, key = { it.id }) { loc ->
|
||||
val name = loc.name.ifBlank { stringResource(R.string.current_location) }
|
||||
val delete = {
|
||||
scope.launch {
|
||||
repo.delete(loc.id)
|
||||
val r = snackbar.showSnackbar(deletedText.format(name), undoText, duration = SnackbarDuration.Short)
|
||||
if (r == SnackbarResult.ActionPerformed) repo.save(Place(loc.name, loc.admin, loc.countryCode, loc.lat, loc.lon, loc.timezone))
|
||||
}
|
||||
Unit
|
||||
}
|
||||
if (loc.isCurrent) CityRow(loc, name, units) { onOpen(loc.id) }
|
||||
else SwipeRow(onDelete = delete) {
|
||||
val deleteLabel = stringResource(R.string.delete)
|
||||
CityRow(loc, name, units, Modifier.semantics {
|
||||
customActions = listOf(CustomAccessibilityAction(deleteLabel) { delete(); true })
|
||||
}) { onOpen(loc.id) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun SwipeRow(onDelete: () -> Unit, content: @Composable () -> Unit) {
|
||||
val state = rememberSwipeToDismissBoxState()
|
||||
LaunchedEffect(state.currentValue) {
|
||||
if (state.currentValue != SwipeToDismissBoxValue.Settled) {
|
||||
onDelete()
|
||||
state.snapTo(SwipeToDismissBoxValue.Settled)
|
||||
}
|
||||
}
|
||||
SwipeToDismissBox(
|
||||
state = state,
|
||||
backgroundContent = {
|
||||
val color by animateColorAsState(
|
||||
if (state.targetValue == SwipeToDismissBoxValue.Settled) MaterialTheme.colorScheme.surfaceContainer else MaterialTheme.colorScheme.error,
|
||||
label = "swipe",
|
||||
)
|
||||
Box(
|
||||
Modifier.fillMaxSize().clip(RoundedCornerShape(WRadius.lg)).background(color).padding(horizontal = WSpace.s24),
|
||||
contentAlignment = Alignment.CenterEnd,
|
||||
) { Icon(Icons.Rounded.Delete, null, tint = MaterialTheme.colorScheme.onError) }
|
||||
},
|
||||
) { content() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CityRow(loc: LocationEntity, name: String, units: Units, modifier: Modifier = Modifier, onClick: () -> Unit) {
|
||||
val forecast by remember(loc.id) { Graph.repo.forecast(loc.id) }.collectAsState(initial = null)
|
||||
val f = forecast
|
||||
val spec = f?.let { SceneSpec(conditionOf(it.current.code), it.current.isDay) } ?: SceneSpec(app.wetter.data.Condition.CLOUDY, true)
|
||||
val fg = spec.onScene
|
||||
Row(
|
||||
modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(WRadius.lg))
|
||||
.background(Brush.horizontalGradient(listOf(spec.top, spec.bottom)))
|
||||
.clickable(onClick = onClick)
|
||||
.padding(horizontal = WSpace.s20, vertical = WSpace.s16),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
if (loc.isCurrent) { Icon(Icons.Rounded.LocationOn, null, Modifier.size(16.dp), tint = fg); Spacer(Modifier.width(4.dp)) }
|
||||
Text(name, style = WType.title, color = fg, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
if (f != null) {
|
||||
Text(
|
||||
stringResource(conditionLabel(conditionOf(f.current.code), f.current.isDay)) +
|
||||
(f.today?.let { " · ${units.temp(it.tMax)} / ${units.temp(it.tMin)}" } ?: ""),
|
||||
style = WType.bodySm, color = fg,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (f != null) {
|
||||
WeatherIcon(conditionOf(f.current.code), f.current.isDay, 36.dp)
|
||||
Spacer(Modifier.width(WSpace.s8))
|
||||
Text(units.temp(f.current.temp), style = WType.metric, color = fg)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package app.wetter.ui.screens
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import app.wetter.R
|
||||
import app.wetter.data.Forecast
|
||||
import app.wetter.data.Graph
|
||||
import app.wetter.data.Place
|
||||
import app.wetter.data.Settings
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/** S15: a searched place, shown in full before it is saved. */
|
||||
@Composable
|
||||
fun PreviewScreen(place: Place, settings: Settings, onBack: () -> Unit, onSaved: (Long) -> Unit) {
|
||||
var forecast by remember { mutableStateOf<Forecast?>(null) }
|
||||
var error by remember { mutableStateOf<Throwable?>(null) }
|
||||
var attempt by remember { mutableStateOf(0) }
|
||||
val scope = rememberCoroutineScope()
|
||||
LaunchedEffect(place, attempt) {
|
||||
error = null
|
||||
runCatching { Graph.repo.preview(place) }.onSuccess { forecast = it }.onFailure { error = it }
|
||||
}
|
||||
ForecastPage(
|
||||
title = place.name,
|
||||
isCurrent = false,
|
||||
forecast = forecast,
|
||||
settings = settings,
|
||||
animate = true,
|
||||
refreshing = false,
|
||||
error = error,
|
||||
onRefresh = { attempt++ },
|
||||
navigation = { IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Rounded.ArrowBack, stringResource(R.string.back)) } },
|
||||
actions = {
|
||||
FilledTonalButton(onClick = { scope.launch { onSaved(Graph.repo.save(place)) } }) { Text(stringResource(R.string.save)) }
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package app.wetter.ui.screens
|
||||
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
|
||||
import androidx.compose.material.icons.outlined.Air
|
||||
import androidx.compose.material.icons.outlined.AutoAwesome
|
||||
import androidx.compose.material.icons.outlined.Compress
|
||||
import androidx.compose.material.icons.outlined.DarkMode
|
||||
import androidx.compose.material.icons.outlined.Info
|
||||
import androidx.compose.material.icons.outlined.Notes
|
||||
import androidx.compose.material.icons.outlined.Thermostat
|
||||
import androidx.compose.material.icons.outlined.Umbrella
|
||||
import androidx.compose.material.icons.outlined.Visibility
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.LargeTopAppBar
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.rememberTopAppBarState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import app.wetter.R
|
||||
import app.wetter.data.DistanceUnit
|
||||
import app.wetter.data.Graph
|
||||
import app.wetter.data.PrecipUnit
|
||||
import app.wetter.data.PressureUnit
|
||||
import app.wetter.data.Settings
|
||||
import app.wetter.data.TempUnit
|
||||
import app.wetter.data.ThemeMode
|
||||
import app.wetter.data.WindUnit
|
||||
import app.wetter.ui.components.SettingsChoice
|
||||
import app.wetter.ui.components.SettingsGroup
|
||||
import app.wetter.ui.components.SettingsItem
|
||||
import app.wetter.ui.components.SettingsSwitch
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/** S08 + S09: units, look, data sources. */
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsScreen(settings: Settings, onBack: () -> Unit) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val set: ((Settings) -> Settings) -> Unit = { t -> scope.launch { Graph.settings.update(t) } }
|
||||
val bar = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState())
|
||||
val themeLabels = mapOf(
|
||||
ThemeMode.SYSTEM to stringResource(R.string.theme_system),
|
||||
ThemeMode.LIGHT to stringResource(R.string.theme_light),
|
||||
ThemeMode.DARK to stringResource(R.string.theme_dark),
|
||||
)
|
||||
Scaffold(
|
||||
modifier = Modifier.nestedScroll(bar.nestedScrollConnection),
|
||||
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||
topBar = {
|
||||
LargeTopAppBar(
|
||||
title = { Text(stringResource(R.string.settings)) },
|
||||
navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Rounded.ArrowBack, stringResource(R.string.back)) } },
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||
scrolledContainerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||
),
|
||||
scrollBehavior = bar,
|
||||
)
|
||||
},
|
||||
) { pad ->
|
||||
androidx.compose.foundation.layout.Column(Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState()).navigationBarsPadding()) {
|
||||
SettingsGroup(stringResource(R.string.set_units)) {
|
||||
item { SettingsChoice(it, stringResource(R.string.set_temp), TempUnit.entries, settings.temp, { u -> if (u == TempUnit.C) "Celsius (°C)" else "Fahrenheit (°F)" }, { v -> set { s -> s.copy(temp = v) } }, Icons.Outlined.Thermostat) }
|
||||
item {
|
||||
SettingsChoice(it, stringResource(R.string.set_wind), WindUnit.entries, settings.wind, { u ->
|
||||
when (u) { WindUnit.KMH -> "km/h"; WindUnit.MS -> "m/s"; WindUnit.MPH -> "mph"; WindUnit.KN -> "Knoten (kn)" }
|
||||
}, { v -> set { s -> s.copy(wind = v) } }, Icons.Outlined.Air)
|
||||
}
|
||||
item { SettingsChoice(it, stringResource(R.string.set_precip), PrecipUnit.entries, settings.precip, { u -> if (u == PrecipUnit.MM) "Millimeter (mm)" else "Zoll (in)" }, { v -> set { s -> s.copy(precip = v) } }, Icons.Outlined.Umbrella) }
|
||||
item { SettingsChoice(it, stringResource(R.string.set_pressure), PressureUnit.entries, settings.pressure, { u -> if (u == PressureUnit.HPA) "Hektopascal (hPa)" else "Zoll Quecksilber (inHg)" }, { v -> set { s -> s.copy(pressure = v) } }, Icons.Outlined.Compress) }
|
||||
item { SettingsChoice(it, stringResource(R.string.set_distance), DistanceUnit.entries, settings.distance, { u -> if (u == DistanceUnit.KM) "Kilometer (km)" else "Meilen (mi)" }, { v -> set { s -> s.copy(distance = v) } }, Icons.Outlined.Visibility) }
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.set_look)) {
|
||||
item { SettingsChoice(it, stringResource(R.string.set_theme), ThemeMode.entries, settings.theme, { m -> themeLabels.getValue(m) }, { v -> set { s -> s.copy(theme = v) } }, Icons.Outlined.DarkMode) }
|
||||
item { SettingsSwitch(it, stringResource(R.string.set_animations), settings.animations, { v -> set { s -> s.copy(animations = v) } }, stringResource(R.string.set_animations_sub), Icons.Outlined.AutoAwesome) }
|
||||
item { SettingsSwitch(it, stringResource(R.string.set_brief), settings.brief, { v -> set { s -> s.copy(brief = v) } }, null, Icons.Outlined.Notes) }
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.set_about)) {
|
||||
item { SettingsItem(it, stringResource(R.string.set_about), stringResource(R.string.attribution), Icons.Outlined.Info) }
|
||||
}
|
||||
androidx.compose.foundation.layout.Spacer(Modifier.padding(bottom = app.wetter.ui.theme.WSpace.s32))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,15 +63,18 @@ private val LightScheme = lightColorScheme(
|
||||
background = WColor.bg, onBackground = WColor.text,
|
||||
surface = WColor.surface, onSurface = WColor.text, onSurfaceVariant = WColor.textMuted,
|
||||
surfaceContainer = WColor.surfaceContainer, surfaceContainerHigh = WColor.surfaceContainerHigh,
|
||||
surfaceContainerLowest = WColor.surface,
|
||||
outline = WColor.borderInput, outlineVariant = WColor.border, error = WColor.danger,
|
||||
)
|
||||
|
||||
private val DarkScheme = darkColorScheme(
|
||||
primary = WColor.darkAccent, onPrimary = WColor.darkOnAccent,
|
||||
primaryContainer = WColor.darkAccentContainer, onPrimaryContainer = WColor.darkOnAccentContainer,
|
||||
secondaryContainer = WColor.darkFillPrimary, onSecondaryContainer = WColor.darkOnFillPrimary,
|
||||
background = WColor.darkBg, onBackground = WColor.darkText,
|
||||
surface = WColor.darkSurface, onSurface = WColor.darkText, onSurfaceVariant = WColor.darkTextMuted,
|
||||
surfaceContainer = WColor.darkSurfaceContainer, surfaceContainerHigh = WColor.darkSurfaceContainer,
|
||||
surfaceContainer = WColor.darkBg, surfaceContainerHigh = WColor.darkSurfaceContainer,
|
||||
surfaceContainerLowest = WColor.darkSurfaceContainer,
|
||||
outline = WColor.darkBorderInput, outlineVariant = WColor.darkBorder, error = WColor.darkDanger,
|
||||
)
|
||||
|
||||
|
||||
@@ -114,6 +114,78 @@ object WColor {
|
||||
val aqiBar6 = Color(0xFF8E24AA)
|
||||
val uvDotLow = Color(0xFF5CCF8A)
|
||||
val uvDotOff = Color(0xFF6B5A52)
|
||||
val widgetOceanLightBg = Color(0xFFCCE4F0)
|
||||
val widgetOceanLightOn = Color(0xFF0F2733)
|
||||
val widgetOceanLightAccent = Color(0xFF20546F)
|
||||
val widgetOceanLightPanel = Color(0xFFF9FAFB)
|
||||
val widgetOceanLightOnpanel = Color(0xFF192124)
|
||||
val widgetOceanLightBadge = Color(0xFFA8D1E6)
|
||||
val widgetOceanLightOnbadge = Color(0xFF0F2733)
|
||||
val widgetOceanDarkBg = Color(0xFF194257)
|
||||
val widgetOceanDarkOn = Color(0xFFDBECF5)
|
||||
val widgetOceanDarkAccent = Color(0xFFB0D5E8)
|
||||
val widgetOceanDarkPanel = Color(0xFF0E1315)
|
||||
val widgetOceanDarkOnpanel = Color(0xFFE7ECEF)
|
||||
val widgetOceanDarkBadge = Color(0xFF1F516B)
|
||||
val widgetOceanDarkOnbadge = Color(0xFFDFEEF6)
|
||||
val widgetForestLightBg = Color(0xFFD2E9DA)
|
||||
val widgetForestLightOn = Color(0xFF162D1D)
|
||||
val widgetForestLightAccent = Color(0xFF2E603F)
|
||||
val widgetForestLightPanel = Color(0xFFF9FBFA)
|
||||
val widgetForestLightOnpanel = Color(0xFF1B221D)
|
||||
val widgetForestLightBadge = Color(0xFFB3DBC0)
|
||||
val widgetForestLightOnbadge = Color(0xFF162D1D)
|
||||
val widgetForestDarkBg = Color(0xFF244C32)
|
||||
val widgetForestDarkOn = Color(0xFFE0F0E5)
|
||||
val widgetForestDarkAccent = Color(0xFFBADEC6)
|
||||
val widgetForestDarkPanel = Color(0xFF101411)
|
||||
val widgetForestDarkOnpanel = Color(0xFFE8EDEA)
|
||||
val widgetForestDarkBadge = Color(0xFF2D5D3D)
|
||||
val widgetForestDarkOnbadge = Color(0xFFE3F2E8)
|
||||
val widgetSunLightBg = Color(0xFFF7E4C5)
|
||||
val widgetSunLightOn = Color(0xFF3A2808)
|
||||
val widgetSunLightAccent = Color(0xFF7D5612)
|
||||
val widgetSunLightPanel = Color(0xFFFBFAF9)
|
||||
val widgetSunLightOnpanel = Color(0xFF272117)
|
||||
val widgetSunLightBadge = Color(0xFFF1D29D)
|
||||
val widgetSunLightOnbadge = Color(0xFF3A2808)
|
||||
val widgetSunDarkBg = Color(0xFF62430E)
|
||||
val widgetSunDarkOn = Color(0xFFF9EDD7)
|
||||
val widgetSunDarkAccent = Color(0xFFF2D6A6)
|
||||
val widgetSunDarkPanel = Color(0xFF17130D)
|
||||
val widgetSunDarkOnpanel = Color(0xFFF0ECE5)
|
||||
val widgetSunDarkBadge = Color(0xFF785311)
|
||||
val widgetSunDarkOnbadge = Color(0xFFFAEFDB)
|
||||
val widgetLavenderLightBg = Color(0xFFDBCFED)
|
||||
val widgetLavenderLightOn = Color(0xFF1F1230)
|
||||
val widgetLavenderLightAccent = Color(0xFF422768)
|
||||
val widgetLavenderLightPanel = Color(0xFFFAF9FB)
|
||||
val widgetLavenderLightOnpanel = Color(0xFF1E1A23)
|
||||
val widgetLavenderLightBadge = Color(0xFFC3AEE0)
|
||||
val widgetLavenderLightOnbadge = Color(0xFF1F1230)
|
||||
val widgetLavenderDarkBg = Color(0xFF341F51)
|
||||
val widgetLavenderDarkOn = Color(0xFFE6DEF2)
|
||||
val widgetLavenderDarkAccent = Color(0xFFC8B5E3)
|
||||
val widgetLavenderDarkPanel = Color(0xFF110F15)
|
||||
val widgetLavenderDarkOnpanel = Color(0xFFEAE7EE)
|
||||
val widgetLavenderDarkBadge = Color(0xFF402664)
|
||||
val widgetLavenderDarkOnbadge = Color(0xFFE9E1F4)
|
||||
val widgetGraphiteLightBg = Color(0xFFDBDDE1)
|
||||
val widgetGraphiteLightOn = Color(0xFF1E2124)
|
||||
val widgetGraphiteLightAccent = Color(0xFF42464D)
|
||||
val widgetGraphiteLightPanel = Color(0xFFFAFAFA)
|
||||
val widgetGraphiteLightOnpanel = Color(0xFF1E1E1F)
|
||||
val widgetGraphiteLightBadge = Color(0xFFC2C6CB)
|
||||
val widgetGraphiteLightOnbadge = Color(0xFF1E2124)
|
||||
val widgetGraphiteDarkBg = Color(0xFF34373D)
|
||||
val widgetGraphiteDarkOn = Color(0xFFE6E8EA)
|
||||
val widgetGraphiteDarkAccent = Color(0xFFC8CBD0)
|
||||
val widgetGraphiteDarkPanel = Color(0xFF111212)
|
||||
val widgetGraphiteDarkOnpanel = Color(0xFFEAEBEB)
|
||||
val widgetGraphiteDarkBadge = Color(0xFF3F444A)
|
||||
val widgetGraphiteDarkOnbadge = Color(0xFFE9EAEC)
|
||||
val darkAccentContainer = Color(0xFF244A80)
|
||||
val darkOnAccentContainer = Color(0xFFD6E3FF)
|
||||
}
|
||||
|
||||
object WType {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package app.wetter.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Build
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.ui.geometry.CornerRadius
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Canvas
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.asAndroidBitmap
|
||||
import androidx.compose.ui.graphics.drawscope.CanvasDrawScope
|
||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||
import androidx.compose.ui.graphics.drawscope.rotate
|
||||
import androidx.compose.ui.unit.Density
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
import app.wetter.data.Condition
|
||||
import app.wetter.ui.components.wavyCircle
|
||||
import app.wetter.ui.scene.drawWeatherIcon
|
||||
import app.wetter.ui.theme.WColor
|
||||
|
||||
/** Colours taken from the wallpaper (Material You) on Android 12+, our own palette below that. */
|
||||
data class WidgetPalette(
|
||||
val bg: Color,
|
||||
val onBg: Color,
|
||||
val muted: Color,
|
||||
val accent: Color,
|
||||
val panel: Color,
|
||||
val onPanel: Color,
|
||||
val badge: Color,
|
||||
val onBadge: Color,
|
||||
)
|
||||
|
||||
/** Widgets cannot draw custom shapes, so icons and shaped backgrounds are rendered to bitmaps. */
|
||||
object WidgetArt {
|
||||
private fun render(w: Int, h: Int, block: DrawScope.() -> Unit): Bitmap {
|
||||
val image = ImageBitmap(w, h)
|
||||
CanvasDrawScope().draw(Density(1f), LayoutDirection.Ltr, Canvas(image), Size(w.toFloat(), h.toFloat()), block)
|
||||
return image.asAndroidBitmap()
|
||||
}
|
||||
|
||||
fun icon(condition: Condition, isDay: Boolean, px: Int = 144): Bitmap = render(px, px) { drawWeatherIcon(condition, isDay) }
|
||||
|
||||
/** A stadium tilted by 45°, filling a square. */
|
||||
fun tiltedPill(color: Color, px: Int = 400): Bitmap = render(px, px) {
|
||||
rotate(-45f) {
|
||||
val w = size.width * .92f
|
||||
val h = size.height * .48f
|
||||
drawRoundRect(color, Offset((size.width - w) / 2, (size.height - h) / 2), Size(w, h), CornerRadius(h / 2))
|
||||
}
|
||||
}
|
||||
|
||||
/** Scalloped "cookie" badge. */
|
||||
fun cookie(color: Color, px: Int = 240): Bitmap = render(px, px) {
|
||||
drawPath(wavyCircle(center, size.minDimension * .44f, 10, size.minDimension * .035f), color)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
package app.wetter.widget
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.FrameLayout
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Check
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FilterChip
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.selected
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.DpSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.glance.appwidget.GlanceAppWidget
|
||||
import androidx.glance.appwidget.GlanceAppWidgetManager
|
||||
import androidx.glance.appwidget.compose
|
||||
import app.wetter.R
|
||||
import app.wetter.data.Graph
|
||||
import app.wetter.data.Settings
|
||||
import app.wetter.data.WidgetConfigEntity
|
||||
import app.wetter.ui.theme.WSpace
|
||||
import app.wetter.ui.theme.WType
|
||||
import app.wetter.ui.theme.WeatherTheme
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
import androidx.compose.material.icons.outlined.DarkMode
|
||||
import androidx.compose.material.icons.outlined.LocationOn
|
||||
import androidx.compose.material3.Slider
|
||||
import app.wetter.ui.components.SettingsChoice
|
||||
import app.wetter.ui.components.SettingsCustom
|
||||
import app.wetter.ui.components.SettingsGroup
|
||||
import app.wetter.ui.components.WShapes
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/** Opens when a widget is added, and again from the launcher's "customise widget". */
|
||||
class WidgetConfigActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
Graph.init(this)
|
||||
val appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
|
||||
// backing out leaves the widget unplaced, as the platform expects
|
||||
setResult(RESULT_CANCELED, Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId))
|
||||
if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); return }
|
||||
val provider = AppWidgetManager.getInstance(this).getAppWidgetInfo(appWidgetId)?.provider?.className.orEmpty()
|
||||
val (widget, size) = widgetFor(provider)
|
||||
|
||||
setContent {
|
||||
val settings by Graph.settings.settings.collectAsState(initial = Settings())
|
||||
WeatherTheme(settings.theme) {
|
||||
ConfigScreen(appWidgetId, widget, size) { config ->
|
||||
lifecycleScope.launch {
|
||||
Graph.repo.saveWidgetConfig(config)
|
||||
runCatching { widget.update(this@WidgetConfigActivity, GlanceAppWidgetManager(this@WidgetConfigActivity).getGlanceIdBy(appWidgetId)) }
|
||||
setResult(RESULT_OK, Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId))
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun widgetFor(providerClass: String): Pair<GlanceAppWidget, DpSize> = when {
|
||||
providerClass.endsWith("PillReceiver") -> PillWidget() to DpSize(300.dp, 130.dp)
|
||||
providerClass.endsWith("TiltReceiver") -> TiltWidget() to DpSize(170.dp, 170.dp)
|
||||
providerClass.endsWith("BarReceiver") -> BarWidget() to DpSize(320.dp, 84.dp)
|
||||
providerClass.endsWith("ClassicReceiver") -> ClassicWidget() to DpSize(320.dp, 160.dp)
|
||||
else -> WeatherCardWidget() to DpSize(320.dp, 240.dp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun ConfigScreen(appWidgetId: Int, widget: GlanceAppWidget, size: DpSize, onDone: (WidgetConfigEntity) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val locations by Graph.repo.locations.collectAsState(initial = emptyList())
|
||||
var config by remember { mutableStateOf(WidgetConfigEntity(appWidgetId, null)) }
|
||||
var loaded by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(appWidgetId) {
|
||||
Graph.repo.widgetConfig(appWidgetId)?.let { config = it }
|
||||
loaded = true
|
||||
}
|
||||
// live preview: render the real widget with the pending settings
|
||||
var preview by remember { mutableStateOf<android.widget.RemoteViews?>(null) }
|
||||
LaunchedEffect(config, loaded) {
|
||||
if (!loaded) return@LaunchedEffect
|
||||
WidgetPreviewOverride.config = config
|
||||
preview = runCatching { widget.compose(context, size = size) }.getOrNull()
|
||||
WidgetPreviewOverride.config = null
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(R.string.widget_customize)) },
|
||||
colors = androidx.compose.material3.TopAppBarDefaults.topAppBarColors(containerColor = MaterialTheme.colorScheme.surfaceContainer),
|
||||
)
|
||||
},
|
||||
) { pad ->
|
||||
Column(Modifier.padding(pad).fillMaxSize().verticalScroll(rememberScrollState())) {
|
||||
Box(
|
||||
Modifier.fillMaxWidth().height(size.height + 48.dp).padding(horizontal = WSpace.s16).clip(RoundedCornerShape(28.dp))
|
||||
.background(Brush.linearGradient(listOf(Color(0xFF5F7A84), Color(0xFFB9A58F)))),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
preview?.let { views ->
|
||||
AndroidView(
|
||||
factory = { FrameLayout(it) },
|
||||
update = { frame -> frame.removeAllViews(); frame.addView(views.apply(frame.context, frame)) },
|
||||
modifier = Modifier.size(size),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val themeLabels = listOf(R.string.theme_system, R.string.theme_light, R.string.theme_dark).map { stringResource(it) }
|
||||
val follow = stringResource(R.string.widget_follow)
|
||||
val names = context.resources.getStringArray(R.array.widget_palettes)
|
||||
val choices = listOf<Long?>(null) + locations.filter { !it.isCurrent }.map { it.id }
|
||||
SettingsGroup(stringResource(R.string.widget_content)) {
|
||||
item {
|
||||
SettingsChoice(it, stringResource(R.string.widget_location), choices, config.locationId,
|
||||
{ id -> if (id == null) follow else locations.firstOrNull { l -> l.id == id }?.name.orEmpty() },
|
||||
{ id -> config = config.copy(locationId = id) }, Icons.Outlined.LocationOn)
|
||||
}
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.set_look)) {
|
||||
item {
|
||||
SettingsChoice(it, stringResource(R.string.set_theme), WidgetStyle.THEMES, config.theme,
|
||||
{ k -> themeLabels[WidgetStyle.THEMES.indexOf(k)] }, { k -> config = config.copy(theme = k) }, Icons.Outlined.DarkMode)
|
||||
}
|
||||
item {
|
||||
SettingsCustom(it) {
|
||||
Text(stringResource(R.string.widget_colors), style = WType.body)
|
||||
Text(names[WidgetStyle.PALETTES.indexOf(config.style).coerceAtLeast(0)], style = WType.bodySm, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
Row(Modifier.horizontalScroll(rememberScrollState()).padding(top = WSpace.s12), horizontalArrangement = Arrangement.spacedBy(WSpace.s12)) {
|
||||
WidgetStyle.PALETTES.forEachIndexed { i, key ->
|
||||
val swatch = resolvePalette(context, WidgetStyle(key, config.theme, 100), null)
|
||||
val selected = config.style == key
|
||||
Box(
|
||||
Modifier.size(48.dp).clip(if (selected) WShapes.cookie8 else CircleShape)
|
||||
.background(Brush.linearGradient(listOf(swatch.bg, swatch.accent)))
|
||||
.clickable { config = config.copy(style = key) }
|
||||
.semantics { contentDescription = names[i]; this.selected = selected },
|
||||
contentAlignment = Alignment.Center,
|
||||
) { if (selected) Icon(Icons.Rounded.Check, null, tint = swatch.onBg) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
item {
|
||||
SettingsCustom(it) {
|
||||
Text(stringResource(R.string.widget_opacity), style = WType.body)
|
||||
Text("${config.opacity} %", style = WType.bodySm, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
val levels = WidgetStyle.OPACITIES.sorted()
|
||||
Slider(
|
||||
value = levels.indexOf(config.opacity).coerceAtLeast(0).toFloat(),
|
||||
onValueChange = { v -> config = config.copy(opacity = levels[v.roundToInt()]) },
|
||||
valueRange = 0f..(levels.size - 1).toFloat(),
|
||||
steps = levels.size - 2,
|
||||
)
|
||||
if (config.opacity <= 25) Text(stringResource(R.string.widget_opacity_hint), style = WType.bodySm, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button(onClick = { onDone(config) }, enabled = loaded, modifier = Modifier.fillMaxWidth().padding(horizontal = WSpace.s16, vertical = WSpace.s24).navigationBarsPadding().height(56.dp)) {
|
||||
Text(stringResource(R.string.widget_done))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package app.wetter.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.lerp
|
||||
import app.wetter.data.Forecast
|
||||
import app.wetter.data.conditionOf
|
||||
import app.wetter.ui.scene.SceneSpec
|
||||
import app.wetter.ui.theme.WColor
|
||||
|
||||
/** What a person picked for one widget in the configuration screen. */
|
||||
data class WidgetStyle(
|
||||
val palette: String = WALLPAPER,
|
||||
val theme: String = SYSTEM,
|
||||
/** background opacity in percent: 100, 75, 50, 25 or 0 */
|
||||
val opacity: Int = 100,
|
||||
) {
|
||||
companion object {
|
||||
const val WALLPAPER = "wallpaper"
|
||||
const val WEATHER = "weather"
|
||||
const val SYSTEM = "system"
|
||||
const val LIGHT = "light"
|
||||
const val DARK = "dark"
|
||||
val PALETTES = listOf(WALLPAPER, WEATHER, "ocean", "forest", "sun", "lavender", "graphite")
|
||||
val THEMES = listOf(SYSTEM, LIGHT, DARK)
|
||||
val OPACITIES = listOf(100, 75, 50, 25, 0)
|
||||
}
|
||||
}
|
||||
|
||||
private fun palette(bg: Color, on: Color, accent: Color, panel: Color, onPanel: Color, badge: Color, onBadge: Color) =
|
||||
WidgetPalette(bg, on, on.copy(alpha = .72f), accent, panel, onPanel, badge, onBadge)
|
||||
|
||||
private val FIXED: Map<Pair<String, Boolean>, WidgetPalette> = mapOf(
|
||||
Pair("ocean", false) to palette(WColor.widgetOceanLightBg, WColor.widgetOceanLightOn, WColor.widgetOceanLightAccent, WColor.widgetOceanLightPanel, WColor.widgetOceanLightOnpanel, WColor.widgetOceanLightBadge, WColor.widgetOceanLightOnbadge),
|
||||
Pair("ocean", true) to palette(WColor.widgetOceanDarkBg, WColor.widgetOceanDarkOn, WColor.widgetOceanDarkAccent, WColor.widgetOceanDarkPanel, WColor.widgetOceanDarkOnpanel, WColor.widgetOceanDarkBadge, WColor.widgetOceanDarkOnbadge),
|
||||
Pair("forest", false) to palette(WColor.widgetForestLightBg, WColor.widgetForestLightOn, WColor.widgetForestLightAccent, WColor.widgetForestLightPanel, WColor.widgetForestLightOnpanel, WColor.widgetForestLightBadge, WColor.widgetForestLightOnbadge),
|
||||
Pair("forest", true) to palette(WColor.widgetForestDarkBg, WColor.widgetForestDarkOn, WColor.widgetForestDarkAccent, WColor.widgetForestDarkPanel, WColor.widgetForestDarkOnpanel, WColor.widgetForestDarkBadge, WColor.widgetForestDarkOnbadge),
|
||||
Pair("sun", false) to palette(WColor.widgetSunLightBg, WColor.widgetSunLightOn, WColor.widgetSunLightAccent, WColor.widgetSunLightPanel, WColor.widgetSunLightOnpanel, WColor.widgetSunLightBadge, WColor.widgetSunLightOnbadge),
|
||||
Pair("sun", true) to palette(WColor.widgetSunDarkBg, WColor.widgetSunDarkOn, WColor.widgetSunDarkAccent, WColor.widgetSunDarkPanel, WColor.widgetSunDarkOnpanel, WColor.widgetSunDarkBadge, WColor.widgetSunDarkOnbadge),
|
||||
Pair("lavender", false) to palette(WColor.widgetLavenderLightBg, WColor.widgetLavenderLightOn, WColor.widgetLavenderLightAccent, WColor.widgetLavenderLightPanel, WColor.widgetLavenderLightOnpanel, WColor.widgetLavenderLightBadge, WColor.widgetLavenderLightOnbadge),
|
||||
Pair("lavender", true) to palette(WColor.widgetLavenderDarkBg, WColor.widgetLavenderDarkOn, WColor.widgetLavenderDarkAccent, WColor.widgetLavenderDarkPanel, WColor.widgetLavenderDarkOnpanel, WColor.widgetLavenderDarkBadge, WColor.widgetLavenderDarkOnbadge),
|
||||
Pair("graphite", false) to palette(WColor.widgetGraphiteLightBg, WColor.widgetGraphiteLightOn, WColor.widgetGraphiteLightAccent, WColor.widgetGraphiteLightPanel, WColor.widgetGraphiteLightOnpanel, WColor.widgetGraphiteLightBadge, WColor.widgetGraphiteLightOnbadge),
|
||||
Pair("graphite", true) to palette(WColor.widgetGraphiteDarkBg, WColor.widgetGraphiteDarkOn, WColor.widgetGraphiteDarkAccent, WColor.widgetGraphiteDarkPanel, WColor.widgetGraphiteDarkOnpanel, WColor.widgetGraphiteDarkBadge, WColor.widgetGraphiteDarkOnbadge),
|
||||
)
|
||||
|
||||
fun resolvePalette(context: Context, style: WidgetStyle, forecast: Forecast?): WidgetPalette {
|
||||
val systemDark = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
|
||||
val dark = when (style.theme) {
|
||||
WidgetStyle.LIGHT -> false
|
||||
WidgetStyle.DARK -> true
|
||||
else -> systemDark
|
||||
}
|
||||
val base = when (style.palette) {
|
||||
WidgetStyle.WALLPAPER -> wallpaper(context, dark)
|
||||
WidgetStyle.WEATHER -> weather(forecast, dark)
|
||||
else -> FIXED[style.palette to dark] ?: wallpaper(context, dark)
|
||||
}
|
||||
val a = style.opacity.coerceIn(0, 100) / 100f
|
||||
return base.copy(bg = base.bg.copy(alpha = base.bg.alpha * a), panel = base.panel.copy(alpha = base.panel.alpha * a), badge = base.badge.copy(alpha = base.badge.alpha * a))
|
||||
}
|
||||
|
||||
private fun wallpaper(context: Context, dark: Boolean): WidgetPalette {
|
||||
if (Build.VERSION.SDK_INT < 31) return FIXED.getValue(("ocean" to dark))
|
||||
val s = if (dark) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
return palette(s.primaryContainer, s.onPrimaryContainer, s.primary, s.surfaceContainerLowest, s.onSurface, s.secondaryContainer, s.onSecondaryContainer)
|
||||
}
|
||||
|
||||
/** Colours of the current sky: the same gradient the app shows behind the forecast. */
|
||||
private fun weather(forecast: Forecast?, dark: Boolean): WidgetPalette {
|
||||
val spec = forecast?.let { SceneSpec(conditionOf(it.current.code), it.current.isDay) } ?: return FIXED.getValue(("graphite" to dark))
|
||||
val bg = if (dark) lerp(spec.top, Color.Black, .35f) else spec.top
|
||||
val light = !dark && spec.isLight
|
||||
val on = if (light) WColor.onSceneDark else WColor.onScene
|
||||
val panel = if (light) WColor.sceneCardLight else WColor.sceneCard
|
||||
val onPanel = if (light) WColor.onSceneDark else WColor.onScene
|
||||
return palette(bg, on, on, panel, onPanel, panel, onPanel)
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
package app.wetter.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.DpSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.glance.GlanceId
|
||||
import androidx.glance.GlanceModifier
|
||||
import androidx.glance.Image
|
||||
import androidx.glance.ImageProvider
|
||||
import androidx.glance.LocalContext
|
||||
import androidx.glance.LocalSize
|
||||
import androidx.glance.action.clickable
|
||||
import androidx.glance.appwidget.GlanceAppWidget
|
||||
import androidx.glance.appwidget.GlanceAppWidgetManager
|
||||
import androidx.glance.appwidget.GlanceAppWidgetReceiver
|
||||
import androidx.glance.appwidget.SizeMode
|
||||
import androidx.glance.appwidget.action.actionStartActivity
|
||||
import androidx.glance.appwidget.cornerRadius
|
||||
import androidx.glance.appwidget.provideContent
|
||||
import androidx.glance.appwidget.updateAll
|
||||
import androidx.glance.background
|
||||
import androidx.glance.layout.Alignment
|
||||
import androidx.glance.layout.Box
|
||||
import androidx.glance.layout.Column
|
||||
import androidx.glance.layout.ContentScale
|
||||
import androidx.glance.layout.Row
|
||||
import androidx.glance.layout.Spacer
|
||||
import androidx.glance.layout.fillMaxSize
|
||||
import androidx.glance.layout.fillMaxWidth
|
||||
import androidx.glance.layout.height
|
||||
import androidx.glance.layout.padding
|
||||
import androidx.glance.layout.size
|
||||
import androidx.glance.layout.width
|
||||
import androidx.glance.semantics.contentDescription
|
||||
import androidx.glance.semantics.semantics
|
||||
import androidx.glance.text.FontWeight
|
||||
import androidx.glance.text.Text
|
||||
import androidx.glance.text.TextAlign
|
||||
import androidx.glance.text.TextStyle
|
||||
import androidx.glance.unit.ColorProvider
|
||||
import app.wetter.MainActivity
|
||||
import app.wetter.R
|
||||
import app.wetter.data.Forecast
|
||||
import app.wetter.data.Fmt
|
||||
import app.wetter.data.Graph
|
||||
import app.wetter.data.LocationEntity
|
||||
import app.wetter.data.Settings
|
||||
import app.wetter.data.Units
|
||||
import app.wetter.data.conditionOf
|
||||
import app.wetter.ui.components.conditionLabel
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
suspend fun updateAllWidgets(context: Context) {
|
||||
WeatherCardWidget().updateAll(context)
|
||||
PillWidget().updateAll(context)
|
||||
TiltWidget().updateAll(context)
|
||||
BarWidget().updateAll(context)
|
||||
ClassicWidget().updateAll(context)
|
||||
}
|
||||
|
||||
/** Picker previews (Android 15+). The system rate-limits this, so failures are ignored. */
|
||||
suspend fun publishWidgetPreviews(context: Context) {
|
||||
if (Build.VERSION.SDK_INT < 35) return
|
||||
val manager = GlanceAppWidgetManager(context)
|
||||
listOf<KClass<out GlanceAppWidgetReceiver>>(
|
||||
WeatherCardReceiver::class, PillReceiver::class, TiltReceiver::class, BarReceiver::class, ClassicReceiver::class,
|
||||
).forEach { runCatching { manager.setWidgetPreviews(it) } }
|
||||
}
|
||||
|
||||
class WidgetData(val location: LocationEntity?, val forecast: Forecast?, val units: Units, val palette: WidgetPalette) {
|
||||
val name: String get() = location?.name.orEmpty()
|
||||
}
|
||||
|
||||
/** Set by the configuration screen while it renders its live preview. */
|
||||
object WidgetPreviewOverride {
|
||||
@Volatile var config: app.wetter.data.WidgetConfigEntity? = null
|
||||
}
|
||||
|
||||
suspend fun loadWidgetData(context: Context, id: GlanceId?): WidgetData {
|
||||
Graph.init(context)
|
||||
// ids that are not real widgets (previews, the debug gallery) fall back to the current location
|
||||
val appWidgetId = id?.let { runCatching { GlanceAppWidgetManager(context).getAppWidgetId(it) }.getOrNull() } ?: -1
|
||||
val config = WidgetPreviewOverride.config ?: Graph.repo.widgetConfig(appWidgetId)
|
||||
val location = config?.locationId?.let { Graph.repo.location(it) } ?: Graph.repo.widgetLocation(appWidgetId)
|
||||
val forecast = location?.let { Graph.repo.forecastOnce(it.id) }
|
||||
val settings = runCatching { Graph.settings.settings.first() }.getOrDefault(Settings())
|
||||
val style = config?.let { WidgetStyle(it.style, it.theme, it.opacity) } ?: WidgetStyle()
|
||||
return WidgetData(location, forecast, Units(settings), resolvePalette(context, style, forecast))
|
||||
}
|
||||
|
||||
/** Base: loads data once per update, renders [Content], and offers the same content as picker preview. */
|
||||
abstract class WeatherWidget : GlanceAppWidget() {
|
||||
override suspend fun provideGlance(context: Context, id: GlanceId) {
|
||||
val data = loadWidgetData(context, id)
|
||||
provideContent { Root(data) }
|
||||
}
|
||||
|
||||
override suspend fun providePreview(context: Context, widgetCategory: Int) {
|
||||
val data = loadWidgetData(context, null)
|
||||
provideContent { Root(data) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Root(data: WidgetData) {
|
||||
val context = LocalContext.current
|
||||
val f = data.forecast
|
||||
if (f == null) {
|
||||
Box(
|
||||
GlanceModifier.fillMaxSize().cornerRadius(24.dp).background(data.palette.bg)
|
||||
.clickable(actionStartActivity(MainActivity.intent(context, null))),
|
||||
contentAlignment = Alignment.Center,
|
||||
) { Text(context.getString(R.string.widget_pick), style = text(data.palette.onBg, 14)) }
|
||||
return
|
||||
}
|
||||
Content(data, f)
|
||||
}
|
||||
|
||||
@Composable
|
||||
abstract fun Content(data: WidgetData, f: Forecast)
|
||||
}
|
||||
|
||||
private fun text(color: Color, size: Int, weight: FontWeight = FontWeight.Normal, align: TextAlign = TextAlign.Start) =
|
||||
TextStyle(color = ColorProvider(color), fontSize = size.sp, fontWeight = weight, textAlign = align)
|
||||
|
||||
@Composable
|
||||
private fun open(data: WidgetData) = actionStartActivity(MainActivity.intent(LocalContext.current, data.location?.id))
|
||||
|
||||
@Composable
|
||||
private fun Icon(f: Forecast, size: Int, code: Int = f.current.code, isDay: Boolean = f.current.isDay) =
|
||||
Image(ImageProvider(WidgetArt.icon(conditionOf(code), isDay)), null, GlanceModifier.size(size.dp))
|
||||
|
||||
@Composable
|
||||
private fun conditionText(f: Forecast): String =
|
||||
LocalContext.current.getString(conditionLabel(conditionOf(f.current.code), f.current.isDay))
|
||||
|
||||
@Composable
|
||||
private fun Attribution(p: WidgetPalette) = Text(
|
||||
LocalContext.current.getString(R.string.widget_source), style = text(p.muted, 10, align = TextAlign.Center),
|
||||
modifier = GlanceModifier.fillMaxWidth(),
|
||||
)
|
||||
|
||||
/** One hour column: temperature, icon, time. */
|
||||
@Composable
|
||||
private fun HourCell(f: Forecast, index: Int, data: WidgetData, color: Color, modifier: GlanceModifier) {
|
||||
val h = f.upcomingHours(index + 1).getOrNull(index) ?: return
|
||||
val ctx = LocalContext.current
|
||||
Column(modifier, horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Text(data.units.temp(h.temp), style = text(color, 13, align = TextAlign.Center))
|
||||
Spacer(GlanceModifier.height(4.dp))
|
||||
Image(ImageProvider(WidgetArt.icon(conditionOf(h.code), h.isDay, 96)), null, GlanceModifier.size(24.dp))
|
||||
Spacer(GlanceModifier.height(4.dp))
|
||||
Text(if (index == 0) ctx.getString(R.string.now) else Fmt.hourLabel(h.time), style = text(color, 12, align = TextAlign.Center))
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// 1. Weather card: grows from a compact 3×2 to a full 4×5 with hourly panel and daily list
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
class WeatherCardWidget : WeatherWidget() {
|
||||
override val sizeMode = SizeMode.Responsive(setOf(COMPACT, MEDIUM, LARGE, FULL))
|
||||
|
||||
@Composable
|
||||
override fun Content(data: WidgetData, f: Forecast) {
|
||||
val cond = conditionText(f)
|
||||
val size = LocalSize.current
|
||||
val p = data.palette
|
||||
val u = data.units
|
||||
val ctx = LocalContext.current
|
||||
val today = f.today
|
||||
Column(
|
||||
GlanceModifier.fillMaxSize().cornerRadius(28.dp).background(p.bg).clickable(open(data)).padding(16.dp)
|
||||
.semantics { contentDescription = "${data.name} ${u.temp(f.current.temp)} $cond" },
|
||||
) {
|
||||
Row(GlanceModifier.fillMaxWidth(), verticalAlignment = Alignment.Top) {
|
||||
Column(GlanceModifier.defaultWeight()) {
|
||||
if (size.height >= LARGE.height && data.name.isNotEmpty()) {
|
||||
Text(data.name, style = text(p.accent, 13, FontWeight.Medium), maxLines = 1)
|
||||
Spacer(GlanceModifier.height(6.dp))
|
||||
}
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(f, 30)
|
||||
Spacer(GlanceModifier.width(8.dp))
|
||||
Text(conditionText(f), style = text(p.onBg, 16, FontWeight.Medium), maxLines = 1)
|
||||
}
|
||||
Spacer(GlanceModifier.height(4.dp))
|
||||
Text(ctx.getString(R.string.feels_like, u.temp(f.current.feelsLike)), style = text(p.onBg, 14), maxLines = 1)
|
||||
if (today != null) Text("${u.temp(today.tMax)} · ${u.temp(today.tMin)}", style = text(p.muted, 14))
|
||||
}
|
||||
Text(u.temp(f.current.temp), style = text(p.onBg, if (size.width >= MEDIUM.width) 56 else 44))
|
||||
}
|
||||
if (size.height < MEDIUM.height) {
|
||||
// compact: two hours under the temperature
|
||||
Spacer(GlanceModifier.defaultWeight())
|
||||
Row(GlanceModifier.fillMaxWidth()) {
|
||||
Spacer(GlanceModifier.defaultWeight())
|
||||
HourCell(f, 0, data, p.onBg, GlanceModifier.width(48.dp))
|
||||
HourCell(f, 1, data, p.onBg, GlanceModifier.width(48.dp))
|
||||
}
|
||||
return@Column
|
||||
}
|
||||
Spacer(GlanceModifier.height(12.dp))
|
||||
Row(GlanceModifier.fillMaxWidth().cornerRadius(20.dp).background(p.panel).padding(vertical = 10.dp)) {
|
||||
for (i in 0 until 6) HourCell(f, i, data, p.onPanel, GlanceModifier.defaultWeight())
|
||||
}
|
||||
if (size.height >= LARGE.height) {
|
||||
Spacer(GlanceModifier.height(8.dp))
|
||||
val days = f.daily.drop(1).take(if (size.height >= FULL.height) 5 else 1)
|
||||
Column(GlanceModifier.fillMaxWidth().cornerRadius(20.dp).background(p.panel)) {
|
||||
days.forEachIndexed { i, d ->
|
||||
Row(GlanceModifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 9.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
d.date.dayOfWeek.getDisplayName(java.time.format.TextStyle.FULL, java.util.Locale.getDefault()),
|
||||
style = text(p.onPanel, 14), modifier = GlanceModifier.defaultWeight(),
|
||||
)
|
||||
Text("${u.temp(d.tMax)} ", style = text(p.onPanel, 14, FontWeight.Medium))
|
||||
Text(u.temp(d.tMin), style = text(p.onPanel.copy(alpha = .7f), 14))
|
||||
Spacer(GlanceModifier.width(8.dp))
|
||||
Image(ImageProvider(WidgetArt.icon(conditionOf(d.code), true, 96)), null, GlanceModifier.size(22.dp))
|
||||
}
|
||||
if (i < days.lastIndex) Spacer(GlanceModifier.fillMaxWidth().height(1.dp).background(p.bg))
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(GlanceModifier.defaultWeight())
|
||||
Attribution(p)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val COMPACT = DpSize(180.dp, 110.dp)
|
||||
val MEDIUM = DpSize(250.dp, 180.dp)
|
||||
val LARGE = DpSize(250.dp, 310.dp)
|
||||
val FULL = DpSize(250.dp, 430.dp)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// 2. Pill: stadium with a big icon and the temperature
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
class PillWidget : WeatherWidget() {
|
||||
override val sizeMode = SizeMode.Responsive(setOf(SMALL, WIDE))
|
||||
|
||||
@Composable
|
||||
override fun Content(data: WidgetData, f: Forecast) {
|
||||
val cond = conditionText(f)
|
||||
val size = LocalSize.current
|
||||
val p = data.palette
|
||||
val u = data.units
|
||||
val big = size.height >= WIDE.height
|
||||
Row(
|
||||
GlanceModifier.fillMaxSize().cornerRadius(999.dp).background(p.bg).clickable(open(data)).padding(horizontal = if (big) 24.dp else 16.dp)
|
||||
.semantics { contentDescription = "${data.name} ${u.temp(f.current.temp)} $cond" },
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Icon(f, if (big) 84 else 36)
|
||||
Spacer(GlanceModifier.width(if (big) 16.dp else 8.dp))
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Text(u.temp(f.current.temp), style = text(p.accent, if (big) 56 else 30))
|
||||
if (big) f.today?.let {
|
||||
Row {
|
||||
Text(u.temp(it.tMax) + " ", style = text(p.accent, 18))
|
||||
Text(u.temp(it.tMin), style = text(p.muted, 18))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val SMALL = DpSize(110.dp, 48.dp)
|
||||
val WIDE = DpSize(200.dp, 110.dp)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// 3. Tilted pill: a 45° stadium, temperature top right, icon bottom left
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
class TiltWidget : WeatherWidget() {
|
||||
override val sizeMode = SizeMode.Exact
|
||||
|
||||
@Composable
|
||||
override fun Content(data: WidgetData, f: Forecast) {
|
||||
val cond = conditionText(f)
|
||||
val p = data.palette
|
||||
val u = data.units
|
||||
val size = LocalSize.current
|
||||
val side = minOf(size.width.value, size.height.value)
|
||||
Box(
|
||||
GlanceModifier.fillMaxSize().clickable(open(data))
|
||||
.semantics { contentDescription = "${data.name} ${u.temp(f.current.temp)} $cond" },
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Box(GlanceModifier.size(side.dp)) {
|
||||
Image(ImageProvider(WidgetArt.tiltedPill(p.bg)), null, GlanceModifier.fillMaxSize(), contentScale = ContentScale.FillBounds)
|
||||
Box(GlanceModifier.fillMaxSize().padding(top = (side * .22f).dp, end = (side * .2f).dp), contentAlignment = Alignment.TopEnd) {
|
||||
Text(u.temp(f.current.temp), style = text(p.onBg, (side * .22f).toInt()))
|
||||
}
|
||||
Box(GlanceModifier.fillMaxSize().padding(bottom = (side * .2f).dp, start = (side * .2f).dp), contentAlignment = Alignment.BottomStart) {
|
||||
Icon(f, (side * .28f).toInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// 4. Bar: one line "today", condition, and a cookie badge with the current temperature
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
class BarWidget : WeatherWidget() {
|
||||
override val sizeMode = SizeMode.Exact
|
||||
|
||||
@Composable
|
||||
override fun Content(data: WidgetData, f: Forecast) {
|
||||
val cond = conditionText(f)
|
||||
val p = data.palette
|
||||
val u = data.units
|
||||
val ctx = LocalContext.current
|
||||
val size = LocalSize.current
|
||||
val badge = minOf(size.height.value - 8f, 88f)
|
||||
Row(
|
||||
GlanceModifier.fillMaxSize().cornerRadius(999.dp).background(p.panel).clickable(open(data)).padding(start = 22.dp, end = 6.dp)
|
||||
.semantics { contentDescription = "${data.name} ${u.temp(f.current.temp)} $cond" },
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Column(GlanceModifier.defaultWeight()) {
|
||||
f.today?.let { Text("${ctx.getString(R.string.today)} ${u.temp(it.tMax)} / ${u.temp(it.tMin)}", style = text(p.onPanel, 15), maxLines = 1) }
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(f, 22)
|
||||
Spacer(GlanceModifier.width(6.dp))
|
||||
Text(conditionText(f), style = text(p.onPanel, 14), maxLines = 1)
|
||||
}
|
||||
}
|
||||
Box(GlanceModifier.size(badge.dp), contentAlignment = Alignment.Center) {
|
||||
Image(ImageProvider(WidgetArt.cookie(p.badge)), null, GlanceModifier.fillMaxSize())
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Icon(f, (badge * .38f).toInt())
|
||||
Text(u.temp(f.current.temp), style = text(p.onBadge, 13, FontWeight.Medium))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// 5. Classic: rounded square, place and condition in the accent colour, hours on the right
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
class ClassicWidget : WeatherWidget() {
|
||||
override val sizeMode = SizeMode.Responsive(setOf(SQUARE, WIDE))
|
||||
|
||||
@Composable
|
||||
override fun Content(data: WidgetData, f: Forecast) {
|
||||
val cond = conditionText(f)
|
||||
val p = data.palette
|
||||
val u = data.units
|
||||
val wide = LocalSize.current.width >= WIDE.width
|
||||
Column(
|
||||
GlanceModifier.fillMaxSize().cornerRadius(24.dp).background(p.bg).clickable(open(data)).padding(16.dp)
|
||||
.semantics { contentDescription = "${data.name} ${u.temp(f.current.temp)} $cond" },
|
||||
) {
|
||||
Row(GlanceModifier.fillMaxWidth(), verticalAlignment = Alignment.Top) {
|
||||
Icon(f, 30)
|
||||
Spacer(GlanceModifier.defaultWeight())
|
||||
Column(horizontalAlignment = Alignment.End) {
|
||||
Text(data.name, style = text(p.accent, 13), maxLines = 1)
|
||||
Text(conditionText(f), style = text(p.accent, 17, FontWeight.Medium), maxLines = 1)
|
||||
}
|
||||
}
|
||||
Spacer(GlanceModifier.defaultWeight())
|
||||
Row(GlanceModifier.fillMaxWidth(), verticalAlignment = Alignment.Bottom) {
|
||||
Column {
|
||||
Text(u.temp(f.current.temp), style = text(p.accent, 46, FontWeight.Medium))
|
||||
f.today?.let {
|
||||
Row {
|
||||
Text(u.temp(it.tMax) + " ", style = text(p.accent, 14))
|
||||
Text(u.temp(it.tMin), style = text(p.muted, 14))
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wide) {
|
||||
Spacer(GlanceModifier.defaultWeight())
|
||||
for (i in 1..4) HourCell(f, i, data, p.onBg, GlanceModifier.width(44.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val SQUARE = DpSize(140.dp, 140.dp)
|
||||
val WIDE = DpSize(250.dp, 110.dp)
|
||||
}
|
||||
}
|
||||
|
||||
class WeatherCardReceiver : GlanceAppWidgetReceiver() { override val glanceAppWidget: GlanceAppWidget = WeatherCardWidget() }
|
||||
class PillReceiver : GlanceAppWidgetReceiver() { override val glanceAppWidget: GlanceAppWidget = PillWidget() }
|
||||
class TiltReceiver : GlanceAppWidgetReceiver() { override val glanceAppWidget: GlanceAppWidget = TiltWidget() }
|
||||
class BarReceiver : GlanceAppWidgetReceiver() { override val glanceAppWidget: GlanceAppWidget = BarWidget() }
|
||||
class ClassicReceiver : GlanceAppWidgetReceiver() { override val glanceAppWidget: GlanceAppWidget = ClassicWidget() }
|
||||
@@ -11,6 +11,7 @@ import androidx.work.PeriodicWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.WorkerParameters
|
||||
import app.wetter.data.Graph
|
||||
import app.wetter.widget.publishWidgetPreviews
|
||||
import app.wetter.widget.updateAllWidgets
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@@ -21,6 +22,7 @@ class RefreshWorker(context: Context, params: WorkerParameters) : CoroutineWorke
|
||||
val force = inputData.getBoolean(KEY_FORCE, false)
|
||||
runCatching { Graph.repo.refreshAll(force) }
|
||||
updateAllWidgets(applicationContext)
|
||||
publishWidgetPreviews(applicationContext)
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="108dp" android:height="108dp" android:viewportWidth="108" android:viewportHeight="108">
|
||||
<path android:fillColor="#FF7CC4EF" android:pathData="M0,0h108v108h-108z"/>
|
||||
<path android:fillColor="#FFFFB02E" android:pathData="M64,40m-16,0a16,16 0,1 1,32 0a16,16 0,1 1,-32 0"/>
|
||||
<path android:fillColor="#FFF4F6F9" android:pathData="M30,74h44a12,12 0,0 0,0 -24a16,16 0,0 0,-30 -4a13,13 0,0 0,-14 28z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp" android:height="108dp" android:viewportWidth="108" android:viewportHeight="108">
|
||||
<path android:pathData="M0,0h108v108h-108z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient android:type="linear" android:startX="0" android:startY="0" android:endX="0" android:endY="108"
|
||||
android:startColor="#FF4E9BE6" android:endColor="#FFBFE3F7"/>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path android:fillColor="#FF8EC2EC" android:pathData="M0.00,108.00 L0.00,77.13 L2.00,76.77 L4.00,76.47 L6.00,76.25 L8.00,76.09 L10.00,76.01 L12.00,76.01 L14.00,76.09 L16.00,76.24 L18.00,76.46 L20.00,76.76 L22.00,77.11 L24.00,77.53 L26.00,77.99 L28.00,78.49 L30.00,79.02 L32.00,79.57 L34.00,80.13 L36.00,80.68 L38.00,81.23 L40.00,81.74 L42.00,82.23 L44.00,82.67 L46.00,83.06 L48.00,83.39 L50.00,83.65 L52.00,83.84 L54.00,83.96 L56.00,84.00 L58.00,83.96 L60.00,83.85 L62.00,83.66 L64.00,83.40 L66.00,83.07 L68.00,82.68 L70.00,82.25 L72.00,81.76 L74.00,81.25 L76.00,80.71 L78.00,80.15 L80.00,79.59 L82.00,79.04 L84.00,78.51 L86.00,78.01 L88.00,77.55 L90.00,77.13 L92.00,76.77 L94.00,76.47 L96.00,76.25 L98.00,76.09 L100.00,76.01 L102.00,76.01 L104.00,76.09 L106.00,76.24 L108.00,76.46 L108.00,108.00 Z"/>
|
||||
<path android:fillColor="#FFA9D3F2" android:pathData="M0.00,108.00 L0.00,85.97 L2.00,86.20 L4.00,86.44 L6.00,86.69 L8.00,86.96 L10.00,87.23 L12.00,87.52 L14.00,87.81 L16.00,88.10 L18.00,88.38 L20.00,88.67 L22.00,88.95 L24.00,89.22 L26.00,89.48 L28.00,89.72 L30.00,89.95 L32.00,90.16 L34.00,90.35 L36.00,90.52 L38.00,90.67 L40.00,90.79 L42.00,90.88 L44.00,90.95 L46.00,90.99 L48.00,91.00 L50.00,90.98 L52.00,90.94 L54.00,90.87 L56.00,90.77 L58.00,90.65 L60.00,90.50 L62.00,90.32 L64.00,90.13 L66.00,89.92 L68.00,89.69 L70.00,89.44 L72.00,89.18 L74.00,88.91 L76.00,88.63 L78.00,88.34 L80.00,88.05 L82.00,87.76 L84.00,87.47 L86.00,87.19 L88.00,86.92 L90.00,86.65 L92.00,86.40 L94.00,86.16 L96.00,85.94 L98.00,85.74 L100.00,85.56 L102.00,85.40 L104.00,85.27 L106.00,85.16 L108.00,85.08 L108.00,108.00 Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp" android:height="108dp" android:viewportWidth="108" android:viewportHeight="108">
|
||||
<path android:fillColor="#FFFFB02E" android:pathData="M78.41,44.00 L78.32,44.76 L78.08,45.49 L77.70,46.20 L77.25,46.87 L76.77,47.50 L76.32,48.10 L75.94,48.71 L75.65,49.33 L75.47,49.99 L75.37,50.70 L75.33,51.46 L75.29,52.25 L75.21,53.05 L75.04,53.83 L74.76,54.55 L74.33,55.19 L73.78,55.71 L73.12,56.12 L72.38,56.42 L71.61,56.64 L70.83,56.81 L70.10,56.99 L69.41,57.21 L68.80,57.50 L68.23,57.89 L67.70,58.37 L67.18,58.92 L66.64,59.50 L66.07,60.07 L65.44,60.56 L64.75,60.93 L64.02,61.14 L63.26,61.19 L62.49,61.08 L61.73,60.83 L61.00,60.50 L60.30,60.14 L59.62,59.80 L58.96,59.53 L58.29,59.36 L57.61,59.29 L56.90,59.32 L56.14,59.41 L55.36,59.50 L54.55,59.56 L53.76,59.54 L52.99,59.38 L52.30,59.08 L51.68,58.62 L51.17,58.04 L50.74,57.37 L50.39,56.64 L50.09,55.91 L49.79,55.21 L49.45,54.58 L49.06,54.02 L48.57,53.53 L48.01,53.10 L47.38,52.68 L46.71,52.25 L46.06,51.78 L45.46,51.24 L44.98,50.64 L44.64,49.95 L44.46,49.21 L44.44,48.44 L44.55,47.65 L44.75,46.87 L44.99,46.11 L45.20,45.38 L45.35,44.68 L45.41,44.00 L45.35,43.32 L45.20,42.62 L44.99,41.89 L44.75,41.13 L44.55,40.35 L44.44,39.56 L44.46,38.79 L44.64,38.05 L44.98,37.36 L45.46,36.76 L46.06,36.22 L46.71,35.75 L47.38,35.32 L48.01,34.90 L48.57,34.47 L49.06,33.98 L49.45,33.42 L49.79,32.79 L50.09,32.09 L50.39,31.36 L50.74,30.63 L51.17,29.96 L51.68,29.38 L52.30,28.92 L52.99,28.62 L53.76,28.46 L54.55,28.44 L55.36,28.50 L56.14,28.59 L56.90,28.68 L57.61,28.71 L58.29,28.64 L58.96,28.47 L59.62,28.20 L60.30,27.86 L61.00,27.50 L61.73,27.17 L62.49,26.92 L63.26,26.81 L64.02,26.86 L64.75,27.07 L65.44,27.44 L66.07,27.93 L66.64,28.50 L67.18,29.08 L67.70,29.63 L68.23,30.11 L68.80,30.50 L69.41,30.79 L70.10,31.01 L70.83,31.19 L71.61,31.36 L72.38,31.58 L73.12,31.88 L73.78,32.29 L74.33,32.81 L74.76,33.45 L75.04,34.17 L75.21,34.95 L75.29,35.75 L75.33,36.54 L75.37,37.30 L75.47,38.01 L75.65,38.67 L75.94,39.29 L76.32,39.90 L76.77,40.50 L77.25,41.13 L77.70,41.80 L78.08,42.51 L78.32,43.24 Z"/>
|
||||
<path android:fillColor="#59FF9A1F" android:pathData="M61,44m-10,0a10,10 0 1,0 20,0a10,10 0 1,0 -20,0"/>
|
||||
<group android:translateY="2.5"><path android:fillColor="#FFD5DEE8" android:pathData="M38,74 h30 a9,9 0 0 0 0,-18 a12,12 0 0 0 -22.5,-3.5 a10,10 0 0 0 -7.5,21.5 z"/></group>
|
||||
<path android:fillColor="#FFFFFFFF" android:pathData="M38,74 h30 a9,9 0 0 0 0,-18 a12,12 0 0 0 -22.5,-3.5 a10,10 0 0 0 -7.5,21.5 z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp" android:height="108dp" android:viewportWidth="108" android:viewportHeight="108">
|
||||
<path android:fillColor="#FF000000" android:pathData="M78.41,44.00 L78.32,44.76 L78.08,45.49 L77.70,46.20 L77.25,46.87 L76.77,47.50 L76.32,48.10 L75.94,48.71 L75.65,49.33 L75.47,49.99 L75.37,50.70 L75.33,51.46 L75.29,52.25 L75.21,53.05 L75.04,53.83 L74.76,54.55 L74.33,55.19 L73.78,55.71 L73.12,56.12 L72.38,56.42 L71.61,56.64 L70.83,56.81 L70.10,56.99 L69.41,57.21 L68.80,57.50 L68.23,57.89 L67.70,58.37 L67.18,58.92 L66.64,59.50 L66.07,60.07 L65.44,60.56 L64.75,60.93 L64.02,61.14 L63.26,61.19 L62.49,61.08 L61.73,60.83 L61.00,60.50 L60.30,60.14 L59.62,59.80 L58.96,59.53 L58.29,59.36 L57.61,59.29 L56.90,59.32 L56.14,59.41 L55.36,59.50 L54.55,59.56 L53.76,59.54 L52.99,59.38 L52.30,59.08 L51.68,58.62 L51.17,58.04 L50.74,57.37 L50.39,56.64 L50.09,55.91 L49.79,55.21 L49.45,54.58 L49.06,54.02 L48.57,53.53 L48.01,53.10 L47.38,52.68 L46.71,52.25 L46.06,51.78 L45.46,51.24 L44.98,50.64 L44.64,49.95 L44.46,49.21 L44.44,48.44 L44.55,47.65 L44.75,46.87 L44.99,46.11 L45.20,45.38 L45.35,44.68 L45.41,44.00 L45.35,43.32 L45.20,42.62 L44.99,41.89 L44.75,41.13 L44.55,40.35 L44.44,39.56 L44.46,38.79 L44.64,38.05 L44.98,37.36 L45.46,36.76 L46.06,36.22 L46.71,35.75 L47.38,35.32 L48.01,34.90 L48.57,34.47 L49.06,33.98 L49.45,33.42 L49.79,32.79 L50.09,32.09 L50.39,31.36 L50.74,30.63 L51.17,29.96 L51.68,29.38 L52.30,28.92 L52.99,28.62 L53.76,28.46 L54.55,28.44 L55.36,28.50 L56.14,28.59 L56.90,28.68 L57.61,28.71 L58.29,28.64 L58.96,28.47 L59.62,28.20 L60.30,27.86 L61.00,27.50 L61.73,27.17 L62.49,26.92 L63.26,26.81 L64.02,26.86 L64.75,27.07 L65.44,27.44 L66.07,27.93 L66.64,28.50 L67.18,29.08 L67.70,29.63 L68.23,30.11 L68.80,30.50 L69.41,30.79 L70.10,31.01 L70.83,31.19 L71.61,31.36 L72.38,31.58 L73.12,31.88 L73.78,32.29 L74.33,32.81 L74.76,33.45 L75.04,34.17 L75.21,34.95 L75.29,35.75 L75.33,36.54 L75.37,37.30 L75.47,38.01 L75.65,38.67 L75.94,39.29 L76.32,39.90 L76.77,40.50 L77.25,41.13 L77.70,41.80 L78.08,42.51 L78.32,43.24 Z"/>
|
||||
<path android:fillColor="#FF000000" android:strokeColor="#FFFFFFFF" android:strokeWidth="0" android:pathData="M38,74 h30 a9,9 0 0 0 0,-18 a12,12 0 0 0 -22.5,-3.5 a10,10 0 0 0 -7.5,21.5 z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
<monochrome android:drawable="@drawable/ic_launcher_monochrome"/>
|
||||
</adaptive-icon>
|
||||
@@ -93,6 +93,8 @@
|
||||
<string name="perm_allow">Standort erlauben</string>
|
||||
<string name="perm_search">Lieber einen Ort suchen</string>
|
||||
<string name="loading_error">Wetterdaten konnten nicht geladen werden</string>
|
||||
<string name="loading_error_busy">Der Wetterdienst ist gerade überlastet. Bitte gleich noch einmal versuchen.</string>
|
||||
<string name="loading_error_offline">Keine Verbindung zum Internet</string>
|
||||
|
||||
<string name="set_units">Einheiten</string>
|
||||
<string name="set_temp">Temperatur</string>
|
||||
@@ -111,10 +113,27 @@
|
||||
<string name="set_about">Datenquellen</string>
|
||||
<string name="attribution">Wetterdaten: Open-Meteo.com (CC BY 4.0) · Ortsnamen: © OpenStreetMap-Mitwirkende</string>
|
||||
|
||||
<string name="widget_now_name">Wetter jetzt</string>
|
||||
<string name="widget_now_desc">Temperatur und Wetterlage auf einen Blick</string>
|
||||
<string name="widget_forecast_name">Vorhersage</string>
|
||||
<string name="widget_forecast_desc">Jetzt, die nächsten Stunden und Tage</string>
|
||||
<string name="widget_card_name">Wetterkarte</string>
|
||||
<string name="widget_card_desc">Jetzt, die nächsten Stunden und Tage. Wächst mit der Größe.</string>
|
||||
<string name="widget_pill_name">Wetter-Pille</string>
|
||||
<string name="widget_pill_desc">Icon und Temperatur in einer Pille</string>
|
||||
<string name="widget_tilt_name">Schräge Pille</string>
|
||||
<string name="widget_tilt_desc">Temperatur in einer schrägen Form</string>
|
||||
<string name="widget_bar_name">Wetterleiste</string>
|
||||
<string name="widget_bar_desc">Heute auf einen Blick, eine Zeile</string>
|
||||
<string name="widget_classic_name">Klassisch</string>
|
||||
<string name="widget_classic_desc">Ort, Wetterlage und die nächsten Stunden</string>
|
||||
<string name="widget_customize">Widget anpassen</string>
|
||||
<string name="widget_location">Ort</string>
|
||||
<string name="widget_content">Inhalt</string>
|
||||
<string name="widget_colors">Farben</string>
|
||||
<string name="widget_opacity">Deckkraft des Hintergrunds</string>
|
||||
<string name="widget_opacity_hint">Bei wenig Deckkraft hängt die Lesbarkeit vom Hintergrundbild ab.</string>
|
||||
<string name="widget_done">Fertig</string>
|
||||
<string-array name="widget_palettes">
|
||||
<item>Wallpaper</item><item>Wetterlage</item><item>Ozean</item><item>Wald</item><item>Sonne</item><item>Lavendel</item><item>Graphit</item>
|
||||
</string-array>
|
||||
<string name="widget_source">Quelle: Open-Meteo</string>
|
||||
<string name="widget_pick">Ort wählen</string>
|
||||
<string name="widget_follow">Mein Standort (folgt dir)</string>
|
||||
<string name="widget_loading">…</string>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/widget_bar_desc"
|
||||
android:initialLayout="@layout/glance_default_loading_layout"
|
||||
android:minWidth="250dp" android:minHeight="60dp"
|
||||
android:targetCellWidth="4" android:targetCellHeight="1"
|
||||
android:minResizeWidth="200dp" android:minResizeHeight="48dp"
|
||||
android:maxResizeWidth="600dp" android:maxResizeHeight="110dp"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="3600000"
|
||||
android:configure="app.wetter.widget.WidgetConfigActivity"
|
||||
android:widgetFeatures="reconfigurable|configuration_optional"
|
||||
android:widgetCategory="home_screen" />
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/widget_card_desc"
|
||||
android:initialLayout="@layout/glance_default_loading_layout"
|
||||
android:minWidth="250dp" android:minHeight="180dp"
|
||||
android:targetCellWidth="4" android:targetCellHeight="2"
|
||||
android:minResizeWidth="180dp" android:minResizeHeight="110dp"
|
||||
android:maxResizeWidth="600dp" android:maxResizeHeight="600dp"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="3600000"
|
||||
android:configure="app.wetter.widget.WidgetConfigActivity"
|
||||
android:widgetFeatures="reconfigurable|configuration_optional"
|
||||
android:widgetCategory="home_screen" />
|
||||
@@ -1,10 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/widget_forecast_desc"
|
||||
android:description="@string/widget_classic_desc"
|
||||
android:initialLayout="@layout/glance_default_loading_layout"
|
||||
android:minWidth="250dp" android:minHeight="110dp"
|
||||
android:targetCellWidth="4" android:targetCellHeight="2"
|
||||
android:minResizeWidth="250dp" android:minResizeHeight="110dp"
|
||||
android:minResizeWidth="140dp" android:minResizeHeight="110dp"
|
||||
android:maxResizeWidth="400dp" android:maxResizeHeight="250dp"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="3600000"
|
||||
android:configure="app.wetter.widget.WidgetConfigActivity"
|
||||
android:widgetFeatures="reconfigurable|configuration_optional"
|
||||
android:widgetCategory="home_screen" />
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/widget_now_desc"
|
||||
android:initialLayout="@layout/glance_default_loading_layout"
|
||||
android:minWidth="110dp" android:minHeight="48dp"
|
||||
android:targetCellWidth="2" android:targetCellHeight="2"
|
||||
android:minResizeWidth="110dp" android:minResizeHeight="48dp"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="3600000"
|
||||
android:widgetCategory="home_screen|keyguard" />
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/widget_pill_desc"
|
||||
android:initialLayout="@layout/glance_default_loading_layout"
|
||||
android:minWidth="200dp" android:minHeight="110dp"
|
||||
android:targetCellWidth="4" android:targetCellHeight="2"
|
||||
android:minResizeWidth="110dp" android:minResizeHeight="48dp"
|
||||
android:maxResizeWidth="400dp" android:maxResizeHeight="200dp"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="3600000"
|
||||
android:configure="app.wetter.widget.WidgetConfigActivity"
|
||||
android:widgetFeatures="reconfigurable|configuration_optional"
|
||||
android:widgetCategory="home_screen" />
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/widget_tilt_desc"
|
||||
android:initialLayout="@layout/glance_default_loading_layout"
|
||||
android:minWidth="110dp" android:minHeight="110dp"
|
||||
android:targetCellWidth="2" android:targetCellHeight="2"
|
||||
android:minResizeWidth="80dp" android:minResizeHeight="80dp"
|
||||
android:maxResizeWidth="300dp" android:maxResizeHeight="300dp"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="3600000"
|
||||
android:configure="app.wetter.widget.WidgetConfigActivity"
|
||||
android:widgetFeatures="reconfigurable|configuration_optional"
|
||||
android:widgetCategory="home_screen" />
|
||||
@@ -0,0 +1,106 @@
|
||||
package app.wetter
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.FormatListBulleted
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import app.wetter.data.Forecast
|
||||
import app.wetter.data.OpenMeteo
|
||||
import app.wetter.data.Quarter
|
||||
import app.wetter.data.Settings
|
||||
import app.wetter.data.ThemeMode
|
||||
import app.wetter.ui.screens.DayContent
|
||||
import app.wetter.ui.screens.ForecastPage
|
||||
import app.wetter.ui.screens.SettingsScreen
|
||||
import app.wetter.ui.theme.WeatherTheme
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import java.time.LocalDateTime
|
||||
|
||||
/** Renders the screens on the JVM into replica/clone-screens/ for replica-diff. Data: a real Open-Meteo response. */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(sdk = [35], qualifiers = "de-rDE-w412dp-h915dp-xxhdpi", application = android.app.Application::class)
|
||||
class ScreenshotTest {
|
||||
@get:Rule val compose = createComposeRule()
|
||||
|
||||
private fun fixture(): Forecast {
|
||||
val f = javaClass.classLoader!!.getResource("berlin_forecast.json")!!.readText()
|
||||
val a = javaClass.classLoader!!.getResource("berlin_air.json")!!.readText()
|
||||
val parsed = OpenMeteo().parse(f, a, System.currentTimeMillis())
|
||||
// pin "now" to the response's own current time so the shots never drift
|
||||
val now = LocalDateTime.parse(Regex("\"current\":\\{\"time\":\"([^\"]+)\"").find(f)!!.groupValues[1])
|
||||
return parsed.copy(clock = now)
|
||||
}
|
||||
|
||||
private fun Forecast.with(code: Int, isDay: Boolean, rainSoon: Boolean = false): Forecast {
|
||||
val minutely = if (!rainSoon) minutely else List(12) { i ->
|
||||
Quarter(now.withMinute(0).plusMinutes(15L * i), if (i in 2..7) listOf(0.2, 0.5, 0.9, 1.4, 0.8, 0.3)[i - 2] else 0.0)
|
||||
}
|
||||
return copy(current = current.copy(code = code, isDay = isDay), minutely = minutely)
|
||||
}
|
||||
|
||||
private fun shot(name: String, theme: ThemeMode, content: @Composable () -> Unit) {
|
||||
compose.setContent { WeatherTheme(theme) { content() } }
|
||||
compose.onRoot().captureRoboImage("../../replica/clone-screens/$name.png")
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Home(f: Forecast, title: String = "Berlin", preview: Boolean = false) = ForecastPage(
|
||||
title = title, isCurrent = !preview, forecast = f, settings = Settings(), animate = false,
|
||||
refreshing = false, error = null, onRefresh = {},
|
||||
navigation = { IconButton(onClick = {}) { Icon(Icons.Rounded.FormatListBulleted, null) } },
|
||||
actions = {
|
||||
if (preview) FilledTonalButton(onClick = {}) { Text("Speichern") }
|
||||
else IconButton(onClick = {}) { Icon(Icons.Rounded.Settings, null) }
|
||||
},
|
||||
)
|
||||
|
||||
@Test fun parserReadsRealResponse() {
|
||||
val f = fixture()
|
||||
assertEquals(10, f.daily.size)
|
||||
assertTrue(f.hourly.size >= 240)
|
||||
assertTrue(f.upcomingHours(25).isNotEmpty())
|
||||
assertTrue(f.air?.aqi != null)
|
||||
}
|
||||
|
||||
@Test fun s01_real_light() = shot("S01-real-light", ThemeMode.LIGHT) { Home(fixture()) }
|
||||
@Test fun s01_clear_day() = shot("S01-clear-day", ThemeMode.LIGHT) { Home(fixture().with(0, true)) }
|
||||
@Test fun s01_clear_night_dark() = shot("S01-clear-night-dark", ThemeMode.DARK) { Home(fixture().with(0, false)) }
|
||||
@Test fun s01_rain_nowcast() = shot("S01-rain-nowcast", ThemeMode.LIGHT) { Home(fixture().with(63, true, rainSoon = true)) }
|
||||
@Test fun s01_snow() = shot("S01-snow", ThemeMode.LIGHT) { Home(fixture().with(73, true)) }
|
||||
@Test fun s01_storm_dark() = shot("S01-storm-dark", ThemeMode.DARK) { Home(fixture().with(95, false)) }
|
||||
|
||||
@Config(qualifiers = "de-rDE-w412dp-h2600dp-xxhdpi")
|
||||
@Test fun s01_full_light() = shot("S01-full-light", ThemeMode.LIGHT) { Home(fixture().with(2, true)) }
|
||||
|
||||
@Config(qualifiers = "de-rDE-w412dp-h2600dp-xxhdpi")
|
||||
@Test fun s01_full_dark() = shot("S01-full-dark", ThemeMode.DARK) { Home(fixture().with(0, false)) }
|
||||
|
||||
@Config(qualifiers = "de-rDE-w412dp-h1800dp-xxhdpi")
|
||||
@Test fun s04_day_dark() = shot("S04-day-dark", ThemeMode.DARK) {
|
||||
val f = fixture()
|
||||
DayContent(f, "Berlin", f.daily[1].date, Settings(), onBack = {})
|
||||
}
|
||||
|
||||
@Test fun s15_preview() = shot("S15-preview", ThemeMode.LIGHT) { Home(fixture().with(1, true), "Zwickau", preview = true) }
|
||||
@Test fun s08_settings() = shot("S08-settings", ThemeMode.LIGHT) { SettingsScreen(Settings(), onBack = {}) }
|
||||
@Test fun s08_settings_dark() = shot("S08-settings-dark", ThemeMode.DARK) { SettingsScreen(Settings(), onBack = {}) }
|
||||
|
||||
@Config(qualifiers = "de-rDE-w840dp-h900dp-xxhdpi")
|
||||
@Test fun s01_tablet() = shot("S01-tablet", ThemeMode.LIGHT) { Box { Home(fixture().with(2, true)) } }
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"latitude":52.5,"longitude":13.400002,"generationtime_ms":0.6562471389770508,"utc_offset_seconds":7200,"timezone":"Europe/Berlin","timezone_abbreviation":"GMT+2","elevation":38.0,"current_units":{"time":"iso8601","interval":"seconds","european_aqi":"EAQI","pm2_5":"μg/m³","pm10":"μg/m³","alder_pollen":"grains/m³","birch_pollen":"grains/m³","grass_pollen":"grains/m³","mugwort_pollen":"grains/m³","olive_pollen":"grains/m³","ragweed_pollen":"grains/m³"},"current":{"time":"2026-10-17T13:00","interval":3600,"european_aqi":20,"pm2_5":5.0,"pm10":5.1,"alder_pollen":0.0,"birch_pollen":0.0,"grass_pollen":0.0,"mugwort_pollen":0.0,"olive_pollen":0.0,"ragweed_pollen":0.0}}
|
||||
@@ -0,0 +1 @@
|
||||
{"latitude":52.512604,"longitude":13.419517,"generationtime_ms":5132.478952407837,"utc_offset_seconds":7200,"timezone":"Europe/Berlin","timezone_abbreviation":"GMT+2","elevation":38.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C","apparent_temperature":"°C","weather_code":"wmo code","is_day":"","relative_humidity_2m":"%","dew_point_2m":"°C","wind_speed_10m":"km/h","wind_direction_10m":"°","wind_gusts_10m":"km/h","pressure_msl":"hPa","visibility":"m","uv_index":""},"current":{"time":"2026-10-17T13:45","interval":900,"temperature_2m":12.2,"apparent_temperature":10.4,"weather_code":3,"is_day":1,"relative_humidity_2m":85,"dew_point_2m":9.8,"wind_speed_10m":12.4,"wind_direction_10m":343,"wind_gusts_10m":27.7,"pressure_msl":1018.6,"visibility":23900.00,"uv_index":0.35},"minutely_15_units":{"time":"iso8601","precipitation":"mm"},"minutely_15":{"time":["2026-10-17T13:45","2026-10-17T14:00","2026-10-17T14:15","2026-10-17T14:30","2026-10-17T14:45","2026-10-17T15:00","2026-10-17T15:15","2026-10-17T15:30","2026-10-17T15:45","2026-10-17T16:00","2026-10-17T16:15","2026-10-17T16:30","2026-10-17T16:45","2026-10-17T17:00","2026-10-17T17:15","2026-10-17T17:30"],"precipitation":[0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.10,0.30,0.50,0.30,0.10,0.00,0.00,0.00]},"hourly_units":{"time":"iso8601","temperature_2m":"°C","weather_code":"wmo code","is_day":"","precipitation_probability":"%","precipitation":"mm","wind_speed_10m":"km/h","relative_humidity_2m":"%"},"hourly":{"time":["2026-10-17T00:00","2026-10-17T01:00","2026-10-17T02:00","2026-10-17T03:00","2026-10-17T04:00","2026-10-17T05:00","2026-10-17T06:00","2026-10-17T07:00","2026-10-17T08:00","2026-10-17T09:00","2026-10-17T10:00","2026-10-17T11:00","2026-10-17T12:00","2026-10-17T13:00","2026-10-17T14:00","2026-10-17T15:00","2026-10-17T16:00","2026-10-17T17:00","2026-10-17T18:00","2026-10-17T19:00","2026-10-17T20:00","2026-10-17T21:00","2026-10-17T22:00","2026-10-17T23:00","2026-10-18T00:00","2026-10-18T01:00","2026-10-18T02:00","2026-10-18T03:00","2026-10-18T04:00","2026-10-18T05:00","2026-10-18T06:00","2026-10-18T07:00","2026-10-18T08:00","2026-10-18T09:00","2026-10-18T10:00","2026-10-18T11:00","2026-10-18T12:00","2026-10-18T13:00","2026-10-18T14:00","2026-10-18T15:00","2026-10-18T16:00","2026-10-18T17:00","2026-10-18T18:00","2026-10-18T19:00","2026-10-18T20:00","2026-10-18T21:00","2026-10-18T22:00","2026-10-18T23:00","2026-10-19T00:00","2026-10-19T01:00","2026-10-19T02:00","2026-10-19T03:00","2026-10-19T04:00","2026-10-19T05:00","2026-10-19T06:00","2026-10-19T07:00","2026-10-19T08:00","2026-10-19T09:00","2026-10-19T10:00","2026-10-19T11:00","2026-10-19T12:00","2026-10-19T13:00","2026-10-19T14:00","2026-10-19T15:00","2026-10-19T16:00","2026-10-19T17:00","2026-10-19T18:00","2026-10-19T19:00","2026-10-19T20:00","2026-10-19T21:00","2026-10-19T22:00","2026-10-19T23:00","2026-10-20T00:00","2026-10-20T01:00","2026-10-20T02:00","2026-10-20T03:00","2026-10-20T04:00","2026-10-20T05:00","2026-10-20T06:00","2026-10-20T07:00","2026-10-20T08:00","2026-10-20T09:00","2026-10-20T10:00","2026-10-20T11:00","2026-10-20T12:00","2026-10-20T13:00","2026-10-20T14:00","2026-10-20T15:00","2026-10-20T16:00","2026-10-20T17:00","2026-10-20T18:00","2026-10-20T19:00","2026-10-20T20:00","2026-10-20T21:00","2026-10-20T22:00","2026-10-20T23:00","2026-10-21T00:00","2026-10-21T01:00","2026-10-21T02:00","2026-10-21T03:00","2026-10-21T04:00","2026-10-21T05:00","2026-10-21T06:00","2026-10-21T07:00","2026-10-21T08:00","2026-10-21T09:00","2026-10-21T10:00","2026-10-21T11:00","2026-10-21T12:00","2026-10-21T13:00","2026-10-21T14:00","2026-10-21T15:00","2026-10-21T16:00","2026-10-21T17:00","2026-10-21T18:00","2026-10-21T19:00","2026-10-21T20:00","2026-10-21T21:00","2026-10-21T22:00","2026-10-21T23:00","2026-10-22T00:00","2026-10-22T01:00","2026-10-22T02:00","2026-10-22T03:00","2026-10-22T04:00","2026-10-22T05:00","2026-10-22T06:00","2026-10-22T07:00","2026-10-22T08:00","2026-10-22T09:00","2026-10-22T10:00","2026-10-22T11:00","2026-10-22T12:00","2026-10-22T13:00","2026-10-22T14:00","2026-10-22T15:00","2026-10-22T16:00","2026-10-22T17:00","2026-10-22T18:00","2026-10-22T19:00","2026-10-22T20:00","2026-10-22T21:00","2026-10-22T22:00","2026-10-22T23:00","2026-10-23T00:00","2026-10-23T01:00","2026-10-23T02:00","2026-10-23T03:00","2026-10-23T04:00","2026-10-23T05:00","2026-10-23T06:00","2026-10-23T07:00","2026-10-23T08:00","2026-10-23T09:00","2026-10-23T10:00","2026-10-23T11:00","2026-10-23T12:00","2026-10-23T13:00","2026-10-23T14:00","2026-10-23T15:00","2026-10-23T16:00","2026-10-23T17:00","2026-10-23T18:00","2026-10-23T19:00","2026-10-23T20:00","2026-10-23T21:00","2026-10-23T22:00","2026-10-23T23:00","2026-10-24T00:00","2026-10-24T01:00","2026-10-24T02:00","2026-10-24T03:00","2026-10-24T04:00","2026-10-24T05:00","2026-10-24T06:00","2026-10-24T07:00","2026-10-24T08:00","2026-10-24T09:00","2026-10-24T10:00","2026-10-24T11:00","2026-10-24T12:00","2026-10-24T13:00","2026-10-24T14:00","2026-10-Line truncated
|
||||
@@ -0,0 +1 @@
|
||||
{"reason":"The service is overloaded","error":true}
|
||||
@@ -0,0 +1 @@
|
||||
{"latitude":48.853382,"longitude":2.355208,"generationtime_ms":5108.713507652283,"utc_offset_seconds":7200,"timezone":"Europe/Paris","timezone_abbreviation":"GMT+2","elevation":46.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C","apparent_temperature":"°C","weather_code":"wmo code","is_day":"","relative_humidity_2m":"%","dew_point_2m":"°C","wind_speed_10m":"km/h","wind_direction_10m":"°","wind_gusts_10m":"km/h","pressure_msl":"hPa","visibility":"m","uv_index":""},"current":{"time":"2026-10-17T14:00","interval":900,"temperature_2m":15.1,"apparent_temperature":11.2,"weather_code":2,"is_day":1,"relative_humidity_2m":51,"dew_point_2m":5.0,"wind_speed_10m":17.8,"wind_direction_10m":21,"wind_gusts_10m":38.5,"pressure_msl":1028.0,"visibility":40940.00,"uv_index":3.30},"minutely_15_units":{"time":"iso8601","precipitation":"mm"},"minutely_15":{"time":["2026-10-17T14:00","2026-10-17T14:15","2026-10-17T14:30","2026-10-17T14:45","2026-10-17T15:00","2026-10-17T15:15","2026-10-17T15:30","2026-10-17T15:45","2026-10-17T16:00","2026-10-17T16:15","2026-10-17T16:30","2026-10-17T16:45","2026-10-17T17:00","2026-10-17T17:15","2026-10-17T17:30","2026-10-17T17:45"],"precipitation":[0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00]},"hourly_units":{"time":"iso8601","temperature_2m":"°C","weather_code":"wmo code","is_day":"","precipitation_probability":"%","precipitation":"mm","wind_speed_10m":"km/h","relative_humidity_2m":"%"},"hourly":{"time":["2026-10-17T00:00","2026-10-17T01:00","2026-10-17T02:00","2026-10-17T03:00","2026-10-17T04:00","2026-10-17T05:00","2026-10-17T06:00","2026-10-17T07:00","2026-10-17T08:00","2026-10-17T09:00","2026-10-17T10:00","2026-10-17T11:00","2026-10-17T12:00","2026-10-17T13:00","2026-10-17T14:00","2026-10-17T15:00","2026-10-17T16:00","2026-10-17T17:00","2026-10-17T18:00","2026-10-17T19:00","2026-10-17T20:00","2026-10-17T21:00","2026-10-17T22:00","2026-10-17T23:00","2026-10-18T00:00","2026-10-18T01:00","2026-10-18T02:00","2026-10-18T03:00","2026-10-18T04:00","2026-10-18T05:00","2026-10-18T06:00","2026-10-18T07:00","2026-10-18T08:00","2026-10-18T09:00","2026-10-18T10:00","2026-10-18T11:00","2026-10-18T12:00","2026-10-18T13:00","2026-10-18T14:00","2026-10-18T15:00","2026-10-18T16:00","2026-10-18T17:00","2026-10-18T18:00","2026-10-18T19:00","2026-10-18T20:00","2026-10-18T21:00","2026-10-18T22:00","2026-10-18T23:00","2026-10-19T00:00","2026-10-19T01:00","2026-10-19T02:00","2026-10-19T03:00","2026-10-19T04:00","2026-10-19T05:00","2026-10-19T06:00","2026-10-19T07:00","2026-10-19T08:00","2026-10-19T09:00","2026-10-19T10:00","2026-10-19T11:00","2026-10-19T12:00","2026-10-19T13:00","2026-10-19T14:00","2026-10-19T15:00","2026-10-19T16:00","2026-10-19T17:00","2026-10-19T18:00","2026-10-19T19:00","2026-10-19T20:00","2026-10-19T21:00","2026-10-19T22:00","2026-10-19T23:00","2026-10-20T00:00","2026-10-20T01:00","2026-10-20T02:00","2026-10-20T03:00","2026-10-20T04:00","2026-10-20T05:00","2026-10-20T06:00","2026-10-20T07:00","2026-10-20T08:00","2026-10-20T09:00","2026-10-20T10:00","2026-10-20T11:00","2026-10-20T12:00","2026-10-20T13:00","2026-10-20T14:00","2026-10-20T15:00","2026-10-20T16:00","2026-10-20T17:00","2026-10-20T18:00","2026-10-20T19:00","2026-10-20T20:00","2026-10-20T21:00","2026-10-20T22:00","2026-10-20T23:00","2026-10-21T00:00","2026-10-21T01:00","2026-10-21T02:00","2026-10-21T03:00","2026-10-21T04:00","2026-10-21T05:00","2026-10-21T06:00","2026-10-21T07:00","2026-10-21T08:00","2026-10-21T09:00","2026-10-21T10:00","2026-10-21T11:00","2026-10-21T12:00","2026-10-21T13:00","2026-10-21T14:00","2026-10-21T15:00","2026-10-21T16:00","2026-10-21T17:00","2026-10-21T18:00","2026-10-21T19:00","2026-10-21T20:00","2026-10-21T21:00","2026-10-21T22:00","2026-10-21T23:00","2026-10-22T00:00","2026-10-22T01:00","2026-10-22T02:00","2026-10-22T03:00","2026-10-22T04:00","2026-10-22T05:00","2026-10-22T06:00","2026-10-22T07:00","2026-10-22T08:00","2026-10-22T09:00","2026-10-22T10:00","2026-10-22T11:00","2026-10-22T12:00","2026-10-22T13:00","2026-10-22T14:00","2026-10-22T15:00","2026-10-22T16:00","2026-10-22T17:00","2026-10-22T18:00","2026-10-22T19:00","2026-10-22T20:00","2026-10-22T21:00","2026-10-22T22:00","2026-10-22T23:00","2026-10-23T00:00","2026-10-23T01:00","2026-10-23T02:00","2026-10-23T03:00","2026-10-23T04:00","2026-10-23T05:00","2026-10-23T06:00","2026-10-23T07:00","2026-10-23T08:00","2026-10-23T09:00","2026-10-23T10:00","2026-10-23T11:00","2026-10-23T12:00","2026-10-23T13:00","2026-10-23T14:00","2026-10-23T15:00","2026-10-23T16:00","2026-10-23T17:00","2026-10-23T18:00","2026-10-23T19:00","2026-10-23T20:00","2026-10-23T21:00","2026-10-23T22:00","2026-10-23T23:00","2026-10-24T00:00","2026-10-24T01:00","2026-10-24T02:00","2026-10-24T03:00","2026-10-24T04:00","2026-10-24T05:00","2026-10-24T06:00","2026-10-24T07:00","2026-10-24T08:00","2026-10-24T09:00","2026-10-24T10:00","2026-10-24T11:00","2026-10-24T12:00","2026-10-24T13:00","2026-10-24T14:00","2026-10-24TLine truncated
|
||||
@@ -0,0 +1 @@
|
||||
{"latitude":64.139565,"longitude":-21.971603,"generationtime_ms":1892.8502798080444,"utc_offset_seconds":0,"timezone":"Atlantic/Reykjavik","timezone_abbreviation":"GMT","elevation":0.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C","apparent_temperature":"°C","weather_code":"wmo code","is_day":"","relative_humidity_2m":"%","dew_point_2m":"°C","wind_speed_10m":"km/h","wind_direction_10m":"°","wind_gusts_10m":"km/h","pressure_msl":"hPa","visibility":"m","uv_index":""},"current":{"time":"2026-10-17T12:00","interval":900,"temperature_2m":8.8,"apparent_temperature":1.5,"weather_code":3,"is_day":1,"relative_humidity_2m":75,"dew_point_2m":4.6,"wind_speed_10m":40.7,"wind_direction_10m":151,"wind_gusts_10m":72.4,"pressure_msl":1015.0,"visibility":50000.00,"uv_index":0.70},"minutely_15_units":{"time":"iso8601","precipitation":"mm"},"minutely_15":{"time":["2026-10-17T12:00","2026-10-17T12:15","2026-10-17T12:30","2026-10-17T12:45","2026-10-17T13:00","2026-10-17T13:15","2026-10-17T13:30","2026-10-17T13:45","2026-10-17T14:00","2026-10-17T14:15","2026-10-17T14:30","2026-10-17T14:45","2026-10-17T15:00","2026-10-17T15:15","2026-10-17T15:30","2026-10-17T15:45"],"precipitation":[0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.10,0.10,0.10,0.10,0.50,0.50,0.50]},"hourly_units":{"time":"iso8601","temperature_2m":"°C","weather_code":"wmo code","is_day":"","precipitation_probability":"%","precipitation":"mm","wind_speed_10m":"km/h","relative_humidity_2m":"%"},"hourly":{"time":["2026-10-17T00:00","2026-10-17T01:00","2026-10-17T02:00","2026-10-17T03:00","2026-10-17T04:00","2026-10-17T05:00","2026-10-17T06:00","2026-10-17T07:00","2026-10-17T08:00","2026-10-17T09:00","2026-10-17T10:00","2026-10-17T11:00","2026-10-17T12:00","2026-10-17T13:00","2026-10-17T14:00","2026-10-17T15:00","2026-10-17T16:00","2026-10-17T17:00","2026-10-17T18:00","2026-10-17T19:00","2026-10-17T20:00","2026-10-17T21:00","2026-10-17T22:00","2026-10-17T23:00","2026-10-18T00:00","2026-10-18T01:00","2026-10-18T02:00","2026-10-18T03:00","2026-10-18T04:00","2026-10-18T05:00","2026-10-18T06:00","2026-10-18T07:00","2026-10-18T08:00","2026-10-18T09:00","2026-10-18T10:00","2026-10-18T11:00","2026-10-18T12:00","2026-10-18T13:00","2026-10-18T14:00","2026-10-18T15:00","2026-10-18T16:00","2026-10-18T17:00","2026-10-18T18:00","2026-10-18T19:00","2026-10-18T20:00","2026-10-18T21:00","2026-10-18T22:00","2026-10-18T23:00","2026-10-19T00:00","2026-10-19T01:00","2026-10-19T02:00","2026-10-19T03:00","2026-10-19T04:00","2026-10-19T05:00","2026-10-19T06:00","2026-10-19T07:00","2026-10-19T08:00","2026-10-19T09:00","2026-10-19T10:00","2026-10-19T11:00","2026-10-19T12:00","2026-10-19T13:00","2026-10-19T14:00","2026-10-19T15:00","2026-10-19T16:00","2026-10-19T17:00","2026-10-19T18:00","2026-10-19T19:00","2026-10-19T20:00","2026-10-19T21:00","2026-10-19T22:00","2026-10-19T23:00","2026-10-20T00:00","2026-10-20T01:00","2026-10-20T02:00","2026-10-20T03:00","2026-10-20T04:00","2026-10-20T05:00","2026-10-20T06:00","2026-10-20T07:00","2026-10-20T08:00","2026-10-20T09:00","2026-10-20T10:00","2026-10-20T11:00","2026-10-20T12:00","2026-10-20T13:00","2026-10-20T14:00","2026-10-20T15:00","2026-10-20T16:00","2026-10-20T17:00","2026-10-20T18:00","2026-10-20T19:00","2026-10-20T20:00","2026-10-20T21:00","2026-10-20T22:00","2026-10-20T23:00","2026-10-21T00:00","2026-10-21T01:00","2026-10-21T02:00","2026-10-21T03:00","2026-10-21T04:00","2026-10-21T05:00","2026-10-21T06:00","2026-10-21T07:00","2026-10-21T08:00","2026-10-21T09:00","2026-10-21T10:00","2026-10-21T11:00","2026-10-21T12:00","2026-10-21T13:00","2026-10-21T14:00","2026-10-21T15:00","2026-10-21T16:00","2026-10-21T17:00","2026-10-21T18:00","2026-10-21T19:00","2026-10-21T20:00","2026-10-21T21:00","2026-10-21T22:00","2026-10-21T23:00","2026-10-22T00:00","2026-10-22T01:00","2026-10-22T02:00","2026-10-22T03:00","2026-10-22T04:00","2026-10-22T05:00","2026-10-22T06:00","2026-10-22T07:00","2026-10-22T08:00","2026-10-22T09:00","2026-10-22T10:00","2026-10-22T11:00","2026-10-22T12:00","2026-10-22T13:00","2026-10-22T14:00","2026-10-22T15:00","2026-10-22T16:00","2026-10-22T17:00","2026-10-22T18:00","2026-10-22T19:00","2026-10-22T20:00","2026-10-22T21:00","2026-10-22T22:00","2026-10-22T23:00","2026-10-23T00:00","2026-10-23T01:00","2026-10-23T02:00","2026-10-23T03:00","2026-10-23T04:00","2026-10-23T05:00","2026-10-23T06:00","2026-10-23T07:00","2026-10-23T08:00","2026-10-23T09:00","2026-10-23T10:00","2026-10-23T11:00","2026-10-23T12:00","2026-10-23T13:00","2026-10-23T14:00","2026-10-23T15:00","2026-10-23T16:00","2026-10-23T17:00","2026-10-23T18:00","2026-10-23T19:00","2026-10-23T20:00","2026-10-23T21:00","2026-10-23T22:00","2026-10-23T23:00","2026-10-24T00:00","2026-10-24T01:00","2026-10-24T02:00","2026-10-24T03:00","2026-10-24T04:00","2026-10-24T05:00","2026-10-24T06:00","2026-10-24T07:00","2026-10-24T08:00","2026-10-24T09:00","2026-10-24T10:00","2026-10-24T11:00","2026-10-24T12:00","2026-10-24T13:00","2026-10-24T14:00","2026-10-2Line truncated
|
||||