KMP/UI: snabbare ”Närliggande” + fullhöjd ”Hittat”
shared(nearby): parallellisera fetchNearbyData med coroutineScope/async; bibehåll DI och fail-safe runCatching per källa. shared(ui): FoundContent fyller tilldelad yta — ta bort height cap 420dp och använd fillMaxSize. app(ui): gör Hittat-sektionen fullhöjd via omslutande Box(fillMaxSize) och lägg subtila scroll-hints (fade top/bottom) för tydlig skrollbarhet.
This commit is contained in:
@@ -88,6 +88,7 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Brush // För vertikal gradient
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
@@ -769,7 +770,7 @@ private fun KlottrApp(
|
||||
// Förbättra etikett för klotter om vi bara har tom/”Okänt klotter”
|
||||
// Berika etiketter för klotter i ett svep via delad hjälpare (IO-tråd)
|
||||
val enriched = withContext(Dispatchers.IO) {
|
||||
enrichKlotterLabels( // [NY]
|
||||
enrichKlotterLabels( //
|
||||
found = foundList,
|
||||
radiusMeters = 60,
|
||||
fetchNearbyKlotter = { la, lo, r ->
|
||||
@@ -793,84 +794,106 @@ private fun KlottrApp(
|
||||
.fillMaxWidth()
|
||||
.weight(1f)
|
||||
) {
|
||||
val my = LastLocationStore.lastKnownLocation // ny: läs senaste position för avståndsberäkning
|
||||
val _tick = locationTick // ny: bind UI till platsuppdateringar
|
||||
val my = LastLocationStore.lastKnownLocation
|
||||
val _tick = locationTick
|
||||
|
||||
FoundContent( // ny: delat material-fritt “Hittat”-innehåll
|
||||
entries = foundList, // oför: dina fynd
|
||||
currentLat = my?.latitude, // ny: skickas till delad formatterare
|
||||
currentLon = my?.longitude, // ny: skickas till delad formatterare
|
||||
showCoords = showCoords, // oför: toggle för koordinater
|
||||
labelOverrides = labelOverrides, // ny: förbättrade etiketter (klotter)
|
||||
isClickable = { f -> // oför: samma klick-regel som innan
|
||||
(f.layer == FoundStore.LAYER_WIKI) ||
|
||||
(f.layer == FoundStore.LAYER_FORNSOK) ||
|
||||
(f.layer == FoundStore.LAYER_KLOTTER) ||
|
||||
(f.layer == FoundStore.LAYER_DM)
|
||||
},
|
||||
onEntryClick = { f -> // oför: samma klickbeteende som tidigare
|
||||
when (f.layer) {
|
||||
FoundStore.LAYER_KLOTTER -> {
|
||||
val display = (labelOverrides["${f.layer}|${f.id}"] ?: f.label).ifBlank { "Okänt klotter" }
|
||||
openKlotter = OpenKlotter(
|
||||
id = f.id,
|
||||
lat = f.lat,
|
||||
lon = f.lon,
|
||||
label = display
|
||||
)
|
||||
}
|
||||
FoundStore.LAYER_WIKI -> {
|
||||
val pid = f.id.toLongOrNull()
|
||||
if (pid != null) openWiki = OpenWiki(pid, f.lat, f.lon)
|
||||
}
|
||||
FoundStore.LAYER_FORNSOK -> {
|
||||
scope.launch {
|
||||
val enriched = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val around = Fornsok.getNearby(f.lat, f.lon, radiusMeters = 150)
|
||||
val want = (labelOverrides["${f.layer}|${f.id}"] ?: f.label)
|
||||
val byTitle = around.firstOrNull { it.title.equals(want, ignoreCase = true) }
|
||||
byTitle ?: around.minByOrNull { app.klottr.util.distanceMeters(f.lat, f.lon, it.lat, it.lon) }
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
openFornsok = OpenFornsok(
|
||||
enriched ?: FornsokItem(
|
||||
id = f.id,
|
||||
title = (labelOverrides["${f.layer}|${f.id}"] ?: f.label).ifBlank { "Fornlämning" },
|
||||
lat = f.lat,
|
||||
lon = f.lon,
|
||||
uri = if (f.id.startsWith("http")) f.id else null,
|
||||
serviceName = "fornsok",
|
||||
desc = null
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
FoundStore.LAYER_DM -> {
|
||||
scope.launch {
|
||||
val exact = withContext(Dispatchers.IO) {
|
||||
try { app.klottr.net.DigitaltMuseum.lookupByIdentifier(f.id) }
|
||||
catch (_: Exception) { null }
|
||||
}
|
||||
openDm = exact ?: app.klottr.net.DigitaltMuseumItem(
|
||||
Box(modifier = Modifier.fillMaxSize()) { // Gör ytan fullhöjd för innehållet
|
||||
FoundContent( // Ingen modifier här
|
||||
entries = foundList, currentLat = my?.latitude, currentLon = my?.longitude, showCoords = showCoords, labelOverrides = labelOverrides, isClickable = { f -> (f.layer == FoundStore.LAYER_WIKI) ||
|
||||
(f.layer == FoundStore.LAYER_FORNSOK) ||
|
||||
(f.layer == FoundStore.LAYER_KLOTTER) ||
|
||||
(f.layer == FoundStore.LAYER_DM)
|
||||
},
|
||||
onEntryClick = { f -> when (f.layer) {
|
||||
FoundStore.LAYER_KLOTTER -> {
|
||||
val display = (labelOverrides["${f.layer}|${f.id}"] ?: f.label).ifBlank { "Okänt klotter" }
|
||||
openKlotter = OpenKlotter(
|
||||
id = f.id,
|
||||
title = (labelOverrides["${f.layer}|${f.id}"] ?: f.label).ifBlank { "DigitaltMuseum" },
|
||||
lat = f.lat,
|
||||
lon = f.lon,
|
||||
url = null, uniqueId = null, webUrl = null, owner = null
|
||||
label = display
|
||||
)
|
||||
}
|
||||
FoundStore.LAYER_WIKI -> {
|
||||
val pid = f.id.toLongOrNull()
|
||||
if (pid != null) openWiki = OpenWiki(pid, f.lat, f.lon)
|
||||
}
|
||||
FoundStore.LAYER_FORNSOK -> {
|
||||
scope.launch {
|
||||
val enriched = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val around = Fornsok.getNearby(f.lat, f.lon, radiusMeters = 150)
|
||||
val want = (labelOverrides["${f.layer}|${f.id}"] ?: f.label)
|
||||
val byTitle = around.firstOrNull { it.title.equals(want, ignoreCase = true) }
|
||||
byTitle ?: around.minByOrNull { app.klottr.util.distanceMeters(f.lat, f.lon, it.lat, it.lon) }
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
openFornsok = OpenFornsok(
|
||||
enriched ?: FornsokItem(
|
||||
id = f.id,
|
||||
title = (labelOverrides["${f.layer}|${f.id}"] ?: f.label).ifBlank { "Fornlämning" },
|
||||
lat = f.lat,
|
||||
lon = f.lon,
|
||||
uri = if (f.id.startsWith("http")) f.id else null,
|
||||
serviceName = "fornsok",
|
||||
desc = null
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
FoundStore.LAYER_DM -> {
|
||||
scope.launch {
|
||||
val exact = withContext(Dispatchers.IO) {
|
||||
try { app.klottr.net.DigitaltMuseum.lookupByIdentifier(f.id) }
|
||||
catch (_: Exception) { null }
|
||||
}
|
||||
openDm = exact ?: app.klottr.net.DigitaltMuseumItem(
|
||||
id = f.id,
|
||||
title = (labelOverrides["${f.layer}|${f.id}"] ?: f.label).ifBlank { "DigitaltMuseum" },
|
||||
lat = f.lat,
|
||||
lon = f.lon,
|
||||
url = null, uniqueId = null, webUrl = null, owner = null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
isBold = { f -> !FoundStore.isAway(context, f.layer, f.id) }, // Fet rubrik när posten inte är "away"
|
||||
distanceFormatter = ::formatDistance, // Plattformsformatterare (meter → text)
|
||||
coordsFormatter = ::formatCoords, // Plattformsformatterare (lat/lon → text)
|
||||
rowTextStyle = MaterialTheme.typography.bodyMedium.copy(
|
||||
color = MaterialTheme.colorScheme.onSurface // Läsbar text dag/natt
|
||||
},
|
||||
isBold = { f -> !FoundStore.isAway(context, f.layer, f.id) }, distanceFormatter = ::formatDistance, coordsFormatter = ::formatCoords, rowTextStyle = MaterialTheme.typography.bodyMedium.copy( color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
)
|
||||
} // [NY]
|
||||
|
||||
// Scroll-hints (behåll som i föregående patch)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopCenter) // [NY]
|
||||
.fillMaxWidth() // [NY]
|
||||
.height(12.dp) // [NY]
|
||||
.background(
|
||||
brush = Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
MaterialTheme.colorScheme.surface,
|
||||
MaterialTheme.colorScheme.surface.copy(alpha = 0f)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomCenter) // [NY]
|
||||
.fillMaxWidth() // [NY]
|
||||
.height(12.dp) // [NY]
|
||||
.background(
|
||||
brush = Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
MaterialTheme.colorScheme.surface.copy(alpha = 0f),
|
||||
MaterialTheme.colorScheme.surface
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (!loggedIn) Button(onClick = onLogin) { Text("Logga in") }
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package app.klottr.nearby // [OFÖR]
|
||||
package app.klottr.nearby
|
||||
|
||||
import app.klottr.net.NoteDTO // [OFÖR] Datamodeller (finns i :shared)
|
||||
import app.klottr.net.WikipediaPage // [OFÖR]
|
||||
import app.klottr.net.DigitaltMuseumItem // [OFÖR]
|
||||
import app.klottr.net.FornsokItem // [OFÖR]
|
||||
import kotlinx.coroutines.async // För parallella jobb
|
||||
import kotlinx.coroutines.awaitAll // För att vänta in flera Deferred
|
||||
import kotlinx.coroutines.coroutineScope // För strukturerad samtidighet
|
||||
|
||||
import app.klottr.net.NoteDTO // Datamodeller (finns i :shared)
|
||||
import app.klottr.net.WikipediaPage //
|
||||
import app.klottr.net.DigitaltMuseumItem //
|
||||
import app.klottr.net.FornsokItem //
|
||||
|
||||
/** Resultatcontainer för “Närliggande” (alla lager). */
|
||||
data class NearbyData( // [OFÖR]
|
||||
data class NearbyData( //
|
||||
val klotter: List<NoteDTO>,
|
||||
val wiki: List<WikipediaPage>,
|
||||
val dm: List<DigitaltMuseumItem>,
|
||||
@@ -14,42 +18,51 @@ data class NearbyData( // [OFÖR]
|
||||
)
|
||||
|
||||
/**
|
||||
* [ÄNDRAD] Plattformsneutral fetcher:
|
||||
* Plattformsneutral fetcher:
|
||||
* - Tar in fetch-funktioner som parametrar (Dependency Injection) i stället för att importera klienter.
|
||||
* - Inga beroenden till :app eller plattforms-specifika källträd.
|
||||
*/
|
||||
suspend fun fetchNearbyData( // [OFÖR] Samma namn – enklare när vi kopplar in från :app
|
||||
lat: Double, // [OFÖR]
|
||||
lon: Double, // [OFÖR]
|
||||
showKlotter: Boolean, // [OFÖR]
|
||||
showWiki: Boolean, // [OFÖR]
|
||||
showDm: Boolean, // [OFÖR]
|
||||
showFornsok: Boolean, // [OFÖR]
|
||||
wikiRadius: Int, // [OFÖR]
|
||||
dmRadius: Int, // [OFÖR]
|
||||
fornsokRadius: Int, // [OFÖR]
|
||||
suspend fun fetchNearbyData( // Samma namn – enklare när vi kopplar in från :app
|
||||
lat: Double, //
|
||||
lon: Double, //
|
||||
showKlotter: Boolean, //
|
||||
showWiki: Boolean, //
|
||||
showDm: Boolean, //
|
||||
showFornsok: Boolean, //
|
||||
wikiRadius: Int, //
|
||||
dmRadius: Int, //
|
||||
fornsokRadius: Int, //
|
||||
// ---- injicerade fetchers (plattformen tillhandahåller dessa) ----
|
||||
klotterFetcher: suspend (lat: Double, lon: Double) -> List<NoteDTO>, //
|
||||
wikiFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<WikipediaPage>, //
|
||||
dmFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<DigitaltMuseumItem>, //
|
||||
fornFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<FornsokItem> //
|
||||
klotterFetcher: suspend (lat: Double, lon: Double) -> List<NoteDTO>, //
|
||||
wikiFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<WikipediaPage>, //
|
||||
dmFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<DigitaltMuseumItem>, //
|
||||
fornFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<FornsokItem> //
|
||||
): NearbyData {
|
||||
// Kör sekventiellt (enkelt/säkert); kan parallelliseras senare om vi vill
|
||||
val kl = if (showKlotter) {
|
||||
runCatching { klotterFetcher(lat, lon) }.getOrElse { emptyList() } //
|
||||
} else emptyList()
|
||||
return coroutineScope { // Kör allt inom strukturerad samtidighet
|
||||
// Starta varje källa parallellt, men respektera show*-flaggorna.
|
||||
val klDeferred = async { //
|
||||
if (showKlotter) runCatching { klotterFetcher(lat, lon) }.getOrElse { emptyList() } else emptyList()
|
||||
}
|
||||
val wiDeferred = async { //
|
||||
if (showWiki) runCatching { wikiFetcher(lat, lon, wikiRadius) }.getOrElse { emptyList() } else emptyList()
|
||||
}
|
||||
val dmDeferred = async { //
|
||||
if (showDm) runCatching { dmFetcher(lat, lon, dmRadius) }.getOrElse { emptyList() } else emptyList()
|
||||
}
|
||||
val foDeferred = async { //
|
||||
if (showFornsok) runCatching { fornFetcher(lat, lon, fornsokRadius) }.getOrElse { emptyList() } else emptyList()
|
||||
}
|
||||
|
||||
val wi = if (showWiki) {
|
||||
runCatching { wikiFetcher(lat, lon, wikiRadius) }.getOrElse { emptyList() } //
|
||||
} else emptyList()
|
||||
// Vänta in alla parallella jobb.
|
||||
awaitAll(klDeferred, wiDeferred, dmDeferred, foDeferred) //
|
||||
|
||||
val dm = if (showDm) {
|
||||
runCatching { dmFetcher(lat, lon, dmRadius) }.getOrElse { emptyList() } //
|
||||
} else emptyList()
|
||||
// Plocka ut resultaten.
|
||||
val kl = klDeferred.getCompleted() //
|
||||
val wi = wiDeferred.getCompleted() //
|
||||
val dm = dmDeferred.getCompleted() //
|
||||
val fo = foDeferred.getCompleted() //
|
||||
|
||||
val fo = if (showFornsok) {
|
||||
runCatching { fornFetcher(lat, lon, fornsokRadius) }.getOrElse { emptyList() } //
|
||||
} else emptyList()
|
||||
|
||||
return NearbyData(klotter = kl, wiki = wi, dm = dm, forn = fo) // [OFÖR]
|
||||
NearbyData(klotter = kl, wiki = wi, dm = dm, forn = fo) // [OFÖR]* Samma returtyp, men nu parallellt
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package app.klottr.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.fillMaxSize // Vi fyller ytan
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.foundation.text.BasicText
|
||||
import app.klottr.util.FoundEntry
|
||||
import app.klottr.nearby.foundSubtitle
|
||||
@@ -38,9 +35,7 @@ fun FoundContent(
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(max = 420.dp)
|
||||
.padding(0.dp)
|
||||
.fillMaxSize() // Fyll hela ytan som föräldern ger (ingen 420dp-gräns)
|
||||
) {
|
||||
if (entries.isEmpty()) {
|
||||
BasicText("Inga fynd ännu.", style = rowTextStyle)
|
||||
|
||||
Reference in New Issue
Block a user