10 Commits
Author SHA1 Message Date
MrBlakeandClaude Opus 5.5 27bf4e88f4 fix: retry Open-Meteo on 429/5xx and show why loading failed
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 14:09:21 +02:00
MrBlakeandClaude Opus 5.5 c61b03b48f test: re-record screenshots after scene path change
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 14:02:14 +02:00
MrBlakeandClaude Opus 5.5 054c76d093 perf: draw-phase scene animation, parallel and de-duplicated loading, release build
- scene time and scroll offset are read only while drawing, so frames no longer recompose the page
- forecast and air quality load in parallel; concurrent refreshes of one location share a request
- saving a previewed place stores the already loaded forecast instead of fetching again
- platform fused location provider first; recent last-known position used at once
- release build signed with the debug key for local installs

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 14:01:38 +02:00
MrBlakeandClaude Opus 5.5 c446798403 test: screenshot tests from a real Open-Meteo response
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 13:52:42 +02:00
MrBlakeandClaude Opus 5.5 c1c76252f1 build: S12 widgets (now, forecast)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 13:52:42 +02:00
MrBlakeandClaude Opus 5.5 c0bf0f6042 build: S08 settings and S09 units
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 13:52:42 +02:00
MrBlakeandClaude Opus 5.5 1d8c3f8f5f build: S04 day detail
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 13:52:42 +02:00
MrBlakeandClaude Opus 5.5 c5c1483544 build: S15 location preview
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 13:52:42 +02:00
MrBlakeandClaude Opus 5.5 a9f2f69398 build: S02 locations and S03 search
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 13:52:42 +02:00
MrBlakeandClaude Opus 5.5 b359249c59 build: S01 home and S14 permission prompt
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 13:52:42 +02:00
30 changed files with 1304 additions and 30 deletions

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 904 KiB

After

Width:  |  Height:  |  Size: 907 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 893 KiB

After

Width:  |  Height:  |  Size: 895 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 794 KiB

After

Width:  |  Height:  |  Size: 800 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 843 KiB

After

Width:  |  Height:  |  Size: 846 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 976 KiB

After

Width:  |  Height:  |  Size: 978 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 887 KiB

After

Width:  |  Height:  |  Size: 890 KiB

+3
View File
@@ -22,6 +22,9 @@ android {
buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
// local installs only; a real release key comes with /replica-deploy
signingConfig = signingConfigs.getByName("debug")
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
@@ -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
}
@@ -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)
@@ -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,120 @@
package app.wetter.ui.screens
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
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.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
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.theme.WSpace
import app.wetter.ui.theme.WType
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) } }
Scaffold(
topBar = {
TopAppBar(
title = { Text(stringResource(R.string.settings)) },
navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Rounded.ArrowBack, stringResource(R.string.back)) } },
)
},
) { pad ->
Column(Modifier.padding(pad).verticalScroll(rememberScrollState()).padding(horizontal = WSpace.s16)) {
Header(stringResource(R.string.set_units))
Choice(stringResource(R.string.set_temp), TempUnit.entries, settings.temp, { if (it == TempUnit.C) "°C" else "°F" }) { v -> set { it.copy(temp = v) } }
Choice(stringResource(R.string.set_wind), WindUnit.entries, settings.wind, {
when (it) { WindUnit.KMH -> "km/h"; WindUnit.MS -> "m/s"; WindUnit.MPH -> "mph"; WindUnit.KN -> "kn" }
}) { v -> set { it.copy(wind = v) } }
Choice(stringResource(R.string.set_precip), PrecipUnit.entries, settings.precip, { if (it == PrecipUnit.MM) "mm" else "in" }) { v -> set { it.copy(precip = v) } }
Choice(stringResource(R.string.set_pressure), PressureUnit.entries, settings.pressure, { if (it == PressureUnit.HPA) "hPa" else "inHg" }) { v -> set { it.copy(pressure = v) } }
Choice(stringResource(R.string.set_distance), DistanceUnit.entries, settings.distance, { if (it == DistanceUnit.KM) "km" else "mi" }) { v -> set { it.copy(distance = v) } }
Header(stringResource(R.string.set_look))
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),
)
Choice(stringResource(R.string.set_theme), ThemeMode.entries, settings.theme, { themeLabels.getValue(it) }) { v -> set { it.copy(theme = v) } }
Toggle(stringResource(R.string.set_animations), stringResource(R.string.set_animations_sub), settings.animations) { v -> set { it.copy(animations = v) } }
Toggle(stringResource(R.string.set_brief), null, settings.brief) { v -> set { it.copy(brief = v) } }
Header(stringResource(R.string.set_about))
Text(stringResource(R.string.attribution), style = WType.bodySm, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(bottom = WSpace.s32))
}
}
}
@Composable
private fun Header(text: String) = Text(
text, style = WType.title, color = MaterialTheme.colorScheme.primary,
modifier = Modifier.padding(top = WSpace.s24, bottom = WSpace.s8).semantics { heading() },
)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun <T> Choice(label: String, options: List<T>, selected: T, name: (T) -> String, onPick: (T) -> Unit) {
Column(Modifier.padding(vertical = WSpace.s8)) {
Text(label, style = WType.body)
SingleChoiceSegmentedButtonRow(Modifier.fillMaxWidth().padding(top = WSpace.s8).selectableGroup()) {
options.forEachIndexed { i, o ->
SegmentedButton(
selected = o == selected,
onClick = { onPick(o) },
shape = SegmentedButtonDefaults.itemShape(i, options.size),
) { Text(name(o)) }
}
}
}
}
@Composable
private fun Toggle(label: String, sub: String?, checked: Boolean, onChange: (Boolean) -> Unit) {
Row(
Modifier.fillMaxWidth().toggleable(checked, role = Role.Switch, onValueChange = onChange).padding(vertical = WSpace.s12),
verticalAlignment = Alignment.CenterVertically,
) {
Column(Modifier.weight(1f)) {
Text(label, style = WType.body)
if (sub != null) Text(sub, style = WType.bodySm, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
Switch(checked, onCheckedChange = null)
}
}
@@ -0,0 +1,34 @@
package app.wetter.widget
import android.graphics.Bitmap
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Canvas
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.unit.Density
import androidx.compose.ui.unit.LayoutDirection
import app.wetter.data.Condition
import app.wetter.ui.scene.Particles
import app.wetter.ui.scene.SceneSpec
import app.wetter.ui.scene.drawSceneLayers
import app.wetter.ui.scene.drawWeatherIcon
/** Widgets cannot run shaders or animations, so the scene and icons 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) }
/** Still frame of the sky, small enough for the RemoteViews size limit. */
fun scene(spec: SceneSpec, w: Int = 480, h: Int = 320): Bitmap = render(w, h) {
drawRect(Brush.verticalGradient(listOf(spec.top, spec.bottom)))
drawSceneLayers(spec, t = .2f, scroll = 0f, particles = Particles.make(spec.condition))
}
}
@@ -0,0 +1,242 @@
package app.wetter.widget
import android.content.Context
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.ActionParameters
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.ActionCallback
import androidx.glance.appwidget.action.actionRunCallback
import androidx.glance.appwidget.action.actionStartActivity
import androidx.glance.appwidget.cornerRadius
import androidx.glance.appwidget.provideContent
import androidx.glance.appwidget.updateAll
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 as FixedColor
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.data.intensityOf
import app.wetter.ui.components.conditionLabel
import app.wetter.ui.scene.SceneSpec
import app.wetter.ui.theme.WRadius
import app.wetter.work.RefreshWorker
import kotlinx.coroutines.flow.first
import java.time.LocalDate
suspend fun updateAllWidgets(context: Context) {
NowWidget().updateAll(context)
ForecastWidget().updateAll(context)
}
private class WidgetData(val location: LocationEntity?, val forecast: Forecast?, val units: Units)
private suspend fun load(context: Context, id: GlanceId): WidgetData {
Graph.init(context)
val appWidgetId = GlanceAppWidgetManager(context).getAppWidgetId(id)
val location = Graph.repo.widgetLocation(appWidgetId)
val forecast = location?.let { Graph.repo.forecastOnce(it.id) }
val settings = runCatching { Graph.settings.settings.first() }.getOrDefault(Settings())
return WidgetData(location, forecast, Units(settings))
}
class RefreshAction : ActionCallback {
override suspend fun onAction(context: Context, glanceId: GlanceId, parameters: ActionParameters) {
RefreshWorker.runNow(context)
}
}
/** Shared frame: scene bitmap behind, rounded, tap opens the city. */
@Composable
private fun Frame(data: WidgetData, content: @Composable (SceneSpec) -> Unit) {
val context = LocalContext.current
val f = data.forecast
val spec = f?.let { SceneSpec(conditionOf(it.current.code), it.current.isDay, intensityOf(it.current.code)) }
?: SceneSpec(app.wetter.data.Condition.CLOUDY, true)
Box(
GlanceModifier.fillMaxSize().cornerRadius(WRadius.widget)
.clickable(actionStartActivity(MainActivity.intent(context, data.location?.id))),
) {
Image(ImageProvider(WidgetArt.scene(spec)), null, GlanceModifier.fillMaxSize(), contentScale = ContentScale.FillBounds)
content(spec)
}
}
private fun text(color: Color, size: Int, weight: FontWeight = FontWeight.Normal, align: TextAlign = TextAlign.Start) =
TextStyle(color = FixedColor(color), fontSize = size.sp, fontWeight = weight, textAlign = align)
/** 2×1 and 2×2: icon + temperature, larger adds city, condition, high/low. */
class NowWidget : GlanceAppWidget() {
override val sizeMode = SizeMode.Responsive(setOf(SMALL, MEDIUM))
override suspend fun provideGlance(context: Context, id: GlanceId) {
val data = load(context, id)
provideContent { Content(data) }
}
@Composable
private fun Content(data: WidgetData) {
val context = LocalContext.current
val size = LocalSize.current
Frame(data) { spec ->
val fg = spec.onScene
val f = data.forecast
if (f == null) {
Box(GlanceModifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(context.getString(R.string.widget_loading), style = text(fg, 16))
}
return@Frame
}
val u = data.units
val cond = conditionOf(f.current.code)
val condText = context.getString(conditionLabel(cond, f.current.isDay))
val name = data.location?.name?.ifBlank { context.getString(R.string.current_location) } ?: ""
val summary = "$name ${u.temp(f.current.temp)} $condText"
if (size.height < MEDIUM.height) {
Row(
GlanceModifier.fillMaxSize().padding(horizontal = 16.dp).semantics { contentDescription = summary },
verticalAlignment = Alignment.CenterVertically, horizontalAlignment = Alignment.CenterHorizontally,
) {
Image(ImageProvider(WidgetArt.icon(cond, f.current.isDay)), null, GlanceModifier.size(40.dp))
Spacer(GlanceModifier.width(8.dp))
Text(u.temp(f.current.temp), style = text(fg, 36, FontWeight.Bold))
}
} else {
Column(GlanceModifier.fillMaxSize().padding(16.dp).semantics { contentDescription = summary }) {
Text(name, style = text(fg, 14, FontWeight.Medium), maxLines = 1)
Spacer(GlanceModifier.defaultWeight())
Row(verticalAlignment = Alignment.CenterVertically) {
Text(u.temp(f.current.temp), style = text(fg, 44, FontWeight.Bold))
Spacer(GlanceModifier.width(6.dp))
Image(ImageProvider(WidgetArt.icon(cond, f.current.isDay)), null, GlanceModifier.size(40.dp))
}
Text(condText, style = text(fg, 13), maxLines = 1)
f.today?.let { Text("↑ ${u.temp(it.tMax)} ↓ ${u.temp(it.tMin)}", style = text(fg, 12)) }
}
}
}
}
companion object {
val SMALL = DpSize(110.dp, 48.dp)
val MEDIUM = DpSize(110.dp, 110.dp)
}
}
/** 4×2 hourly, 4×3 and up adds the next days. */
class ForecastWidget : GlanceAppWidget() {
override val sizeMode = SizeMode.Responsive(setOf(WIDE, TALL))
override suspend fun provideGlance(context: Context, id: GlanceId) {
val data = load(context, id)
provideContent { Content(data) }
}
@Composable
private fun Content(data: WidgetData) {
val context = LocalContext.current
val size = LocalSize.current
Frame(data) { spec ->
val fg = spec.onScene
val f = data.forecast
if (f == null) {
Box(GlanceModifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(context.getString(R.string.widget_loading), style = text(fg, 16))
}
return@Frame
}
val u = data.units
val cond = conditionOf(f.current.code)
val name = data.location?.name?.ifBlank { context.getString(R.string.current_location) } ?: ""
Column(GlanceModifier.fillMaxSize().padding(16.dp)) {
Row(GlanceModifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
Column(GlanceModifier.defaultWeight()) {
Text(name, style = text(fg, 14, FontWeight.Medium), maxLines = 1)
Text(context.getString(conditionLabel(cond, f.current.isDay)), style = text(fg, 12), maxLines = 1)
}
Text(u.temp(f.current.temp), style = text(fg, 36, FontWeight.Bold))
Image(ImageProvider(WidgetArt.icon(cond, f.current.isDay)), null, GlanceModifier.size(36.dp))
Image(
ImageProvider(R.drawable.ic_refresh), context.getString(R.string.retry),
GlanceModifier.size(28.dp).padding(4.dp).clickable(actionRunCallback<RefreshAction>()),
colorFilter = androidx.glance.ColorFilter.tint(FixedColor(fg)),
)
}
Spacer(GlanceModifier.height(10.dp))
Row(GlanceModifier.fillMaxWidth()) {
f.upcomingHours(6).forEachIndexed { i, h ->
Column(GlanceModifier.defaultWeight(), horizontalAlignment = Alignment.CenterHorizontally) {
Text(if (i == 0) context.getString(R.string.now) else Fmt.hourLabel(h.time), style = text(fg, 11, align = TextAlign.Center))
Image(ImageProvider(WidgetArt.icon(conditionOf(h.code), h.isDay, 96)), null, GlanceModifier.size(26.dp))
Text(u.temp(h.temp), style = text(fg, 13, FontWeight.Medium, TextAlign.Center))
}
}
}
if (size.height >= TALL.height) {
Spacer(GlanceModifier.height(12.dp))
val today = f.daily.firstOrNull()?.date
f.daily.take(5).forEach { d ->
Row(GlanceModifier.fillMaxWidth().padding(vertical = 2.dp), verticalAlignment = Alignment.CenterVertically) {
Text(
if (d.date == today) context.getString(R.string.today) else Fmt.weekdayShort(d.date),
style = text(fg, 13), modifier = GlanceModifier.width(56.dp),
)
Image(ImageProvider(WidgetArt.icon(conditionOf(d.code), true, 96)), null, GlanceModifier.size(22.dp))
Text(if (d.precipProb >= 10) " ${d.precipProb} %" else "", style = text(fg, 11), modifier = GlanceModifier.defaultWeight())
Text("${u.temp(d.tMin)} ${u.temp(d.tMax)}", style = text(fg, 13, FontWeight.Medium))
}
}
}
}
}
}
companion object {
val WIDE = DpSize(250.dp, 110.dp)
val TALL = DpSize(250.dp, 250.dp)
}
}
class NowWidgetReceiver : GlanceAppWidgetReceiver() {
override val glanceAppWidget: GlanceAppWidget = NowWidget()
}
class ForecastWidgetReceiver : GlanceAppWidgetReceiver() {
override val glanceAppWidget: GlanceAppWidget = ForecastWidget()
}
@@ -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>
@@ -0,0 +1,105 @@
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 = {}) }
@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