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:
@@ -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()
|
||||||
|
|||||||
@@ -33,13 +33,20 @@ 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
|
||||||
|
if (showWiki) { //
|
||||||
for (w in wiki) { //
|
for (w in wiki) { //
|
||||||
val d = distanceMeters(lat, lon, w.lat, w.lon).roundToInt() //
|
val d = distanceMeters(lat, lon, w.lat, w.lon).roundToInt() //
|
||||||
|
if (d <= wikiRadius) { // [NY] filtrera på radie
|
||||||
out += NearbyEntryShared( //
|
out += NearbyEntryShared( //
|
||||||
layer = FoundStore.LAYER_WIKI, //
|
layer = FoundStore.LAYER_WIKI, //
|
||||||
id = w.pageId.toString(), //
|
id = w.pageId.toString(), //
|
||||||
@@ -49,10 +56,14 @@ fun buildNearbyEntries( //
|
|||||||
insideRadiusM = wikiRadius //
|
insideRadiusM = wikiRadius //
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//DigitaltMuseum
|
//DigitaltMuseum
|
||||||
|
if (showDm) { // [NY]
|
||||||
for (dmi in dm) { //
|
for (dmi in dm) { //
|
||||||
val d = distanceMeters(lat, lon, dmi.lat, dmi.lon).roundToInt() //
|
val d = distanceMeters(lat, lon, dmi.lat, dmi.lon).roundToInt() //
|
||||||
|
if (d <= dmRadius) { // [NY] filtrera på radie
|
||||||
out += NearbyEntryShared( //
|
out += NearbyEntryShared( //
|
||||||
layer = FoundStore.LAYER_DM, //
|
layer = FoundStore.LAYER_DM, //
|
||||||
id = dmi.id, //
|
id = dmi.id, //
|
||||||
@@ -62,10 +73,14 @@ fun buildNearbyEntries( //
|
|||||||
insideRadiusM = dmRadius //
|
insideRadiusM = dmRadius //
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Fornsök
|
//Fornsök
|
||||||
|
if (showFornsok) { // [NY]
|
||||||
for (f in forn) { //
|
for (f in forn) { //
|
||||||
val d = distanceMeters(lat, lon, f.lat, f.lon).roundToInt() //
|
val d = distanceMeters(lat, lon, f.lat, f.lon).roundToInt() //
|
||||||
|
if (d <= fornsokRadius) { // [NY] filtrera på radie
|
||||||
out += NearbyEntryShared( //
|
out += NearbyEntryShared( //
|
||||||
layer = FoundStore.LAYER_FORNSOK, // Använd delad konstant från KMP istället för hårdkodad sträng
|
layer = FoundStore.LAYER_FORNSOK, // Använd delad konstant från KMP istället för hårdkodad sträng
|
||||||
id = f.id, //
|
id = f.id, //
|
||||||
@@ -75,11 +90,15 @@ fun buildNearbyEntries( //
|
|||||||
insideRadiusM = fornsokRadius //
|
insideRadiusM = fornsokRadius //
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Klotter
|
//Klotter
|
||||||
|
if (showKlotter) { // [NY]
|
||||||
for (n in klotter) { //
|
for (n in klotter) { //
|
||||||
val d = distanceMeters(lat, lon, n.a, n.o).roundToInt() //
|
val d = distanceMeters(lat, lon, n.a, n.o).roundToInt() //
|
||||||
val known = knownKlotterLabel(n.i.toString()) //Låt anropare ge känd etikett om sådan finns
|
val known =
|
||||||
|
knownKlotterLabel(n.i.toString()) //Låt anropare ge känd etikett om sådan finns
|
||||||
val display = when { //Replikerar Android-logiken utan Context
|
val display = when { //Replikerar Android-logiken utan Context
|
||||||
!known.isNullOrBlank() && known != "Okänt klotter" -> known //
|
!known.isNullOrBlank() && known != "Okänt klotter" -> known //
|
||||||
d <= defaultKlotterRadiusM && n.t.isNotBlank() -> n.t //
|
d <= defaultKlotterRadiusM && n.t.isNotBlank() -> n.t //
|
||||||
@@ -94,6 +113,7 @@ fun buildNearbyEntries( //
|
|||||||
insideRadiusM = defaultKlotterRadiusM //
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user