Fix: reinstate cross-platform hit notifications via KMP Notifier; trigger on first new item found

This commit is contained in:
2025-10-15 14:07:12 +02:00
parent 100a7f3f2d
commit 5b846b634f
10 changed files with 128 additions and 6 deletions

View File

@@ -289,6 +289,14 @@ fun KlottrAppShell(
}
}
// Initiera notifieraren på Android
LaunchedEffect(Unit) {
try {
app.klottr.platform.PlatformNotifierProvider.provide()
} catch (e: Exception) {
// I iOS krävs ingen init; Android får context senare via PlatformNotifierProvider.init(context)
}
}
// 🔴 NYTT: Omedelbar UI-uppdatering när FoundStore ändras
// Found updates via shared event bus (no broadcasts)
@@ -659,7 +667,7 @@ fun KlottrAppShell(
// Trigga scanning när fliken blir aktiv (och när lager-inställningar ändras)
LaunchedEffect(selectedTab, showKlotter, showWiki, wikiRadius, showDm, dmRadius, showFornsok, fornsokRadius) {
if (selectedTab != "nearby") return@LaunchedEffect
nearbyRefreshing = true
nearbyRefreshing = true // Visa den grafiska loading-effekten.
nearbyError = null
val gp = LocationServiceProvider.get().current(highAccuracy = false)

View File

@@ -55,13 +55,17 @@ suspend fun scanAndMarkFound(
}
var anyNew = false
var firstNewLabel: String? = null
// Wikipedia
for (w in wikiDef.await()) {
val d = distanceMeters(lat, lon, w.lat, w.lon).roundToInt()
if (d <= config.wikiRadius) {
val added = markFound(FoundStore.LAYER_WIKI, w.pageId.toString(), w.title, w.lat, w.lon, now)
if (added) anyNew = true
if (added) {
anyNew = true
if (firstNewLabel == null) firstNewLabel = w.title
}
}
}
@@ -70,7 +74,10 @@ suspend fun scanAndMarkFound(
val d = distanceMeters(lat, lon, dmi.lat, dmi.lon).roundToInt()
if (d <= config.dmRadius) {
val added = markFound(FoundStore.LAYER_DM, dmi.id, dmi.title, dmi.lat, dmi.lon, now)
if (added) anyNew = true
if (added) {
anyNew = true
if (firstNewLabel == null) firstNewLabel = dmi.title
}
}
}
@@ -79,9 +86,21 @@ suspend fun scanAndMarkFound(
val d = distanceMeters(lat, lon, f.lat, f.lon).roundToInt()
if (d <= config.fornsokRadius) {
val added = markFound(FoundStore.LAYER_FORNSOK, f.id, f.title, f.lat, f.lon, now)
if (added) anyNew = true
if (added) {
anyNew = true
if (firstNewLabel == null) firstNewLabel = f.title
}
}
}
// Skicka notifiering om nya fynd hittats
if (anyNew) {
val notifier = app.klottr.platform.PlatformNotifierProvider.provide()
val title = firstNewLabel ?: "Nytt fynd"
// Dessa lager har inte brödtext här — vi skickar bara titeln.
val message = ""
notifier.notifyNewHit(title, message)
}
// Returnera om något nytt markerades
anyNew
}

View File

@@ -128,11 +128,10 @@ object Geocache {
return@withContext items
}
return@withContext firstItems
}
// Skyddad fetch som aldrig kastar – använder KlottrApiShared.nearby från din KlottrApiShared.kt
// Skyddad fetch som aldrig kastar – använder KlottrApiShared.nearby från KlottrApiShared.kt
private suspend fun safeFetch(
lat: Double,
lon: Double,

View File

@@ -0,0 +1,9 @@
package app.klottr.platform
/**
* Plattformsgemensamt gränssnitt för att skicka lokala notiser.
* Implementeras separat i androidMain och iosMain.
*/
interface Notifier {
fun notifyNewHit(title: String, message: String)
}

View File

@@ -0,0 +1,8 @@
package app.klottr.platform
/**
* Gemensam "expect"-deklaration som plattformerna implementerar var för sig.
*/
expect object PlatformNotifierProvider {
fun provide(): Notifier
}