From 4ecc9747f10800ceea141c7a7c1b60a500a3e3c3 Mon Sep 17 00:00:00 2001 From: Fabian Norlin Date: Wed, 8 Oct 2025 20:28:35 +0200 Subject: [PATCH] Bugfix for klotter update: Home: rescan and mark nearby Klotter so new finds appear on location/setting changes --- .../kotlin/app/klottr/KlottrAppShell.kt | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/shared/src/commonMain/kotlin/app/klottr/KlottrAppShell.kt b/shared/src/commonMain/kotlin/app/klottr/KlottrAppShell.kt index 0ff35bd..04aec60 100644 --- a/shared/src/commonMain/kotlin/app/klottr/KlottrAppShell.kt +++ b/shared/src/commonMain/kotlin/app/klottr/KlottrAppShell.kt @@ -329,6 +329,61 @@ fun KlottrAppShell( } } + // Löser bugg som gjorde att Klotter-fynd inte dök upp: Klotter: skanna nära klotter och markera i FoundStore så Hem-fliken uppdateras + LaunchedEffect(showKlotter, locationTick) { + if (!showKlotter) return@LaunchedEffect + + val gp = LocationServiceProvider.get().current(highAccuracy = false) ?: return@LaunchedEffect + lastKnownLat = gp.lat + lastKnownLon = gp.lon + + // Hämta klotter inom standardradien (20 m) + val nearby = withContext(Dispatchers.IO) { + Geocache.getNearby( + lat = gp.lat, + lon = gp.lon, + radiusMeters = Config.DEFAULT_KLOTTER_RADIUS_M, + ttlMs = 0L + ) + } + + // Markera nya (ej tidigare kända) som "hittade" + val known = FoundStore.getAll() + .asSequence() + .filter { it.layer == LAYER_KLOTTER } + .map { it.id } + .toSet() + + var anyNew = false + val now = Clock.System.now().toEpochMilliseconds() + + for (n in nearby) { + val idStr = n.i.toString() + if (idStr !in known) { + FoundStore.markFound( + layer = LAYER_KLOTTER, + id = idStr, + label = n.t ?: "Klotter", + lat = n.a, + lon = n.o, + timeMillis = now + ) + anyNew = true + } + } + + // Uppdatera away-flaggor (fetstil i listan blir korrekt) + FoundStore.updateAwayFlags(gp.lat, gp.lon) + + if (anyNew) { + // Återställ ev. "tvinga tomt" och trigga omritning + forceEmptyFound = false + FoundEvents.notifyFoundUpdated() + refreshFound() + } + } + + Scaffold( topBar = { CenterAlignedTopAppBar(