Fix edit button shown when image has no location (#6029)

Changed the commons.filepicker.UploadableFile's hasLocation method to use the existing ImageCoordinates class for detecting the presence of geolocation in an image's exif
This commit is contained in:
Tanmay Gupta 2024-12-14 14:01:25 +05:30 committed by GitHub
parent c1acdbe31a
commit 235e8cdba2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,7 @@ import android.os.Parcelable
import androidx.exifinterface.media.ExifInterface
import fr.free.nrw.commons.upload.FileUtils
import fr.free.nrw.commons.upload.ImageCoordinates
import java.io.File
import java.io.IOException
import java.util.Date
@ -87,9 +88,7 @@ class UploadableFile : Parcelable {
fun hasLocation(): Boolean {
return try {
val exif = ExifInterface(file.absolutePath)
val latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE)
val longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE)
latitude != null && longitude != null
ImageCoordinates(exif, null).imageCoordsExists
} catch (e: IOException) {
Timber.tag("UploadableFile").d(e)
false