diff --git a/shared/src/commonMain/kotlin/app/klottr/KlottrAppShell.kt b/shared/src/commonMain/kotlin/app/klottr/KlottrAppShell.kt index 0d22e46..f5df8c9 100644 --- a/shared/src/commonMain/kotlin/app/klottr/KlottrAppShell.kt +++ b/shared/src/commonMain/kotlin/app/klottr/KlottrAppShell.kt @@ -691,7 +691,9 @@ fun KlottrAppShell( onFornsokClick = { item -> openFornsok = OpenFornsok(item) }, isKnownNote = { noteId -> FoundStore.getAll().any { it.layer == LAYER_KLOTTER && it.id == noteId.toString() } - } + }, + satellite = satellite, + night = night ) } }, @@ -1001,7 +1003,9 @@ fun KlottrAppShell( revealKlotterTitles = true, klotterRadiusM = 0, // obegränsat onlyExtraKlotter = true, - onFeaturesApplied = { myNotesLoading = false } + onFeaturesApplied = { myNotesLoading = false }, + satellite = satellite, + night = night ) } }, diff --git a/shared/src/commonMain/kotlin/app/klottr/ui/MapContent.kt b/shared/src/commonMain/kotlin/app/klottr/ui/MapContent.kt index ee43e00..4ec6be5 100644 --- a/shared/src/commonMain/kotlin/app/klottr/ui/MapContent.kt +++ b/shared/src/commonMain/kotlin/app/klottr/ui/MapContent.kt @@ -2,6 +2,7 @@ package app.klottr.ui import androidx.compose.foundation.layout.* import androidx.compose.runtime.* +import androidx.compose.runtime.collectAsState import androidx.compose.ui.Modifier import app.klottr.location.LastLocationStore import app.klottr.location.LocationServiceProvider @@ -31,9 +32,14 @@ fun MapContent( // Radie-override för klotter; null = använd default, 0 = obegränsat klotterRadiusM: Int? = null, onlyExtraKlotter: Boolean = false, - onFeaturesApplied: (() -> Unit)? = null + onFeaturesApplied: (() -> Unit)? = null, + satellite: Boolean, + night: Boolean ) { - val satellite = SettingsStore.getSatelliteMap() + println("🛰 Satellite flag = $satellite") + + // --- Läs aktuella inställningar från SettingsStore (utan Flow) --- + // satellite kommer redan som parameter från KlottrAppShell val showKlotter = SettingsStore.getShowKlotter() val showWiki = SettingsStore.getShowWikipedia() val wikiRadius = SettingsStore.getWikiRadiusMeters() @@ -42,6 +48,7 @@ fun MapContent( val showFornsok = SettingsStore.getShowFornsok() val fornsokRadius = SettingsStore.getFornsokRadiusMeters() + var myLat by remember { mutableStateOf(null) } var myLon by remember { mutableStateOf(null) } @@ -208,7 +215,7 @@ fun MapContent( val startLat = initialLat ?: lastKnown?.lat ?: 59.2974 // Årsta Torg val startLon = initialLon ?: lastKnown?.lon ?: 18.0520 - val mapState = remember { + val mapState = remember(satellite) { MapState( initialCamera = CameraPosition( target = LatLng(startLat, startLon), @@ -235,7 +242,8 @@ fun MapContent( val n = klotter.firstOrNull { it.i.toString() == nid } ?: extraKlotter.firstOrNull { it.i.toString() == nid } if (n != null) { - val titleLine = n.t.substringBefore('\n').ifBlank { "Okänt klotter" } + val titleLine = + n.t.substringBefore('\n').ifBlank { "Okänt klotter" } onKlotterClick(nid, n.a, n.o, titleLine) } } @@ -270,7 +278,6 @@ fun MapContent( onFeaturesApplied?.invoke() } ) - MapSyncEffects( controller = mapController, myLat = if (onlyExtraKlotter) null else myLat, @@ -288,6 +295,7 @@ fun MapContent( } } } + } @Composable diff --git a/shared/src/commonMain/kotlin/app/klottr/util/SettingsStore.kt b/shared/src/commonMain/kotlin/app/klottr/util/SettingsStore.kt index e4bf8b2..8cfb6be 100644 --- a/shared/src/commonMain/kotlin/app/klottr/util/SettingsStore.kt +++ b/shared/src/commonMain/kotlin/app/klottr/util/SettingsStore.kt @@ -1,6 +1,8 @@ package app.klottr.util import app.klottr.prefs.KvPrefs +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow object SettingsStore { // Nycklar (samma namn som tidigare för kompatibilitet) @@ -16,6 +18,17 @@ object SettingsStore { const val KEY_SHOW_FORNSOK = "show_fornsok" const val KEY_FORNSOK_RADIUS = "fornsok_radius_m" + // --- Flows för reaktiva uppdateringar till Compose --- + val satelliteFlow: Flow = preferenceFlow("satellite_map", false) + val showKlotterFlow: Flow = preferenceFlow("show_klotter", true) + val showWikiFlow: Flow = preferenceFlow("show_wiki", true) + val wikiRadiusFlow: Flow = preferenceFlow("wiki_radius", 200) + val showDmFlow: Flow = preferenceFlow("show_dm", true) + val dmRadiusFlow: Flow = preferenceFlow("dm_radius", 500) + val showFornsokFlow: Flow = preferenceFlow("show_fornsok", true) + val fornsokRadiusFlow: Flow = preferenceFlow("fornsok_radius", 500) + + // --- Observers via KvPrefs (plattformoberoende) --- fun observe(onChanged: (key: String?) -> Unit): (String?) -> Unit { KvPrefs.addListener(onChanged) @@ -88,4 +101,8 @@ object SettingsStore { fun setFornsokRadiusMeters(meters: Int) { KvPrefs.putInt(KEY_FORNSOK_RADIUS, meters) } + // Enkel implementation tills vidare – returnerar bara ett statiskt Flow + private fun preferenceFlow(key: String, defaultValue: T): Flow { + return MutableStateFlow(defaultValue) + } } \ No newline at end of file