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()) { FoundContent(
Text("Inga fynd ännu.") entries = foundList,
} else { currentLat = my?.latitude,
val my = LastLocationStore.lastKnownLocation currentLon = my?.longitude,
val _tick = locationTick showCoords = showCoords,
labelOverrides = labelOverrides,
Box(modifier = Modifier.fillMaxSize()) { isClickable = { f ->
FoundContent( (f.layer == FoundStore.LAYER_WIKI) ||
entries = foundList, (f.layer == FoundStore.LAYER_FORNSOK) ||
currentLat = my?.latitude, (f.layer == FoundStore.LAYER_KLOTTER) ||
currentLon = my?.longitude, (f.layer == FoundStore.LAYER_DM)
showCoords = showCoords, },
labelOverrides = labelOverrides, onEntryClick = { f ->
isClickable = { f -> scope.launch {
(f.layer == FoundStore.LAYER_WIKI) || val action = withContext(Dispatchers.IO) {
(f.layer == FoundStore.LAYER_FORNSOK) || resolveFoundOpenAction(
(f.layer == FoundStore.LAYER_KLOTTER) || entry = f,
(f.layer == FoundStore.LAYER_DM) labelOverrides = labelOverrides,
}, fornsokAround = { lat, lon, radius ->
onEntryClick = { f -> try { Fornsok.getNearby(lat, lon, radius) } catch (_: Exception) { emptyList() }
scope.launch { },
val action = withContext(Dispatchers.IO) { dmLookupByIdentifier = { id ->
resolveFoundOpenAction( try { app.klottr.net.DigitaltMuseum.lookupByIdentifier(id) } catch (_: Exception) { null }
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
} }
)
}
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) }
isBold = { f -> !FoundStore.isAway(context, f.layer, f.id) }, is FoundOpenAction.Fornsok -> { openFornsok = OpenFornsok(action.item) }
distanceFormatter = ::formatDistance, is FoundOpenAction.DigitaltMuseum -> { openDm = action.item }
coordsFormatter = ::formatCoords, FoundOpenAction.None -> Unit
rowTextStyle = MaterialTheme.typography.bodyMedium.copy( }
color = MaterialTheme.colorScheme.onSurface }
) },
) isBold = { f -> !FoundStore.isAway(context, f.layer, f.id) },
} distanceFormatter = ::formatDistance,
} coordsFormatter = ::formatCoords,
rowTextStyle = MaterialTheme.typography.bodyMedium.copy(
color = MaterialTheme.colorScheme.onSurface
)
)
}, },
footerContent = { footerContent = {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {