mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Converted ExtMetadata to kotlin
This commit is contained in:
		
							parent
							
								
									e4fdb7914c
								
							
						
					
					
						commit
						fd18f6a67a
					
				
					 4 changed files with 71 additions and 110 deletions
				
			
		|  | @ -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()) | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -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 | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Paul Hawke
						Paul Hawke