Rely on shared FoundContent for empty state; simplify MainActivity

This commit is contained in:
2025-09-18 21:17:51 +02:00
parent ee440e3ffb
commit f0d9f8ef2e

View File

@@ -764,71 +764,58 @@ private fun KlottrApp(
}
}
}
val my = LastLocationStore.lastKnownLocation // Ny: Flytta upp så FoundContent alltid ritas
val _tick = locationTick // Ny: Behåll trigger
if (foundList.isEmpty()) {
Text("Inga fynd ännu.")
} else {
val my = LastLocationStore.lastKnownLocation
val _tick = locationTick
Box(modifier = Modifier.fillMaxSize()) {
FoundContent(
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 ->
scope.launch {
val action = withContext(Dispatchers.IO) {
resolveFoundOpenAction(
entry = f,
labelOverrides = labelOverrides,
fornsokAround = { lat, lon, radius ->
try { Fornsok.getNearby(lat, lon, radius) } catch (_: Exception) { emptyList() }
},
dmLookupByIdentifier = { id ->
try { app.klottr.net.DigitaltMuseum.lookupByIdentifier(id) } catch (_: Exception) { null }
}
)
}
when (action) {
is FoundOpenAction.Klotter -> {
openKlotter = OpenKlotter(
id = action.id,
lat = action.lat,
lon = action.lon,
label = action.label
)
}
is FoundOpenAction.Wiki -> {
openWiki = OpenWiki(action.pageId, action.lat, action.lon)
}
is FoundOpenAction.Fornsok -> {
openFornsok = OpenFornsok(action.item)
}
is FoundOpenAction.DigitaltMuseum -> {
openDm = action.item
}
FoundOpenAction.None -> Unit
FoundContent(
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 ->
scope.launch {
val action = withContext(Dispatchers.IO) {
resolveFoundOpenAction(
entry = f,
labelOverrides = labelOverrides,
fornsokAround = { lat, lon, radius ->
try { Fornsok.getNearby(lat, lon, radius) } catch (_: Exception) { emptyList() }
},
dmLookupByIdentifier = { id ->
try { app.klottr.net.DigitaltMuseum.lookupByIdentifier(id) } catch (_: Exception) { null }
}
)
}
when (action) {
is FoundOpenAction.Klotter -> {
openKlotter = OpenKlotter(
id = action.id,
lat = action.lat,
lon = action.lon,
label = action.label
)
}
},
isBold = { f -> !FoundStore.isAway(context, f.layer, f.id) },
distanceFormatter = ::formatDistance,
coordsFormatter = ::formatCoords,
rowTextStyle = MaterialTheme.typography.bodyMedium.copy(
color = MaterialTheme.colorScheme.onSurface
)
)
}
}
is FoundOpenAction.Wiki -> { openWiki = OpenWiki(action.pageId, action.lat, action.lon) }
is FoundOpenAction.Fornsok -> { openFornsok = OpenFornsok(action.item) }
is FoundOpenAction.DigitaltMuseum -> { openDm = action.item }
FoundOpenAction.None -> Unit
}
}
},
isBold = { f -> !FoundStore.isAway(context, f.layer, f.id) },
distanceFormatter = ::formatDistance,
coordsFormatter = ::formatCoords,
rowTextStyle = MaterialTheme.typography.bodyMedium.copy(
color = MaterialTheme.colorScheme.onSurface
)
)
},
footerContent = {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {