Move detail body to shared CMP: add FoundDetailContent and integrate in MainActivity (preserve image click, keep Android actions)
This commit is contained in:
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