Add split-view for "Nära" tab with map on top and nearby list below, auto-scanning location on open
This commit is contained in:
@@ -41,6 +41,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.decodeToImageBitmap
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.cash.sqldelight.coroutines.asFlow // SQLDelight coroutine-extensions (Flow-stöd för queries)
|
||||
import app.cash.sqldelight.coroutines.mapToList // SQLDelight coroutine-extensions (Flow-stöd för queries)
|
||||
@@ -83,7 +84,10 @@ import app.klottr.ui.DmDialog
|
||||
import app.klottr.ui.FornsokDialog
|
||||
import app.klottr.ui.KlottrHomeContent
|
||||
import app.klottr.ui.LoginRequiredContent
|
||||
import app.klottr.ui.MapContent
|
||||
import app.klottr.ui.NearbyContent
|
||||
import app.klottr.ui.NearbyDialog
|
||||
import app.klottr.ui.NearbyDialogContent
|
||||
import app.klottr.ui.UsernameDialog
|
||||
import app.klottr.ui.WikiArticleDialog
|
||||
import app.klottr.util.AuthShared
|
||||
@@ -423,29 +427,86 @@ fun KlottrAppShell(
|
||||
)
|
||||
}
|
||||
"nearby" -> {
|
||||
// 1) När fliken "Nära" öppnas (eller inställningarna för lager ändras) → gör en scan
|
||||
LaunchedEffect(selectedTab, showKlotter, showWiki, wikiRadius, showDm, dmRadius, showFornsok, fornsokRadius) {
|
||||
if (selectedTab != "nearby") return@LaunchedEffect
|
||||
nearbyLoading = true
|
||||
nearbyError = null
|
||||
|
||||
val gp = LocationServiceProvider.get().current(highAccuracy = false)
|
||||
if (gp == null) {
|
||||
nearbyLoading = false
|
||||
nearbyError = "Ingen plats ännu – prova igen."
|
||||
} else {
|
||||
lastKnownLat = gp.lat
|
||||
lastKnownLon = gp.lon
|
||||
|
||||
val bundle = withContext(Dispatchers.IO) {
|
||||
getNearbyBundle(
|
||||
lat = gp.lat,
|
||||
lon = gp.lon,
|
||||
showKlotter = showKlotter,
|
||||
showWiki = showWiki,
|
||||
showDm = showDm,
|
||||
showFornsok = showFornsok,
|
||||
wikiRadius = wikiRadius,
|
||||
dmRadius = dmRadius,
|
||||
fornsokRadius = fornsokRadius,
|
||||
defaultKlotterRadiusM = Config.DEFAULT_KLOTTER_RADIUS_M,
|
||||
knownKlotterLabel = { id ->
|
||||
FoundStore.getAll()
|
||||
.asSequence()
|
||||
.filter { it.layer == FoundStore.LAYER_KLOTTER }
|
||||
.associate { it.id to it.label }[id]
|
||||
},
|
||||
klotterFetcher = { la, lo ->
|
||||
Geocache.getNearby(
|
||||
lat = la,
|
||||
lon = lo,
|
||||
radiusMeters = 300,
|
||||
ttlMs = 0L
|
||||
)
|
||||
},
|
||||
wikiFetcher = { la, lo, r ->
|
||||
Wikipedia.getNearby(la, lo, radiusMeters = r)
|
||||
},
|
||||
dmFetcher = { la, lo, r ->
|
||||
DigitaltMuseum.getNearby(la, lo, radiusMeters = r)
|
||||
},
|
||||
fornFetcher = { la, lo, r ->
|
||||
FornsokShared.getNearby(la, lo, radiusMeters = r)
|
||||
}
|
||||
)
|
||||
}
|
||||
nearbyBundle = bundle
|
||||
nearbyLoading = false
|
||||
}
|
||||
}
|
||||
|
||||
// 2) Delad layout: övre halvan = karta, nedre halvan = närliggande-lista
|
||||
Column(modifier = Modifier.padding(innerPadding)) {
|
||||
// Övre halvan: karta
|
||||
// Övre halvan: Karta (inline, ingen dialog)
|
||||
Box(modifier = Modifier.weight(1f).fillMaxWidth()) {
|
||||
MapDialog(
|
||||
onClose = { /* inget, vi stänger inte i nya UI */ },
|
||||
MapContent(
|
||||
onKlotterClick = { id, la, lo, label ->
|
||||
openKlotter = OpenKlotter(id = id, lat = la, lon = lo, label = label)
|
||||
openKlotter = OpenKlotter(id, la, lo, label)
|
||||
},
|
||||
onOpenUrl = { _, url -> AppNavigator.openUrl(url) },
|
||||
isKnownNote = { noteId ->
|
||||
FoundStore.getAll().any { it.layer == LAYER_KLOTTER && it.id == noteId.toString() }
|
||||
FoundStore.getAll()
|
||||
.any { it.layer == LAYER_KLOTTER && it.id == noteId.toString() }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// Nedre halvan: närliggande-lista
|
||||
// Nedre halvan: Närliggande-lista (inline, ingen dialog)
|
||||
Box(modifier = Modifier.weight(1f).fillMaxWidth()) {
|
||||
NearbyDialog(
|
||||
val hasLocation = (lastKnownLat != null && lastKnownLon != null)
|
||||
NearbyContent(
|
||||
loading = nearbyLoading,
|
||||
error = nearbyError,
|
||||
lat = lastKnownLat,
|
||||
lon = lastKnownLon,
|
||||
entries = nearbyBundle?.entries.orEmpty(),
|
||||
hasLocation = hasLocation,
|
||||
entries = if (hasLocation) nearbyBundle?.entries.orEmpty() else emptyList(),
|
||||
dm = nearbyBundle?.dm.orEmpty(),
|
||||
forn = nearbyBundle?.forn.orEmpty(),
|
||||
onOpenAction = { action ->
|
||||
@@ -461,7 +522,9 @@ fun KlottrAppShell(
|
||||
FoundOpenAction.None -> Unit
|
||||
}
|
||||
},
|
||||
onClose = { /* inget i nya UI */ }
|
||||
rowTextStyle = MaterialTheme.typography.bodyMedium.copy(
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user