Location refactor compiles and seemingly works

Location updates now handled in a more compose friendly way via StateFlow
Lots of small changed in MainActivity and DetailDialogShell to make them platform independent
Add new platform apis for openUrl, openMap (AppNavigator)
Add Platform independent OutboxScheduler
Try to clean up event handling of FoundEvents and location updates (need more cleanup)
New wrapper for handling App Context in shared (could be used to clean up integration further)
This commit is contained in:
Olof Hedman
2025-09-24 16:23:38 +02:00
parent 0d1e54fcd8
commit 642e546a09
20 changed files with 317 additions and 230 deletions

View File

@@ -0,0 +1,15 @@
package app.klottr.events
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
object FoundEvents {
private val _foundUpdated = MutableSharedFlow<Unit>(extraBufferCapacity = 8)
val foundUpdated: SharedFlow<Unit> = _foundUpdated
private val _locationTick = MutableSharedFlow<Unit>(extraBufferCapacity = 8)
val locationTick: SharedFlow<Unit> = _locationTick
fun notifyFoundUpdated() { _foundUpdated.tryEmit(Unit) }
fun notifyLocationTick() { _locationTick.tryEmit(Unit) }
}

View File

@@ -42,7 +42,7 @@ data class LocationUpdates(
/** Simple, common store (replaces various platform stores). */
object LastLocationStore {
private val _lastKnown = MutableStateFlow<GeoPoint?>(null)
val lastKnown: StateFlow<GeoPoint?> = _lastKnown.asStateFlow()
val lastKnownLocation: StateFlow<GeoPoint?> = _lastKnown.asStateFlow()
fun update(p: GeoPoint?) { _lastKnown.value = p }
}

View File

@@ -19,7 +19,6 @@ fun isClickable( //
//Markera nya fynd i FoundStore baserat på delade entries (plattformneutral hjälpare)
fun markNewFinds( //
ctx: Any?, //Context-parameter hålls som Any? i KMP
entries: List<NearbyEntryShared>, //Delade “Närliggande”-rader
nowMillis: Long, //Tidpunkt för markering
onMarked: () -> Unit //Callback om något faktiskt markerats nytt

View File

@@ -0,0 +1,24 @@
package app.klottr.platform
/**
* Platform-independent navigation helpers used from common UI.
* Android uses Intents; iOS opens via UIApplication.
*/
expect object AppNavigator {
fun openUrl(url: String)
fun openMap(lat: Double, lon: Double, label: String? = null)
}
enum class UiFeedbackDuration {
SHORT,
LONG
}
/**
* Lightweight user feedback facade (e.g. toast / banner).
* On iOS this can no-op or present a subtle HUD, implementation-defined.
*/
expect object UiFeedback {
fun showMessage(text: String, duration: UiFeedbackDuration = UiFeedbackDuration.LONG)
}

View File

@@ -0,0 +1,8 @@
package app.klottr.platform
/**
* Schedule a one-shot upload job when network is connected.
*/
expect object OutboxScheduler {
fun scheduleUpload()
}

View File

@@ -3,12 +3,15 @@ package app.klottr.ui
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize // Vi fyller ytan
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.foundation.text.BasicText
import app.klottr.location.GeoPoint
import app.klottr.util.FoundEntry
import app.klottr.nearby.foundSubtitle
import app.klottr.nearby.layerDisplayName
import kotlinx.coroutines.flow.StateFlow
/**
* Material-fritt innehåll för "Hittat".
@@ -18,8 +21,7 @@ import app.klottr.nearby.layerDisplayName
@Composable
fun FoundContent(
entries: List<FoundEntry>,
currentLat: Double?,
currentLon: Double?,
location: State<GeoPoint?>,
showCoords: Boolean,
// Förbättrade etiketter (klotter): nyckel = "layer|id"
labelOverrides: Map<String, String>,
@@ -55,8 +57,8 @@ fun FoundContent(
subtitleFor = { f ->
foundSubtitle(
entry = f,
currentLat = currentLat,
currentLon = currentLon,
currentLat = location.value?.lat,
currentLon = location.value?.lon,
showCoords = showCoords,
distanceFormatter = distanceFormatter,
coordsFormatter = coordsFormatter

View File

@@ -2,9 +2,11 @@ package app.klottr.ui
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp // För .dp i padding/spacedBy
import app.klottr.location.GeoPoint
import app.klottr.util.FoundEntry
@Composable
@@ -12,8 +14,7 @@ fun KlottrHomeContent(
contentPadding: PaddingValues,
// FoundContent-parametrar (delat)
entries: List<FoundEntry>,
currentLat: Double?,
currentLon: Double?,
location: State<GeoPoint?>,
showCoords: Boolean,
labelOverrides: Map<String, String>,
isClickable: (FoundEntry) -> Boolean,
@@ -41,8 +42,7 @@ fun KlottrHomeContent(
) {
FoundContent(
entries = entries,
currentLat = currentLat,
currentLon = currentLon,
location = location,
showCoords = showCoords,
labelOverrides = labelOverrides,
isClickable = isClickable,