Treat JSON null city/country/date as absent

The overlay showed 'null, null' for photos without location because
JSONObject.optString returns the string "null" for JSON null.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012BvT3RjNpBmMUsyPqHq7fm
This commit is contained in:
2026-09-11 21:38:15 +00:00
parent bdfb462eb9
commit e4015e8a90
2 changed files with 9 additions and 5 deletions
+2 -2
View File
@@ -14,8 +14,8 @@ android {
applicationId = "cloud.alexandrevazquez.immichtv"
minSdk = 26
targetSdk = 35
versionCode = 2
versionName = "1.1.0"
versionCode = 3
versionName = "1.1.1"
}
signingConfigs {
@@ -104,13 +104,17 @@ class ImmichApi(baseUrl: String, private val apiKey: String) {
width = w,
height = h,
fileName = o.optString("originalFileName", ""),
takenAt = o.optString("localDateTime").ifBlank { exif?.optString("dateTimeOriginal") }?.ifBlank { null },
city = exif?.optString("city")?.ifBlank { null },
country = exif?.optString("country")?.ifBlank { null },
takenAt = o.str("localDateTime") ?: exif?.str("dateTimeOriginal"),
city = exif?.str("city"),
country = exif?.str("country"),
durationMs = parseDuration(o.opt("duration")),
)
}
/** Like optString but treats JSON null and blank as absent instead of returning "null". */
private fun JSONObject.str(key: String): String? =
if (isNull(key)) null else optString(key).ifBlank { null }
private fun get(url: String): String = execute(Request.Builder().url(url).get().build())
private fun post(url: String, body: JSONObject): String = execute(