From fd18f6a67a72c95e5c5b6ca0530c16190f904b23 Mon Sep 17 00:00:00 2001 From: Paul Hawke Date: Thu, 5 Dec 2024 21:27:22 -0600 Subject: [PATCH] Converted ExtMetadata to kotlin --- .../commons/explore/media/MediaConverter.kt | 11 +- .../fr/free/nrw/commons/location/LatLng.kt | 7 ++ .../wikidata/model/gallery/ExtMetadata.java | 102 ------------------ .../wikidata/model/gallery/ExtMetadata.kt | 61 +++++++++++ 4 files changed, 71 insertions(+), 110 deletions(-) delete mode 100644 app/src/main/java/fr/free/nrw/commons/wikidata/model/gallery/ExtMetadata.java create mode 100644 app/src/main/java/fr/free/nrw/commons/wikidata/model/gallery/ExtMetadata.kt diff --git a/app/src/main/java/fr/free/nrw/commons/explore/media/MediaConverter.kt b/app/src/main/java/fr/free/nrw/commons/explore/media/MediaConverter.kt index a3103d41a..765086c0d 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/media/MediaConverter.kt +++ b/app/src/main/java/fr/free/nrw/commons/explore/media/MediaConverter.kt @@ -11,7 +11,6 @@ import fr.free.nrw.commons.wikidata.model.Entities import fr.free.nrw.commons.wikidata.model.gallery.ExtMetadata import fr.free.nrw.commons.wikidata.model.gallery.ImageInfo import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage -import org.apache.commons.lang3.StringUtils import java.text.ParseException import java.util.Date import javax.inject.Inject @@ -41,7 +40,7 @@ class MediaConverter metadata.prefixedLicenseUrl, getAuthor(metadata), getAuthor(metadata), - MediaDataExtractorUtil.extractCategoriesFromList(metadata.categories), + MediaDataExtractorUtil.extractCategoriesFromList(metadata.categories()), metadata.latLng, entity.labels().mapValues { it.value.value() }, entity.descriptions().mapValues { it.value.value() }, @@ -104,9 +103,5 @@ private val ExtMetadata.prefixedLicenseUrl: String } private val ExtMetadata.latLng: LatLng? - get() = - if (!StringUtils.isBlank(gpsLatitude) && !StringUtils.isBlank(gpsLongitude)) { - LatLng(gpsLatitude.toDouble(), gpsLongitude.toDouble(), 0.0f) - } else { - null - } + get() = LatLng.latLongOrNull(gpsLatitude(), gpsLongitude()) + diff --git a/app/src/main/java/fr/free/nrw/commons/location/LatLng.kt b/app/src/main/java/fr/free/nrw/commons/location/LatLng.kt index 4e21b93c2..7dd9a49ce 100644 --- a/app/src/main/java/fr/free/nrw/commons/location/LatLng.kt +++ b/app/src/main/java/fr/free/nrw/commons/location/LatLng.kt @@ -41,6 +41,13 @@ data class LatLng( * Accepts a non-null [Location] and converts it to a [LatLng]. */ companion object { + fun latLongOrNull(latitude: String?, longitude: String?): LatLng? = + if (!latitude.isNullOrBlank() && !longitude.isNullOrBlank()) { + LatLng(latitude.toDouble(), longitude.toDouble(), 0.0f) + } else { + null + } + /** * gets the latitude and longitude of a given non-null location * @param location the non-null location of the user diff --git a/app/src/main/java/fr/free/nrw/commons/wikidata/model/gallery/ExtMetadata.java b/app/src/main/java/fr/free/nrw/commons/wikidata/model/gallery/ExtMetadata.java deleted file mode 100644 index 2bd63400f..000000000 --- a/app/src/main/java/fr/free/nrw/commons/wikidata/model/gallery/ExtMetadata.java +++ /dev/null @@ -1,102 +0,0 @@ -package fr.free.nrw.commons.wikidata.model.gallery; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.google.gson.annotations.SerializedName; - -import org.apache.commons.lang3.StringUtils; - - -public class ExtMetadata { - @SerializedName("DateTime") @Nullable private Values dateTime; - @SerializedName("ObjectName") @Nullable private Values objectName; - @SerializedName("CommonsMetadataExtension") @Nullable private Values commonsMetadataExtension; - @SerializedName("Categories") @Nullable private Values categories; - @SerializedName("Assessments") @Nullable private Values assessments; - @SerializedName("GPSLatitude") @Nullable private Values gpsLatitude; - @SerializedName("GPSLongitude") @Nullable private Values gpsLongitude; - @SerializedName("ImageDescription") @Nullable private Values imageDescription; - @SerializedName("DateTimeOriginal") @Nullable private Values dateTimeOriginal; - @SerializedName("Artist") @Nullable private Values artist; - @SerializedName("Credit") @Nullable private Values credit; - @SerializedName("Permission") @Nullable private Values permission; - @SerializedName("AuthorCount") @Nullable private Values authorCount; - @SerializedName("LicenseShortName") @Nullable private Values licenseShortName; - @SerializedName("UsageTerms") @Nullable private Values usageTerms; - @SerializedName("LicenseUrl") @Nullable private Values licenseUrl; - @SerializedName("AttributionRequired") @Nullable private Values attributionRequired; - @SerializedName("Copyrighted") @Nullable private Values copyrighted; - @SerializedName("Restrictions") @Nullable private Values restrictions; - @SerializedName("License") @Nullable private Values license; - - @NonNull public String licenseShortName() { - return StringUtils.defaultString(licenseShortName == null ? null : licenseShortName.value()); - } - - @NonNull public String licenseUrl() { - return StringUtils.defaultString(licenseUrl == null ? null : licenseUrl.value()); - } - - @NonNull public String license() { - return StringUtils.defaultString(license == null ? null : license.value()); - } - - @NonNull public String imageDescription() { - return StringUtils.defaultString(imageDescription == null ? null : imageDescription.value()); - } - - @NonNull public String imageDescriptionSource() { - return StringUtils.defaultString(imageDescription == null ? null : imageDescription.source()); - } - - @NonNull public String objectName() { - return StringUtils.defaultString(objectName == null ? null : objectName.value()); - } - - @NonNull public String usageTerms() { - return StringUtils.defaultString(usageTerms == null ? null : usageTerms.value()); - } - - @NonNull public String dateTimeOriginal() { - return StringUtils.defaultString(dateTimeOriginal == null ? null : dateTimeOriginal.value()); - } - - @NonNull public String dateTime() { - return StringUtils.defaultString(dateTime == null ? null : dateTime.value()); - } - - @NonNull public String artist() { - return StringUtils.defaultString(artist == null ? null : artist.value()); - } - - @NonNull public String getCategories() { - return StringUtils.defaultString(categories == null ? null : categories.value()); - } - - @NonNull public String getGpsLatitude() { - return StringUtils.defaultString(gpsLatitude == null ? null : gpsLatitude.value()); - } - - @NonNull public String getGpsLongitude() { - return StringUtils.defaultString(gpsLongitude == null ? null : gpsLongitude.value()); - } - - @NonNull public String credit() { - return StringUtils.defaultString(credit == null ? null : credit.value()); - } - - public class Values { - @Nullable private String value; - @Nullable private String source; - @Nullable private String hidden; - - @Nullable public String value() { - return value; - } - - @Nullable public String source() { - return source; - } - } -} diff --git a/app/src/main/java/fr/free/nrw/commons/wikidata/model/gallery/ExtMetadata.kt b/app/src/main/java/fr/free/nrw/commons/wikidata/model/gallery/ExtMetadata.kt new file mode 100644 index 000000000..63c018252 --- /dev/null +++ b/app/src/main/java/fr/free/nrw/commons/wikidata/model/gallery/ExtMetadata.kt @@ -0,0 +1,61 @@ +package fr.free.nrw.commons.wikidata.model.gallery + +import com.google.gson.annotations.SerializedName +import org.apache.commons.lang3.StringUtils + +class ExtMetadata { + @SerializedName("DateTime") private val dateTime: Values? = null + @SerializedName("ObjectName") private val objectName: Values? = null + @SerializedName("CommonsMetadataExtension") private val commonsMetadataExtension: Values? = null + @SerializedName("Categories") private val categories: Values? = null + @SerializedName("Assessments") private val assessments: Values? = null + @SerializedName("GPSLatitude") private val gpsLatitude: Values? = null + @SerializedName("GPSLongitude") private val gpsLongitude: Values? = null + @SerializedName("ImageDescription") private val imageDescription: Values? = null + @SerializedName("DateTimeOriginal") private val dateTimeOriginal: Values? = null + @SerializedName("Artist") private val artist: Values? = null + @SerializedName("Credit") private val credit: Values? = null + @SerializedName("Permission") private val permission: Values? = null + @SerializedName("AuthorCount") private val authorCount: Values? = null + @SerializedName("LicenseShortName") private val licenseShortName: Values? = null + @SerializedName("UsageTerms") private val usageTerms: Values? = null + @SerializedName("LicenseUrl") private val licenseUrl: Values? = null + @SerializedName("AttributionRequired") private val attributionRequired: Values? = null + @SerializedName("Copyrighted") private val copyrighted: Values? = null + @SerializedName("Restrictions") private val restrictions: Values? = null + @SerializedName("License") private val license: Values? = null + + fun licenseShortName(): String = licenseShortName?.value ?: "" + + fun licenseUrl(): String = licenseUrl?.value ?: "" + + fun license(): String = license?.value ?: "" + + fun imageDescription(): String = imageDescription?.value ?: "" + + fun imageDescriptionSource(): String = imageDescription?.source ?: "" + + fun objectName(): String = objectName?.value ?: "" + + fun usageTerms(): String = usageTerms?.value ?: "" + + fun dateTimeOriginal(): String = dateTimeOriginal?.value ?: "" + + fun dateTime(): String = dateTime?.value ?: "" + + fun artist(): String = artist?.value ?: "" + + fun categories(): String = categories?.value ?: "" + + fun gpsLatitude(): String = gpsLatitude?.value ?: "" + + fun gpsLongitude(): String = gpsLongitude?.value ?: "" + + fun credit(): String = credit?.value ?: "" + + class Values { + val value: String? = null + val source: String? = null + val hidden: String? = null + } +}