From f0d9f8ef2ee8006b674df80db9261e0f13349f76 Mon Sep 17 00:00:00 2001 From: Fabian Norlin Date: Thu, 18 Sep 2025 21:17:51 +0200 Subject: [PATCH] Rely on shared FoundContent for empty state; simplify MainActivity --- app/src/main/java/app/klottr/MainActivity.kt | 111 ++++++++----------- 1 file changed, 49 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/app/klottr/MainActivity.kt b/app/src/main/java/app/klottr/MainActivity.kt index b2820c2..d962f93 100644 --- a/app/src/main/java/app/klottr/MainActivity.kt +++ b/app/src/main/java/app/klottr/MainActivity.kt @@ -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)) {