shared(ui): add material-free FoundList;

app(found): render Hittat via shared FoundList; keep dark-mode text and click behavior
This commit is contained in:
2025-09-12 21:04:04 +02:00
parent 88c041ef2b
commit 23e237c457

View File

@@ -126,6 +126,7 @@ import app.klottr.net.fetchNoteDetail
import app.klottr.net.uploadImageFromUri import app.klottr.net.uploadImageFromUri
import app.klottr.shared.SharedPing import app.klottr.shared.SharedPing
import app.klottr.theme.KlottrTheme import app.klottr.theme.KlottrTheme
import app.klottr.ui.FoundList // Delad, material-fri listkomponent för "Hittat"
import app.klottr.ui.NearbyEntryRow import app.klottr.ui.NearbyEntryRow
import app.klottr.ui.NearbyList // Delad material-fri listkomponent import app.klottr.ui.NearbyList // Delad material-fri listkomponent
import app.klottr.util.Auth import app.klottr.util.Auth
@@ -602,8 +603,8 @@ private fun KlottrApp(
Scaffold( Scaffold(
topBar = { topBar = {
CenterAlignedTopAppBar( CenterAlignedTopAppBar(
title = { Text("") }, // [ÅTERSTÄLLD] Standardtitel i appbaren (ingen special-Box, inga extra modifiers) title = { Text("") }, // Standardtitel i appbaren (ingen special-Box, inga extra modifiers)
actions = { // [OFÖR] Dina befintliga actions (Info/Inställningar) actions = { // Dina befintliga actions (Info/Inställningar)
IconButton(onClick = { showAbout = true }) { IconButton(onClick = { showAbout = true }) {
Icon(imageVector = Icons.Filled.Info, contentDescription = "Om") Icon(imageVector = Icons.Filled.Info, contentDescription = "Om")
} }
@@ -764,7 +765,7 @@ private fun KlottrApp(
} }
} }
} }
// [NY] 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”
if (f.label.isBlank() || f.label == "Okänt klotter") { if (f.label.isBlank() || f.label == "Okänt klotter") {
val improved = withContext(Dispatchers.IO) { val improved = withContext(Dispatchers.IO) {
try { try {
@@ -773,7 +774,7 @@ private fun KlottrApp(
} catch (_: Exception) { null } } catch (_: Exception) { null }
} }
if (improved != null) { if (improved != null) {
labelOverrides["${f.layer}|${f.id}"] = improved // [NY] Spara bättre etikett för denna rad labelOverrides["${f.layer}|${f.id}"] = improved // Spara bättre etikett för denna rad
} }
} }
@@ -784,125 +785,107 @@ private fun KlottrApp(
if (foundList.isEmpty()) { if (foundList.isEmpty()) {
Text("Inga fynd ännu.") Text("Inga fynd ännu.")
} else { } else {
LazyColumn(Modifier.fillMaxWidth().weight(1f)) { Box( // Behåll layout: fyll bredd + ta resterande höjd i kolumnen
items( modifier = Modifier
items = foundList, .fillMaxWidth() //
key = { f -> "${f.layer}:${f.id}" } // ⬅️ stabil nyckel per rad .weight(1f) // samma som tidigare LazyColumn hade
) { f -> ) {
val displayLabel = labelOverrides["${f.layer}|${f.id}"] ?: f.label // [använd ev. förbättrad etikett; annars original FoundList( // Delad, material-fri listkomponent
entries = foundList, // Vi skickar in befintliga "Hittat"-poster
val clickable = (f.layer == FoundStore.LAYER_WIKI) || labelFor = { f -> // Rubrik per rad (med ev. förbättrad etikett)
(f.layer == FoundStore.LAYER_FORNSOK) || val key = "${f.layer}|${f.id}" //
(f.layer == FoundStore.LAYER_KLOTTER) || val base = labelOverrides[key] ?: f.label // Ta förbättrad etikett om finns
(f.layer == FoundStore.LAYER_DM) if (base.isBlank()) { // Fallbacks om label saknas
// --- Hämta away för UI ---
val away = FoundStore.isAway(context, f.layer, f.id)
ListItem(
headlineContent = {
Text(
displayLabel.ifBlank {
when (f.layer) {
FoundStore.LAYER_KLOTTER -> "Okänt klotter"
FoundStore.LAYER_DM -> "DigitaltMuseum"
FoundStore.LAYER_FORNSOK -> "Fornsök"
else -> "Wikipedia"
}
},
// Fet stil när posten är "aktiv" (inte bortamarkerad)
fontWeight = if (!away) FontWeight.Bold else FontWeight.Normal
)
},
supportingContent = {
// 1) Typ (lager)
val layerName = when (f.layer) {
FoundStore.LAYER_KLOTTER -> "Klotter"
FoundStore.LAYER_FORNSOK -> "Fornsök"
FoundStore.LAYER_DM -> "DigitaltMuseum"
FoundStore.LAYER_WIKI -> "Wikipedia"
else -> "Plats"
}
// 2) Avstånd från senaste kända position
val my = LastLocationStore.lastKnownLocation
val distM = my?.let { app.klottr.util.distanceMeters(it.latitude, it.longitude, f.lat, f.lon).roundToInt() }
val distText = distM?.let { formatDistance(it) } ?: "-"
// 3) Ev. koordinater (om toggeln är på)
val coordPart = if (showCoords) " • " + formatCoords(f.lat, f.lon) else ""
// Ska bara läsas så att Compose vet att innehållet beror på det. Gör så att raderna ritas om när platsen uppdateras.
val _tick = locationTick // ignoreras, men binder UI till ticks
Text("$layerName • $distText$coordPart")
},
modifier = if (clickable) Modifier.clickable {
when (f.layer) { when (f.layer) {
FoundStore.LAYER_KLOTTER -> { FoundStore.LAYER_KLOTTER -> "Okänt klotter"
// Öppna samma detaljruta som från “Närliggande” FoundStore.LAYER_DM -> "DigitaltMuseum"
openKlotter = OpenKlotter( FoundStore.LAYER_FORNSOK -> "Fornsök"
id = f.id, else -> "Wikipedia"
lat = f.lat, }
lon = f.lon, } else base
label = displayLabel.ifBlank { "Okänt klotter" } // vi har ofta redan berikat displayLabel ovan },
) subtitleFor = { f -> // Undertext "<lager> • <avstånd> m" (+ ev. koordinater)
} val layerName = when (f.layer) {
FoundStore.LAYER_WIKI -> { FoundStore.LAYER_KLOTTER -> "Klotter"
val pid = f.id.toLongOrNull() FoundStore.LAYER_FORNSOK -> "Fornsök"
if (pid != null) openWiki = OpenWiki(pid, f.lat, f.lon) FoundStore.LAYER_DM -> "DigitaltMuseum"
} FoundStore.LAYER_WIKI -> "Wikipedia"
FoundStore.LAYER_FORNSOK -> { else -> "Plats"
// Hämta riktiga fält (desc/type/uri) nära fyndets position innan vi öppnar dialogen }
scope.launch { val my = LastLocationStore.lastKnownLocation //
val enriched = withContext(Dispatchers.IO) { val distM = my?.let { app.klottr.util.distanceMeters(it.latitude, it.longitude, f.lat, f.lon).roundToInt() } //
try { val distText = distM?.let { formatDistance(it) } ?: "-" //
val around = Fornsok.getNearby(f.lat, f.lon, radiusMeters = 150) val coordPart = if (showCoords) " • " + formatCoords(f.lat, f.lon) else "" //
val byTitle = around.firstOrNull { it.title.equals(displayLabel, ignoreCase = true) } val _tick = locationTick // Binda till plats-ticks så raden uppdateras när positionen uppdateras
byTitle ?: around.minByOrNull { app.klottr.util.distanceMeters(f.lat, f.lon, it.lat, it.lon) } "$layerName • $distText$coordPart" //
} catch (_: Exception) { null } },
} isClickable = { f -> // Samma klick-regel som tidigare
openFornsok = OpenFornsok( (f.layer == FoundStore.LAYER_WIKI) ||
enriched ?: FornsokItem( (f.layer == FoundStore.LAYER_FORNSOK) ||
id = f.id, (f.layer == FoundStore.LAYER_KLOTTER) ||
title = displayLabel.ifBlank { "Fornlämning" }, (f.layer == FoundStore.LAYER_DM)
lat = f.lat, },
lon = f.lon, onEntryClick = { f -> // Samma klickbeteende som tidigare rader
uri = if (f.id.startsWith("http")) f.id else null, when (f.layer) {
serviceName = "fornsok", FoundStore.LAYER_KLOTTER -> {
desc = null 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 { // Samma enrich-flöde som tidigare
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(
FoundStore.LAYER_DM -> { enriched ?: FornsokItem(
// Öppna EXAKT det klickade objektet (inte "något i närheten")
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 = displayLabel.ifBlank { "DigitaltMuseum" }, title = (labelOverrides["${f.layer}|${f.id}"] ?: f.label).ifBlank { "Fornlämning" },
lat = f.lat, lat = f.lat,
lon = f.lon, lon = f.lon,
url = null, uri = if (f.id.startsWith("http")) f.id else null,
uniqueId = null, serviceName = "fornsok",
webUrl = null, desc = null
owner = null
) )
} )
} }
} }
} else Modifier FoundStore.LAYER_DM -> {
scope.launch { // Samma DM-lookup som tidigare
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 stil när posten är “aktiv”
rowTextStyle = MaterialTheme.typography.bodyMedium.copy( // Tydlig text i dag/natt
color = MaterialTheme.colorScheme.onSurface
) )
HorizontalDivider() )
}
} }
} }
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") }