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