app: switch MainActivity to no-arg SettingsStore setters (remove Context at call sites)

This commit is contained in:
2025-09-09 01:05:49 +02:00
parent 0003e74011
commit 1cf2857094

View File

@@ -116,7 +116,6 @@ import app.klottr.util.LastLocationStore
import app.klottr.util.NoteDetailCache
import app.klottr.util.OutboxStore
import app.klottr.util.SettingsStore
import app.klottr.util.distanceMeters
import app.klottr.util.formatDistance
import app.klottr.util.formatRelativeOrTime
import app.klottr.util.formatCoords
@@ -502,7 +501,7 @@ private fun KlottrApp(
val now = System.currentTimeMillis()
var anyNew = false
items.forEach { w ->
val d = distanceMeters(loc.latitude, loc.longitude, w.lat, w.lon).roundToInt()
val d = app.klottr.util.distanceMeters(loc.latitude, loc.longitude, w.lat, w.lon).roundToInt()
if (d <= wikiRadius) {
val added = FoundStore.markFound(
context, LAYER_WIKI, w.pageId.toString(),
@@ -531,7 +530,7 @@ private fun KlottrApp(
val now = System.currentTimeMillis()
var anyNew = false
items.forEach { dmi ->
val d = distanceMeters(loc.latitude, loc.longitude, dmi.lat, dmi.lon).roundToInt()
val d = app.klottr.util.distanceMeters(loc.latitude, loc.longitude, dmi.lat, dmi.lon).roundToInt()
if (d <= dmRadius) {
val added = FoundStore.markFound(
context, LAYER_DM, dmi.id,
@@ -560,7 +559,7 @@ private fun KlottrApp(
val now = System.currentTimeMillis()
var anyNew = false
items.forEach { f ->
val d = distanceMeters(loc.latitude, loc.longitude, f.lat, f.lon).roundToInt()
val d = app.klottr.util.distanceMeters(loc.latitude, loc.longitude, f.lat, f.lon).roundToInt()
if (d <= fornsokRadius) {
val added = FoundStore.markFound(
context, LAYER_FORNSOK, f.id,
@@ -608,7 +607,7 @@ private fun KlottrApp(
checked = onlyNew,
onCheckedChange = {
onlyNew = it
SettingsStore.setOnlyNewHits(context, it)
SettingsStore.setOnlyNewHits(it)
}
)
}
@@ -702,7 +701,7 @@ private fun KlottrApp(
foundList.forEach { f ->
if (f.layer == LAYER_KLOTTER) {
val inside = if (myLat != null && myLon != null)
distanceMeters(myLat, myLon, f.lat, f.lon) <= Config.DEFAULT_KLOTTER_RADIUS_M
app.klottr.util.distanceMeters(myLat, myLon, f.lat, f.lon) <= Config.DEFAULT_KLOTTER_RADIUS_M
else true
if (inside) {
val idL = f.id.toLongOrNull() ?: return@forEach
@@ -785,7 +784,7 @@ private fun KlottrApp(
// 2) Avstånd från senaste kända position
val my = LastLocationStore.lastKnownLocation
val distM = my?.let { distanceMeters(it.latitude, it.longitude, f.lat, f.lon).roundToInt() }
val distM = my?.let { app.klottr.util.distanceMeters(it.latitude, it.longitude, f.lat, f.lon).roundToInt() }
val distText = distM?.let { formatDistance(it) } ?: "-"
@@ -819,7 +818,7 @@ private fun KlottrApp(
try {
val around = Fornsok.getNearby(f.lat, f.lon, radiusMeters = 150)
val byTitle = around.firstOrNull { it.title.equals(displayLabel, ignoreCase = true) }
byTitle ?: around.minByOrNull { distanceMeters(f.lat, f.lon, it.lat, it.lon) }
byTitle ?: around.minByOrNull { app.klottr.util.distanceMeters(f.lat, f.lon, it.lat, it.lon) }
} catch (_: Exception) { null }
}
openFornsok = OpenFornsok(
@@ -931,7 +930,7 @@ private fun KlottrApp(
night = night,
// ⬇️ NYTT:
showCoords = showCoords,
onShowCoordsChanged = { SettingsStore.setShowCoordinates(context, it); showCoords = it },
onShowCoordsChanged = { SettingsStore.setShowCoordinates(it); showCoords = it },
showKlotter = showKlotter,
showWiki = showWiki,
wikiRadius = wikiRadius,
@@ -939,16 +938,16 @@ private fun KlottrApp(
dmRadius = dmRadius,
showFornsok = showFornsok,
fornsokRadius = fornsokRadius,
onOnlyNewChanged = { SettingsStore.setOnlyNewHits(context, it); onlyNew = it },
onSatelliteChanged = { SettingsStore.setSatelliteMap(context, it); satellite = it },
onNightChanged = { SettingsStore.setNightMode(context, it); night = it },
onShowKlotterChanged = { SettingsStore.setShowKlotter(context, it); showKlotter = it },
onShowWikiChanged = { SettingsStore.setShowWikipedia(context, it); showWiki = it },
onWikiRadiusChanged = { SettingsStore.setWikiRadiusMeters(context, it); wikiRadius = it },
onShowDmChanged = { SettingsStore.setShowDigitaltMuseum(context, it); showDm = it },
onDmRadiusChanged = { SettingsStore.setDigitaltMuseumRadiusMeters(context, it); dmRadius = it },
onShowFornsokChanged = { SettingsStore.setShowFornsok(context, it); showFornsok = it },
onFornsokRadiusChanged = { SettingsStore.setFornsokRadiusMeters(context, it); fornsokRadius = it },
onOnlyNewChanged = { SettingsStore.setOnlyNewHits(it); onlyNew = it },
onSatelliteChanged = { SettingsStore.setSatelliteMap(it); satellite = it },
onNightChanged = { SettingsStore.setNightMode(it); night = it },
onShowKlotterChanged = { SettingsStore.setShowKlotter(it); showKlotter = it },
onShowWikiChanged = { SettingsStore.setShowWikipedia(it); showWiki = it },
onWikiRadiusChanged = { SettingsStore.setWikiRadiusMeters(it); wikiRadius = it },
onShowDmChanged = { SettingsStore.setShowDigitaltMuseum(it); showDm = it },
onDmRadiusChanged = { SettingsStore.setDigitaltMuseumRadiusMeters(it); dmRadius = it },
onShowFornsokChanged = { SettingsStore.setShowFornsok(it); showFornsok = it },
onFornsokRadiusChanged = { SettingsStore.setFornsokRadiusMeters(it); fornsokRadius = it },
onClearFinds = {
FoundStore.clearAll(context)
@@ -1250,7 +1249,7 @@ private fun NearbyDialog(
val entries = buildList {
wiki.forEach { w ->
val d = distanceMeters(lat, lon, w.lat, w.lon).roundToInt()
val d = app.klottr.util.distanceMeters(lat, lon, w.lat, w.lon).roundToInt()
add(
NearbyEntry(
layer = FoundStore.LAYER_WIKI,
@@ -1265,7 +1264,7 @@ private fun NearbyDialog(
)
}
dm.forEach { dmi ->
val d = distanceMeters(lat, lon, dmi.lat, dmi.lon).roundToInt()
val d = app.klottr.util.distanceMeters(lat, lon, dmi.lat, dmi.lon).roundToInt()
add(
NearbyEntry(
layer = FoundStore.LAYER_DM,
@@ -1280,7 +1279,7 @@ private fun NearbyDialog(
)
}
forn.forEach { f ->
val d = distanceMeters(lat, lon, f.lat, f.lon).roundToInt()
val d = app.klottr.util.distanceMeters(lat, lon, f.lat, f.lon).roundToInt()
add(
NearbyEntry(
layer = LAYER_FORNSOK,
@@ -1295,7 +1294,7 @@ private fun NearbyDialog(
)
}
klotter.forEach { n ->
val d = distanceMeters(lat, lon, n.a, n.o).roundToInt()
val d = app.klottr.util.distanceMeters(lat, lon, n.a, n.o).roundToInt()
val known = FoundStore.getAll(ctx)
.firstOrNull { it.layer == LAYER_KLOTTER && it.id == n.i.toString() }
?.label
@@ -2058,7 +2057,7 @@ private fun KlotterDialog(
fun recalcDistance() {
val my = app.klottr.util.LastLocationStore.lastKnownLocation
val d = my?.let { distanceMeters(it.latitude, it.longitude, lat, lon).roundToInt() }
val d = my?.let { app.klottr.util.distanceMeters(it.latitude, it.longitude, lat, lon).roundToInt() }
distanceText = d?.let { "$it\u00A0m" } ?: "-" // hårt mellanslag
}
@@ -2122,7 +2121,7 @@ private fun KlotterDialog(
val qLon = current?.longitude ?: my?.longitude
val withinRadius = if (qLat != null && qLon != null) {
distanceMeters(qLat, qLon, lat, lon) <= Config.DEFAULT_KLOTTER_RADIUS_M.toDouble()
app.klottr.util.distanceMeters(qLat, qLon, lat, lon) <= Config.DEFAULT_KLOTTER_RADIUS_M.toDouble()
} else false
@@ -2477,7 +2476,7 @@ private fun WikiArticleDialog(
fun recalcWikiDistance() {
val my = app.klottr.util.LastLocationStore.lastKnownLocation
val d = if (lat != null && lon != null && my != null)
distanceMeters(my.latitude, my.longitude, lat, lon).roundToInt()
app.klottr.util.distanceMeters(my.latitude, my.longitude, lat, lon).roundToInt()
else null
wikiDistanceText = d?.let { "$it\u00A0m" } ?: "-"
}
@@ -2612,7 +2611,7 @@ private fun FornsokDialog(
fun recalcFornDistance() {
val my = app.klottr.util.LastLocationStore.lastKnownLocation
val d = if (my != null)
distanceMeters(my.latitude, my.longitude, platLat, platLon).roundToInt()
app.klottr.util.distanceMeters(my.latitude, my.longitude, platLat, platLon).roundToInt()
else null
fornDistanceText = d?.let { "$it\u00A0m" } ?: "-"
}
@@ -2719,7 +2718,7 @@ private fun DmDialog(
fun recalcDmDistance() {
val my = LastLocationStore.lastKnownLocation
val d = if (my != null) distanceMeters(my.latitude, my.longitude, item.lat, item.lon).roundToInt() else null
val d = if (my != null) app.klottr.util.distanceMeters(my.latitude, my.longitude, item.lat, item.lon).roundToInt() else null
dmDistanceText = d?.let { formatDistance(it) } ?: "-"
}