shared(location): move AndroidLocationProvider to shared/androidMain; add play-services-location and coroutines-play-services deps; add iOS stub
app(main): update imports and keep using centralized provider for startup, auto-scans, and “Nearby” flow
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package app.klottr.location
|
||||
|
||||
import android.content.Context
|
||||
import com.google.android.gms.location.LocationServices
|
||||
import com.google.android.gms.location.Priority
|
||||
import kotlinx.coroutines.tasks.await
|
||||
|
||||
/** Android-implementation som använder FusedLocationProvider. */
|
||||
object AndroidLocationProvider : LocationProvider {
|
||||
|
||||
/** Hämtar lastLocation och faller tillbaka till getCurrentLocation. */
|
||||
suspend fun currentOrLastKnown(context: Context): GeoPoint? {
|
||||
val client = LocationServices.getFusedLocationProviderClient(context)
|
||||
return try {
|
||||
val last = client.lastLocation.await()
|
||||
val loc = last ?: client.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, null).await()
|
||||
loc?.let { GeoPoint(it.latitude, it.longitude) }
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
// Interface-override finns för framtida DI utan Context (används ej av :app idag).
|
||||
override suspend fun currentOrLastKnown(): GeoPoint? = null
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package app.klottr.location
|
||||
|
||||
/** iOS-stub tills riktig plats läggs till. */
|
||||
object IosLocationProvider : LocationProvider {
|
||||
override suspend fun currentOrLastKnown(): GeoPoint? = null
|
||||
}
|
||||
Reference in New Issue
Block a user