shared(nearby): apply toggle+radius filtering in KMP builder; app(nearby): pass toggles to builder and dialog

- shared: buildNearbyEntries(...) now accepts showKlotter/showWiki/showDm/showFornsok and
  filters by per-layer radii (Wiki/DM/Fornsok) while keeping Klotter visible outside 20 m
  (label falls back to “Okänt klotter”). Sorting by distance remains.
- app: NearbyDialog signature includes toggles and forwards them to the shared builder.
- app: call site updated to pass toggles; behavior unified across platforms.
- No Material dependencies added; Android build stays green.
This commit is contained in:
2025-09-15 23:25:30 +02:00
parent 2d5312ab57
commit 4119f4165e
2 changed files with 77 additions and 45 deletions

View File

@@ -839,6 +839,10 @@ private fun KlottrApp(
dmRadius = dmRadius, dmRadius = dmRadius,
forn = nearbyFornsok, forn = nearbyFornsok,
fornsokRadius = fornsokRadius, fornsokRadius = fornsokRadius,
showKlotter = showKlotter, // [NY]
showWiki = showWiki, // [NY]
showDm = showDm, // [NY]
showFornsok = showFornsok, // [NY]
onOpenAction = { action -> onOpenAction = { action ->
when (action) { when (action) {
is FoundOpenAction.Klotter -> is FoundOpenAction.Klotter ->
@@ -1318,6 +1322,10 @@ private fun NearbyDialog(
dmRadius: Int, dmRadius: Int,
forn: List<FornsokItem>, forn: List<FornsokItem>,
fornsokRadius: Int, fornsokRadius: Int,
showKlotter: Boolean, // [NY]
showWiki: Boolean, // [NY]
showDm: Boolean, // [NY]
showFornsok: Boolean, // [NY]
onOpenAction: (FoundOpenAction) -> Unit, // Enhetlig callback onOpenAction: (FoundOpenAction) -> Unit, // Enhetlig callback
onMarkedFound: () -> Unit, onMarkedFound: () -> Unit,
onClose: () -> Unit onClose: () -> Unit
@@ -1348,6 +1356,10 @@ private fun NearbyDialog(
dmRadius = dmRadius, dmRadius = dmRadius,
fornsokRadius = fornsokRadius, fornsokRadius = fornsokRadius,
defaultKlotterRadiusM = Config.DEFAULT_KLOTTER_RADIUS_M, defaultKlotterRadiusM = Config.DEFAULT_KLOTTER_RADIUS_M,
showKlotter = showKlotter, // [NY]
showWiki = showWiki, // [NY]
showDm = showDm, // [NY]
showFornsok = showFornsok, // [NY]
knownKlotterLabel = { id -> knownKlotterLabels[id] } knownKlotterLabel = { id -> knownKlotterLabels[id] }
) )
} else emptyList() } else emptyList()

View File

@@ -33,66 +33,86 @@ fun buildNearbyEntries( //
dmRadius: Int, //Radie för DM dmRadius: Int, //Radie för DM
fornsokRadius: Int, //Radie för Fornsök fornsokRadius: Int, //Radie för Fornsök
defaultKlotterRadiusM: Int, //Standardradie för klotter (t.ex. 20 m) defaultKlotterRadiusM: Int, //Standardradie för klotter (t.ex. 20 m)
// [NY] Togglar flyttas hit (default true för bakåtkompatibilitet)
showKlotter: Boolean = true, // [NY]
showWiki: Boolean = true, // [NY]
showDm: Boolean = true, // [NY]
showFornsok: Boolean = true, // [NY]
knownKlotterLabel: (id: String) -> String? = { null } //Hämtar ev. “känd” etikett för klotter-id knownKlotterLabel: (id: String) -> String? = { null } //Hämtar ev. “känd” etikett för klotter-id
): List<NearbyEntryShared> { // ): List<NearbyEntryShared> { //
val out = mutableListOf<NearbyEntryShared>() // val out = mutableListOf<NearbyEntryShared>() //
//Wikipedia //Wikipedia
for (w in wiki) { // if (showWiki) { //
val d = distanceMeters(lat, lon, w.lat, w.lon).roundToInt() // for (w in wiki) { //
out += NearbyEntryShared( // val d = distanceMeters(lat, lon, w.lat, w.lon).roundToInt() //
layer = FoundStore.LAYER_WIKI, // if (d <= wikiRadius) { // [NY] filtrera på radie
id = w.pageId.toString(), // out += NearbyEntryShared( //
label = w.title, // layer = FoundStore.LAYER_WIKI, //
lat = w.lat, lon = w.lon, // id = w.pageId.toString(), //
distanceM = d, // label = w.title, //
insideRadiusM = wikiRadius // lat = w.lat, lon = w.lon, //
) distanceM = d, //
insideRadiusM = wikiRadius //
)
}
}
} }
//DigitaltMuseum //DigitaltMuseum
for (dmi in dm) { // if (showDm) { // [NY]
val d = distanceMeters(lat, lon, dmi.lat, dmi.lon).roundToInt() // for (dmi in dm) { //
out += NearbyEntryShared( // val d = distanceMeters(lat, lon, dmi.lat, dmi.lon).roundToInt() //
layer = FoundStore.LAYER_DM, // if (d <= dmRadius) { // [NY] filtrera på radie
id = dmi.id, // out += NearbyEntryShared( //
label = dmi.title, // layer = FoundStore.LAYER_DM, //
lat = dmi.lat, lon = dmi.lon, // id = dmi.id, //
distanceM = d, // label = dmi.title, //
insideRadiusM = dmRadius // lat = dmi.lat, lon = dmi.lon, //
) distanceM = d, //
insideRadiusM = dmRadius //
)
}
}
} }
//Fornsök //Fornsök
for (f in forn) { // if (showFornsok) { // [NY]
val d = distanceMeters(lat, lon, f.lat, f.lon).roundToInt() // for (f in forn) { //
out += NearbyEntryShared( // val d = distanceMeters(lat, lon, f.lat, f.lon).roundToInt() //
layer = FoundStore.LAYER_FORNSOK, // Använd delad konstant från KMP istället för hårdkodad sträng if (d <= fornsokRadius) { // [NY] filtrera på radie
id = f.id, // out += NearbyEntryShared( //
label = f.title, // layer = FoundStore.LAYER_FORNSOK, // Använd delad konstant från KMP istället för hårdkodad sträng
lat = f.lat, lon = f.lon, // id = f.id, //
distanceM = d, // label = f.title, //
insideRadiusM = fornsokRadius // lat = f.lat, lon = f.lon, //
) distanceM = d, //
insideRadiusM = fornsokRadius //
)
}
}
} }
//Klotter //Klotter
for (n in klotter) { // if (showKlotter) { // [NY]
val d = distanceMeters(lat, lon, n.a, n.o).roundToInt() // for (n in klotter) { //
val known = knownKlotterLabel(n.i.toString()) //Låt anropare ge känd etikett om sådan finns val d = distanceMeters(lat, lon, n.a, n.o).roundToInt() //
val display = when { //Replikerar Android-logiken utan Context val known =
!known.isNullOrBlank() && known != "Okänt klotter" -> known // knownKlotterLabel(n.i.toString()) //Låt anropare ge känd etikett om sådan finns
d <= defaultKlotterRadiusM && n.t.isNotBlank() -> n.t // val display = when { //Replikerar Android-logiken utan Context
else -> "Okänt klotter" // !known.isNullOrBlank() && known != "Okänt klotter" -> known //
d <= defaultKlotterRadiusM && n.t.isNotBlank() -> n.t //
else -> "Okänt klotter" //
}
out += NearbyEntryShared( //
layer = FoundStore.LAYER_KLOTTER, //
id = n.i.toString(), //
label = display, //
lat = n.a, lon = n.o, //
distanceM = d, //
insideRadiusM = defaultKlotterRadiusM //
)
} }
out += NearbyEntryShared( //
layer = FoundStore.LAYER_KLOTTER, //
id = n.i.toString(), //
label = display, //
lat = n.a, lon = n.o, //
distanceM = d, //
insideRadiusM = defaultKlotterRadiusM //
)
} }
return out.sortedBy { it.distanceM } //Sortera stigande avstånd (samma som i Android idag) return out.sortedBy { it.distanceM } //Sortera stigande avstånd (samma som i Android idag)