Share home UI: add material-free KlottrHomeContent and use it from Android
- New: shared/ui/KlottrHomeContent.kt (material-free; header/footer slots) - Android: replace Scaffold body Column with KlottrHomeContent(); keep AppBar and dialog shells - Fix: add dp import in shared; use weight(1f) for center area so Login/Logout footer stays visible - No behavior change; prepares moving root towards :shared
This commit is contained in:
@@ -142,6 +142,7 @@ import app.klottr.ui.FornsokDetailContent // Ny: delad Fornsök-layout
|
|||||||
import app.klottr.ui.FoundList // Delad, material-fri listkomponent för "Hittat"
|
import app.klottr.ui.FoundList // Delad, material-fri listkomponent för "Hittat"
|
||||||
import app.klottr.ui.FoundContent // Delat innehåll för “Hittat”
|
import app.klottr.ui.FoundContent // Delat innehåll för “Hittat”
|
||||||
import app.klottr.ui.FoundDetailContent // Delad detalj-UI (CMP)
|
import app.klottr.ui.FoundDetailContent // Delad detalj-UI (CMP)
|
||||||
|
import app.klottr.ui.KlottrHomeContent // Ny: delat mittinnehåll
|
||||||
import app.klottr.ui.NearbyContent // Delat material-fritt innehåll för Närliggande
|
import app.klottr.ui.NearbyContent // Delat material-fritt innehåll för Närliggande
|
||||||
import app.klottr.ui.MapPanelShell
|
import app.klottr.ui.MapPanelShell
|
||||||
import app.klottr.ui.SettingsContent // Delad material-fri UI för inställningar
|
import app.klottr.ui.SettingsContent // Delad material-fri UI för inställningar
|
||||||
@@ -595,130 +596,14 @@ private fun KlottrApp(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
) { padding ->
|
) { padding ->
|
||||||
Column(
|
// --- Nytt: definiera listan + overrides före UI-anropet ---
|
||||||
Modifier
|
val foundList = remember(foundRefresh, forceEmptyFound) {
|
||||||
.fillMaxSize()
|
if (forceEmptyFound) emptyList() else FoundStore.getAll(context)
|
||||||
.padding(padding)
|
|
||||||
.padding(12.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
val hasPerms = hasFgLocationPerms(context)
|
|
||||||
if (!hasPerms) {
|
|
||||||
Button(onClick = onRequestPerms) { Text("Begär platstillstånd") }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
||||||
Text("Avisera endast nya fynd", modifier = Modifier.weight(1f))
|
|
||||||
Switch(
|
|
||||||
checked = onlyNew,
|
|
||||||
onCheckedChange = {
|
|
||||||
onlyNew = it
|
|
||||||
SettingsStore.setOnlyNewHits(it)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
||||||
Button(onClick = {
|
|
||||||
if (loggedIn) showWrite = true else showLoginRequired = true
|
|
||||||
}) { Text("Klottra") }
|
|
||||||
|
|
||||||
Button(onClick = {
|
|
||||||
nearbyLoading = true
|
|
||||||
nearbyError = null
|
|
||||||
showNearby = true
|
|
||||||
val ctx = context
|
|
||||||
scope.launch {
|
|
||||||
val gp = AndroidLocationProvider.currentOrLastKnown(ctx) // Nytt: centraliserad plats
|
|
||||||
if (gp == null) {
|
|
||||||
nearbyLoading = false
|
|
||||||
nearbyError = "Ingen plats ännu – prova igen."
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
lastKnownLat = gp.lat // Nytt
|
|
||||||
lastKnownLon = gp.lon // Nytt
|
|
||||||
|
|
||||||
KLog.d { "Närliggande-debug: toggles klotter=$showKlotter wiki=$showWiki dm=$showDm forn=$showFornsok"}
|
|
||||||
KLog.d { "Närliggande-debug: loc=${lastKnownLat},${lastKnownLon}"}
|
|
||||||
|
|
||||||
// Re-arm: markera alla tidigare fynd som "borta" om vi nu står >200 m från dem
|
|
||||||
// Hämta alla lager via delad KMP-funktion (DI med våra befintliga klientanrop)
|
|
||||||
// [ÄNDRAD] Kör delad use-case som både hämtar och bygger entries
|
|
||||||
val bundle = withContext(Dispatchers.IO) {
|
|
||||||
getNearbyBundle(
|
|
||||||
lat = gp.lat,
|
|
||||||
lon = gp.lon,
|
|
||||||
showKlotter = showKlotter,
|
|
||||||
showWiki = showWiki,
|
|
||||||
showDm = showDm,
|
|
||||||
showFornsok = showFornsok,
|
|
||||||
wikiRadius = wikiRadius,
|
|
||||||
dmRadius = dmRadius,
|
|
||||||
fornsokRadius = fornsokRadius,
|
|
||||||
defaultKlotterRadiusM = Config.DEFAULT_KLOTTER_RADIUS_M,
|
|
||||||
knownKlotterLabel = { id ->
|
|
||||||
// [NY] samma källor för “känd etikett” som du redan använde i dialogen
|
|
||||||
FoundStore.getAll(context)
|
|
||||||
.asSequence()
|
|
||||||
.filter { it.layer == FoundStore.LAYER_KLOTTER }
|
|
||||||
.associate { it.id to it.label }[id]
|
|
||||||
},
|
|
||||||
klotterFetcher = { la, lo ->
|
|
||||||
Geocache.getNearby(lat = la, lon = lo, radiusMeters = 300, ttlMs = 0L)
|
|
||||||
},
|
|
||||||
wikiFetcher = { la, lo, r -> Wikipedia.getNearby(la, lo, radiusMeters = r) },
|
|
||||||
dmFetcher = { la, lo, r -> DigitaltMuseum.getNearby(la, lo, radiusMeters = r) },
|
|
||||||
fornFetcher = { la, lo, r -> Fornsok.getNearby(la, lo, radiusMeters = r) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// [NY] Sätt färdiga entries + listor som behövs för öppna-aktioner
|
|
||||||
nearbyEntries = bundle.entries
|
|
||||||
nearbyDm = bundle.dm
|
|
||||||
nearbyFornsok = bundle.forn
|
|
||||||
// [NY] Markera nya fynd direkt här (inte i dialogen)
|
|
||||||
val nowMillis = System.currentTimeMillis() // [NY]
|
|
||||||
app.klottr.nearby.markNewFinds( // [NY] (fullt kvalificerat anrop, ingen extra import)
|
|
||||||
ctx = ctx, // [NY]
|
|
||||||
entries = nearbyEntries, // [NY]
|
|
||||||
nowMillis = nowMillis, // [NY]
|
|
||||||
onMarked = { refreshFound() } // [NY] trigga samma uppdatering som tidigare
|
|
||||||
)
|
|
||||||
|
|
||||||
// [VALFRITT] Logg – nu summerar vi entries + per-lager
|
|
||||||
KLog.d {
|
|
||||||
"Närliggande-resultat: entries=${nearbyEntries.size}, dm=${nearbyDm.size}, forn=${nearbyFornsok.size}"
|
|
||||||
}
|
|
||||||
|
|
||||||
nearbyLoading = false
|
|
||||||
}
|
|
||||||
}) { Text("Närliggande") }
|
|
||||||
|
|
||||||
Button(onClick = { showMap = true }) { Text("Karta") }
|
|
||||||
}
|
|
||||||
|
|
||||||
HorizontalDivider() // Avdelare under knappraden
|
|
||||||
|
|
||||||
MapPanelShell(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.weight(1f),
|
|
||||||
title = "Senaste",
|
|
||||||
titleTextStyle = MaterialTheme.typography.titleLarge.copy(
|
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
|
||||||
),
|
|
||||||
mainContent = {
|
|
||||||
// Hittat (flyttat hit för att kapslas i skalet)
|
|
||||||
// Hittat – bind till refreshflaggan så UI uppdaterar direkt
|
|
||||||
val foundList = remember(foundRefresh, forceEmptyFound) { // Trigga om vid foundRefresh/clear
|
|
||||||
if (forceEmptyFound) emptyList() else FoundStore.getAll(context) // Hämta aktuell lista
|
|
||||||
}
|
|
||||||
|
|
||||||
val labelOverrides = remember { androidx.compose.runtime.mutableStateMapOf<String, String>() }
|
val labelOverrides = remember { androidx.compose.runtime.mutableStateMapOf<String, String>() }
|
||||||
|
|
||||||
val foundKey = foundList.joinToString("|") { "${it.layer}:${it.id}" }
|
val foundKey = foundList.joinToString("|") { "${it.layer}:${it.id}" }
|
||||||
|
|
||||||
// Förbättra etiketter och förladda detaljer/bilder när innehållet ändras
|
// Förladdning av etiketter/bilder (oförändrad logik, flyttad hit)
|
||||||
LaunchedEffect(foundKey) {
|
LaunchedEffect(foundKey) {
|
||||||
val my = LastLocationStore.lastKnownLocation
|
val my = LastLocationStore.lastKnownLocation
|
||||||
val myLat = my?.latitude
|
val myLat = my?.latitude
|
||||||
@@ -764,13 +649,13 @@ private fun KlottrApp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val my = LastLocationStore.lastKnownLocation // Ny: Flytta upp så FoundContent alltid ritas
|
|
||||||
val _tick = locationTick // Ny: Behåll trigger
|
|
||||||
|
|
||||||
FoundContent(
|
// --- Nytt: KlottrHomeContent (delat mitt-innehåll) ---
|
||||||
|
KlottrHomeContent(
|
||||||
|
contentPadding = padding,
|
||||||
entries = foundList,
|
entries = foundList,
|
||||||
currentLat = my?.latitude,
|
currentLat = LastLocationStore.lastKnownLocation?.latitude,
|
||||||
currentLon = my?.longitude,
|
currentLon = LastLocationStore.lastKnownLocation?.longitude,
|
||||||
showCoords = showCoords,
|
showCoords = showCoords,
|
||||||
labelOverrides = labelOverrides,
|
labelOverrides = labelOverrides,
|
||||||
isClickable = { f ->
|
isClickable = { f ->
|
||||||
@@ -814,10 +699,100 @@ private fun KlottrApp(
|
|||||||
coordsFormatter = ::formatCoords,
|
coordsFormatter = ::formatCoords,
|
||||||
rowTextStyle = MaterialTheme.typography.bodyMedium.copy(
|
rowTextStyle = MaterialTheme.typography.bodyMedium.copy(
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
color = MaterialTheme.colorScheme.onSurface
|
||||||
|
),
|
||||||
|
header = {
|
||||||
|
val hasPerms = hasFgLocationPerms(context)
|
||||||
|
if (!hasPerms) {
|
||||||
|
Button(onClick = onRequestPerms) { Text("Begär platstillstånd") }
|
||||||
|
}
|
||||||
|
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
Text("Avisera endast nya fynd", modifier = Modifier.weight(1f))
|
||||||
|
Switch(
|
||||||
|
checked = onlyNew,
|
||||||
|
onCheckedChange = {
|
||||||
|
onlyNew = it
|
||||||
|
SettingsStore.setOnlyNewHits(it)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
|
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
Button(onClick = {
|
||||||
|
if (loggedIn) showWrite = true else showLoginRequired = true
|
||||||
|
}) { Text("Klottra") }
|
||||||
|
|
||||||
|
Button(onClick = {
|
||||||
|
nearbyLoading = true
|
||||||
|
nearbyError = null
|
||||||
|
showNearby = true
|
||||||
|
val ctx = context
|
||||||
|
scope.launch {
|
||||||
|
val gp = AndroidLocationProvider.currentOrLastKnown(ctx)
|
||||||
|
if (gp == null) {
|
||||||
|
nearbyLoading = false
|
||||||
|
nearbyError = "Ingen plats ännu – prova igen."
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
lastKnownLat = gp.lat
|
||||||
|
lastKnownLon = gp.lon
|
||||||
|
|
||||||
|
KLog.d { "Närliggande-debug: toggles klotter=$showKlotter wiki=$showWiki dm=$showDm forn=$showFornsok"}
|
||||||
|
KLog.d { "Närliggande-debug: loc=${lastKnownLat},${lastKnownLon}"}
|
||||||
|
|
||||||
|
val bundle = withContext(Dispatchers.IO) {
|
||||||
|
getNearbyBundle(
|
||||||
|
lat = gp.lat,
|
||||||
|
lon = gp.lon,
|
||||||
|
showKlotter = showKlotter,
|
||||||
|
showWiki = showWiki,
|
||||||
|
showDm = showDm,
|
||||||
|
showFornsok = showFornsok,
|
||||||
|
wikiRadius = wikiRadius,
|
||||||
|
dmRadius = dmRadius,
|
||||||
|
fornsokRadius = fornsokRadius,
|
||||||
|
defaultKlotterRadiusM = Config.DEFAULT_KLOTTER_RADIUS_M,
|
||||||
|
knownKlotterLabel = { id ->
|
||||||
|
FoundStore.getAll(context)
|
||||||
|
.asSequence()
|
||||||
|
.filter { it.layer == FoundStore.LAYER_KLOTTER }
|
||||||
|
.associate { it.id to it.label }[id]
|
||||||
},
|
},
|
||||||
footerContent = {
|
klotterFetcher = { la, lo ->
|
||||||
|
Geocache.getNearby(lat = la, lon = lo, radiusMeters = 300, ttlMs = 0L)
|
||||||
|
},
|
||||||
|
wikiFetcher = { la, lo, r -> Wikipedia.getNearby(la, lo, radiusMeters = r) },
|
||||||
|
dmFetcher = { la, lo, r -> DigitaltMuseum.getNearby(la, lo, radiusMeters = r) },
|
||||||
|
fornFetcher = { la, lo, r -> Fornsok.getNearby(la, lo, radiusMeters = r) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
nearbyEntries = bundle.entries
|
||||||
|
nearbyDm = bundle.dm
|
||||||
|
nearbyFornsok = bundle.forn
|
||||||
|
|
||||||
|
val nowMillis = System.currentTimeMillis()
|
||||||
|
app.klottr.nearby.markNewFinds(
|
||||||
|
ctx = ctx,
|
||||||
|
entries = nearbyEntries,
|
||||||
|
nowMillis = nowMillis,
|
||||||
|
onMarked = { refreshFound() }
|
||||||
|
)
|
||||||
|
|
||||||
|
KLog.d {
|
||||||
|
"Närliggande-resultat: entries=${nearbyEntries.size}, dm=${nearbyDm.size}, forn=${nearbyFornsok.size}"
|
||||||
|
}
|
||||||
|
|
||||||
|
nearbyLoading = false
|
||||||
|
}
|
||||||
|
}) { Text("Närliggande") }
|
||||||
|
|
||||||
|
Button(onClick = { showMap = true }) { Text("Karta") }
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalDivider()
|
||||||
|
},
|
||||||
|
footer = {
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
if (!loggedIn) Button(onClick = onLogin) { Text("Logga in") }
|
if (!loggedIn) Button(onClick = onLogin) { Text("Logga in") }
|
||||||
if (loggedIn) Button(onClick = onLogout) { Text("Logga ut") }
|
if (loggedIn) Button(onClick = onLogout) { Text("Logga ut") }
|
||||||
@@ -825,7 +800,6 @@ private fun KlottrApp(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Om-appen
|
// Om-appen
|
||||||
if (showAbout) {
|
if (showAbout) {
|
||||||
AboutDialog { showAbout = false }
|
AboutDialog { showAbout = false }
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package app.klottr.ui
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.TextStyle
|
||||||
|
import androidx.compose.ui.unit.dp // För .dp i padding/spacedBy
|
||||||
|
import app.klottr.util.FoundEntry
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun KlottrHomeContent(
|
||||||
|
contentPadding: PaddingValues,
|
||||||
|
// FoundContent-parametrar (delat)
|
||||||
|
entries: List<FoundEntry>,
|
||||||
|
currentLat: Double?,
|
||||||
|
currentLon: Double?,
|
||||||
|
showCoords: Boolean,
|
||||||
|
labelOverrides: Map<String, String>,
|
||||||
|
isClickable: (FoundEntry) -> Boolean,
|
||||||
|
onEntryClick: (FoundEntry) -> Unit,
|
||||||
|
isBold: (FoundEntry) -> Boolean,
|
||||||
|
distanceFormatter: (Int) -> String,
|
||||||
|
coordsFormatter: (Double, Double) -> String,
|
||||||
|
rowTextStyle: TextStyle,
|
||||||
|
// Slots från Android (Material-komponenter placeras här)
|
||||||
|
header: @Composable ColumnScope.() -> Unit,
|
||||||
|
footer: @Composable () -> Unit
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(contentPadding)
|
||||||
|
.padding(12.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
|
) {
|
||||||
|
header()
|
||||||
|
Box(
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.weight(1f) // Låt innehållet ta resten av höjden så footern syns
|
||||||
|
) {
|
||||||
|
FoundContent(
|
||||||
|
entries = entries,
|
||||||
|
currentLat = currentLat,
|
||||||
|
currentLon = currentLon,
|
||||||
|
showCoords = showCoords,
|
||||||
|
labelOverrides = labelOverrides,
|
||||||
|
isClickable = isClickable,
|
||||||
|
onEntryClick = onEntryClick,
|
||||||
|
isBold = isBold,
|
||||||
|
distanceFormatter = distanceFormatter,
|
||||||
|
coordsFormatter = coordsFormatter,
|
||||||
|
rowTextStyle = rowTextStyle
|
||||||
|
)
|
||||||
|
}
|
||||||
|
footer()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user