WIP: Add new location service, disable old.
Note: this commit does not compile
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package app.klottr.location
|
||||
|
||||
/** Delad platsstore: senaste kända position som enkel GeoPoint. */
|
||||
expect object LastLocationStore {
|
||||
var lastKnown: GeoPoint?
|
||||
}
|
||||
///** Delad platsstore: senaste kända position som enkel GeoPoint. */
|
||||
//expect object LastLocationStore {
|
||||
// var lastKnown: GeoPoint?
|
||||
//}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package app.klottr.location
|
||||
|
||||
/** Enkel delad platsmodell för KMP. */
|
||||
data class GeoPoint(val lat: Double, val lon: Double)
|
||||
|
||||
/** Gränssnitt för plattforms-specifik platsinhämtning. */
|
||||
interface LocationProvider {
|
||||
/** Returnerar aktuell plats eller senaste kända, eller null vid fel/tidsutlöpning. */
|
||||
suspend fun currentOrLastKnown(): GeoPoint?
|
||||
}
|
||||
///** Enkel delad platsmodell för KMP. */
|
||||
//data class GeoPoint(val lat: Double, val lon: Double)
|
||||
//
|
||||
///** Gränssnitt för plattforms-specifik platsinhämtning. */
|
||||
//interface LocationProvider {
|
||||
// /** Returnerar aktuell plats eller senaste kända, eller null vid fel/tidsutlöpning. */
|
||||
// suspend fun currentOrLastKnown(): GeoPoint?
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package app.klottr.location
|
||||
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
/**
|
||||
* Platform-independent, Flow-based location API.
|
||||
* Everything used by UI/Workers should depend on this interface.
|
||||
*/
|
||||
interface LocationService {
|
||||
/** Last known or most recent location (null until the first fix). */
|
||||
val location: StateFlow<GeoPoint?>
|
||||
|
||||
/** Start continuous updates (idempotent). */
|
||||
fun start(updates: LocationUpdates = LocationUpdates())
|
||||
|
||||
/** Stop updates (idempotent). */
|
||||
fun stop()
|
||||
|
||||
/** Try to get a fresh fix (falls back to last known). */
|
||||
suspend fun current(highAccuracy: Boolean = true, timeoutMillis: Long = 10_000): GeoPoint?
|
||||
|
||||
/** Whether platform indicates location services are enabled. */
|
||||
suspend fun isLocationEnabled(): Boolean
|
||||
}
|
||||
|
||||
/** Minimal, platform-agnostic location model for UI/worker. */
|
||||
data class GeoPoint(
|
||||
val lat: Double,
|
||||
val lon: Double,
|
||||
val accuracyMeters: Double? = null,
|
||||
val timeMillis: Long? = null,
|
||||
)
|
||||
|
||||
data class LocationUpdates(
|
||||
val desiredIntervalMillis: Long = 5_000,
|
||||
val fastestIntervalMillis: Long = 2_000,
|
||||
val highAccuracy: Boolean = true,
|
||||
)
|
||||
|
||||
/** Simple, common store (replaces various platform stores). */
|
||||
object LastLocationStore {
|
||||
private val _lastKnown = MutableStateFlow<GeoPoint?>(null)
|
||||
val lastKnown: StateFlow<GeoPoint?> = _lastKnown.asStateFlow()
|
||||
|
||||
fun update(p: GeoPoint?) { _lastKnown.value = p }
|
||||
}
|
||||
|
||||
/** Accessor to a shared instance (can be replaced via DI if you like). */
|
||||
expect object LocationServiceProvider {
|
||||
fun get(): LocationService
|
||||
}
|
||||
Reference in New Issue
Block a user