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.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.geometry.Offset
|
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.Color
|
||||||
import androidx.compose.ui.graphics.asImageBitmap
|
import androidx.compose.ui.graphics.asImageBitmap
|
||||||
import androidx.compose.ui.graphics.graphicsLayer
|
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”
|
// 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)
|
// Berika etiketter för klotter i ett svep via delad hjälpare (IO-tråd)
|
||||||
val enriched = withContext(Dispatchers.IO) {
|
val enriched = withContext(Dispatchers.IO) {
|
||||||
enrichKlotterLabels( // [NY]
|
enrichKlotterLabels( //
|
||||||
found = foundList,
|
found = foundList,
|
||||||
radiusMeters = 60,
|
radiusMeters = 60,
|
||||||
fetchNearbyKlotter = { la, lo, r ->
|
fetchNearbyKlotter = { la, lo, r ->
|
||||||
@@ -793,84 +794,106 @@ private fun KlottrApp(
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
) {
|
) {
|
||||||
val my = LastLocationStore.lastKnownLocation // ny: läs senaste position för avståndsberäkning
|
val my = LastLocationStore.lastKnownLocation
|
||||||
val _tick = locationTick // ny: bind UI till platsuppdateringar
|
val _tick = locationTick
|
||||||
|
|
||||||
FoundContent( // ny: delat material-fritt “Hittat”-innehåll
|
Box(modifier = Modifier.fillMaxSize()) { // Gör ytan fullhöjd för innehållet
|
||||||
entries = foundList, // oför: dina fynd
|
FoundContent( // Ingen modifier här
|
||||||
currentLat = my?.latitude, // ny: skickas till delad formatterare
|
entries = foundList, currentLat = my?.latitude, currentLon = my?.longitude, showCoords = showCoords, labelOverrides = labelOverrides, isClickable = { f -> (f.layer == FoundStore.LAYER_WIKI) ||
|
||||||
currentLon = my?.longitude, // ny: skickas till delad formatterare
|
(f.layer == FoundStore.LAYER_FORNSOK) ||
|
||||||
showCoords = showCoords, // oför: toggle för koordinater
|
(f.layer == FoundStore.LAYER_KLOTTER) ||
|
||||||
labelOverrides = labelOverrides, // ny: förbättrade etiketter (klotter)
|
(f.layer == FoundStore.LAYER_DM)
|
||||||
isClickable = { f -> // oför: samma klick-regel som innan
|
},
|
||||||
(f.layer == FoundStore.LAYER_WIKI) ||
|
onEntryClick = { f -> when (f.layer) {
|
||||||
(f.layer == FoundStore.LAYER_FORNSOK) ||
|
FoundStore.LAYER_KLOTTER -> {
|
||||||
(f.layer == FoundStore.LAYER_KLOTTER) ||
|
val display = (labelOverrides["${f.layer}|${f.id}"] ?: f.label).ifBlank { "Okänt klotter" }
|
||||||
(f.layer == FoundStore.LAYER_DM)
|
openKlotter = OpenKlotter(
|
||||||
},
|
|
||||||
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(
|
|
||||||
id = f.id,
|
id = f.id,
|
||||||
title = (labelOverrides["${f.layer}|${f.id}"] ?: f.label).ifBlank { "DigitaltMuseum" },
|
|
||||||
lat = f.lat,
|
lat = f.lat,
|
||||||
lon = f.lon,
|
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) }, distanceFormatter = ::formatDistance, coordsFormatter = ::formatCoords, rowTextStyle = MaterialTheme.typography.bodyMedium.copy( color = MaterialTheme.colorScheme.onSurface
|
||||||
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
|
|
||||||
)
|
)
|
||||||
|
} // [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)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
if (!loggedIn) Button(onClick = onLogin) { Text("Logga in") }
|
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 kotlinx.coroutines.async // För parallella jobb
|
||||||
import app.klottr.net.WikipediaPage // [OFÖR]
|
import kotlinx.coroutines.awaitAll // För att vänta in flera Deferred
|
||||||
import app.klottr.net.DigitaltMuseumItem // [OFÖR]
|
import kotlinx.coroutines.coroutineScope // För strukturerad samtidighet
|
||||||
import app.klottr.net.FornsokItem // [OFÖR]
|
|
||||||
|
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). */
|
/** Resultatcontainer för “Närliggande” (alla lager). */
|
||||||
data class NearbyData( // [OFÖR]
|
data class NearbyData( //
|
||||||
val klotter: List<NoteDTO>,
|
val klotter: List<NoteDTO>,
|
||||||
val wiki: List<WikipediaPage>,
|
val wiki: List<WikipediaPage>,
|
||||||
val dm: List<DigitaltMuseumItem>,
|
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.
|
* - 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.
|
* - 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
|
suspend fun fetchNearbyData( // Samma namn – enklare när vi kopplar in från :app
|
||||||
lat: Double, // [OFÖR]
|
lat: Double, //
|
||||||
lon: Double, // [OFÖR]
|
lon: Double, //
|
||||||
showKlotter: Boolean, // [OFÖR]
|
showKlotter: Boolean, //
|
||||||
showWiki: Boolean, // [OFÖR]
|
showWiki: Boolean, //
|
||||||
showDm: Boolean, // [OFÖR]
|
showDm: Boolean, //
|
||||||
showFornsok: Boolean, // [OFÖR]
|
showFornsok: Boolean, //
|
||||||
wikiRadius: Int, // [OFÖR]
|
wikiRadius: Int, //
|
||||||
dmRadius: Int, // [OFÖR]
|
dmRadius: Int, //
|
||||||
fornsokRadius: Int, // [OFÖR]
|
fornsokRadius: Int, //
|
||||||
// ---- injicerade fetchers (plattformen tillhandahåller dessa) ----
|
// ---- injicerade fetchers (plattformen tillhandahåller dessa) ----
|
||||||
klotterFetcher: suspend (lat: Double, lon: Double) -> List<NoteDTO>, //
|
klotterFetcher: suspend (lat: Double, lon: Double) -> List<NoteDTO>, //
|
||||||
wikiFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<WikipediaPage>, //
|
wikiFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<WikipediaPage>, //
|
||||||
dmFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<DigitaltMuseumItem>, //
|
dmFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<DigitaltMuseumItem>, //
|
||||||
fornFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<FornsokItem> //
|
fornFetcher: suspend (lat: Double, lon: Double, radius: Int) -> List<FornsokItem> //
|
||||||
): NearbyData {
|
): NearbyData {
|
||||||
// Kör sekventiellt (enkelt/säkert); kan parallelliseras senare om vi vill
|
return coroutineScope { // Kör allt inom strukturerad samtidighet
|
||||||
val kl = if (showKlotter) {
|
// Starta varje källa parallellt, men respektera show*-flaggorna.
|
||||||
runCatching { klotterFetcher(lat, lon) }.getOrElse { emptyList() } //
|
val klDeferred = async { //
|
||||||
} else emptyList()
|
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) {
|
// Vänta in alla parallella jobb.
|
||||||
runCatching { wikiFetcher(lat, lon, wikiRadius) }.getOrElse { emptyList() } //
|
awaitAll(klDeferred, wiDeferred, dmDeferred, foDeferred) //
|
||||||
} else emptyList()
|
|
||||||
|
|
||||||
val dm = if (showDm) {
|
// Plocka ut resultaten.
|
||||||
runCatching { dmFetcher(lat, lon, dmRadius) }.getOrElse { emptyList() } //
|
val kl = klDeferred.getCompleted() //
|
||||||
} else emptyList()
|
val wi = wiDeferred.getCompleted() //
|
||||||
|
val dm = dmDeferred.getCompleted() //
|
||||||
|
val fo = foDeferred.getCompleted() //
|
||||||
|
|
||||||
val fo = if (showFornsok) {
|
NearbyData(klotter = kl, wiki = wi, dm = dm, forn = fo) // [OFÖR]* Samma returtyp, men nu parallellt
|
||||||
runCatching { fornFetcher(lat, lon, fornsokRadius) }.getOrElse { emptyList() } //
|
}
|
||||||
} else emptyList()
|
|
||||||
|
|
||||||
return NearbyData(klotter = kl, wiki = wi, dm = dm, forn = fo) // [OFÖR]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package app.klottr.ui
|
package app.klottr.ui
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxSize // Vi fyller ytan
|
||||||
import androidx.compose.foundation.layout.heightIn
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.foundation.text.BasicText
|
import androidx.compose.foundation.text.BasicText
|
||||||
import app.klottr.util.FoundEntry
|
import app.klottr.util.FoundEntry
|
||||||
import app.klottr.nearby.foundSubtitle
|
import app.klottr.nearby.foundSubtitle
|
||||||
@@ -38,9 +35,7 @@ fun FoundContent(
|
|||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxSize() // Fyll hela ytan som föräldern ger (ingen 420dp-gräns)
|
||||||
.heightIn(max = 420.dp)
|
|
||||||
.padding(0.dp)
|
|
||||||
) {
|
) {
|
||||||
if (entries.isEmpty()) {
|
if (entries.isEmpty()) {
|
||||||
BasicText("Inga fynd ännu.", style = rowTextStyle)
|
BasicText("Inga fynd ännu.", style = rowTextStyle)
|
||||||
|
|||||||
Reference in New Issue
Block a user