shared(location): add expect/actual LastLocationStore (GeoPoint)
app(util): adapt LastLocationStore to delegate to shared store while keeping android.location.Location API
This commit is contained in:
@@ -25,5 +25,19 @@ object MatchBus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object LastLocationStore {
|
object LastLocationStore {
|
||||||
@Volatile var lastKnownLocation: Location? = null
|
// Adapter som låter befintlig Android-kod använda android.location.Location,
|
||||||
|
// men under huven lagras värdet i KMP-store (GeoPoint) i :shared.
|
||||||
|
var lastKnownLocation: Location?
|
||||||
|
get() {
|
||||||
|
val gp = app.klottr.location.LastLocationStore.lastKnown // Hämta från delad store
|
||||||
|
return gp?.let {
|
||||||
|
Location("klottr").apply { latitude = it.lat; longitude = it.lon }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
app.klottr.location.LastLocationStore.lastKnown = value?.let {
|
||||||
|
app.klottr.location.GeoPoint(it.latitude, it.longitude)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package app.klottr.location
|
||||||
|
|
||||||
|
/** Android-implementationen håller bara ett volatilt fält. */
|
||||||
|
actual object LastLocationStore {
|
||||||
|
@Volatile
|
||||||
|
actual var lastKnown: GeoPoint? = null
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package app.klottr.location
|
||||||
|
|
||||||
|
/** Delad platsstore: senaste kända position som enkel GeoPoint. */
|
||||||
|
expect object LastLocationStore {
|
||||||
|
var lastKnown: GeoPoint?
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user