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:
@@ -126,6 +126,7 @@ import app.klottr.net.fetchNoteDetail
|
||||
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.NearbyEntryRow
|
||||
import app.klottr.ui.NearbyList // Delad material-fri listkomponent
|
||||
import app.klottr.util.Auth
|
||||
@@ -602,8 +603,8 @@ private fun KlottrApp(
|
||||
Scaffold(
|
||||
topBar = {
|
||||
CenterAlignedTopAppBar(
|
||||
title = { Text("") }, // [ÅTERSTÄLLD] Standardtitel i appbaren (ingen special-Box, inga extra modifiers)
|
||||
actions = { // [OFÖR] Dina befintliga actions (Info/Inställningar)
|
||||
title = { Text("") }, // Standardtitel i appbaren (ingen special-Box, inga extra modifiers)
|
||||
actions = { // Dina befintliga actions (Info/Inställningar)
|
||||
IconButton(onClick = { showAbout = true }) {
|
||||
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") {
|
||||
val improved = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
@@ -773,7 +774,7 @@ private fun KlottrApp(
|
||||
} catch (_: Exception) { 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,38 +785,26 @@ private fun KlottrApp(
|
||||
if (foundList.isEmpty()) {
|
||||
Text("Inga fynd ännu.")
|
||||
} else {
|
||||
LazyColumn(Modifier.fillMaxWidth().weight(1f)) {
|
||||
items(
|
||||
items = foundList,
|
||||
key = { f -> "${f.layer}:${f.id}" } // ⬅️ stabil nyckel per rad
|
||||
) { f ->
|
||||
val displayLabel = labelOverrides["${f.layer}|${f.id}"] ?: f.label // [använd ev. förbättrad etikett; annars original
|
||||
|
||||
val clickable = (f.layer == FoundStore.LAYER_WIKI) ||
|
||||
(f.layer == FoundStore.LAYER_FORNSOK) ||
|
||||
(f.layer == FoundStore.LAYER_KLOTTER) ||
|
||||
(f.layer == FoundStore.LAYER_DM)
|
||||
|
||||
// --- Hämta away för UI ---
|
||||
val away = FoundStore.isAway(context, f.layer, f.id)
|
||||
|
||||
ListItem(
|
||||
headlineContent = {
|
||||
Text(
|
||||
displayLabel.ifBlank {
|
||||
Box( // Behåll layout: fyll bredd + ta resterande höjd i kolumnen
|
||||
modifier = Modifier
|
||||
.fillMaxWidth() //
|
||||
.weight(1f) // samma som tidigare LazyColumn hade
|
||||
) {
|
||||
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
|
||||
},
|
||||
// Fet stil när posten är "aktiv" (inte bortamarkerad)
|
||||
fontWeight = if (!away) FontWeight.Bold else FontWeight.Normal
|
||||
)
|
||||
},
|
||||
supportingContent = {
|
||||
// 1) Typ (lager)
|
||||
subtitleFor = { f -> // Undertext "<lager> • <avstånd> m" (+ ev. koordinater)
|
||||
val layerName = when (f.layer) {
|
||||
FoundStore.LAYER_KLOTTER -> "Klotter"
|
||||
FoundStore.LAYER_FORNSOK -> "Fornsök"
|
||||
@@ -823,50 +812,48 @@ private fun KlottrApp(
|
||||
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")
|
||||
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) } ?: "-" //
|
||||
val coordPart = if (showCoords) " • " + formatCoords(f.lat, f.lon) else "" //
|
||||
val _tick = locationTick // Binda till plats-ticks så raden uppdateras när positionen uppdateras
|
||||
"$layerName • $distText$coordPart" //
|
||||
},
|
||||
modifier = if (clickable) Modifier.clickable {
|
||||
isClickable = { f -> // Samma klick-regel som tidigare
|
||||
(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
|
||||
when (f.layer) {
|
||||
FoundStore.LAYER_KLOTTER -> {
|
||||
// Öppna samma detaljruta som från “Närliggande”
|
||||
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,
|
||||
label = displayLabel.ifBlank { "Okänt klotter" } // vi har ofta redan berikat displayLabel ovan
|
||||
label = display
|
||||
)
|
||||
}
|
||||
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 -> {
|
||||
// Hämta riktiga fält (desc/type/uri) nära fyndets position innan vi öppnar dialogen
|
||||
scope.launch {
|
||||
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 byTitle = around.firstOrNull { it.title.equals(displayLabel, ignoreCase = true) }
|
||||
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 = displayLabel.ifBlank { "Fornlämning" },
|
||||
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,
|
||||
@@ -877,33 +864,29 @@ private fun KlottrApp(
|
||||
}
|
||||
}
|
||||
FoundStore.LAYER_DM -> {
|
||||
// Öppna EXAKT det klickade objektet (inte "något i närheten")
|
||||
scope.launch {
|
||||
scope.launch { // Samma DM-lookup som tidigare
|
||||
val exact = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
app.klottr.net.DigitaltMuseum.lookupByIdentifier(f.id)
|
||||
} catch (_: Exception) { null }
|
||||
try { app.klottr.net.DigitaltMuseum.lookupByIdentifier(f.id) }
|
||||
catch (_: Exception) { null }
|
||||
}
|
||||
openDm = exact ?: app.klottr.net.DigitaltMuseumItem(
|
||||
id = f.id,
|
||||
title = displayLabel.ifBlank { "DigitaltMuseum" },
|
||||
title = (labelOverrides["${f.layer}|${f.id}"] ?: f.label).ifBlank { "DigitaltMuseum" },
|
||||
lat = f.lat,
|
||||
lon = f.lon,
|
||||
url = null,
|
||||
uniqueId = null,
|
||||
webUrl = null,
|
||||
owner = null
|
||||
url = null, uniqueId = null, webUrl = null, owner = null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else Modifier
|
||||
},
|
||||
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)) {
|
||||
if (!loggedIn) Button(onClick = onLogin) { Text("Logga in") }
|
||||
if (loggedIn) Button(onClick = onLogout) { Text("Logga ut") }
|
||||
|
||||
Reference in New Issue
Block a user