Files
Klottr/shared/src/commonMain/kotlin/app/klottr/nearby/FoundFormat.kt

37 lines
1.8 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package app.klottr.nearby //
import app.klottr.util.distanceMeters // Delad Haversine
import app.klottr.nearby.layerDisplayName // Central visningssträng för lager
import app.klottr.util.FoundEntry // Hittat-modellen (delad)
/**
* Bygger undertext för en Hittat-rad:
* "<Lagernamn> • <avstånd> [• <lat,lon>]"
* - Tar in ev. aktuell position (nullable) från anroparen (Android/iOS).
* - showCoords styr om lat/lon ska inkluderas.
* - Formatterare för avstånd/koordinater skickas in från plattformen
* (så :shared slipper bero på :app’s util-funktioner).
*/
fun foundSubtitle( // Samma funktionsnamn
entry: FoundEntry, //
currentLat: Double?, //
currentLon: Double?, //
showCoords: Boolean, //
distanceFormatter: (Int) -> String, // Formatterare för meter → visningssträng
coordsFormatter: (Double, Double) -> String // Formatterare för lat/lon → visningssträng
): String {
val layerName = layerDisplayName(entry.layer) //
val distText = if (currentLat != null && currentLon != null) { //
val d = distanceMeters(currentLat, currentLon, entry.lat, entry.lon).toInt() //
distanceFormatter(d) // Låt plattform formatera avståndet
} else {
"-" //
}
val coordPart = if (showCoords) { //
" • " + coordsFormatter(entry.lat, entry.lon) // Låt plattform formatera koordinaterna
} else {
"" //
}
return "$layerName • $distText$coordPart" //
}