Add “My Notes” ("Mitt klotter)" screen, enable distant note clicks, and add draggable map/list splitter to Nearby & My Notes
This commit is contained in:
@@ -24,7 +24,14 @@ fun MapContent(
|
||||
initialLat: Double? = null,
|
||||
initialLon: Double? = null,
|
||||
modifier: Modifier = Modifier.fillMaxSize(),
|
||||
onFornsokClick: (FornsokItem) -> Unit
|
||||
onFornsokClick: (FornsokItem) -> Unit,
|
||||
// Extra-data och styrning för titel/radie
|
||||
extraKlotter: List<NoteDTO> = emptyList(),
|
||||
revealKlotterTitles: Boolean = false,
|
||||
// Radie-override för klotter; null = använd default, 0 = obegränsat
|
||||
klotterRadiusM: Int? = null,
|
||||
onlyExtraKlotter: Boolean = false,
|
||||
onFeaturesApplied: (() -> Unit)? = null
|
||||
) {
|
||||
val satellite = SettingsStore.getSatelliteMap()
|
||||
val showKlotter = SettingsStore.getShowKlotter()
|
||||
@@ -88,15 +95,75 @@ fun MapContent(
|
||||
fun buildFeatures(): List<MapFeature> {
|
||||
val lat = myLat; val lon = myLon
|
||||
val out = mutableListOf<MapFeature>()
|
||||
if (showKlotter) {
|
||||
klotter.forEach { n ->
|
||||
|
||||
// ----- "Mitt klotter"-läge: visa ENDAST extraKlotter oavsett SettingsStore -----
|
||||
if (onlyExtraKlotter) {
|
||||
val radius = (klotterRadiusM ?: Config.DEFAULT_KLOTTER_RADIUS_M)
|
||||
val unlimited = (radius == 0)
|
||||
extraKlotter
|
||||
.distinctBy { it.i }
|
||||
.forEach { n ->
|
||||
val d = if (lat != null && lon != null)
|
||||
distanceMeters(lat, lon, n.a, n.o).roundToInt() else Int.MAX_VALUE
|
||||
val within = if (unlimited) true else (d != Int.MAX_VALUE && d <= radius)
|
||||
val titleLine = n.t.substringBefore('\n').ifBlank { "Okänt klotter" }
|
||||
val radius = Config.DEFAULT_KLOTTER_RADIUS_M
|
||||
// I "Mitt klotter" ska rubriker ALLTID synas (det är ju dina egna), oavsett avstånd:
|
||||
val display = titleLine
|
||||
// Vi ritar ALLA markörer (within påverkar inte synlighet här):
|
||||
out += MapFeature.Marker(
|
||||
id = "klotter:${n.i}",
|
||||
position = LatLng(n.a, n.o),
|
||||
title = display
|
||||
)
|
||||
}
|
||||
return out
|
||||
}
|
||||
// === Klotter-markörer (bakåtkompatibelt läge) ===
|
||||
run {
|
||||
// Om inga nya parametrar används → exakt gamla koden
|
||||
val usingExtras = (extraKlotter.isNotEmpty() || revealKlotterTitles || klotterRadiusM != null)
|
||||
|
||||
if (!usingExtras) {
|
||||
if (showKlotter) {
|
||||
klotter.forEach { n ->
|
||||
val d = if (lat != null && lon != null)
|
||||
distanceMeters(lat, lon, n.a, n.o).roundToInt() else Int.MAX_VALUE
|
||||
val titleLine = n.t.substringBefore('\n').ifBlank { "Okänt klotter" }
|
||||
val radius = Config.DEFAULT_KLOTTER_RADIUS_M
|
||||
val visited = isKnownNote(n.i.toLong())
|
||||
val within = (d != Int.MAX_VALUE && d <= radius)
|
||||
val display = if (visited || (within && titleLine != "Okänt klotter")) titleLine else "Okänt klotter"
|
||||
out += MapFeature.Marker(
|
||||
id = "klotter:${n.i}",
|
||||
position = LatLng(n.a, n.o),
|
||||
title = display
|
||||
)
|
||||
}
|
||||
}
|
||||
return@run
|
||||
}
|
||||
|
||||
// Nytt beteende (endast när extras faktiskt används)
|
||||
val combined: List<app.klottr.net.NoteDTO> = when {
|
||||
extraKlotter.isNotEmpty() && showKlotter -> (klotter + extraKlotter).distinctBy { it.i }
|
||||
extraKlotter.isNotEmpty() && !showKlotter -> extraKlotter.distinctBy { it.i }
|
||||
else -> if (showKlotter) klotter else emptyList()
|
||||
}
|
||||
|
||||
val radius = (klotterRadiusM ?: Config.DEFAULT_KLOTTER_RADIUS_M)
|
||||
val unlimited = (radius == 0)
|
||||
|
||||
combined.forEach { n ->
|
||||
val d = if (lat != null && lon != null)
|
||||
distanceMeters(lat, lon, n.a, n.o).roundToInt() else Int.MAX_VALUE
|
||||
|
||||
val titleLine = n.t.substringBefore('\n').ifBlank { "Okänt klotter" }
|
||||
val within = if (unlimited) true else (d != Int.MAX_VALUE && d <= radius)
|
||||
val visited = isKnownNote(n.i.toLong())
|
||||
val within = (d != Int.MAX_VALUE && d <= radius)
|
||||
val display = if (visited || (within && titleLine != "Okänt klotter")) titleLine else "Okänt klotter"
|
||||
|
||||
val display = if (revealKlotterTitles || visited || (within && titleLine != "Okänt klotter"))
|
||||
titleLine else "Okänt klotter"
|
||||
|
||||
out += MapFeature.Marker(
|
||||
id = "klotter:${n.i}",
|
||||
position = LatLng(n.a, n.o),
|
||||
@@ -104,6 +171,7 @@ fun MapContent(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (showWiki) {
|
||||
wiki.forEach { w ->
|
||||
out += MapFeature.Marker(
|
||||
@@ -159,11 +227,14 @@ fun MapContent(
|
||||
MapContainer(
|
||||
state = mapState,
|
||||
onMapClick = { /* inget extra här */ },
|
||||
|
||||
onMarkerClick = { id ->
|
||||
when {
|
||||
id.startsWith("klotter:") -> {
|
||||
val nid = id.removePrefix("klotter:")
|
||||
klotter.firstOrNull { it.i.toString() == nid }?.let { n ->
|
||||
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" }
|
||||
onKlotterClick(nid, n.a, n.o, titleLine)
|
||||
}
|
||||
@@ -196,17 +267,26 @@ fun MapContent(
|
||||
mapController = ctrl
|
||||
ctrl.setMyLocationEnabled(hasFgLocationPerms())
|
||||
ctrl.setFeatures(buildFeatures())
|
||||
onFeaturesApplied?.invoke()
|
||||
}
|
||||
)
|
||||
|
||||
MapSyncEffects(
|
||||
controller = mapController,
|
||||
myLat = myLat,
|
||||
myLon = myLon,
|
||||
myLat = if (onlyExtraKlotter) null else myLat,
|
||||
myLon = if (onlyExtraKlotter) null else myLon,
|
||||
featuresBuilder = { buildFeatures() },
|
||||
showKlotter, showWiki, wikiRadius, showDm, dmRadius, showFornsok, fornsokRadius,
|
||||
klotter, wiki, dm, forn
|
||||
)
|
||||
// När vi visar endast egna klotter: applicera features igen när datan ändras,
|
||||
// och signalera att features är på plats (så "Laddar..." kan stängas).
|
||||
LaunchedEffect(onlyExtraKlotter, extraKlotter) {
|
||||
if (onlyExtraKlotter) {
|
||||
mapController?.setFeatures(buildFeatures())
|
||||
onFeaturesApplied?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user