From d6d8155ceeec33edecbe730ac67c60ecdd1017b5 Mon Sep 17 00:00:00 2001 From: Rsedp8 <91428886+Rsedp8@users.noreply.github.com> Date: Sat, 24 May 2025 17:35:45 +0200 Subject: [PATCH] fix: check placeBindings for null instead of checking each destructured value --- .../nrw/commons/mwapi/OkHttpJsonApiClient.kt | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/mwapi/OkHttpJsonApiClient.kt b/app/src/main/java/fr/free/nrw/commons/mwapi/OkHttpJsonApiClient.kt index 291c834bd..bfbfb1585 100644 --- a/app/src/main/java/fr/free/nrw/commons/mwapi/OkHttpJsonApiClient.kt +++ b/app/src/main/java/fr/free/nrw/commons/mwapi/OkHttpJsonApiClient.kt @@ -531,40 +531,38 @@ ${"wd:" + place.wikiDataEntityId}""" ) if (placeBindings != null) { for ((item1, label, location, clas) in placeBindings) { - if (item1 != null && label != null && clas != null) { - val input = location.value - val pattern = Pattern.compile( - "Point\\(([-+]?[0-9]*\\.?[0-9]+) ([-+]?[0-9]*\\.?[0-9]+)\\)" - ) - val matcher = pattern.matcher(input) + val input = location.value + val pattern = Pattern.compile( + "Point\\(([-+]?[0-9]*\\.?[0-9]+) ([-+]?[0-9]*\\.?[0-9]+)\\)" + ) + val matcher = pattern.matcher(input) - if (matcher.find()) { - val longStr = matcher.group(1) - val latStr = matcher.group(2) - val itemUrl = item1.value - val itemName = label.value.replace("&", "&") - val itemLatitude = latStr - val itemLongitude = longStr - val itemClass = clas.value + if (matcher.find()) { + val longStr = matcher.group(1) + val latStr = matcher.group(2) + val itemUrl = item1.value + val itemName = label.value.replace("&", "&") + val itemLatitude = latStr + val itemLongitude = longStr + val itemClass = clas.value - val formattedItemName = - if (!itemClass.isEmpty()) - "$itemName ($itemClass)" - else - itemName + val formattedItemName = + if (!itemClass.isEmpty()) + "$itemName ($itemClass)" + else + itemName - val kmlEntry = (""" - - $formattedItemName - $itemUrl - - $itemLongitude,$itemLatitude - - """) - kmlString = kmlString + kmlEntry - } else { - Timber.e("No match found") - } + val kmlEntry = (""" + + $formattedItemName + $itemUrl + + $itemLongitude,$itemLatitude + + """) + kmlString = kmlString + kmlEntry + } else { + Timber.e("No match found") } } }