Share DM/Wiki/Fornsok detail UI (material-free); Android keeps only dialog shells

This commit is contained in:
2025-09-18 20:00:11 +02:00
parent eb23694091
commit ee440e3ffb
4 changed files with 227 additions and 135 deletions

View File

@@ -137,12 +137,15 @@ import app.klottr.net.fetchNoteDetail
import app.klottr.net.uploadImageFromUri
import app.klottr.shared.SharedPing
import app.klottr.theme.KlottrTheme
import app.klottr.ui.DmDetailContent // Ny: delad DM-layout
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.FoundContent // Delat innehåll för “Hittat”
import app.klottr.ui.FoundDetailContent // Delad detalj-UI (CMP)
import app.klottr.ui.NearbyContent // Delat material-fritt innehåll för Närliggande
import app.klottr.ui.MapPanelShell
import app.klottr.ui.SettingsContent // Delad material-fri UI för inställningar
import app.klottr.ui.WikiDetailContent // Ny: delad Wiki-layout
import app.klottr.ui.WriteDocContent // Använd delad, material-fri formulär-UI
import app.klottr.util.Auth
import app.klottr.util.Config
@@ -2074,11 +2077,17 @@ private fun KlotterDialog(
loading = loading,
firstVisitText = firstVisitText,
lastVisitText = lastVisitText,
titleStyle = MaterialTheme.typography.titleLarge, // Android ger stil
bodyStyle = MaterialTheme.typography.bodyMedium, // Android ger stil
captionStyle = MaterialTheme.typography.bodySmall.copy( // Android ger stil
titleStyle = MaterialTheme.typography.titleLarge.copy( // Ändrad: ge färg
color = MaterialTheme.colorScheme.onSurface
),
bodyStyle = MaterialTheme.typography.bodyMedium.copy( // Ändrad: ge färg
color = MaterialTheme.colorScheme.onSurface
),
captionStyle = MaterialTheme.typography.bodySmall.copy( // Ändrad: ge färg
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontWeight = FontWeight.Normal
),
// Actions-slot: vi ritar Maps / Radera / Stäng med Android-komponenter
actions = {
val canDelete = currentUserId != null && ownerUserId != null && currentUserId == ownerUserId
@@ -2305,51 +2314,26 @@ private fun WikiArticleDialog(
if (loading) {
Text("Söker …")
} else {
Column(
modifier = Modifier
.fillMaxWidth()
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
if (thumb != null) {
Image(
bitmap = thumb!!.asImageBitmap(),
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 120.dp)
.clip(RoundedCornerShape(8.dp)),
contentScale = ContentScale.Crop
)
}
Text(extract.ifBlank { "Ingen sammanfattning tillgänglig." })
HorizontalDivider()
val bottomCoordPart = if (showCoords) " • (%.5f, %.5f)".format(lat, lon) else ""
Text(
"Klotter • $wikiDistanceText bort$bottomCoordPart",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Button(
onClick = {
val url = "https://sv.m.wikipedia.org/?curid=$pageId"
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
}
) { Text("Läs mer") }
WikiDetailContent(
titleText = title,
extractText = extract,
distanceText = wikiDistanceText, // Oför: redan beräknad
coordText = if (showCoords && lat != null && lon != null) formatCoords(lat, lon) else null,
thumb = thumb?.asImageBitmap(),
titleStyle = MaterialTheme.typography.titleLarge,
bodyStyle = MaterialTheme.typography.bodyMedium,
captionStyle = MaterialTheme.typography.bodySmall.copy(color = MaterialTheme.colorScheme.onSurfaceVariant),
actions = {
Button(onClick = {
val url = "https://sv.m.wikipedia.org/?curid=$pageId"
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
}) { Text("Läs mer") }
Button(
onClick = {
if (lat != null && lon != null) {
val uri = Uri.parse("geo:$lat,$lon?q=$lat,$lon(${Uri.encode(title.ifBlank { "Wikipedia-plats" })})")
val intent = Intent(
Intent.ACTION_VIEW,
uri
).apply { setPackage("com.google.android.apps.maps") }
val intent = Intent(Intent.ACTION_VIEW, uri).apply { setPackage("com.google.android.apps.maps") }
try { context.startActivity(intent) } catch (_: Exception) {
context.startActivity(Intent(Intent.ACTION_VIEW, uri))
}
@@ -2358,7 +2342,7 @@ private fun WikiArticleDialog(
enabled = lat != null && lon != null
) { Text("Maps") }
}
}
)
}
}
},
@@ -2429,33 +2413,20 @@ private fun FornsokDialog(
.widthIn(max = dialogWidth)
.heightIn(max = 520.dp)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
Text(desc.ifBlank { "Ingen sammanfattning tillgänglig." })
HorizontalDivider()
val coordPart = if (showCoords) " • " + formatCoords(platLat, platLon) else ""
Text(
"Fornsök • $fornDistanceText bort$coordPart",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
FornsokDetailContent(
titleText = title,
descText = desc,
distanceText = fornDistanceText,
coordText = if (showCoords) formatCoords(platLat, platLon) else null,
titleStyle = MaterialTheme.typography.titleLarge,
bodyStyle = MaterialTheme.typography.bodyMedium,
captionStyle = MaterialTheme.typography.bodySmall.copy(color = MaterialTheme.colorScheme.onSurfaceVariant),
actions = {
Button(
onClick = {
val geoTitle = Uri.encode(title)
val geo = Uri.parse("geo:$platLat,$platLon?q=$platLat,$platLon($geoTitle)")
val intent = Intent(
Intent.ACTION_VIEW,
geo
).apply { setPackage("com.google.android.apps.maps") }
val intent = Intent(Intent.ACTION_VIEW, geo).apply { setPackage("com.google.android.apps.maps") }
try { context.startActivity(intent) } catch (_: Exception) {
context.startActivity(Intent(Intent.ACTION_VIEW, geo))
}
@@ -2470,9 +2441,10 @@ private fun FornsokDialog(
enabled = link != null
) { Text("Läs mer") }
}
}
)
}
},
confirmButton = { Button(onClick = onClose) { Text("Stäng") } }
)
}
@@ -2578,75 +2550,56 @@ private fun DmDialog(
.widthIn(max = dialogWidth)
.heightIn(max = 520.dp)
) {
if (loading) {
Text("Söker …")
} else {
Column(
modifier = Modifier
.fillMaxWidth()
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
if (thumb != null) {
Image(
bitmap = thumb!!.asImageBitmap(),
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 120.dp)
.clip(RoundedCornerShape(8.dp)),
contentScale = ContentScale.Crop
)
}
displayBody?.let { Text(it) }
HorizontalDivider()
val bottomCoordPart = if (showCoords) " • (%.5f, %.5f)".format(item.lat, item.lon) else ""
Text(
"DigitaltMuseum • $dmDistanceText$bottomCoordPart",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Button(
onClick = {
if (!item.url.isNullOrBlank()) {
val i = Intent(Intent.ACTION_VIEW, Uri.parse(item.url))
try { context.startActivity(i) } catch (_: Exception) {}
}
},
enabled = !item.url.isNullOrBlank()
) { Text("Öppna bild") }
Button(
onClick = {
val uri = Uri.parse("geo:${item.lat},${item.lon}?q=${item.lat},${item.lon}(${Uri.encode(item.title.ifBlank { "DigitaltMuseum" })})")
val i = Intent(Intent.ACTION_VIEW, uri).apply {
setPackage("com.google.android.apps.maps")
}
try { context.startActivity(i) } catch (_: Exception) {
context.startActivity(Intent(Intent.ACTION_VIEW, uri))
}
}
) { Text("Maps") }
Button(
onClick = {
val u = item.webUrl
if (!u.isNullOrBlank()) {
val i = Intent(Intent.ACTION_VIEW, Uri.parse(u))
try { context.startActivity(i) } catch (_: Exception) {}
}
},
enabled = !item.webUrl.isNullOrBlank()
) { Text("Läs mer") }
}
val displayTitle = remember(item.id, detailText) {
val t = item.title.ifBlank { "DigitaltMuseum" }.trim()
t
}
// Samma heuristik som du hade: splitta ev. text
val (firstLine, restText) = remember(item.id, detailText) {
val body = detailText?.trim().orEmpty()
if (body.isBlank()) "" to null
else {
val idx = body.indexOfFirst { it == '.' || it == '!' || it == '?' }
if (idx >= 0 && idx + 1 < body.length) {
val first = body.substring(0, idx + 1).trim()
val rest = body.substring(idx + 1).trim().ifEmpty { null }
first to rest
} else body to null
}
}
DmDetailContent(
titleText = displayTitle,
bodyText = listOfNotNull(firstLine, restText).joinToString("\n\n"),
distanceText = dmDistanceText,
coordText = if (showCoords) formatCoords(item.lat, item.lon) else null,
image = thumb?.asImageBitmap(),
titleStyle = MaterialTheme.typography.titleLarge,
bodyStyle = MaterialTheme.typography.bodyMedium,
captionStyle = MaterialTheme.typography.bodySmall.copy(color = MaterialTheme.colorScheme.onSurfaceVariant),
actions = {
Button(
onClick = {
val labelEnc = Uri.encode(displayTitle)
val uri = Uri.parse("geo:${item.lat},${item.lon}?q=${item.lat},${item.lon}($labelEnc)")
val intent = Intent(Intent.ACTION_VIEW, uri).apply { setPackage("com.google.android.apps.maps") }
try { context.startActivity(intent) } catch (_: Exception) {
context.startActivity(Intent(Intent.ACTION_VIEW, uri))
}
}
) { Text("Maps") }
Button(
onClick = {
val u = item.webUrl // Ändrad: objectUrl -> webUrl
if (!u.isNullOrBlank()) {
val i = Intent(Intent.ACTION_VIEW, Uri.parse(u))
try { context.startActivity(i) } catch (_: Exception) {}
}
},
enabled = !item.webUrl.isNullOrBlank() // Ändrad: objectUrl -> webUrl
) { Text("Läs mer") }
}
)
}
},
confirmButton = { Button(onClick = onClose) { Text("Stäng") } }