shared(ui): add NearbyContent (material-free) and subtitle/list wiring
app(ui): use NearbyContent in NearbyDialog and mark finds before render
This commit is contained in:
@@ -107,6 +107,7 @@ import androidx.work.OneTimeWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import app.klottr.data.AppDatabase
|
||||
import app.klottr.data.NoteRepository
|
||||
import app.klottr.ui.NearbyContent // Delat material-fritt innehåll för Närliggande
|
||||
import app.klottr.nearby.NearbyEntryShared //Delad radmodell
|
||||
import app.klottr.nearby.buildNearbyEntries //Delad builder för “Närliggande”
|
||||
import app.klottr.nearby.enrichKlotterLabels // delad etikett-berikning
|
||||
@@ -1252,68 +1253,58 @@ private fun NearbyDialog(
|
||||
AlertDialog(
|
||||
onDismissRequest = onClose,
|
||||
title = { Text("Närliggande") },
|
||||
text = {
|
||||
Column(Modifier.fillMaxWidth().heightIn(max = 420.dp)) {
|
||||
when {
|
||||
loading -> Text("Söker …")
|
||||
error != null -> Text(error)
|
||||
(lat == null || lon == null) -> Text("Okänt avstånd – försök igen.")
|
||||
(klotter.isEmpty() && wiki.isEmpty() && dm.isEmpty() && forn.isEmpty()) -> Text("Inga träffar i närheten.")
|
||||
else -> {
|
||||
val knownKlotterLabels = FoundStore.getAll(ctx) // Hämta allt en gång
|
||||
.asSequence() // Effektiv filtrering
|
||||
.filter { it.layer == FoundStore.LAYER_KLOTTER } // Bara klotter-poster
|
||||
.associate { it.id to it.label } // Map: id -> label
|
||||
text = { // Använd delat dialoginnehåll
|
||||
val hasLocation = (lat != null && lon != null) // Flagga för plats
|
||||
// Kända klotteretiketter (cache) — O(1)-lookup
|
||||
val knownKlotterLabels = FoundStore.getAll(ctx)
|
||||
.asSequence()
|
||||
.filter { it.layer == FoundStore.LAYER_KLOTTER }
|
||||
.associate { it.id to it.label }
|
||||
|
||||
//Bygg plattformsneutral lista i :shared (ingen Context, inga Android-beroenden)
|
||||
val entries: List<NearbyEntryShared> = buildNearbyEntries( // List<> istället för List(...)
|
||||
lat = lat, //Min latitud
|
||||
lon = lon, //Min longitud
|
||||
klotter = klotter, //Klotterposter
|
||||
wiki = wiki, //Wikipedia-poster
|
||||
dm = dm, //DigitaltMuseum-poster
|
||||
forn = forn, //Fornsök-poster
|
||||
wikiRadius = wikiRadius, //Radie för Wikipedia
|
||||
dmRadius = dmRadius, //Radie för DigitaltMuseum
|
||||
fornsokRadius = fornsokRadius, //Radie för Fornsök
|
||||
defaultKlotterRadiusM = Config.DEFAULT_KLOTTER_RADIUS_M, //Standardradie för klotter
|
||||
knownKlotterLabel = { id -> knownKlotterLabels[id] } // Använd förberäknad map (O(1) lookup)
|
||||
)
|
||||
// Bygg delade entries om vi har plats, annars tom lista
|
||||
val entries: List<NearbyEntryShared> =
|
||||
if (hasLocation) {
|
||||
buildNearbyEntries(
|
||||
lat = lat!!,
|
||||
lon = lon!!,
|
||||
klotter = klotter,
|
||||
wiki = wiki,
|
||||
dm = dm,
|
||||
forn = forn,
|
||||
wikiRadius = wikiRadius,
|
||||
dmRadius = dmRadius,
|
||||
fornsokRadius = fornsokRadius,
|
||||
defaultKlotterRadiusM = Config.DEFAULT_KLOTTER_RADIUS_M,
|
||||
knownKlotterLabel = { id -> knownKlotterLabels[id] }
|
||||
)
|
||||
} else emptyList()
|
||||
|
||||
// Markera hittade poster innan vi renderar listan (minskar arbete vid recomposition)
|
||||
app.klottr.nearby.markNewFinds( // Anropa delad hjälpare istället för lokal loop
|
||||
ctx = ctx, // Samma ctx som tidigare
|
||||
entries = entries, // Den delade listan vi just byggde
|
||||
nowMillis = now, // Samma tidsstämpel som tidigare
|
||||
onMarked = { onMarkedFound() } // Kör din callback om något blev nytt
|
||||
)
|
||||
|
||||
NearbyList( // Delad list-renderare från :shared/ui
|
||||
entries = entries, // Den redan byggda delade listan
|
||||
isClickable = { e -> app.klottr.nearby.isClickable(e, dm, forn) }, // Anropa delade regeln med FQN (slipper import/alias)
|
||||
onEntryClick = { e -> // Mappa klick till dina befintliga callbacks
|
||||
when (e.layer) {
|
||||
FoundStore.LAYER_WIKI -> {
|
||||
val id = e.id; if (id != null) onWikiClick(id.toLong(), e.lat, e.lon)
|
||||
}
|
||||
FoundStore.LAYER_DM -> {
|
||||
val item = dm.firstOrNull { it.id == e.id }; if (item != null) onDmClick(item)
|
||||
}
|
||||
FoundStore.LAYER_FORNSOK -> {
|
||||
val item = forn.firstOrNull { it.id == e.id }; if (item != null) onFornsokClick(item)
|
||||
}
|
||||
FoundStore.LAYER_KLOTTER -> {
|
||||
val id = e.id; if (id != null) onKlotterClick(id, e.lat, e.lon, e.label)
|
||||
}
|
||||
}
|
||||
},
|
||||
rowTextStyle = MaterialTheme.typography.bodyMedium.copy( // Tydlig text i både dag/natt
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
// Markera “hittade” innan render (endast när vi inte laddar/har fel och har plats)
|
||||
if (hasLocation && !loading && error == null) {
|
||||
app.klottr.nearby.markNewFinds(
|
||||
ctx = ctx,
|
||||
entries = entries,
|
||||
nowMillis = now,
|
||||
onMarked = { onMarkedFound() }
|
||||
)
|
||||
}
|
||||
|
||||
// Rendera material-fritt delat innehåll (hanterar själv loading/fel/tom-lista)
|
||||
NearbyContent(
|
||||
loading = loading,
|
||||
error = error,
|
||||
hasLocation = hasLocation,
|
||||
entries = entries,
|
||||
dm = dm,
|
||||
forn = forn,
|
||||
onWikiClick = onWikiClick,
|
||||
onDmClick = onDmClick,
|
||||
onFornsokClick = onFornsokClick,
|
||||
onKlotterClick = onKlotterClick,
|
||||
rowTextStyle = MaterialTheme.typography.bodyMedium.copy( // Säker textfärg i dag/natt
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
)
|
||||
},
|
||||
confirmButton = { Button(onClick = onClose) { Text("Stäng") } }
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user