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:
@@ -137,6 +137,7 @@ import app.klottr.ui.UsernameDialog
|
|||||||
import app.klottr.ui.WikiArticleDialog // Ny: dialogskalet ligger nu i ui-paketet
|
import app.klottr.ui.WikiArticleDialog // Ny: dialogskalet ligger nu i ui-paketet
|
||||||
import app.klottr.ui.WriteDocContent // Använd delad, material-fri formulär-UI
|
import app.klottr.ui.WriteDocContent // Använd delad, material-fri formulär-UI
|
||||||
import app.klottr.auth.AuthPlatform
|
import app.klottr.auth.AuthPlatform
|
||||||
|
import app.klottr.events.FoundEvents
|
||||||
import app.klottr.util.AuthShared
|
import app.klottr.util.AuthShared
|
||||||
import app.klottr.util.PlatformAuthStorage
|
import app.klottr.util.PlatformAuthStorage
|
||||||
import app.klottr.util.AuthStorageDelegate
|
import app.klottr.util.AuthStorageDelegate
|
||||||
@@ -145,7 +146,7 @@ import app.klottr.util.FoundStore
|
|||||||
import app.klottr.util.FoundStore.LAYER_KLOTTER
|
import app.klottr.util.FoundStore.LAYER_KLOTTER
|
||||||
import app.klottr.util.ImageBitmapCache
|
import app.klottr.util.ImageBitmapCache
|
||||||
import app.klottr.util.KLog
|
import app.klottr.util.KLog
|
||||||
import app.klottr.util.LastLocationStore
|
import app.klottr.location.LastLocationStore
|
||||||
import app.klottr.util.NoteDetailCache
|
import app.klottr.util.NoteDetailCache
|
||||||
import app.klottr.util.OutboxStore
|
import app.klottr.util.OutboxStore
|
||||||
import app.klottr.util.SettingsStore
|
import app.klottr.util.SettingsStore
|
||||||
@@ -172,6 +173,11 @@ import app.klottr.maps.MapContainer
|
|||||||
import app.klottr.maps.MapFeature
|
import app.klottr.maps.MapFeature
|
||||||
import app.klottr.maps.MapState
|
import app.klottr.maps.MapState
|
||||||
import app.klottr.maps.MapUiSettings
|
import app.klottr.maps.MapUiSettings
|
||||||
|
import app.klottr.platform.AndroidAppContext
|
||||||
|
import app.klottr.platform.AppNavigator
|
||||||
|
import app.klottr.platform.OutboxScheduler
|
||||||
|
import app.klottr.platform.UiFeedback
|
||||||
|
import app.klottr.platform.UiFeedbackDuration
|
||||||
import app.klottr.maps.MapType as CrossMapType
|
import app.klottr.maps.MapType as CrossMapType
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
@@ -186,6 +192,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
KLog.setEnabled(BuildConfig.KLLOG_DEBUG) // Styr loggnivå via buildflagga
|
KLog.setEnabled(BuildConfig.KLLOG_DEBUG) // Styr loggnivå via buildflagga
|
||||||
app.klottr.prefs.KvPrefs.init(applicationContext)
|
app.klottr.prefs.KvPrefs.init(applicationContext)
|
||||||
LocationServiceProvider.init(applicationContext)
|
LocationServiceProvider.init(applicationContext)
|
||||||
|
AndroidAppContext.install(applicationContext)
|
||||||
|
|
||||||
// FG + (ev) BG platstillstånd
|
// FG + (ev) BG platstillstånd
|
||||||
fgPermissionLauncher =
|
fgPermissionLauncher =
|
||||||
@@ -391,58 +398,40 @@ private fun KlottrAppShell(
|
|||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
val gp = LocationServiceProvider.get().current(highAccuracy = false)
|
val gp = LocationServiceProvider.get().current(highAccuracy = false)
|
||||||
if (gp != null) {
|
if (gp != null) {
|
||||||
LastLocationStore.lastKnownLocation = android.location.Location("kmp").apply {
|
// LastLocationStore.lastKnownLocation = android.location.Location("kmp").apply {
|
||||||
latitude = gp.lat
|
// latitude = gp.lat
|
||||||
longitude = gp.lon
|
// longitude = gp.lon
|
||||||
time = gp.timeMillis ?: System.currentTimeMillis()
|
// time = gp.timeMillis ?: System.currentTimeMillis()
|
||||||
accuracy = (gp.accuracyMeters ?: 0.0).toFloat()
|
// accuracy = (gp.accuracyMeters ?: 0.0).toFloat()
|
||||||
}
|
// }
|
||||||
FoundStore.updateAwayFlags(gp.lat, gp.lon)
|
FoundStore.updateAwayFlags(gp.lat, gp.lon)
|
||||||
locationTick++
|
locationTick++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Direkt UI-uppdatering från LocationService
|
|
||||||
DisposableEffect(Unit) {
|
|
||||||
val filter = IntentFilter(LocationService.ACTION_FOUND_UPDATED)
|
|
||||||
val receiver = object : BroadcastReceiver() {
|
|
||||||
override fun onReceive(ctx: Context?, intent: Intent?) {
|
|
||||||
forceEmptyFound = false
|
|
||||||
refreshFound()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 33) {
|
|
||||||
context.registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED)
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
context.registerReceiver(receiver, filter)
|
|
||||||
}
|
|
||||||
onDispose { try { context.unregisterReceiver(receiver) } catch (_: Exception) {} }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Direkt UI-uppdatering när FoundStore/KvPrefs ändras (oavsett broadcast)
|
// Direkt UI-uppdatering när FoundStore/KvPrefs ändras (oavsett broadcast)
|
||||||
DisposableEffect(Unit) {
|
// TODO: OH: Detta ska inte behövas
|
||||||
val handler = android.os.Handler(android.os.Looper.getMainLooper())
|
// DisposableEffect(Unit) {
|
||||||
val kvListener: (String?) -> Unit = {
|
// val handler = android.os.Handler(android.os.Looper.getMainLooper())
|
||||||
handler.post {
|
// val kvListener: (String?) -> Unit = {
|
||||||
forceEmptyFound = false
|
// handler.post {
|
||||||
refreshFound() // trigga recomposition av “Senaste”
|
// forceEmptyFound = false
|
||||||
}
|
// refreshFound() // trigga recomposition av “Senaste”
|
||||||
}
|
// }
|
||||||
app.klottr.prefs.KvPrefs.addListener(kvListener)
|
// }
|
||||||
onDispose { app.klottr.prefs.KvPrefs.removeListener(kvListener) }
|
// app.klottr.prefs.KvPrefs.addListener(kvListener)
|
||||||
}
|
// onDispose { app.klottr.prefs.KvPrefs.removeListener(kvListener) }
|
||||||
|
// }
|
||||||
|
|
||||||
// Lyssna på KMP LocationService-flöde istället för broadcast
|
// Lyssna på KMP LocationService-flöde istället för broadcast
|
||||||
LaunchedEffect(currentLoc.value?.lat, currentLoc.value?.lon) {
|
LaunchedEffect(currentLoc.value?.lat, currentLoc.value?.lon) {
|
||||||
currentLoc.value?.let { gp ->
|
currentLoc.value?.let { gp ->
|
||||||
LastLocationStore.lastKnownLocation = android.location.Location("kmp").apply {
|
// LastLocationStore.lastKnownLocation = android.location.Location("kmp").apply {
|
||||||
latitude = gp.lat
|
// latitude = gp.lat
|
||||||
longitude = gp.lon
|
// longitude = gp.lon
|
||||||
time = gp.timeMillis ?: System.currentTimeMillis()
|
// time = gp.timeMillis ?: System.currentTimeMillis()
|
||||||
accuracy = (gp.accuracyMeters ?: 0.0).toFloat()
|
// accuracy = (gp.accuracyMeters ?: 0.0).toFloat()
|
||||||
}
|
// }
|
||||||
FoundStore.updateAwayFlags(gp.lat, gp.lon)
|
FoundStore.updateAwayFlags(gp.lat, gp.lon)
|
||||||
locationTick++
|
locationTick++
|
||||||
}
|
}
|
||||||
@@ -450,15 +439,13 @@ private fun KlottrAppShell(
|
|||||||
|
|
||||||
|
|
||||||
// 🔴 NYTT: Omedelbar UI-uppdatering när FoundStore ändras (SharedPreferences)
|
// 🔴 NYTT: Omedelbar UI-uppdatering när FoundStore ändras (SharedPreferences)
|
||||||
DisposableEffect(Unit) {
|
// Found updates via shared event bus (no broadcasts)
|
||||||
val prefs = context.getSharedPreferences("klottr_found_store", Context.MODE_PRIVATE)
|
LaunchedEffect(Unit) {
|
||||||
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, _ ->
|
FoundEvents.foundUpdated.collect {
|
||||||
// Trigga omritning varje gång FoundStore uppdateras
|
// Trigga omritning varje gång FoundStore uppdateras
|
||||||
forceEmptyFound = false
|
forceEmptyFound = false
|
||||||
refreshFound()
|
refreshFound()
|
||||||
}
|
}
|
||||||
prefs.registerOnSharedPreferenceChangeListener(listener)
|
|
||||||
onDispose { prefs.unregisterOnSharedPreferenceChangeListener(listener) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(showWiki, wikiRadius, showDm, dmRadius, showFornsok, fornsokRadius) {
|
LaunchedEffect(showWiki, wikiRadius, showDm, dmRadius, showFornsok, fornsokRadius) {
|
||||||
@@ -525,8 +512,8 @@ private fun KlottrAppShell(
|
|||||||
// Förladdning av etiketter/bilder (oförändrad logik, flyttad hit)
|
// Förladdning av etiketter/bilder (oförändrad logik, flyttad hit)
|
||||||
LaunchedEffect(foundKey) {
|
LaunchedEffect(foundKey) {
|
||||||
val my = LastLocationStore.lastKnownLocation
|
val my = LastLocationStore.lastKnownLocation
|
||||||
val myLat = my?.latitude
|
val myLat = my.value?.lat
|
||||||
val myLon = my?.longitude
|
val myLon = my.value?.lon
|
||||||
labelOverrides.clear()
|
labelOverrides.clear()
|
||||||
foundList.forEach { f ->
|
foundList.forEach { f ->
|
||||||
if (f.layer == LAYER_KLOTTER) {
|
if (f.layer == LAYER_KLOTTER) {
|
||||||
@@ -581,8 +568,7 @@ private fun KlottrAppShell(
|
|||||||
KlottrHomeContent(
|
KlottrHomeContent(
|
||||||
contentPadding = padding,
|
contentPadding = padding,
|
||||||
entries = foundList,
|
entries = foundList,
|
||||||
currentLat = LastLocationStore.lastKnownLocation?.latitude,
|
location = LastLocationStore.lastKnownLocation.collectAsState(),
|
||||||
currentLon = LastLocationStore.lastKnownLocation?.longitude,
|
|
||||||
showCoords = showCoords,
|
showCoords = showCoords,
|
||||||
labelOverrides = labelOverrides,
|
labelOverrides = labelOverrides,
|
||||||
isClickable = { f ->
|
isClickable = { f ->
|
||||||
@@ -653,7 +639,6 @@ private fun KlottrAppShell(
|
|||||||
nearbyLoading = true
|
nearbyLoading = true
|
||||||
nearbyError = null
|
nearbyError = null
|
||||||
showNearby = true
|
showNearby = true
|
||||||
val ctx = context
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val gp = LocationServiceProvider.get().current(highAccuracy = false)
|
val gp = LocationServiceProvider.get().current(highAccuracy = false)
|
||||||
if (gp == null) {
|
if (gp == null) {
|
||||||
@@ -697,7 +682,6 @@ private fun KlottrAppShell(
|
|||||||
|
|
||||||
val nowMillis = System.currentTimeMillis()
|
val nowMillis = System.currentTimeMillis()
|
||||||
app.klottr.nearby.markNewFinds(
|
app.klottr.nearby.markNewFinds(
|
||||||
ctx = ctx,
|
|
||||||
entries = bundle.entries, // Använd direkt från bundle
|
entries = bundle.entries, // Använd direkt från bundle
|
||||||
nowMillis = nowMillis,
|
nowMillis = nowMillis,
|
||||||
onMarked = { refreshFound() }
|
onMarked = { refreshFound() }
|
||||||
@@ -760,10 +744,7 @@ private fun KlottrAppShell(
|
|||||||
onKlotterClick = { id, la, lo, label ->
|
onKlotterClick = { id, la, lo, label ->
|
||||||
openKlotter = OpenKlotter(id = id, lat = la, lon = lo, label = label)
|
openKlotter = OpenKlotter(id = id, lat = la, lon = lo, label = label)
|
||||||
},
|
},
|
||||||
onOpenUrl = { _, url ->
|
onOpenUrl = { _, url -> AppNavigator.openUrl(url) },
|
||||||
val i = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
|
||||||
try { context.startActivity(i) } catch (_: Exception) {}
|
|
||||||
},
|
|
||||||
isKnownNote = { noteId ->
|
isKnownNote = { noteId ->
|
||||||
// Känd = finns i Hittat (FoundStore) → ska alltid visa titel
|
// Känd = finns i Hittat (FoundStore) → ska alltid visa titel
|
||||||
FoundStore
|
FoundStore
|
||||||
@@ -807,14 +788,17 @@ private fun KlottrAppShell(
|
|||||||
forceEmptyFound = true // Visa tomt direkt
|
forceEmptyFound = true // Visa tomt direkt
|
||||||
refreshFound() // Tvinga omritning
|
refreshFound() // Tvinga omritning
|
||||||
|
|
||||||
// 1) Nollställ sessions-gates inne i tjänsten
|
// Clear session + notify via shared events (handled in platform location impl)
|
||||||
context.startService(
|
FoundStore.clearAll();
|
||||||
Intent(context, LocationService::class.java)
|
FoundEvents.notifyFoundUpdated()
|
||||||
.setAction(LocationService.ACTION_CLEAR_FOUND_SESSION)
|
// // 1) Nollställ sessions-gates inne i tjänsten
|
||||||
)
|
// context.startService(
|
||||||
|
// Intent(context, LocationService::class.java)
|
||||||
// 2) Pinga UI:t att rita om (nollat läge)
|
// .setAction(LocationService.ACTION_CLEAR_FOUND_SESSION)
|
||||||
context.sendBroadcast(Intent(LocationService.ACTION_FOUND_UPDATED))
|
// )
|
||||||
|
//
|
||||||
|
// // 2) Pinga UI:t att rita om (nollat läge)
|
||||||
|
// context.sendBroadcast(Intent(LocationService.ACTION_FOUND_UPDATED))
|
||||||
|
|
||||||
// 3) Be tjänsten göra en rescan
|
// 3) Be tjänsten göra en rescan
|
||||||
// old Android service call removed (handled in shared layer)
|
// old Android service call removed (handled in shared layer)
|
||||||
@@ -907,9 +891,9 @@ private fun KlottrAppShell(
|
|||||||
var isSavingDoc by remember { mutableStateOf(false) }
|
var isSavingDoc by remember { mutableStateOf(false) }
|
||||||
if (showWrite) {
|
if (showWrite) {
|
||||||
// Lagra positionen när man klickat Klottra:
|
// Lagra positionen när man klickat Klottra:
|
||||||
val initial = LastLocationStore.lastKnownLocation
|
val initial = LastLocationStore.lastKnownLocation.collectAsState()
|
||||||
val initialLat = initial?.latitude
|
val initialLat = initial.value?.lat
|
||||||
val initialLon = initial?.longitude
|
val initialLon = initial.value?.lon
|
||||||
|
|
||||||
WriteDocDialog(
|
WriteDocDialog(
|
||||||
onClose = { showWrite = false },
|
onClose = { showWrite = false },
|
||||||
@@ -967,7 +951,7 @@ private fun KlottrAppShell(
|
|||||||
|
|
||||||
when (outcome) {
|
when (outcome) {
|
||||||
is CreateNoteOutcome.Success -> {
|
is CreateNoteOutcome.Success -> {
|
||||||
Toast.makeText(context, "Sparat.", Toast.LENGTH_SHORT).show()
|
UiFeedback.showMessage("Sparat.")
|
||||||
|
|
||||||
// Markera nyskapad notis som "hittad" och uppdatera UI direkt
|
// Markera nyskapad notis som "hittad" och uppdatera UI direkt
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
@@ -997,16 +981,18 @@ private fun KlottrAppShell(
|
|||||||
timeMillis = System.currentTimeMillis()
|
timeMillis = System.currentTimeMillis()
|
||||||
)
|
)
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
context.sendBroadcast(Intent(LocationService.ACTION_FOUND_UPDATED))
|
// TODO: OH: Nog renare om foundstore är ansvarig för att skicka FoundEvents.
|
||||||
|
FoundEvents.notifyFoundUpdated()
|
||||||
}
|
}
|
||||||
// Tysta avisering för just detta klotter under 60s (slipper “pling” på eget klotter)
|
// Tysta avisering för just detta klotter under 60s (slipper “pling” på eget klotter)
|
||||||
context.startService(
|
// TODO: OH: How to implement? Via foundstore?
|
||||||
Intent(context, LocationService::class.java)
|
// context.startService(
|
||||||
.setAction(LocationService.ACTION_SUPPRESS_NOTIFY)
|
// Intent(context, LocationService::class.java)
|
||||||
.putExtra("layer", LAYER_KLOTTER)
|
// .setAction(LocationService.ACTION_SUPPRESS_NOTIFY)
|
||||||
.putExtra("id", match.i.toString())
|
// .putExtra("layer", LAYER_KLOTTER)
|
||||||
.putExtra("ttlMs", 60_000L) // Valfri – hur länge det ska vara tyst
|
// .putExtra("id", match.i.toString())
|
||||||
)
|
// .putExtra("ttlMs", 60_000L) // Valfri – hur länge det ska vara tyst
|
||||||
|
// )
|
||||||
}
|
}
|
||||||
} catch (_: Throwable) { /* no-op */ }
|
} catch (_: Throwable) { /* no-op */ }
|
||||||
}
|
}
|
||||||
@@ -1060,24 +1046,26 @@ private fun KlottrAppShell(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
scheduleUpload = {
|
scheduleUpload = {
|
||||||
val constraints = Constraints.Builder()
|
//TODO: OH: Make sure sheduleUpload adhere to connected constraint.
|
||||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
OutboxScheduler.scheduleUpload();
|
||||||
.build()
|
// val constraints = Constraints.Builder()
|
||||||
val req = OneTimeWorkRequestBuilder<OutboxWorker>()
|
// .setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
.setConstraints(constraints).build()
|
// .build()
|
||||||
WorkManager.getInstance(context).enqueue(req)
|
// val req = OneTimeWorkRequestBuilder<OutboxWorker>()
|
||||||
|
// .setConstraints(constraints).build()
|
||||||
|
// WorkManager.getInstance(context).enqueue(req)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
when (queued) {
|
when (queued) {
|
||||||
QueueOutboxOutcome.Queued -> {
|
QueueOutboxOutcome.Queued -> {
|
||||||
Toast.makeText(context, "Offline. Sparas i utkorgen.", Toast.LENGTH_LONG).show()
|
UiFeedback.showMessage( "Offline. Sparas i utkorgen.")
|
||||||
showWrite = false
|
showWrite = false
|
||||||
}
|
}
|
||||||
QueueOutboxOutcome.ImagePersistFailed -> {
|
QueueOutboxOutcome.ImagePersistFailed -> {
|
||||||
val msg = outcome.message ?: "Bilduppladdning misslyckades."
|
val msg = outcome.message ?: "Bilduppladdning misslyckades."
|
||||||
Toast.makeText(context, "$msg\nKunde inte spara bilden lokalt.", Toast.LENGTH_LONG).show()
|
UiFeedback.showMessage("$msg\nKunde inte spara bilden lokalt.")
|
||||||
// Stanna kvar i dialogen
|
// Stanna kvar i dialogen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1130,12 +1118,14 @@ private fun KlottrAppShell(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
scheduleUpload = {
|
scheduleUpload = {
|
||||||
val constraints = Constraints.Builder()
|
//TODO: OH: Make sure sheduleUpload adhere to connected constraint.
|
||||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
OutboxScheduler.scheduleUpload()
|
||||||
.build()
|
// val constraints = Constraints.Builder()
|
||||||
val req = OneTimeWorkRequestBuilder<OutboxWorker>()
|
// .setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
.setConstraints(constraints).build()
|
// .build()
|
||||||
WorkManager.getInstance(context).enqueue(req)
|
// val req = OneTimeWorkRequestBuilder<OutboxWorker>()
|
||||||
|
// .setConstraints(constraints).build()
|
||||||
|
// WorkManager.getInstance(context).enqueue(req)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1143,11 +1133,11 @@ private fun KlottrAppShell(
|
|||||||
|
|
||||||
when (queued) {
|
when (queued) {
|
||||||
QueueOutboxOutcome.Queued -> {
|
QueueOutboxOutcome.Queued -> {
|
||||||
Toast.makeText(context, "Offline. Sparas i utkorgen.", Toast.LENGTH_LONG).show()
|
UiFeedback.showMessage( "Offline. Sparas i utkorgen.")
|
||||||
showWrite = false
|
showWrite = false
|
||||||
}
|
}
|
||||||
QueueOutboxOutcome.ImagePersistFailed -> {
|
QueueOutboxOutcome.ImagePersistFailed -> {
|
||||||
Toast.makeText(context, "Kunde inte spara bilden lokalt.", Toast.LENGTH_LONG).show()
|
UiFeedback.showMessage("Kunde inte spara bilden lokalt.")
|
||||||
// Stanna kvar i dialogen, låt användaren försöka igen eller spara utan bild
|
// Stanna kvar i dialogen, låt användaren försöka igen eller spara utan bild
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1197,7 +1187,8 @@ private fun KlottrAppShell(
|
|||||||
scope.launch {
|
scope.launch {
|
||||||
me = withContext(Dispatchers.IO) { app.klottr.net.fetchMe() }
|
me = withContext(Dispatchers.IO) { app.klottr.net.fetchMe() }
|
||||||
}
|
}
|
||||||
Toast.makeText(context, "Användarnamn satt till ”$chosen”.", Toast.LENGTH_SHORT).show()
|
// Should be short message.
|
||||||
|
UiFeedback.showMessage("Användarnamn satt till ”$chosen”.", UiFeedbackDuration.SHORT)
|
||||||
},
|
},
|
||||||
onLogout = {
|
onLogout = {
|
||||||
onLogout() // ← samma onLogout som du redan skickar in till KlottrApp
|
onLogout() // ← samma onLogout som du redan skickar in till KlottrApp
|
||||||
@@ -1296,16 +1287,16 @@ private fun WriteDocDialog(
|
|||||||
) {
|
) {
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
val L = LastLocationStore.lastKnownLocation
|
val L = LastLocationStore.lastKnownLocation.value
|
||||||
if (L == null) {
|
if (L == null) {
|
||||||
Toast.makeText(context, "Ingen plats ännu – försök igen.", Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, "Ingen plats ännu – försök igen.", Toast.LENGTH_SHORT).show()
|
||||||
} else {
|
} else {
|
||||||
selectedLat = L.latitude
|
selectedLat = L.lat
|
||||||
selectedLon = L.longitude
|
selectedLon = L.lon
|
||||||
lastPosUpdateMs = System.currentTimeMillis()
|
lastPosUpdateMs = System.currentTimeMillis()
|
||||||
// update marker + camera
|
// update marker + camera
|
||||||
val la = L.latitude
|
val la = L.lat
|
||||||
val lo = L.longitude
|
val lo = L.lon
|
||||||
mapState.features = listOf(
|
mapState.features = listOf(
|
||||||
MapFeature.Marker(id = "sel", position = CrossLatLng(la, lo))
|
MapFeature.Marker(id = "sel", position = CrossLatLng(la, lo))
|
||||||
)
|
)
|
||||||
@@ -1444,22 +1435,22 @@ private fun SettingsDialog(
|
|||||||
properties = DialogProperties(usePlatformDefaultWidth = false),
|
properties = DialogProperties(usePlatformDefaultWidth = false),
|
||||||
title = { Text("Inställningar") },
|
title = { Text("Inställningar") },
|
||||||
text = {
|
text = {
|
||||||
val context = LocalContext.current
|
// val context = LocalContext.current
|
||||||
// Version-info (Android-only) → skickas som rena strängar till delad UI
|
// // Version-info (Android-only) → skickas som rena strängar till delad UI
|
||||||
val pInfo = remember {
|
// val pInfo = remember {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
context.packageManager.getPackageInfo(
|
// context.packageManager.getPackageInfo(
|
||||||
context.packageName,
|
// context.packageName,
|
||||||
PackageManager.PackageInfoFlags.of(0)
|
// PackageManager.PackageInfoFlags.of(0)
|
||||||
)
|
// )
|
||||||
} else {
|
// } else {
|
||||||
@Suppress("DEPRECATION")
|
// @Suppress("DEPRECATION")
|
||||||
context.packageManager.getPackageInfo(context.packageName, 0)
|
// context.packageManager.getPackageInfo(context.packageName, 0)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
val versionCode = PackageInfoCompat.getLongVersionCode(pInfo)
|
// val versionCode = PackageInfoCompat.getLongVersionCode(pInfo)
|
||||||
val versionLine = "Klottr v${BuildConfig.VERSION_NAME} (${BuildConfig.BUILD_TYPE}) • build $versionCode"
|
// val versionLine = "Klottr v${BuildConfig.VERSION_NAME} (${BuildConfig.BUILD_TYPE}) • build $versionCode"
|
||||||
val buildTimeLine = "Byggd ${BuildConfig.BUILD_TIME_UTC}"
|
// val buildTimeLine = "Byggd ${BuildConfig.BUILD_TIME_UTC}"
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
Modifier
|
Modifier
|
||||||
@@ -1467,8 +1458,8 @@ private fun SettingsDialog(
|
|||||||
.height(maxDialogHeight)
|
.height(maxDialogHeight)
|
||||||
) {
|
) {
|
||||||
SettingsContent(
|
SettingsContent(
|
||||||
versionLine = versionLine,
|
versionLine = "FIXME_VERSIONLINE", // TODO: OH: Do this platform independenlty
|
||||||
buildTimeLine = buildTimeLine,
|
buildTimeLine = "FIXME_BUILDTIME",
|
||||||
onlyNew = onlyNew,
|
onlyNew = onlyNew,
|
||||||
onOnlyNewChanged = onOnlyNewChanged,
|
onOnlyNewChanged = onOnlyNewChanged,
|
||||||
showCoords = showCoords,
|
showCoords = showCoords,
|
||||||
@@ -1565,27 +1556,22 @@ private fun KlotterDialog(
|
|||||||
var distanceText by remember { mutableStateOf("-") }
|
var distanceText by remember { mutableStateOf("-") }
|
||||||
|
|
||||||
fun recalcDistance() {
|
fun recalcDistance() {
|
||||||
val my = app.klottr.util.LastLocationStore.lastKnownLocation
|
val my = LastLocationStore.lastKnownLocation.value
|
||||||
val d = my?.let { app.klottr.util.distanceMeters(it.latitude, it.longitude, lat, lon).roundToInt() }
|
val d = my?.let { app.klottr.util.distanceMeters(it.lat, it.lon, lat, lon).roundToInt() }
|
||||||
distanceText = d?.let { "$it\u00A0m" } ?: "-" // hårt mellanslag
|
distanceText = d?.let { "$it\u00A0m" } ?: "-" // hårt mellanslag
|
||||||
}
|
}
|
||||||
|
|
||||||
// Räkna ut direkt vid öppning
|
// Räkna ut direkt vid öppning
|
||||||
LaunchedEffect(Unit) { recalcDistance() }
|
LaunchedEffect(Unit) { recalcDistance() }
|
||||||
|
|
||||||
// Lyssna på plats-tick så avståndet uppdateras live
|
val locService = remember { LocationServiceProvider.get() }
|
||||||
DisposableEffect(Unit) {
|
DisposableEffect(Unit) {
|
||||||
val filter = IntentFilter(LocationService.ACTION_LOCATION_TICK)
|
locService.start()
|
||||||
val receiver = object : BroadcastReceiver() {
|
onDispose { locService.stop() }
|
||||||
override fun onReceive(ctx: Context?, intent: Intent?) { recalcDistance() }
|
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= 33) {
|
val currentLocation = locService.location.collectAsState(initial = null)
|
||||||
context.registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED)
|
LaunchedEffect(currentLocation.value?.lat, currentLocation.value?.lon, lat, lon) {
|
||||||
} else {
|
recalcDistance()
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
context.registerReceiver(receiver, filter)
|
|
||||||
}
|
|
||||||
onDispose { try { context.unregisterReceiver(receiver) } catch (_: Exception) {} }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Snabb hydrering från cache om vi redan har detalj/bild
|
// Snabb hydrering från cache om vi redan har detalj/bild
|
||||||
@@ -1664,6 +1650,7 @@ private fun KlotterDialog(
|
|||||||
updatedMs = detail.updatedAt
|
updatedMs = detail.updatedAt
|
||||||
|
|
||||||
// Bild: hämta via POST (GDPR-fix), tunga saker i IO — uppdatera UI på huvudtråden.
|
// Bild: hämta via POST (GDPR-fix), tunga saker i IO — uppdatera UI på huvudtråden.
|
||||||
|
// TODO: OH: Fix image decoding platform independently
|
||||||
val imgMeta = detail.image
|
val imgMeta = detail.image
|
||||||
if (imgMeta != null && imgMeta.id > 0) {
|
if (imgMeta != null && imgMeta.id > 0) {
|
||||||
// 1) Nätverk + bitmap-dekodning i IO
|
// 1) Nätverk + bitmap-dekodning i IO
|
||||||
@@ -1755,14 +1742,7 @@ private fun KlotterDialog(
|
|||||||
) {
|
) {
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
val labelEnc = Uri.encode(titleText.ifBlank { "Plats" })
|
AppNavigator.openMap(lat, lon, titleText.ifBlank { "Plats" })
|
||||||
val uri = Uri.parse("geo:$lat,$lon?q=$lat,$lon($labelEnc)")
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW, uri).apply {
|
|
||||||
setPackage("com.google.android.apps.maps")
|
|
||||||
}
|
|
||||||
try { context.startActivity(intent) } catch (_: Exception) {
|
|
||||||
context.startActivity(Intent(Intent.ACTION_VIEW, uri))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
) { Text("Maps") }
|
) { Text("Maps") }
|
||||||
|
|
||||||
@@ -1804,7 +1784,7 @@ private fun KlotterDialog(
|
|||||||
if (deleting) return@Button
|
if (deleting) return@Button
|
||||||
val idL = id.toLongOrNull()
|
val idL = id.toLongOrNull()
|
||||||
if (idL == null) {
|
if (idL == null) {
|
||||||
Toast.makeText(context, "Ogiltigt id.", Toast.LENGTH_SHORT).show()
|
UiFeedback.showMessage( "Ogiltigt id.", UiFeedbackDuration.SHORT)
|
||||||
askDelete = false
|
askDelete = false
|
||||||
return@Button
|
return@Button
|
||||||
}
|
}
|
||||||
@@ -1813,20 +1793,15 @@ private fun KlotterDialog(
|
|||||||
try {
|
try {
|
||||||
val ok = withContext(Dispatchers.IO) { deleteNote(idL) }
|
val ok = withContext(Dispatchers.IO) { deleteNote(idL) }
|
||||||
if (ok) {
|
if (ok) {
|
||||||
Toast.makeText(context, "Klottret raderat.", Toast.LENGTH_SHORT).show()
|
UiFeedback.showMessage("Klottret raderat.", UiFeedbackDuration.SHORT)
|
||||||
|
|
||||||
// 0) Ta bort ev. detaljer ur cachen (om remove finns – annars hoppar try{} över)
|
|
||||||
try { NoteDetailCache.remove(idL) } catch (_: Throwable) {}
|
|
||||||
|
|
||||||
FoundStore.remove(LAYER_KLOTTER, id) // id är din String i KlotterDialog
|
FoundStore.remove(LAYER_KLOTTER, id) // id är din String i KlotterDialog
|
||||||
|
FoundEvents.notifyFoundUpdated();
|
||||||
// Pinga UI:t (din DisposableEffect lyssnar på ACTION_FOUND_UPDATED och kör refreshFound())
|
|
||||||
context.sendBroadcast(Intent(LocationService.ACTION_FOUND_UPDATED))
|
|
||||||
|
|
||||||
askDelete = false
|
askDelete = false
|
||||||
onClose()
|
onClose()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(context, "Kunde inte radera (behörighet/nät).", Toast.LENGTH_SHORT).show()
|
UiFeedback.showMessage("Kunde inte radera (behörighet/nät).", UiFeedbackDuration.SHORT)
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
package app.klottr.ui
|
package app.klottr.ui
|
||||||
|
|
||||||
import android.content.BroadcastReceiver
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.content.IntentFilter
|
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Build
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.heightIn
|
import androidx.compose.foundation.layout.heightIn
|
||||||
@@ -31,6 +25,7 @@ import app.klottr.net.DigitaltMuseumItem
|
|||||||
import app.klottr.net.FornsokItem
|
import app.klottr.net.FornsokItem
|
||||||
import app.klottr.net.Wikipedia
|
import app.klottr.net.Wikipedia
|
||||||
import app.klottr.location.LocationServiceProvider
|
import app.klottr.location.LocationServiceProvider
|
||||||
|
import app.klottr.platform.AppNavigator
|
||||||
import app.klottr.util.SettingsStore
|
import app.klottr.util.SettingsStore
|
||||||
import app.klottr.util.formatCoords
|
import app.klottr.util.formatCoords
|
||||||
import app.klottr.util.formatDistance
|
import app.klottr.util.formatDistance
|
||||||
@@ -47,7 +42,6 @@ fun WikiArticleDialog(
|
|||||||
lon: Double?,
|
lon: Double?,
|
||||||
onClose: () -> Unit
|
onClose: () -> Unit
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
|
||||||
val configuration = LocalConfiguration.current
|
val configuration = LocalConfiguration.current
|
||||||
val dialogWidth = (configuration.screenWidthDp.dp * 0.98f)
|
val dialogWidth = (configuration.screenWidthDp.dp * 0.98f)
|
||||||
|
|
||||||
@@ -59,7 +53,10 @@ fun WikiArticleDialog(
|
|||||||
var wikiDistanceText by remember { mutableStateOf("-") }
|
var wikiDistanceText by remember { mutableStateOf("-") }
|
||||||
val showCoords = remember { app.klottr.util.SettingsStore.getShowCoordinates() }
|
val showCoords = remember { app.klottr.util.SettingsStore.getShowCoordinates() }
|
||||||
val locService = remember { LocationServiceProvider.get() }
|
val locService = remember { LocationServiceProvider.get() }
|
||||||
LaunchedEffect(Unit) { locService.start() }
|
DisposableEffect(Unit) {
|
||||||
|
locService.start()
|
||||||
|
onDispose { locService.stop() }
|
||||||
|
}
|
||||||
val current = locService.location.collectAsState(initial = null)
|
val current = locService.location.collectAsState(initial = null)
|
||||||
LaunchedEffect(current.value?.lat, current.value?.lon, lat, lon) {
|
LaunchedEffect(current.value?.lat, current.value?.lon, lat, lon) {
|
||||||
val gp = current.value
|
val gp = current.value
|
||||||
@@ -113,18 +110,14 @@ fun WikiArticleDialog(
|
|||||||
actions = {
|
actions = {
|
||||||
Button(onClick = {
|
Button(onClick = {
|
||||||
val url = "https://sv.m.wikipedia.org/?curid=$pageId"
|
val url = "https://sv.m.wikipedia.org/?curid=$pageId"
|
||||||
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
|
AppNavigator.openUrl(url);
|
||||||
}) { Text("Läs mer") }
|
}) { Text("Läs mer") }
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
if (lat != null && lon != null) {
|
if (lat != null && lon != null) {
|
||||||
val label = if (title.isNullOrBlank()) "Wikipedia-plats" else title // Ny: hantera null/blank
|
val label = if (title.isNullOrBlank()) "Wikipedia-plats" else title // Ny: hantera null/blank
|
||||||
val uri = Uri.parse("geo:$lat,$lon?q=$lat,$lon(${Uri.encode(label)})") // Ändrad: använd label
|
AppNavigator.openMap(lat, lon, label)
|
||||||
val intent = Intent(Intent.ACTION_VIEW, uri).apply { setPackage("com.google.android.apps.maps") }
|
|
||||||
try { context.startActivity(intent) } catch (_: Exception) {
|
|
||||||
context.startActivity(Intent(Intent.ACTION_VIEW, uri))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enabled = lat != null && lon != null
|
enabled = lat != null && lon != null
|
||||||
@@ -201,19 +194,14 @@ fun FornsokDialog(
|
|||||||
actions = {
|
actions = {
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
val geoTitle = Uri.encode(title)
|
AppNavigator.openMap(platLat, platLon, title)
|
||||||
val geo = Uri.parse("geo:$platLat,$platLon?q=$platLat,$platLon($geoTitle)")
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW, geo).apply { setPackage("com.google.android.apps.maps") }
|
|
||||||
try { context.startActivity(intent) } catch (_: Exception) {
|
|
||||||
context.startActivity(Intent(Intent.ACTION_VIEW, geo))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
) { Text("Maps") }
|
) { Text("Maps") }
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
val u = link ?: return@Button
|
val u = link ?: return@Button
|
||||||
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(u)))
|
AppNavigator.openUrl(u)
|
||||||
},
|
},
|
||||||
enabled = link != null
|
enabled = link != null
|
||||||
) { Text("Läs mer") }
|
) { Text("Läs mer") }
|
||||||
@@ -243,7 +231,7 @@ fun DmDialog(
|
|||||||
val showCoords = remember { SettingsStore.getShowCoordinates() }
|
val showCoords = remember { SettingsStore.getShowCoordinates() }
|
||||||
|
|
||||||
fun recalcDmDistance() {
|
fun recalcDmDistance() {
|
||||||
val my = app.klottr.location.LastLocationStore.lastKnown.value
|
val my = app.klottr.location.LastLocationStore.lastKnownLocation.value
|
||||||
val d = my?.let {
|
val d = my?.let {
|
||||||
app.klottr.util.distanceMeters(it.lat, it.lon, item.lat, item.lon).roundToInt()
|
app.klottr.util.distanceMeters(it.lat, it.lon, item.lat, item.lon).roundToInt()
|
||||||
}
|
}
|
||||||
@@ -341,18 +329,7 @@ fun DmDialog(
|
|||||||
actions = {
|
actions = {
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
val labelEnc = Uri.encode(displayTitle)
|
AppNavigator.openMap(item.lat, item.lon, displayTitle)
|
||||||
val uri =
|
|
||||||
Uri.parse("geo:${item.lat},${item.lon}?q=${item.lat},${item.lon}($labelEnc)")
|
|
||||||
val intent = Intent(
|
|
||||||
Intent.ACTION_VIEW,
|
|
||||||
uri
|
|
||||||
).apply { setPackage("com.google.android.apps.maps") }
|
|
||||||
try {
|
|
||||||
context.startActivity(intent)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
context.startActivity(Intent(Intent.ACTION_VIEW, uri))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
) { Text("Maps") }
|
) { Text("Maps") }
|
||||||
|
|
||||||
@@ -360,11 +337,7 @@ fun DmDialog(
|
|||||||
onClick = {
|
onClick = {
|
||||||
val u = item.webUrl // Ändrad: objectUrl -> webUrl
|
val u = item.webUrl // Ändrad: objectUrl -> webUrl
|
||||||
if (!u.isNullOrBlank()) {
|
if (!u.isNullOrBlank()) {
|
||||||
val i = Intent(Intent.ACTION_VIEW, Uri.parse(u))
|
AppNavigator.openUrl(u)
|
||||||
try {
|
|
||||||
context.startActivity(i)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enabled = !item.webUrl.isNullOrBlank() // Ändrad: objectUrl -> webUrl
|
enabled = !item.webUrl.isNullOrBlank() // Ändrad: objectUrl -> webUrl
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package app.klottr.util
|
package app.klottr.util
|
||||||
|
|
||||||
import android.location.Location
|
//import android.location.Location
|
||||||
import app.klottr.data.NoteEntity
|
import app.klottr.data.NoteEntity
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlin.math.*
|
import kotlin.math.*
|
||||||
@@ -17,27 +17,27 @@ import kotlin.math.*
|
|||||||
// return 2 * R * atan2(sqrt(a), sqrt(1 - a))
|
// return 2 * R * atan2(sqrt(a), sqrt(1 - a))
|
||||||
//}
|
//}
|
||||||
|
|
||||||
fun roundCoord(v: Double): Double = (v * 1e5).roundToInt() / 1e5
|
//fun roundCoord(v: Double): Double = (v * 1e5).roundToInt() / 1e5
|
||||||
|
//
|
||||||
|
//object MatchBus {
|
||||||
|
// val match = MutableSharedFlow<NoteEntity?>(extraBufferCapacity = 1)
|
||||||
|
// fun emit(n: NoteEntity) { match.tryEmit(n) }
|
||||||
|
//}
|
||||||
|
|
||||||
object MatchBus {
|
//object LastLocationStore {
|
||||||
val match = MutableSharedFlow<NoteEntity?>(extraBufferCapacity = 1)
|
// // Adapter som låter befintlig Android-kod använda android.location.Location,
|
||||||
fun emit(n: NoteEntity) { match.tryEmit(n) }
|
// // men under huven lagras värdet i KMP-store (GeoPoint) i :shared.
|
||||||
}
|
// var lastKnownLocation: Location?
|
||||||
|
// get() {
|
||||||
object LastLocationStore {
|
// val gp = app.klottr.location.LastLocationStore.lastKnownLocation // Hämta från delad store
|
||||||
// Adapter som låter befintlig Android-kod använda android.location.Location,
|
// return gp?.let {
|
||||||
// men under huven lagras värdet i KMP-store (GeoPoint) i :shared.
|
// Location("klottr").apply { latitude = it.lat; longitude = it.lon }
|
||||||
var lastKnownLocation: Location?
|
// }
|
||||||
get() {
|
// }
|
||||||
val gp = app.klottr.location.LastLocationStore.lastKnown // Hämta från delad store
|
// set(value) {
|
||||||
return gp?.let {
|
// app.klottr.location.LastLocationStore.lastKnownLocation = value?.let {
|
||||||
Location("klottr").apply { latitude = it.lat; longitude = it.lon }
|
// app.klottr.location.GeoPoint(it.latitude, it.longitude)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
set(value) {
|
//}
|
||||||
app.klottr.location.LastLocationStore.lastKnown = value?.let {
|
|
||||||
app.klottr.location.GeoPoint(it.latitude, it.longitude)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ core = "1.5.0"
|
|||||||
ktor = "3.2.3"
|
ktor = "3.2.3"
|
||||||
kotlinxSerialization = "1.7.3"
|
kotlinxSerialization = "1.7.3"
|
||||||
ksp = "2.2.10-2.0.2"
|
ksp = "2.2.10-2.0.2"
|
||||||
|
workRuntimeKtx = "2.10.4"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ ktor-client-okhttp = { group = "io.ktor", name = "ktor-client-okhttp", version.r
|
|||||||
ktor-client-darwin = { group = "io.ktor", name = "ktor-client-darwin", version.ref = "ktor" }
|
ktor-client-darwin = { group = "io.ktor", name = "ktor-client-darwin", version.ref = "ktor" }
|
||||||
|
|
||||||
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinxSerialization" }
|
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinxSerialization" }
|
||||||
|
androidx-work-runtime-ktx = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "workRuntimeKtx" }
|
||||||
|
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ kotlin {
|
|||||||
implementation("com.google.maps.android:maps-compose:6.10.0") // Sep 9, 2025
|
implementation("com.google.maps.android:maps-compose:6.10.0") // Sep 9, 2025
|
||||||
// Google Sign-In
|
// Google Sign-In
|
||||||
implementation("com.google.android.gms:play-services-auth:21.4.0")
|
implementation("com.google.android.gms:play-services-auth:21.4.0")
|
||||||
|
implementation(libs.androidx.work.runtime.ktx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package app.klottr.work
|
package app.klottr.work
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import androidx.work.CoroutineWorker
|
import androidx.work.CoroutineWorker
|
||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
|
import app.klottr.events.FoundEvents
|
||||||
import app.klottr.net.Geocache
|
import app.klottr.net.Geocache
|
||||||
import app.klottr.net.createNote
|
import app.klottr.net.createNote
|
||||||
import app.klottr.net.createNoteDoc
|
import app.klottr.net.createNoteDoc
|
||||||
@@ -145,7 +145,7 @@ class OutboxWorker(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Pinga UI så “Senaste” uppdateras direkt
|
// Pinga UI så “Senaste” uppdateras direkt
|
||||||
// ctx.sendBroadcast(Intent(LocationService.ACTION_FOUND_UPDATED))
|
FoundEvents.notifyFoundUpdated()
|
||||||
}
|
}
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
// Tyst fallback – Workern ska inte krascha pga visuell uppdatering
|
// Tyst fallback – Workern ska inte krascha pga visuell uppdatering
|
||||||
@@ -78,7 +78,7 @@ private class AndroidLocationService(
|
|||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
override suspend fun current(highAccuracy: Boolean, timeoutMillis: Long): GeoPoint? {
|
override suspend fun current(highAccuracy: Boolean, timeoutMillis: Long): GeoPoint? {
|
||||||
if (!hasPermission()) return _location.value ?: LastLocationStore.lastKnown.value
|
if (!hasPermission()) return _location.value ?: LastLocationStore.lastKnownLocation.value
|
||||||
// Try current quick, with fallback to last known
|
// Try current quick, with fallback to last known
|
||||||
return try {
|
return try {
|
||||||
withTimeout(timeoutMillis) {
|
withTimeout(timeoutMillis) {
|
||||||
@@ -94,7 +94,7 @@ private class AndroidLocationService(
|
|||||||
} ?: lastKnownImmediate()
|
} ?: lastKnownImmediate()
|
||||||
}
|
}
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
_location.value ?: LastLocationStore.lastKnown.value ?: lastKnownImmediate()
|
_location.value ?: LastLocationStore.lastKnownLocation.value ?: lastKnownImmediate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,10 +105,6 @@ private class AndroidLocationService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
|
||||||
internal fun AndroidLocationService(appContext: Context): LocationService =
|
|
||||||
AndroidLocationService(appContext)
|
|
||||||
|
|
||||||
actual object LocationServiceProvider {
|
actual object LocationServiceProvider {
|
||||||
private var instance: LocationService? = null
|
private var instance: LocationService? = null
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package app.klottr.platform
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
|
||||||
|
/**
|
||||||
|
* App-internal way to expose applicationContext to platform actuals
|
||||||
|
* without referencing it from app UI files.
|
||||||
|
*/
|
||||||
|
object AndroidAppContext {
|
||||||
|
private val ref = AtomicReference<Context?>()
|
||||||
|
fun install(appContext: Context) { ref.set(appContext.applicationContext) }
|
||||||
|
fun get(): Context? = ref.get()
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package app.klottr.platform
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.widget.Toast
|
||||||
|
|
||||||
|
actual object AppNavigator {
|
||||||
|
actual fun openUrl(url: String) {
|
||||||
|
val c = AndroidAppContext.get() ?: return
|
||||||
|
val i = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||||
|
try { c.startActivity(i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) } catch (_: Exception) {}
|
||||||
|
}
|
||||||
|
actual fun openMap(lat: Double, lon: Double, label: String?) {
|
||||||
|
val c = AndroidAppContext.get() ?: return
|
||||||
|
val enc = Uri.encode(label ?: "Plats")
|
||||||
|
val geo = Uri.parse("geo:$lat,$lon?q=$lat,$lon($enc)")
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW, geo).setPackage("com.google.android.apps.maps")
|
||||||
|
try { c.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) } catch (_: Exception) {
|
||||||
|
try { c.startActivity(Intent(Intent.ACTION_VIEW, geo).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) } catch (_: Exception) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actual object UiFeedback {
|
||||||
|
actual fun showMessage(text: String, duration: UiFeedbackDuration) {
|
||||||
|
val toastDuration = if (duration == UiFeedbackDuration.SHORT) Toast.LENGTH_SHORT else Toast.LENGTH_LONG
|
||||||
|
AndroidAppContext.get()?.let { Toast.makeText(it, text, toastDuration).show() }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package app.klottr.platform
|
||||||
|
|
||||||
|
import androidx.work.Constraints
|
||||||
|
import androidx.work.NetworkType
|
||||||
|
import androidx.work.OneTimeWorkRequestBuilder
|
||||||
|
import androidx.work.WorkManager
|
||||||
|
import app.klottr.platform.AndroidAppContext
|
||||||
|
import app.klottr.work.OutboxWorker
|
||||||
|
|
||||||
|
actual object OutboxScheduler {
|
||||||
|
actual fun scheduleUpload() {
|
||||||
|
val c = AndroidAppContext.get() ?: return
|
||||||
|
val constraints = Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()
|
||||||
|
val req = OneTimeWorkRequestBuilder<OutboxWorker>().setConstraints(constraints).build()
|
||||||
|
WorkManager.getInstance(c).enqueue(req)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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) }
|
||||||
|
}
|
||||||
@@ -42,7 +42,7 @@ data class LocationUpdates(
|
|||||||
/** Simple, common store (replaces various platform stores). */
|
/** Simple, common store (replaces various platform stores). */
|
||||||
object LastLocationStore {
|
object LastLocationStore {
|
||||||
private val _lastKnown = MutableStateFlow<GeoPoint?>(null)
|
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 }
|
fun update(p: GeoPoint?) { _lastKnown.value = p }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ fun isClickable( //
|
|||||||
|
|
||||||
//Markera nya fynd i FoundStore baserat på delade entries (plattformneutral hjälpare)
|
//Markera nya fynd i FoundStore baserat på delade entries (plattformneutral hjälpare)
|
||||||
fun markNewFinds( //
|
fun markNewFinds( //
|
||||||
ctx: Any?, //Context-parameter hålls som Any? i KMP
|
|
||||||
entries: List<NearbyEntryShared>, //Delade “Närliggande”-rader
|
entries: List<NearbyEntryShared>, //Delade “Närliggande”-rader
|
||||||
nowMillis: Long, //Tidpunkt för markering
|
nowMillis: Long, //Tidpunkt för markering
|
||||||
onMarked: () -> Unit //Callback om något faktiskt markerats nytt
|
onMarked: () -> Unit //Callback om något faktiskt markerats nytt
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package app.klottr.platform
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a one-shot upload job when network is connected.
|
||||||
|
*/
|
||||||
|
expect object OutboxScheduler {
|
||||||
|
fun scheduleUpload()
|
||||||
|
}
|
||||||
@@ -3,12 +3,15 @@ package app.klottr.ui
|
|||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.fillMaxSize // Vi fyller ytan
|
import androidx.compose.foundation.layout.fillMaxSize // Vi fyller ytan
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.foundation.text.BasicText
|
import androidx.compose.foundation.text.BasicText
|
||||||
|
import app.klottr.location.GeoPoint
|
||||||
import app.klottr.util.FoundEntry
|
import app.klottr.util.FoundEntry
|
||||||
import app.klottr.nearby.foundSubtitle
|
import app.klottr.nearby.foundSubtitle
|
||||||
import app.klottr.nearby.layerDisplayName
|
import app.klottr.nearby.layerDisplayName
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Material-fritt innehåll för "Hittat".
|
* Material-fritt innehåll för "Hittat".
|
||||||
@@ -18,8 +21,7 @@ import app.klottr.nearby.layerDisplayName
|
|||||||
@Composable
|
@Composable
|
||||||
fun FoundContent(
|
fun FoundContent(
|
||||||
entries: List<FoundEntry>,
|
entries: List<FoundEntry>,
|
||||||
currentLat: Double?,
|
location: State<GeoPoint?>,
|
||||||
currentLon: Double?,
|
|
||||||
showCoords: Boolean,
|
showCoords: Boolean,
|
||||||
// Förbättrade etiketter (klotter): nyckel = "layer|id"
|
// Förbättrade etiketter (klotter): nyckel = "layer|id"
|
||||||
labelOverrides: Map<String, String>,
|
labelOverrides: Map<String, String>,
|
||||||
@@ -55,8 +57,8 @@ fun FoundContent(
|
|||||||
subtitleFor = { f ->
|
subtitleFor = { f ->
|
||||||
foundSubtitle(
|
foundSubtitle(
|
||||||
entry = f,
|
entry = f,
|
||||||
currentLat = currentLat,
|
currentLat = location.value?.lat,
|
||||||
currentLon = currentLon,
|
currentLon = location.value?.lon,
|
||||||
showCoords = showCoords,
|
showCoords = showCoords,
|
||||||
distanceFormatter = distanceFormatter,
|
distanceFormatter = distanceFormatter,
|
||||||
coordsFormatter = coordsFormatter
|
coordsFormatter = coordsFormatter
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package app.klottr.ui
|
|||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.unit.dp // För .dp i padding/spacedBy
|
import androidx.compose.ui.unit.dp // För .dp i padding/spacedBy
|
||||||
|
import app.klottr.location.GeoPoint
|
||||||
import app.klottr.util.FoundEntry
|
import app.klottr.util.FoundEntry
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -12,8 +14,7 @@ fun KlottrHomeContent(
|
|||||||
contentPadding: PaddingValues,
|
contentPadding: PaddingValues,
|
||||||
// FoundContent-parametrar (delat)
|
// FoundContent-parametrar (delat)
|
||||||
entries: List<FoundEntry>,
|
entries: List<FoundEntry>,
|
||||||
currentLat: Double?,
|
location: State<GeoPoint?>,
|
||||||
currentLon: Double?,
|
|
||||||
showCoords: Boolean,
|
showCoords: Boolean,
|
||||||
labelOverrides: Map<String, String>,
|
labelOverrides: Map<String, String>,
|
||||||
isClickable: (FoundEntry) -> Boolean,
|
isClickable: (FoundEntry) -> Boolean,
|
||||||
@@ -41,8 +42,7 @@ fun KlottrHomeContent(
|
|||||||
) {
|
) {
|
||||||
FoundContent(
|
FoundContent(
|
||||||
entries = entries,
|
entries = entries,
|
||||||
currentLat = currentLat,
|
location = location,
|
||||||
currentLon = currentLon,
|
|
||||||
showCoords = showCoords,
|
showCoords = showCoords,
|
||||||
labelOverrides = labelOverrides,
|
labelOverrides = labelOverrides,
|
||||||
isClickable = isClickable,
|
isClickable = isClickable,
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ private class IOSLocationService(
|
|||||||
_location.value
|
_location.value
|
||||||
}
|
}
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
_location.value ?: LastLocationStore.lastKnown.value
|
_location.value ?: LastLocationStore.lastKnownLocation.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package app.klottr.platform
|
||||||
|
|
||||||
|
import platform.Foundation.NSURL
|
||||||
|
import platform.UIKit.UIApplication
|
||||||
|
import platform.UIKit.UIApplicationOpenSettingsURLString
|
||||||
|
import platform.UIKit.UIApplicationSharedApplication
|
||||||
|
|
||||||
|
actual object AppNavigator {
|
||||||
|
actual fun openUrl(url: String) {
|
||||||
|
val nsUrl = NSURL.URLWithString(url) ?: return
|
||||||
|
UIApplication.sharedApplication.openURL(nsUrl)
|
||||||
|
}
|
||||||
|
actual fun openMap(lat: Double, lon: Double, label: String?) {
|
||||||
|
// Use Apple Maps URL scheme
|
||||||
|
val encoded = label?.let { it } ?: "Place"
|
||||||
|
val url = "http://maps.apple.com/?ll=$lat,$lon&q=$encoded"
|
||||||
|
openUrl(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actual object UiFeedback {
|
||||||
|
actual fun showMessage(text: String, duration: UiFeedbackDuration) {
|
||||||
|
// No-op or implement a lightweight HUD; keeping no-op by default.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package app.klottr.platform
|
||||||
|
|
||||||
|
actual object OutboxScheduler {
|
||||||
|
actual fun scheduleUpload() {
|
||||||
|
// iOS can use BGTaskScheduler / background URLSession; left as future hook.
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user