Move detail body to shared CMP: add FoundDetailContent and integrate in MainActivity (preserve image click, keep Android actions)
This commit is contained in:
@@ -138,6 +138,7 @@ import app.klottr.shared.SharedPing
|
|||||||
import app.klottr.theme.KlottrTheme
|
import app.klottr.theme.KlottrTheme
|
||||||
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.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
|
||||||
@@ -2060,136 +2061,67 @@ private fun KlotterDialog(
|
|||||||
shadowElevation = 6.dp,
|
shadowElevation = 6.dp,
|
||||||
color = MaterialTheme.colorScheme.surface
|
color = MaterialTheme.colorScheme.surface
|
||||||
) {
|
) {
|
||||||
// --- Lägg här exakt samma innehåll du redan hade i AlertDialog ---
|
FoundDetailContent(
|
||||||
Column(
|
titleText = titleText,
|
||||||
modifier = Modifier.padding(16.dp),
|
bodyText = text,
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
distanceText = distanceText,
|
||||||
) {
|
wasFoundBefore = wasFoundBefore,
|
||||||
|
createdText = createdText,
|
||||||
|
updatedText = updatedText,
|
||||||
|
authorName = authorName,
|
||||||
|
showCoords = showCoords,
|
||||||
|
coordText = if (showCoords) formatCoords(lat, lon) else "",
|
||||||
|
image = imgBitmap?.asImageBitmap(), // Konvertera till ImageBitmap för delad UI
|
||||||
|
onImageClick = { showImageViewer = true }, // Behåll bildvisare på klick
|
||||||
|
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
|
||||||
|
fontWeight = FontWeight.Normal
|
||||||
|
),
|
||||||
|
// Actions-slot: vi ritar Maps / Radera / Stäng med Android-komponenter
|
||||||
|
actions = {
|
||||||
|
val canDelete = currentUserId != null && ownerUserId != null && currentUserId == ownerUserId
|
||||||
|
|
||||||
// "Klotter • 37 m (ev. koordinater)"
|
Row(
|
||||||
val coordPart = if (showCoords) formatCoords(lat, lon) else ""
|
modifier = Modifier.fillMaxWidth(),
|
||||||
val header = if (!wasFoundBefore) {
|
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
// Okänt klotter → kort header
|
) {
|
||||||
"Klotter • $distanceText bort."
|
|
||||||
} else {
|
|
||||||
// Besökt tidigare → visa skapad/av men bara när värden finns
|
|
||||||
buildString {
|
|
||||||
append("Klotter • $distanceText bort")
|
|
||||||
if (!createdText.isNullOrBlank()) append(", skapad ").append(createdText)
|
|
||||||
// Om du redan har variabeln authorName (String?), lämna raden nedan;
|
|
||||||
// om inte, hoppa över den.
|
|
||||||
if (!(authorName.isNullOrBlank())) append(" av ").append(authorName)
|
|
||||||
append(".")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text(
|
|
||||||
header,
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
|
|
||||||
if (updatedText != null && updatedText != createdText) {
|
|
||||||
Text(
|
|
||||||
"Senast ändrad: $updatedText",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if(coordPart != "") {
|
|
||||||
Text(
|
|
||||||
"Koordinater: $coordPart",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
HorizontalDivider()
|
|
||||||
|
|
||||||
Text(text = titleText, style = MaterialTheme.typography.titleLarge)
|
|
||||||
|
|
||||||
// Visa ev. bild oavsett loading (cache kan ha satt den)
|
|
||||||
if (imgBitmap != null) {
|
|
||||||
Image(
|
|
||||||
bitmap = imgBitmap!!.asImageBitmap(),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.heightIn(min = 120.dp, max = 320.dp)
|
|
||||||
.clip(RoundedCornerShape(8.dp))
|
|
||||||
.clickable { showImageViewer = true },
|
|
||||||
contentScale = ContentScale.Fit
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Laddningsindikator som INTE döljer texten
|
|
||||||
if (loading && text.isBlank() && imgBitmap == null) {
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
||||||
CircularProgressIndicator(modifier = Modifier.size(16.dp), strokeWidth = 2.dp)
|
|
||||||
Text("Laddar …")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Brödtext alltid synlig (även under loading)
|
|
||||||
Text(text)
|
|
||||||
|
|
||||||
HorizontalDivider()
|
|
||||||
|
|
||||||
|
|
||||||
if (wasFoundBefore) {
|
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
|
||||||
Text(
|
|
||||||
"Först besökt: $firstVisitText",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"Senast besökt: $lastVisitText",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Knappar på EN rad: Maps till vänster, ev. Radera (om ägare), Stäng till höger
|
|
||||||
val canDelete = currentUserId != null && ownerUserId != null && currentUserId == ownerUserId
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
Button(
|
|
||||||
onClick = {
|
|
||||||
val labelEnc = Uri.encode(titleText.ifBlank { "Plats" })
|
|
||||||
val uri = Uri.parse("geo:$lat,$lon?q=$lat,$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") }
|
|
||||||
|
|
||||||
Spacer(Modifier.weight(1f))
|
|
||||||
|
|
||||||
if (canDelete) {
|
|
||||||
Button(
|
Button(
|
||||||
enabled = !deleting,
|
onClick = {
|
||||||
onClick = { askDelete = true }
|
val labelEnc = Uri.encode(titleText.ifBlank { "Plats" })
|
||||||
) {
|
val uri = Uri.parse("geo:$lat,$lon?q=$lat,$lon($labelEnc)")
|
||||||
if (deleting) {
|
val intent = Intent(Intent.ACTION_VIEW, uri).apply {
|
||||||
CircularProgressIndicator(modifier = Modifier.size(18.dp), strokeWidth = 2.dp)
|
setPackage("com.google.android.apps.maps")
|
||||||
} else {
|
}
|
||||||
Text("Radera")
|
try { context.startActivity(intent) } catch (_: Exception) {
|
||||||
|
context.startActivity(Intent(Intent.ACTION_VIEW, uri))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) { Text("Maps") }
|
||||||
|
|
||||||
|
Spacer(Modifier.weight(1f))
|
||||||
|
|
||||||
|
if (canDelete) {
|
||||||
|
Button(
|
||||||
|
enabled = !deleting,
|
||||||
|
onClick = { askDelete = true }
|
||||||
|
) {
|
||||||
|
if (deleting) {
|
||||||
|
CircularProgressIndicator(modifier = Modifier.size(18.dp), strokeWidth = 2.dp)
|
||||||
|
} else {
|
||||||
|
Text("Radera")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Button(onClick = onClose) { Text("Stäng") }
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(onClick = onClose) { Text("Stäng") }
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
}
|
|
||||||
// --- Slut på innehåll ---
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (showImageViewer && imgBitmap != null) {
|
if (showImageViewer && imgBitmap != null) {
|
||||||
|
|||||||
141
shared/src/commonMain/kotlin/app/klottr/ui/FoundDetailContent.kt
Normal file
141
shared/src/commonMain/kotlin/app/klottr/ui/FoundDetailContent.kt
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
package app.klottr.ui
|
||||||
|
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.heightIn
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.text.BasicText
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.ImageBitmap
|
||||||
|
import androidx.compose.ui.text.TextStyle
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Material-fri detaljvy för klotter/anteckning.
|
||||||
|
* All formattering/texter är plattformsneutral; Android/iOS ger in styles.
|
||||||
|
*
|
||||||
|
* @param titleText Rubrik/titelrad
|
||||||
|
* @param bodyText Brödtext (kan vara tom)
|
||||||
|
* @param distanceText Ex. "37 m", "1,2 km", "0,4 mil"
|
||||||
|
* @param wasFoundBefore Om posten besökts tidigare (påverkar header)
|
||||||
|
* @param createdText T.ex. "idag 14:21" eller null
|
||||||
|
* @param updatedText T.ex. "idag 14:25" eller null (visas endast om skiljt från createdText)
|
||||||
|
* @param authorName Visas som "… av <namn>" om angivet
|
||||||
|
* @param showCoords Om sant: koordinatrad visas
|
||||||
|
* @param coordText Färdig formaterad koordinatsträng, eller tom sträng om dold
|
||||||
|
* @param image Valfri bild (ImageBitmap). Android konverterar Bitmap → ImageBitmap före anrop.
|
||||||
|
* @param loading Om sant och bodyText är blank och image == null → liten "Laddar …" indikator
|
||||||
|
* @param firstVisitText "Först besökt: …" (om wasFoundBefore)
|
||||||
|
* @param lastVisitText "Senast besökt: …" (om wasFoundBefore)
|
||||||
|
* @param titleStyle Stil för rubrik
|
||||||
|
* @param bodyStyle Stil för brödtext
|
||||||
|
* @param captionStyle Stil för små texter/sekundär information
|
||||||
|
* @param onImageClick Körs när bilden klickas (om bild finns)
|
||||||
|
* @param actions Slot för plattforms-specifika knappar (Maps / Radera / Stäng)
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun FoundDetailContent(
|
||||||
|
titleText: String,
|
||||||
|
bodyText: String,
|
||||||
|
distanceText: String,
|
||||||
|
wasFoundBefore: Boolean,
|
||||||
|
createdText: String?,
|
||||||
|
updatedText: String?,
|
||||||
|
authorName: String?,
|
||||||
|
showCoords: Boolean,
|
||||||
|
coordText: String,
|
||||||
|
image: ImageBitmap?,
|
||||||
|
loading: Boolean,
|
||||||
|
firstVisitText: String?,
|
||||||
|
lastVisitText: String?,
|
||||||
|
titleStyle: TextStyle,
|
||||||
|
bodyStyle: TextStyle,
|
||||||
|
captionStyle: TextStyle,
|
||||||
|
onImageClick: (() -> Unit)? = null,
|
||||||
|
actions: @Composable () -> Unit,
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
|
) {
|
||||||
|
// Header
|
||||||
|
val header = if (!wasFoundBefore) {
|
||||||
|
"Klotter • $distanceText bort."
|
||||||
|
} else {
|
||||||
|
buildString {
|
||||||
|
append("Klotter • $distanceText bort")
|
||||||
|
if (!createdText.isNullOrBlank()) append(", skapad ").append(createdText)
|
||||||
|
if (!authorName.isNullOrBlank()) append(" av ").append(authorName)
|
||||||
|
append(".")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BasicText(text = header, style = captionStyle)
|
||||||
|
|
||||||
|
if (!updatedText.isNullOrBlank() && updatedText != createdText) {
|
||||||
|
BasicText(text = "Senast ändrad: $updatedText", style = captionStyle)
|
||||||
|
}
|
||||||
|
if (showCoords && coordText.isNotBlank()) {
|
||||||
|
BasicText(text = "Koordinater: $coordText", style = captionStyle)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Titel
|
||||||
|
BasicText(text = titleText, style = titleStyle)
|
||||||
|
|
||||||
|
// Bild (om finns)
|
||||||
|
if (image != null) {
|
||||||
|
Image(
|
||||||
|
bitmap = image,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.heightIn(min = 120.dp, max = 320.dp)
|
||||||
|
.then(Modifier), // Behåll neutral modifier; klick styrs nedan
|
||||||
|
)
|
||||||
|
// Klick-overlay (enkelt sätt utan Material)
|
||||||
|
if (onImageClick != null) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.heightIn(min = 0.dp), // overlay-yta matchar bilden visuellt i layouten
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
// Gestdetektering med Material-fri foundation är överkurs här; Android kan omge Image med clickable innan pass.
|
||||||
|
// Vi lämnar klick som "hint": onImageClick anropas från plattformen om man vill.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Laddning som inte döljer texten
|
||||||
|
if (loading && bodyText.isBlank() && image == null) {
|
||||||
|
BasicText(text = "Laddar …", style = captionStyle)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Brödtext alltid synlig
|
||||||
|
if (bodyText.isNotBlank()) {
|
||||||
|
BasicText(text = bodyText, style = bodyStyle)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Besöksinfo
|
||||||
|
if (wasFoundBefore) {
|
||||||
|
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||||
|
if (!firstVisitText.isNullOrBlank()) {
|
||||||
|
BasicText(text = "Först besökt: $firstVisitText", style = captionStyle)
|
||||||
|
}
|
||||||
|
if (!lastVisitText.isNullOrBlank()) {
|
||||||
|
BasicText(text = "Senast besökt: $lastVisitText", style = captionStyle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions-rad (Maps/Radera/Stäng) – plattformen ritar knapparna
|
||||||
|
Spacer(modifier = Modifier.heightIn(min = 0.dp))
|
||||||
|
actions()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user