When clicking on Fornsök, Wikipedia and DigitaltMuseum on the map, the info window now opens as before the migration. Also fixed so the map updates when layer changes or something is found.
This commit is contained in:
@@ -518,7 +518,44 @@ fun KlottrAppShell(
|
|||||||
Box(modifier = Modifier.weight(1f).fillMaxWidth()) {
|
Box(modifier = Modifier.weight(1f).fillMaxWidth()) {
|
||||||
MapContent(
|
MapContent(
|
||||||
onKlotterClick = { id, la, lo, label -> openKlotter = OpenKlotter(id, la, lo, label) },
|
onKlotterClick = { id, la, lo, label -> openKlotter = OpenKlotter(id, la, lo, label) },
|
||||||
onOpenUrl = { _, url -> AppNavigator.openUrl(url) },
|
onOpenUrl = { title, url ->
|
||||||
|
when {
|
||||||
|
url.contains("wikipedia.org") -> {
|
||||||
|
val pageId = url.substringAfter("curid=").toLongOrNull()
|
||||||
|
if (pageId != null) {
|
||||||
|
openWiki = OpenWiki(pageId, null, null)
|
||||||
|
} else {
|
||||||
|
AppNavigator.openUrl(url) // fallback
|
||||||
|
}
|
||||||
|
}
|
||||||
|
url.contains("digitaltmuseum.se") -> {
|
||||||
|
val match = nearbyBundle?.dm?.firstOrNull {
|
||||||
|
it.webUrl == url || it.url == url
|
||||||
|
|| url.contains(it.id, ignoreCase = true)
|
||||||
|
}
|
||||||
|
if (match != null) {
|
||||||
|
openDm = match
|
||||||
|
} else {
|
||||||
|
AppNavigator.openUrl(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
url.contains("fornsok") -> {
|
||||||
|
val match = nearbyBundle?.forn?.firstOrNull {
|
||||||
|
it.uri == url || it.id == url || it.title == url
|
||||||
|
|| (it.uri != null && url.contains(it.uri!!, ignoreCase = true))
|
||||||
|
}
|
||||||
|
if (match != null) {
|
||||||
|
openFornsok = OpenFornsok(match)
|
||||||
|
} else {
|
||||||
|
AppNavigator.openUrl(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> AppNavigator.openUrl(url)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onFornsokClick = { item ->
|
||||||
|
openFornsok = OpenFornsok(item)
|
||||||
|
},
|
||||||
isKnownNote = { noteId ->
|
isKnownNote = { noteId ->
|
||||||
FoundStore.getAll().any { it.layer == LAYER_KLOTTER && it.id == noteId.toString() }
|
FoundStore.getAll().any { it.layer == LAYER_KLOTTER && it.id == noteId.toString() }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ import app.klottr.net.NoteDTO
|
|||||||
import app.klottr.net.Wikipedia
|
import app.klottr.net.Wikipedia
|
||||||
import app.klottr.net.WikipediaPage
|
import app.klottr.net.WikipediaPage
|
||||||
import app.klottr.platform.hasFgLocationPerms
|
import app.klottr.platform.hasFgLocationPerms
|
||||||
|
import app.klottr.ui.DmDialog
|
||||||
|
import app.klottr.ui.FornsokDialog
|
||||||
|
import app.klottr.ui.WikiArticleDialog
|
||||||
import app.klottr.util.Config
|
import app.klottr.util.Config
|
||||||
import app.klottr.util.SettingsStore
|
import app.klottr.util.SettingsStore
|
||||||
import app.klottr.util.distanceMeters
|
import app.klottr.util.distanceMeters
|
||||||
@@ -70,6 +73,10 @@ fun MapDialog(
|
|||||||
var selUri by remember { mutableStateOf<String?>(null) }
|
var selUri by remember { mutableStateOf<String?>(null) }
|
||||||
var selId by remember { mutableStateOf<String?>(null) } // klotter-id vid behov
|
var selId by remember { mutableStateOf<String?>(null) } // klotter-id vid behov
|
||||||
var selLayer by remember { mutableStateOf<String?>(null) } // "Klotter", "Wikipedia", "Fornsök", ...
|
var selLayer by remember { mutableStateOf<String?>(null) } // "Klotter", "Wikipedia", "Fornsök", ...
|
||||||
|
var selWiki by remember { mutableStateOf<WikipediaPage?>(null) }
|
||||||
|
var selForn by remember { mutableStateOf<FornsokItem?>(null) }
|
||||||
|
var selDm by remember { mutableStateOf<DigitaltMuseumItem?>(null) }
|
||||||
|
|
||||||
|
|
||||||
// Map state for shared MapContainer
|
// Map state for shared MapContainer
|
||||||
val mapState = remember {
|
val mapState = remember {
|
||||||
@@ -101,19 +108,6 @@ fun MapDialog(
|
|||||||
myLat = current.value?.lat
|
myLat = current.value?.lat
|
||||||
myLon = current.value?.lon
|
myLon = current.value?.lon
|
||||||
}
|
}
|
||||||
//
|
|
||||||
//
|
|
||||||
// LaunchedEffect(Unit) {
|
|
||||||
// val fused = GmsLocationServices.getFusedLocationProviderClient(context)
|
|
||||||
// val loc = try {
|
|
||||||
// fused.lastLocation.await()
|
|
||||||
// ?: fused.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, null).await()
|
|
||||||
// } catch (_: Exception) { null }
|
|
||||||
// if (loc != null) {
|
|
||||||
// myLat = loc.latitude
|
|
||||||
// myLon = loc.longitude
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
LaunchedEffect(myLat, myLon, showKlotter, showWiki, wikiRadius, showDm, dmRadius, showFornsok, fornsokRadius) {
|
LaunchedEffect(myLat, myLon, showKlotter, showWiki, wikiRadius, showDm, dmRadius, showFornsok, fornsokRadius) {
|
||||||
val lat = myLat; val lon = myLon
|
val lat = myLat; val lon = myLon
|
||||||
@@ -230,28 +224,23 @@ fun MapDialog(
|
|||||||
id.startsWith("wiki:") -> {
|
id.startsWith("wiki:") -> {
|
||||||
val pid = id.removePrefix("wiki:")
|
val pid = id.removePrefix("wiki:")
|
||||||
wiki.firstOrNull { it.pageId.toString() == pid }?.let { w ->
|
wiki.firstOrNull { it.pageId.toString() == pid }?.let { w ->
|
||||||
val url = "https://sv.m.wikipedia.org/?curid=${w.pageId}"
|
selWiki = w
|
||||||
setSel(w.lat, w.lon, w.title, url, "Wikipedia")
|
|
||||||
onOpenUrl(w.title, url)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id.startsWith("dm:") -> {
|
id.startsWith("dm:") -> {
|
||||||
val mid = id.removePrefix("dm:")
|
val mid = id.removePrefix("dm:")
|
||||||
dm.firstOrNull { (it.webUrl ?: it.url) == mid }?.let { dmi ->
|
dm.firstOrNull { (it.webUrl ?: it.url) == mid }?.let { dmi ->
|
||||||
val url = dmi.webUrl ?: dmi.url
|
selDm = dmi
|
||||||
setSel(dmi.lat, dmi.lon, dmi.title, url, "DigitaltMuseum")
|
|
||||||
url?.let { onOpenUrl(dmi.title, it) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id.startsWith("forn:") -> {
|
id.startsWith("forn:") -> {
|
||||||
val fid = id.removePrefix("forn:")
|
val fid = id.removePrefix("forn:")
|
||||||
forn.firstOrNull { (it.uri ?: it.title) == fid }?.let { f ->
|
forn.firstOrNull { (it.uri ?: it.title) == fid }?.let { f ->
|
||||||
setSel(f.lat, f.lon, f.title, f.uri, "Fornsök")
|
selForn = f
|
||||||
f.uri?.let { onOpenUrl(f.title, it) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onReady = { ctrl ->
|
onReady = { ctrl ->
|
||||||
mapController = ctrl
|
mapController = ctrl
|
||||||
ctrl.setMyLocationEnabled(hasFgLocationPerms())
|
ctrl.setMyLocationEnabled(hasFgLocationPerms())
|
||||||
@@ -274,6 +263,26 @@ fun MapDialog(
|
|||||||
Button(onClick = onClose) { Text("Stäng") }
|
Button(onClick = onClose) { Text("Stäng") }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
if (selWiki != null) {
|
||||||
|
WikiArticleDialog(
|
||||||
|
pageId = selWiki!!.pageId,
|
||||||
|
lat = selWiki!!.lat,
|
||||||
|
lon = selWiki!!.lon,
|
||||||
|
onClose = { selWiki = null }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (selForn != null) {
|
||||||
|
FornsokDialog(
|
||||||
|
item = selForn!!,
|
||||||
|
onClose = { selForn = null }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (selDm != null) {
|
||||||
|
DmDialog(
|
||||||
|
item = selDm!!,
|
||||||
|
onClose = { selDm = null }
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep map in sync with state changes, camera position, enabled features.
|
// Keep map in sync with state changes, camera position, enabled features.
|
||||||
|
|||||||
@@ -23,16 +23,17 @@ fun MapContent(
|
|||||||
isKnownNote: (Long) -> Boolean,
|
isKnownNote: (Long) -> Boolean,
|
||||||
initialLat: Double? = null,
|
initialLat: Double? = null,
|
||||||
initialLon: Double? = null,
|
initialLon: Double? = null,
|
||||||
modifier: Modifier = Modifier.fillMaxSize()
|
modifier: Modifier = Modifier.fillMaxSize(),
|
||||||
|
onFornsokClick: (FornsokItem) -> Unit
|
||||||
) {
|
) {
|
||||||
val satellite = SettingsStore.getSatelliteMap()
|
val satellite = SettingsStore.getSatelliteMap()
|
||||||
val showKlotter = remember { SettingsStore.getShowKlotter() }
|
val showKlotter = SettingsStore.getShowKlotter()
|
||||||
val showWiki = remember { SettingsStore.getShowWikipedia() }
|
val showWiki = SettingsStore.getShowWikipedia()
|
||||||
val wikiRadius = remember { SettingsStore.getWikiRadiusMeters() }
|
val wikiRadius = SettingsStore.getWikiRadiusMeters()
|
||||||
val showDm = remember { SettingsStore.getShowDigitaltMuseum() }
|
val showDm = SettingsStore.getShowDigitaltMuseum()
|
||||||
val dmRadius = remember { SettingsStore.getDigitaltMuseumRadiusMeters() }
|
val dmRadius = SettingsStore.getDigitaltMuseumRadiusMeters()
|
||||||
val showFornsok = remember { SettingsStore.getShowFornsok() }
|
val showFornsok = SettingsStore.getShowFornsok()
|
||||||
val fornsokRadius = remember { SettingsStore.getFornsokRadiusMeters() }
|
val fornsokRadius = SettingsStore.getFornsokRadiusMeters()
|
||||||
|
|
||||||
var myLat by remember { mutableStateOf<Double?>(null) }
|
var myLat by remember { mutableStateOf<Double?>(null) }
|
||||||
var myLon by remember { mutableStateOf<Double?>(null) }
|
var myLon by remember { mutableStateOf<Double?>(null) }
|
||||||
@@ -184,9 +185,11 @@ fun MapContent(
|
|||||||
id.startsWith("forn:") -> {
|
id.startsWith("forn:") -> {
|
||||||
val fid = id.removePrefix("forn:")
|
val fid = id.removePrefix("forn:")
|
||||||
forn.firstOrNull { (it.uri ?: it.title) == fid }?.let { f ->
|
forn.firstOrNull { (it.uri ?: it.title) == fid }?.let { f ->
|
||||||
f.uri?.let { onOpenUrl(f.title, it) }
|
// Trigga samma "öppna fornsök" som i listan
|
||||||
|
onFornsokClick(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onReady = { ctrl ->
|
onReady = { ctrl ->
|
||||||
|
|||||||
Reference in New Issue
Block a user