shared(ui): FoundContent – add isBold param and forward to FoundList
app(found): pass isBold using !FoundStore.isAway(...) in FoundContent call
This commit is contained in:
@@ -130,6 +130,7 @@ import app.klottr.net.uploadImageFromUri
|
||||
import app.klottr.shared.SharedPing
|
||||
import app.klottr.theme.KlottrTheme
|
||||
import app.klottr.ui.FoundList // Delad, material-fri listkomponent för "Hittat"
|
||||
import app.klottr.ui.FoundContent // Delat innehåll för “Hittat”
|
||||
import app.klottr.ui.NearbyEntryRow
|
||||
import app.klottr.ui.NearbyList // Delad material-fri listkomponent
|
||||
import app.klottr.util.Auth
|
||||
@@ -787,49 +788,31 @@ private fun KlottrApp(
|
||||
if (foundList.isEmpty()) {
|
||||
Text("Inga fynd ännu.")
|
||||
} else {
|
||||
Box( // Behåll layout: fyll bredd + ta resterande höjd i kolumnen
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth() //
|
||||
.weight(1f) // samma som tidigare LazyColumn hade
|
||||
.fillMaxWidth()
|
||||
.weight(1f)
|
||||
) {
|
||||
FoundList( // Delad, material-fri listkomponent
|
||||
entries = foundList, // Vi skickar in befintliga "Hittat"-poster
|
||||
labelFor = { f -> // Rubrik per rad (med ev. förbättrad etikett)
|
||||
val key = "${f.layer}|${f.id}" //
|
||||
val base = labelOverrides[key] ?: f.label // Ta förbättrad etikett om finns
|
||||
if (base.isBlank()) { // Fallbacks om label saknas
|
||||
when (f.layer) {
|
||||
FoundStore.LAYER_KLOTTER -> "Okänt klotter"
|
||||
FoundStore.LAYER_DM -> "DigitaltMuseum"
|
||||
FoundStore.LAYER_FORNSOK -> "Fornsök"
|
||||
else -> "Wikipedia"
|
||||
}
|
||||
} else base
|
||||
},
|
||||
subtitleFor = { f -> // Byt till delad formatterare
|
||||
val my = LastLocationStore.lastKnownLocation // Aktuell position (kan vara null)
|
||||
val _tick = locationTick // Bind rad-UI till plats-tick (så avstånd uppdateras)
|
||||
app.klottr.nearby.foundSubtitle( // Anropa KMP-funktionen
|
||||
entry = f, // Hittat-raden
|
||||
currentLat = my?.latitude, // Nullable lat
|
||||
currentLon = my?.longitude, // Nullable lon
|
||||
showCoords = showCoords, // Samma toggle som tidigare
|
||||
distanceFormatter = ::formatDistance, // Plattformens avståndsformatterare
|
||||
coordsFormatter = ::formatCoords // Plattformens koordinatformatterare
|
||||
)
|
||||
},
|
||||
val my = LastLocationStore.lastKnownLocation // ny: läs senaste position för avståndsberäkning
|
||||
val _tick = locationTick // ny: bind UI till platsuppdateringar
|
||||
|
||||
isClickable = { f -> // Samma klick-regel som tidigare
|
||||
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 -> // Samma klickbeteende som tidigare rader
|
||||
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( //
|
||||
val display = (labelOverrides["${f.layer}|${f.id}"] ?: f.label).ifBlank { "Okänt klotter" }
|
||||
openKlotter = OpenKlotter(
|
||||
id = f.id,
|
||||
lat = f.lat,
|
||||
lon = f.lon,
|
||||
@@ -837,11 +820,11 @@ private fun KlottrApp(
|
||||
)
|
||||
}
|
||||
FoundStore.LAYER_WIKI -> {
|
||||
val pid = f.id.toLongOrNull() //
|
||||
if (pid != null) openWiki = OpenWiki(pid, f.lat, f.lon) //
|
||||
val pid = f.id.toLongOrNull()
|
||||
if (pid != null) openWiki = OpenWiki(pid, f.lat, f.lon)
|
||||
}
|
||||
FoundStore.LAYER_FORNSOK -> {
|
||||
scope.launch { // Samma enrich-flöde som tidigare
|
||||
scope.launch {
|
||||
val enriched = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val around = Fornsok.getNearby(f.lat, f.lon, radiusMeters = 150)
|
||||
@@ -864,7 +847,7 @@ private fun KlottrApp(
|
||||
}
|
||||
}
|
||||
FoundStore.LAYER_DM -> {
|
||||
scope.launch { // Samma DM-lookup som tidigare
|
||||
scope.launch {
|
||||
val exact = withContext(Dispatchers.IO) {
|
||||
try { app.klottr.net.DigitaltMuseum.lookupByIdentifier(f.id) }
|
||||
catch (_: Exception) { null }
|
||||
@@ -880,9 +863,11 @@ private fun KlottrApp(
|
||||
}
|
||||
}
|
||||
},
|
||||
isBold = { f -> !FoundStore.isAway(context, f.layer, f.id) }, // Fet stil när posten är “aktiv”
|
||||
rowTextStyle = MaterialTheme.typography.bodyMedium.copy( // Tydlig text i dag/natt
|
||||
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
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
77
shared/src/commonMain/kotlin/app/klottr/ui/FoundContent.kt
Normal file
77
shared/src/commonMain/kotlin/app/klottr/ui/FoundContent.kt
Normal file
@@ -0,0 +1,77 @@
|
||||
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.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
|
||||
import app.klottr.nearby.layerDisplayName
|
||||
|
||||
/**
|
||||
* Material-fritt innehåll för "Hittat".
|
||||
* - Visar "Inga fynd ännu." om listan är tom.
|
||||
* - Annars renderar listan via FoundList med delegater för label/undertext/klick.
|
||||
*/
|
||||
@Composable
|
||||
fun FoundContent(
|
||||
entries: List<FoundEntry>,
|
||||
currentLat: Double?,
|
||||
currentLon: Double?,
|
||||
showCoords: Boolean,
|
||||
// Förbättrade etiketter (klotter): nyckel = "layer|id"
|
||||
labelOverrides: Map<String, String>,
|
||||
// Avgör om rad ska vara klickbar (lagerstyrt)
|
||||
isClickable: (FoundEntry) -> Boolean,
|
||||
// Klickhantering (öppna detalj etc.)
|
||||
onEntryClick: (FoundEntry) -> Unit,
|
||||
isBold: (FoundEntry) -> Boolean,
|
||||
// Plattformens formatterare (Android skickar ::formatDistance/::formatCoords)
|
||||
distanceFormatter: (Int) -> String,
|
||||
coordsFormatter: (Double, Double) -> String,
|
||||
rowTextStyle: TextStyle
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(max = 420.dp)
|
||||
.padding(0.dp)
|
||||
) {
|
||||
if (entries.isEmpty()) {
|
||||
BasicText("Inga fynd ännu.", style = rowTextStyle)
|
||||
} else {
|
||||
FoundList(
|
||||
entries = entries,
|
||||
labelFor = { f ->
|
||||
val key = "${f.layer}|${f.id}"
|
||||
val base = labelOverrides[key] ?: f.label
|
||||
if (base.isBlank()) {
|
||||
when (layerDisplayName(f.layer)) {
|
||||
"Klotter" -> "Okänt klotter"
|
||||
else -> layerDisplayName(f.layer)
|
||||
}
|
||||
} else base
|
||||
},
|
||||
subtitleFor = { f ->
|
||||
foundSubtitle(
|
||||
entry = f,
|
||||
currentLat = currentLat,
|
||||
currentLon = currentLon,
|
||||
showCoords = showCoords,
|
||||
distanceFormatter = distanceFormatter,
|
||||
coordsFormatter = coordsFormatter
|
||||
)
|
||||
},
|
||||
isClickable = isClickable,
|
||||
onEntryClick = onEntryClick,
|
||||
isBold = isBold,
|
||||
rowTextStyle = rowTextStyle
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user