Show recent finds under "Hem" tab in new UI using reused KlottrHomeContent logic
This commit is contained in:
@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
|
import androidx.compose.material.icons.filled.Home
|
||||||
import androidx.compose.material.icons.filled.Info
|
import androidx.compose.material.icons.filled.Info
|
||||||
import androidx.compose.material.icons.filled.Layers
|
import androidx.compose.material.icons.filled.Layers
|
||||||
import androidx.compose.material.icons.filled.Menu
|
import androidx.compose.material.icons.filled.Menu
|
||||||
@@ -290,6 +291,7 @@ fun KlottrAppShell(
|
|||||||
}
|
}
|
||||||
) { padding ->
|
) { padding ->
|
||||||
if (useNewUi) {
|
if (useNewUi) {
|
||||||
|
var selectedTab by remember { mutableStateOf("home") }
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
CenterAlignedTopAppBar(
|
CenterAlignedTopAppBar(
|
||||||
@@ -306,6 +308,12 @@ fun KlottrAppShell(
|
|||||||
},
|
},
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
NavigationBar {
|
NavigationBar {
|
||||||
|
NavigationBarItem(
|
||||||
|
selected = (selectedTab == "home"),
|
||||||
|
onClick = { selectedTab = "home" },
|
||||||
|
icon = { Icon(Icons.Filled.Home, contentDescription = "Hem") },
|
||||||
|
label = { Text("Hem") }
|
||||||
|
)
|
||||||
NavigationBarItem(
|
NavigationBarItem(
|
||||||
selected = false,
|
selected = false,
|
||||||
onClick = { /* TODO Lager */ },
|
onClick = { /* TODO Lager */ },
|
||||||
@@ -318,12 +326,6 @@ fun KlottrAppShell(
|
|||||||
icon = { Icon(Icons.Filled.Place, contentDescription = "Nära") },
|
icon = { Icon(Icons.Filled.Place, contentDescription = "Nära") },
|
||||||
label = { Text("Nära") }
|
label = { Text("Nära") }
|
||||||
)
|
)
|
||||||
NavigationBarItem(
|
|
||||||
selected = false,
|
|
||||||
onClick = { /* TODO Konto */ },
|
|
||||||
icon = { Icon(Icons.Filled.Person, contentDescription = "Konto") },
|
|
||||||
label = { Text("Konto") }
|
|
||||||
)
|
|
||||||
NavigationBarItem(
|
NavigationBarItem(
|
||||||
selected = false,
|
selected = false,
|
||||||
onClick = { /* TODO Meny */ },
|
onClick = { /* TODO Meny */ },
|
||||||
@@ -341,12 +343,92 @@ fun KlottrAppShell(
|
|||||||
},
|
},
|
||||||
floatingActionButtonPosition = androidx.compose.material3.FabPosition.Center,
|
floatingActionButtonPosition = androidx.compose.material3.FabPosition.Center,
|
||||||
content = { innerPadding ->
|
content = { innerPadding ->
|
||||||
Box(modifier = Modifier.padding(innerPadding)) {
|
when (selectedTab) {
|
||||||
// Här kan vi i framtiden lägga innehåll för de olika menyvalen
|
"home" -> {
|
||||||
|
// --- Återanvänd gamla layoutens lista med fynd ---
|
||||||
|
val foundList = remember(foundRefresh, forceEmptyFound) {
|
||||||
|
if (forceEmptyFound) emptyList() else FoundStore.getAll().reversed()
|
||||||
|
}
|
||||||
|
val labelOverrides = remember { androidx.compose.runtime.mutableStateMapOf<String, String>() }
|
||||||
|
val foundKey = foundList.joinToString("|") { "${it.layer}:${it.id}" }
|
||||||
|
|
||||||
|
LaunchedEffect(foundKey) {
|
||||||
|
val my = LastLocationStore.lastKnownLocation
|
||||||
|
val myLat = my.value?.lat
|
||||||
|
val myLon = my.value?.lon
|
||||||
|
labelOverrides.clear()
|
||||||
|
foundList.forEach { f ->
|
||||||
|
if (f.layer == LAYER_KLOTTER) {
|
||||||
|
val inside = if (myLat != null && myLon != null)
|
||||||
|
app.klottr.util.distanceMeters(myLat, myLon, f.lat, f.lon) <= Config.DEFAULT_KLOTTER_RADIUS_M
|
||||||
|
else true
|
||||||
|
if (inside) {
|
||||||
|
val idL = f.id.toLongOrNull() ?: return@forEach
|
||||||
|
if (NoteDetailCache.get(idL) == null) {
|
||||||
|
val detail = fetchNoteDetail(idL, f.lat, f.lon)
|
||||||
|
if (detail != null) {
|
||||||
|
NoteDetailCache.put(idL, detail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KlottrHomeContent(
|
||||||
|
contentPadding = innerPadding,
|
||||||
|
entries = foundList,
|
||||||
|
location = LastLocationStore.lastKnownLocation.collectAsState(),
|
||||||
|
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 { FornsokShared.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(action.id, action.lat, action.lon, 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isBold = { f -> !FoundStore.isAway(f.layer, f.id) },
|
||||||
|
distanceFormatter = ::formatDistance,
|
||||||
|
coordsFormatter = ::formatCoords,
|
||||||
|
rowTextStyle = MaterialTheme.typography.bodyMedium.copy(
|
||||||
|
color = MaterialTheme.colorScheme.onSurface
|
||||||
|
),
|
||||||
|
header = { /* tom i nya layouten */ },
|
||||||
|
footer = { /* tom i nya layouten */ }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Box(modifier = Modifier.padding(innerPadding)) {
|
||||||
|
Text("Här kommer ${selectedTab}-sidan")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
//Box(modifier = Modifier.padding(padding)) { }
|
|
||||||
} else {
|
} else {
|
||||||
// --- Nytt: definiera listan + overrides före UI-anropet ---
|
// --- Nytt: definiera listan + overrides före UI-anropet ---
|
||||||
val foundList = remember(foundRefresh, forceEmptyFound) {
|
val foundList = remember(foundRefresh, forceEmptyFound) {
|
||||||
|
|||||||
Reference in New Issue
Block a user