Removed old-UI and cleaned up.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package app.klottr
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -50,7 +48,6 @@ import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -66,15 +63,12 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.graphics.decodeToImageBitmap
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.zIndex
|
||||
import app.cash.sqldelight.coroutines.asFlow // SQLDelight coroutine-extensions (Flow-stöd för queries)
|
||||
import app.cash.sqldelight.coroutines.mapToList // SQLDelight coroutine-extensions (Flow-stöd för queries)
|
||||
import app.klottr.SettingsScreen
|
||||
import app.klottr.create.CreateNoteOutcome
|
||||
import app.klottr.create.QueueOutboxOutcome
|
||||
import app.klottr.create.createNoteFlow
|
||||
@@ -90,7 +84,6 @@ import app.klottr.nearby.OpenFornsok
|
||||
import app.klottr.nearby.OpenKlotter
|
||||
import app.klottr.nearby.OpenWiki
|
||||
import app.klottr.nearby.ScanConfig
|
||||
import app.klottr.nearby.enrichKlotterLabels
|
||||
import app.klottr.nearby.getNearbyBundle
|
||||
import app.klottr.nearby.resolveFoundOpenAction
|
||||
import app.klottr.nearby.scanAndMarkFound
|
||||
@@ -102,7 +95,6 @@ import app.klottr.net.Geocache
|
||||
import app.klottr.net.UserStats
|
||||
import app.klottr.net.Wikipedia
|
||||
import app.klottr.net.createNoteDoc
|
||||
import app.klottr.net.fetchImageStreamPost
|
||||
import app.klottr.net.fetchMe
|
||||
import app.klottr.net.fetchNoteDetail
|
||||
import app.klottr.net.fetchUserStats
|
||||
@@ -112,7 +104,6 @@ import app.klottr.platform.AppNavigator
|
||||
import app.klottr.platform.OutboxScheduler
|
||||
import app.klottr.platform.UiFeedback
|
||||
import app.klottr.platform.UiFeedbackDuration
|
||||
import app.klottr.platform.hasFgLocationPerms
|
||||
import app.klottr.ui.AboutScreen
|
||||
import app.klottr.ui.DmDialog
|
||||
import app.klottr.ui.FornsokDialog
|
||||
@@ -120,16 +111,12 @@ import app.klottr.ui.KlottrHomeContent
|
||||
import app.klottr.ui.LoginRequiredContent
|
||||
import app.klottr.ui.MapContent
|
||||
import app.klottr.ui.NearbyContent
|
||||
import app.klottr.ui.NearbyDialog
|
||||
import app.klottr.ui.NearbyDialogContent
|
||||
import app.klottr.ui.UsernameDialog
|
||||
import app.klottr.ui.WikiArticleDialog
|
||||
import app.klottr.util.AuthShared
|
||||
import app.klottr.util.Config
|
||||
import app.klottr.util.FoundStore
|
||||
import app.klottr.util.FoundStore.LAYER_KLOTTER
|
||||
import app.klottr.util.ImageBitmapCache
|
||||
import app.klottr.util.KLog
|
||||
import app.klottr.util.NoteDetailCache
|
||||
import app.klottr.util.OutboxStore
|
||||
import app.klottr.util.SettingsStore
|
||||
@@ -140,11 +127,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.IO
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.collections.component1
|
||||
import kotlin.collections.component2
|
||||
import kotlin.collections.iterator
|
||||
import kotlin.collections.orEmpty
|
||||
import kotlin.collections.set
|
||||
import kotlin.time.Clock
|
||||
import kotlin.time.ExperimentalTime
|
||||
|
||||
@@ -315,41 +298,17 @@ fun KlottrAppShell(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var showAbout by remember { mutableStateOf(false) }
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
CenterAlignedTopAppBar(
|
||||
title = { Text("") }, // Standardtitel i appbaren (ingen special-Box, inga extra modifiers)
|
||||
actions = { // Dina befintliga actions (Info/Inställningar)
|
||||
IconButton(onClick = { showAbout = true }) {
|
||||
Icon(imageVector = Icons.Filled.Info, contentDescription = "Om")
|
||||
}
|
||||
IconButton(onClick = { showSettings = true }) {
|
||||
Icon(imageVector = Icons.Filled.Settings, contentDescription = "Inställningar")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
if (useNewUi) {
|
||||
|
||||
var selectedTab by rememberSaveable { mutableStateOf("home") }
|
||||
var showChangeUsernameDialog by remember { mutableStateOf(false) }
|
||||
Scaffold(
|
||||
topBar = {
|
||||
CenterAlignedTopAppBar(
|
||||
title = { Text("") },
|
||||
actions = {
|
||||
IconButton(onClick = { showAbout = true }) {
|
||||
Icon(imageVector = Icons.Filled.Info, contentDescription = "Om")
|
||||
}
|
||||
IconButton(onClick = { showSettings = true }) {
|
||||
Icon(imageVector = Icons.Filled.Settings, contentDescription = "Inställningar")
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
bottomBar = {
|
||||
NavigationBar {
|
||||
NavigationBarItem(
|
||||
@@ -830,391 +789,6 @@ fun KlottrAppShell(
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
// --- Nytt: definiera listan + overrides före UI-anropet ---
|
||||
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}" }
|
||||
|
||||
// Förladdning av etiketter/bilder (oförändrad logik, flyttad hit)
|
||||
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)
|
||||
val img = detail.image
|
||||
if (img != null && img.id > 0 && ImageBitmapCache.get(img.id) == null) {
|
||||
withContext(Dispatchers.IO) {
|
||||
fetchImageStreamPost(
|
||||
imageId = img.id,
|
||||
noteId = detail.id,
|
||||
lat = f.lat,
|
||||
lon = f.lon
|
||||
)?.decodeToImageBitmap()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val enriched = withContext(Dispatchers.IO) {
|
||||
enrichKlotterLabels(
|
||||
found = foundList,
|
||||
radiusMeters = 60,
|
||||
fetchNearbyKlotter = { la, lo, r ->
|
||||
Geocache.getNearby(
|
||||
lat = la,
|
||||
lon = lo,
|
||||
radiusMeters = r,
|
||||
ttlMs = 0L
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
for ((k, v) in enriched) {
|
||||
labelOverrides[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Nytt: KlottrHomeContent (delat mitt-innehåll) ---
|
||||
KlottrHomeContent(
|
||||
contentPadding = padding,
|
||||
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(
|
||||
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
|
||||
}
|
||||
}
|
||||
},
|
||||
isBold = { f -> !FoundStore.isAway(f.layer, f.id) },
|
||||
distanceFormatter = ::formatDistance,
|
||||
coordsFormatter = ::formatCoords,
|
||||
rowTextStyle = MaterialTheme.typography.bodyMedium.copy(
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
),
|
||||
header = {
|
||||
val hasPerms = hasFgLocationPerms()
|
||||
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
|
||||
scope.launch {
|
||||
val gp = LocationServiceProvider.get().current(highAccuracy = false)
|
||||
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()
|
||||
.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 ->
|
||||
FornsokShared.getNearby(
|
||||
la,
|
||||
lo,
|
||||
radiusMeters = r
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
nearbyBundle = bundle
|
||||
|
||||
val nowMillis = Clock.System.now().toEpochMilliseconds()
|
||||
app.klottr.nearby.markNewFinds(
|
||||
entries = bundle.entries, // Använd direkt från bundle
|
||||
nowMillis = nowMillis,
|
||||
onMarked = { refreshFound() }
|
||||
)
|
||||
|
||||
nearbyLoading = false
|
||||
}
|
||||
}) { Text("Närliggande") }
|
||||
|
||||
Button(onClick = { showMap = true }) { Text("Karta") }
|
||||
}
|
||||
|
||||
HorizontalDivider()
|
||||
},
|
||||
footer = {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (!loggedIn) Button(onClick = onLogin) { Text("Logga in") }
|
||||
if (loggedIn) Button(onClick = onLogout) { Text("Logga ut") }
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
// Närliggande
|
||||
if (showNearby) {
|
||||
NearbyDialog(
|
||||
loading = nearbyLoading,
|
||||
error = nearbyError,
|
||||
lat = lastKnownLat,
|
||||
lon = lastKnownLon,
|
||||
// Använd namngivna fält från NearbyBundleShared
|
||||
entries = nearbyBundle?.entries.orEmpty(), // Ändrad
|
||||
dm = nearbyBundle?.dm.orEmpty(), // Ändrad
|
||||
forn = nearbyBundle?.forn.orEmpty(), // Ändrad
|
||||
|
||||
onOpenAction = { action ->
|
||||
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
|
||||
}
|
||||
},
|
||||
onClose = { showNearby = false }
|
||||
)
|
||||
}
|
||||
|
||||
// Karta
|
||||
if (showMap) {
|
||||
MapDialog(
|
||||
onClose = { showMap = false },
|
||||
onKlotterClick = { id, la, lo, label ->
|
||||
openKlotter = OpenKlotter(id = id, lat = la, lon = lo, label = label)
|
||||
},
|
||||
onOpenUrl = { _, url -> AppNavigator.openUrl(url) },
|
||||
isKnownNote = { noteId ->
|
||||
// Känd = finns i Hittat (FoundStore) → ska alltid visa titel
|
||||
FoundStore
|
||||
.getAll()
|
||||
.any { it.layer == LAYER_KLOTTER && it.id == noteId.toString() }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
// Inställningar
|
||||
if (showSettings) {
|
||||
SettingsDialog(
|
||||
onlyNew = onlyNew,
|
||||
satellite = satellite,
|
||||
night = night,
|
||||
showCoords = showCoords,
|
||||
|
||||
useNewUi = useNewUi,
|
||||
onUseNewUiChanged = { SettingsStore.setUseNewUi(it); useNewUi = it },
|
||||
|
||||
// Sparar via KMP SettingsStore no-arg setters (kompat-overloads med Context är utfasade här).
|
||||
onShowCoordsChanged = { SettingsStore.setShowCoordinates(it); showCoords = it },
|
||||
showKlotter = showKlotter,
|
||||
showWiki = showWiki,
|
||||
wikiRadius = wikiRadius,
|
||||
showDm = showDm,
|
||||
dmRadius = dmRadius,
|
||||
showFornsok = showFornsok,
|
||||
fornsokRadius = fornsokRadius,
|
||||
onOnlyNewChanged = { SettingsStore.setOnlyNewHits(it); onlyNew = it },
|
||||
onSatelliteChanged = { SettingsStore.setSatelliteMap(it); satellite = it },
|
||||
onNightChanged = { SettingsStore.setNightMode(it); night = it },
|
||||
onShowKlotterChanged = { SettingsStore.setShowKlotter(it); showKlotter = it },
|
||||
onShowWikiChanged = { SettingsStore.setShowWikipedia(it); showWiki = it },
|
||||
onWikiRadiusChanged = { SettingsStore.setWikiRadiusMeters(it); wikiRadius = it },
|
||||
onShowDmChanged = { SettingsStore.setShowDigitaltMuseum(it); showDm = it },
|
||||
onDmRadiusChanged = { SettingsStore.setDigitaltMuseumRadiusMeters(it); dmRadius = it },
|
||||
onShowFornsokChanged = { SettingsStore.setShowFornsok(it); showFornsok = it },
|
||||
onFornsokRadiusChanged = { SettingsStore.setFornsokRadiusMeters(it); fornsokRadius = it },
|
||||
|
||||
onClearFinds = {
|
||||
FoundStore.clearAll() // Töm allt
|
||||
forceEmptyFound = true // Visa tomt direkt
|
||||
refreshFound() // Tvinga omritning
|
||||
|
||||
// Clear session + notify via shared events (handled in platform location impl)
|
||||
FoundStore.clearAll();
|
||||
FoundEvents.notifyFoundUpdated()
|
||||
// // 1) Nollställ sessions-gates inne i tjänsten
|
||||
// context.startService(
|
||||
// Intent(context, LocationService::class.java)
|
||||
// .setAction(LocationService.ACTION_CLEAR_FOUND_SESSION)
|
||||
// )
|
||||
//
|
||||
// // 2) Pinga UI:t att rita om (nollat läge)
|
||||
// context.sendBroadcast(Intent(LocationService.ACTION_FOUND_UPDATED))
|
||||
|
||||
// 3) Be tjänsten göra en rescan
|
||||
// old Android service call removed (handled in shared layer)
|
||||
|
||||
// 4) Gör även en direkt lokal scan nu (parallellt) → snabb UI-återfyllnad
|
||||
// Använder vår delade scanAndMarkFound så listan fylls utan att vänta på tjänsten.
|
||||
val cfg = ScanConfig(
|
||||
showWiki = showWiki,
|
||||
wikiRadius = wikiRadius,
|
||||
showDm = showDm,
|
||||
dmRadius = dmRadius,
|
||||
showFornsok = showFornsok,
|
||||
fornsokRadius = fornsokRadius
|
||||
)
|
||||
scope.launch {
|
||||
val gp = LocationServiceProvider.get().current(highAccuracy = false)
|
||||
if (gp != null) {
|
||||
val anyNew = withContext(Dispatchers.IO) {
|
||||
scanAndMarkFound(
|
||||
lat = gp.lat, lon = gp.lon,
|
||||
config = cfg,
|
||||
fetchWiki = { la, lo, r -> Wikipedia.getNearby(la, lo, radiusMeters = r) },
|
||||
fetchDm = { la, lo, r -> DigitaltMuseum.getNearby(la, lo, radiusMeters = r) },
|
||||
fetchFornsok = { la, lo, r -> FornsokShared.getNearby(la, lo, radiusMeters = r) },
|
||||
markFound = { layer, id, label, la, lo, now ->
|
||||
FoundStore.markFound(layer, id, label, la, lo, now)
|
||||
},
|
||||
updateAwayFlags = { la, lo ->
|
||||
FoundStore.updateAwayFlags(la, lo)
|
||||
}
|
||||
)
|
||||
}
|
||||
if (anyNew) {
|
||||
forceEmptyFound = false // Tillåt visning igen
|
||||
refreshFound() // Rita om “Senaste”
|
||||
/* notify listeners inline: refreshFound() already called */
|
||||
}
|
||||
}
|
||||
}
|
||||
UiFeedback.showMessage( "Alla fynd rensade.", UiFeedbackDuration.SHORT)
|
||||
},
|
||||
onClose = { showSettings = false }
|
||||
)
|
||||
}
|
||||
|
||||
// Klotter-detalj
|
||||
@@ -1259,7 +833,6 @@ fun KlottrAppShell(
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
// Skrivdialog (dokument)
|
||||
var isSavingDoc by remember { mutableStateOf(false) }
|
||||
if (showWrite) {
|
||||
@@ -1553,21 +1126,6 @@ fun KlottrAppShell(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MenuItem(icon: ImageVector, label: String, onClick: () -> Unit) {
|
||||
Button(
|
||||
onClick = onClick,
|
||||
modifier = Modifier.fillMaxWidth().height(64.dp)
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Icon(icon, contentDescription = label)
|
||||
Text(label)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MenuTile(icon: ImageVector, label: String, onClick: () -> Unit) {
|
||||
|
||||
@@ -24,107 +24,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import app.klottr.ui.SettingsContent
|
||||
|
||||
/* ---------- Inställningar (scroll + “Stäng” synlig) ---------- */
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsDialog(
|
||||
onlyNew: Boolean,
|
||||
satellite: Boolean,
|
||||
night: Boolean,
|
||||
showCoords: Boolean,
|
||||
onShowCoordsChanged: (Boolean) -> Unit,
|
||||
useNewUi: Boolean,
|
||||
onUseNewUiChanged: (Boolean) -> Unit,
|
||||
showKlotter: Boolean,
|
||||
showWiki: Boolean,
|
||||
wikiRadius: Int,
|
||||
showDm: Boolean,
|
||||
dmRadius: Int,
|
||||
showFornsok: Boolean,
|
||||
fornsokRadius: Int,
|
||||
onOnlyNewChanged: (Boolean) -> Unit,
|
||||
onSatelliteChanged: (Boolean) -> Unit,
|
||||
onNightChanged: (Boolean) -> Unit,
|
||||
onShowKlotterChanged: (Boolean) -> Unit,
|
||||
onShowWikiChanged: (Boolean) -> Unit,
|
||||
onWikiRadiusChanged: (Int) -> Unit,
|
||||
onShowDmChanged: (Boolean) -> Unit,
|
||||
onDmRadiusChanged: (Int) -> Unit,
|
||||
onShowFornsokChanged: (Boolean) -> Unit,
|
||||
onFornsokRadiusChanged: (Int) -> Unit,
|
||||
onClearFinds: () -> Unit,
|
||||
onClose: () -> Unit
|
||||
) {
|
||||
val maxDialogHeight = (LocalWindowInfo.current.containerSize.height.dp * 0.75f)
|
||||
|
||||
val wikiOptions = listOf(20, 50, 100, 200, 500, 1000, 2000, 5000)
|
||||
val fornsokOptions = listOf(50, 100, 200, 500, 1000, 2000, 5000)
|
||||
val dmOptions = listOf(50, 100, 200, 500, 1000, 2000)
|
||||
|
||||
var askClear by remember { mutableStateOf(false) }
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onClose,
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false),
|
||||
title = { Text("Inställningar") },
|
||||
text = {
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.height(maxDialogHeight)
|
||||
) {
|
||||
SettingsContent(
|
||||
versionLine = "FIXME_VERSIONLINE", // TODO: OH: Do this platform independenlty
|
||||
buildTimeLine = "FIXME_BUILDTIME",
|
||||
onlyNew = onlyNew,
|
||||
onOnlyNewChanged = onOnlyNewChanged,
|
||||
showCoords = showCoords,
|
||||
onShowCoordsChanged = onShowCoordsChanged,
|
||||
satellite = satellite,
|
||||
onSatelliteChanged = onSatelliteChanged,
|
||||
night = night,
|
||||
onNightChanged = onNightChanged,
|
||||
useNewUi = useNewUi,
|
||||
onUseNewUiChanged = onUseNewUiChanged,
|
||||
showKlotter = showKlotter,
|
||||
onShowKlotterChanged = onShowKlotterChanged,
|
||||
showWiki = showWiki,
|
||||
wikiRadius = wikiRadius,
|
||||
wikiOptions = listOf(20, 50, 100, 200, 500, 1000, 2000, 5000),
|
||||
onShowWikiChanged = onShowWikiChanged,
|
||||
onWikiRadiusChanged = onWikiRadiusChanged,
|
||||
showDm = showDm,
|
||||
dmRadius = dmRadius,
|
||||
dmOptions = listOf(50, 100, 200, 500, 1000, 2000),
|
||||
onShowDmChanged = onShowDmChanged,
|
||||
onDmRadiusChanged = onDmRadiusChanged,
|
||||
showFornsok = showFornsok,
|
||||
fornsokRadius = fornsokRadius,
|
||||
fornsokOptions = listOf(50, 100, 200, 500, 1000, 2000, 5000),
|
||||
onShowFornsokChanged = onShowFornsokChanged,
|
||||
onFornsokRadiusChanged = onFornsokRadiusChanged,
|
||||
onRequestClear = { askClear = true }, // trigga bekräftelsedialog
|
||||
rowTextStyle = MaterialTheme.typography.bodyMedium.copy(
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
)
|
||||
|
||||
// Behåll den inre bekräftelsedialogen för rensning
|
||||
if (askClear) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { askClear = false },
|
||||
title = { Text("Radera historik?") },
|
||||
text = { Text("Vill du verkligen radera alla fynd? Detta går inte att ångra.") },
|
||||
confirmButton = { Button(onClick = { askClear = false; onClearFinds() }) { Text("Ja, radera") } },
|
||||
dismissButton = { Button(onClick = { askClear = false }) { Text("Avbryt") } }
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = { Button(onClick = onClose) { Text("Stäng") } }
|
||||
)
|
||||
}
|
||||
/* ---------- Inställningar ---------- */
|
||||
|
||||
@Composable
|
||||
fun SettingsScreen(
|
||||
|
||||
@@ -60,65 +60,6 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/* ---------- Nearby (shared) ---------- */
|
||||
|
||||
@Composable
|
||||
fun NearbyDialog(
|
||||
loading: Boolean,
|
||||
error: String?,
|
||||
lat: Double?,
|
||||
lon: Double?,
|
||||
entries: List<NearbyEntryShared>,
|
||||
dm: List<DigitaltMuseumItem>,
|
||||
forn: List<FornsokItem>,
|
||||
onOpenAction: (FoundOpenAction) -> Unit,
|
||||
onClose: () -> Unit,
|
||||
/** Optional max content height; if null, content becomes scrollable. */
|
||||
maxHeight: Dp? = null
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onClose,
|
||||
title = { Text("Närliggande") },
|
||||
text = {
|
||||
val hasLocation = (lat != null && lon != null)
|
||||
|
||||
// Cap to caller-provided height or ~75% of the real screen height (platform-agnostic).
|
||||
val percentageCap = (platformScreenHeightDp() * 0.75f)
|
||||
val cap = (maxHeight ?: percentageCap).coerceAtLeast(320.dp)
|
||||
|
||||
val container = @Composable { inner: @Composable () -> Unit ->
|
||||
// Bound the height BEFORE measuring child content; do NOT add verticalScroll here.
|
||||
Box(
|
||||
Modifier
|
||||
.widthIn(min = 280.dp)
|
||||
.requiredHeightIn(max = cap)
|
||||
) {
|
||||
// Let inner content (NearbyList) own scrolling; fill available space.
|
||||
Column(Modifier.fillMaxSize()) { inner() }
|
||||
}
|
||||
}
|
||||
|
||||
NearbyDialogContent(maxHeight = cap) {
|
||||
container {
|
||||
NearbyContent(
|
||||
loading = loading,
|
||||
error = error,
|
||||
hasLocation = hasLocation,
|
||||
entries = if (hasLocation) entries else emptyList(),
|
||||
dm = dm,
|
||||
forn = forn,
|
||||
onOpenAction = onOpenAction,
|
||||
rowTextStyle = MaterialTheme.typography.bodyMedium.copy(
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = { Button(onClick = onClose) { Text("Stäng") } }
|
||||
)
|
||||
}
|
||||
|
||||
/* ---------- Username (shared) ---------- */
|
||||
|
||||
@Composable
|
||||
@@ -283,100 +224,6 @@ fun UsernameDialog(
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- About (shared, platform-fed) ---------- */
|
||||
|
||||
@Composable
|
||||
fun AboutDialog(onDismiss: () -> Unit) {
|
||||
val info = remember { appAboutInfo() } // platform provides
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false),
|
||||
confirmButton = { TextButton(onClick = onDismiss) { Text("Stäng") } },
|
||||
text = {
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.widthIn(max = 520.dp)
|
||||
) {
|
||||
KlottrAboutContent(
|
||||
header = {
|
||||
KlottrLogo(modifier = Modifier.height(48.dp))
|
||||
},
|
||||
lines = listOf(
|
||||
"Version ${info.versionName} (${info.buildType}) • build ${info.buildNumber}",
|
||||
"Byggd ${info.buildTimeUtc}",
|
||||
"Utvecklad av ${info.devBy}.",
|
||||
"IOS-ansvarig: ${info.iosLead}.",
|
||||
"Mejlkontakt: ${info.contactEmail}"
|
||||
),
|
||||
lineStyle = MaterialTheme.typography.bodyMedium.copy(
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
),
|
||||
spacingDp = 12
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/* ---------- Image viewer (shared, byte[] + Coil KMP, pinch/zoom) ---------- */
|
||||
|
||||
@Composable
|
||||
fun ImageViewerDialog(
|
||||
bytes: ByteArray,
|
||||
mimeType: String? = null,
|
||||
onClose: () -> Unit
|
||||
) {
|
||||
Dialog(
|
||||
onDismissRequest = onClose,
|
||||
properties = DialogProperties(usePlatformDefaultWidth = false)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.Black)
|
||||
) {
|
||||
var scale by remember { mutableStateOf(1f) }
|
||||
var offset by remember { mutableStateOf(Offset.Zero) }
|
||||
|
||||
AsyncImage(
|
||||
model = ImageRequest.Builder(LocalPlatformContext.current)
|
||||
.data(bytes)
|
||||
.build(),
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.clipToBounds()
|
||||
.pointerInput(Unit) {
|
||||
detectTransformGestures { _, pan, zoom, _ ->
|
||||
scale = (scale * zoom).coerceIn(0.5f, 6f)
|
||||
offset += pan
|
||||
val clamp = 2000f
|
||||
offset = Offset(
|
||||
x = offset.x.coerceIn(-clamp, clamp),
|
||||
y = offset.y.coerceIn(-clamp, clamp)
|
||||
)
|
||||
}
|
||||
}
|
||||
.graphicsLayer(
|
||||
scaleX = scale,
|
||||
scaleY = scale,
|
||||
translationX = offset.x,
|
||||
translationY = offset.y
|
||||
)
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.padding(12.dp)
|
||||
) {
|
||||
Button(onClick = onClose) { Text("Stäng") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AboutScreen(modifier: Modifier = Modifier) {
|
||||
val info = remember { appAboutInfo() } // platform provides
|
||||
|
||||
Reference in New Issue
Block a user