Detail access via shared rule: integrate decideDetailAccess in KlotterDialog and fix blockedText nullability
This commit is contained in:
@@ -116,6 +116,7 @@ import app.klottr.location.AndroidLocationProvider
|
|||||||
import app.klottr.nearby.FoundOpenAction // Delat åtgärds-ADT
|
import app.klottr.nearby.FoundOpenAction // Delat åtgärds-ADT
|
||||||
import app.klottr.nearby.NearbyEntryShared // Delad radmodell
|
import app.klottr.nearby.NearbyEntryShared // Delad radmodell
|
||||||
import app.klottr.nearby.ScanConfig
|
import app.klottr.nearby.ScanConfig
|
||||||
|
import app.klottr.nearby.decideDetailAccess // Delad beslutsregel
|
||||||
import app.klottr.nearby.enrichKlotterLabels // Delad etikett-berikning
|
import app.klottr.nearby.enrichKlotterLabels // Delad etikett-berikning
|
||||||
import app.klottr.nearby.getNearbyBundle // Delad use-case
|
import app.klottr.nearby.getNearbyBundle // Delad use-case
|
||||||
import app.klottr.nearby.resolveFoundOpenAction // Delad öppna-resolver
|
import app.klottr.nearby.resolveFoundOpenAction // Delad öppna-resolver
|
||||||
@@ -1949,7 +1950,6 @@ private fun KlotterDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(id, lat, lon, label) {
|
LaunchedEffect(id, lat, lon, label) {
|
||||||
loading = !prefilledFromCache
|
loading = !prefilledFromCache
|
||||||
|
|
||||||
@@ -1966,24 +1966,25 @@ private fun KlotterDialog(
|
|||||||
val qLat = current?.latitude ?: my?.latitude
|
val qLat = current?.latitude ?: my?.latitude
|
||||||
val qLon = current?.longitude ?: my?.longitude
|
val qLon = current?.longitude ?: my?.longitude
|
||||||
|
|
||||||
val withinRadius = if (qLat != null && qLon != null) {
|
// --- Delad beslutsregel: ersätter withinRadius/canAttempt/reqLat/reqLon --------------------
|
||||||
app.klottr.util.distanceMeters(qLat, qLon, lat, lon) <= Config.DEFAULT_KLOTTER_RADIUS_M.toDouble()
|
val access = decideDetailAccess( // Ny: Beräkna om vi får hämta + vilka coords som ska skickas
|
||||||
} else false
|
wasFoundBefore = wasFoundBefore, // Ny
|
||||||
|
userLat = qLat, userLon = qLon, // Ny
|
||||||
|
noteLat = lat, noteLon = lon, // Ny
|
||||||
|
radiusMeters = Config.DEFAULT_KLOTTER_RADIUS_M // Ny
|
||||||
|
)
|
||||||
|
KLog.d { "KlotterDialog canAttempt=${access.canAttempt} wasFoundBefore=$wasFoundBefore" } // Ändrad: Logga via access
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if (access.canAttempt) { // Ändrad: Villkor använder delad regel
|
||||||
// Försök hämta detalj/bild om posten har besökts tidigare ELLER vi är inom radien
|
|
||||||
val canAttempt = wasFoundBefore || withinRadius
|
|
||||||
KLog.d { "KlotterDialog canAttempt=$canAttempt withinRadius=$withinRadius wasFoundBefore=$wasFoundBefore" }
|
|
||||||
|
|
||||||
if (canAttempt) {
|
|
||||||
// get_note.php ska få: Besökt tidigare => NOTISENS coords, annars besökarens (fallback notisens)
|
// get_note.php ska få: Besökt tidigare => NOTISENS coords, annars besökarens (fallback notisens)
|
||||||
val reqLat = if (wasFoundBefore) lat else (qLat ?: lat)
|
// (Nu levererat av access.reqLat/reqLon från delad regel)
|
||||||
val reqLon = if (wasFoundBefore) lon else (qLon ?: lon)
|
val reqLat = access.reqLat // Ny: Koordinater från delad regel
|
||||||
|
val reqLon = access.reqLon // Ny
|
||||||
|
|
||||||
val detail = withContext(Dispatchers.IO) {
|
val detail = withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
fetchNoteDetail(id.toLong(), reqLat, reqLon)
|
fetchNoteDetail(id.toLong(), reqLat, reqLon) // Ändrad: Skicka delad regel-coords
|
||||||
} catch (_: Throwable) { null }
|
} catch (_: Throwable) { null }
|
||||||
}
|
}
|
||||||
KLog.d { "detail fetch id=$id ok=${detail != null}" }
|
KLog.d { "detail fetch id=$id ok=${detail != null}" }
|
||||||
@@ -2032,19 +2033,20 @@ private fun KlotterDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Kunde inte få detalj – behåll fallback (endast om aldrig funnen och utanför radie)
|
// Kunde inte få detalj – behåll fallback (endast om aldrig funnen och spärr gäller)
|
||||||
if (!wasFoundBefore && !withinRadius) {
|
if (!wasFoundBefore && access.blockedText != null) { // Ändrad: Använd delad spärrtext
|
||||||
titleText = "Okänt klotter"
|
titleText = "Okänt klotter"
|
||||||
text = "Du måste vara inom ${Config.DEFAULT_KLOTTER_RADIUS_M}\u00A0m för att se det."
|
text = access.blockedText ?: "Du måste vara inom ${Config.DEFAULT_KLOTTER_RADIUS_M}\u00A0m för att se det." // Null-säkert: text kräver icke-null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Verkligen okänd och för långt bort
|
// Verkligen okänd och för långt bort
|
||||||
titleText = "Okänt klotter"
|
titleText = "Okänt klotter"
|
||||||
text = "Du måste vara inom ${Config.DEFAULT_KLOTTER_RADIUS_M}\u00A0m för att se det."
|
text = access.blockedText ?: "Du måste vara inom ${Config.DEFAULT_KLOTTER_RADIUS_M}\u00A0m för att se det." // Ändrad: Delad spärrtext
|
||||||
}
|
}
|
||||||
loading = false
|
loading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = onClose,
|
onDismissRequest = onClose,
|
||||||
properties = DialogProperties(usePlatformDefaultWidth = false)
|
properties = DialogProperties(usePlatformDefaultWidth = false)
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package app.klottr.nearby
|
||||||
|
|
||||||
|
import app.klottr.util.distanceMeters
|
||||||
|
|
||||||
|
data class DetailAccess(
|
||||||
|
val canAttempt: Boolean, // Om vi får hämta detalj nu
|
||||||
|
val reqLat: Double, // Lat som ska skickas i request (se kommentar nedan)
|
||||||
|
val reqLon: Double, // Lon som ska skickas i request
|
||||||
|
val blockedText: String? // Spärrmeddelande när canAttempt = false (annars null)
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Beslutar om detalj får hämtas och vilka koordinater som ska skickas:
|
||||||
|
* - Om posten har besökts tidigare: använd postens koordinater (låser upp text).
|
||||||
|
* - Annars: använd besökarens koordinater om kända, annars fall back till postens.
|
||||||
|
* - canAttempt=true om besökt tidigare ELLER inom radius från postens position.
|
||||||
|
*/
|
||||||
|
fun decideDetailAccess(
|
||||||
|
wasFoundBefore: Boolean,
|
||||||
|
userLat: Double?, userLon: Double?,
|
||||||
|
noteLat: Double, noteLon: Double,
|
||||||
|
radiusMeters: Int
|
||||||
|
): DetailAccess {
|
||||||
|
val withinRadius = run {
|
||||||
|
val uLat = userLat
|
||||||
|
val uLon = userLon
|
||||||
|
if (uLat != null && uLon != null) {
|
||||||
|
distanceMeters(uLat, uLon, noteLat, noteLon) <= radiusMeters
|
||||||
|
} else false
|
||||||
|
}
|
||||||
|
|
||||||
|
val can = wasFoundBefore || withinRadius
|
||||||
|
val reqLat = if (wasFoundBefore) noteLat else (userLat ?: noteLat)
|
||||||
|
val reqLon = if (wasFoundBefore) noteLon else (userLon ?: noteLon)
|
||||||
|
|
||||||
|
val blocked = if (!can) "Du måste vara inom ${radiusMeters}\u00A0m för att se det." else null
|
||||||
|
|
||||||
|
return DetailAccess(
|
||||||
|
canAttempt = can,
|
||||||
|
reqLat = reqLat,
|
||||||
|
reqLon = reqLon,
|
||||||
|
blockedText = blocked
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user