#135 safer entry fetch
This commit is contained in:
parent
42aad255f1
commit
5d61d28838
3 changed files with 13 additions and 11 deletions
|
@ -636,16 +636,16 @@ class MetadataFetchHandler(private val context: Context) : MethodCallHandler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val saveExposureTime: (value: Rational) -> Unit = {
|
val saveExposureTime = fun(value: Rational) {
|
||||||
// `TAG_EXPOSURE_TIME` as a string is sometimes a ratio, sometimes a decimal
|
// `TAG_EXPOSURE_TIME` as a string is sometimes a ratio, sometimes a decimal
|
||||||
// so we explicitly request it as a rational (e.g. 1/100, 1/14, 71428571/1000000000, 4000/1000, 2000000000/500000000)
|
// so we explicitly request it as a rational (e.g. 1/100, 1/14, 71428571/1000000000, 4000/1000, 2000000000/500000000)
|
||||||
// and process it to make sure the numerator is `1` when the ratio value is less than 1
|
// and process it to make sure the numerator is `1` when the ratio value is less than 1
|
||||||
val num = it.numerator
|
val num = value.numerator
|
||||||
val denom = it.denominator
|
val denom = value.denominator
|
||||||
metadataMap[KEY_EXPOSURE_TIME] = when {
|
metadataMap[KEY_EXPOSURE_TIME] = when {
|
||||||
num >= denom -> "${it.toSimpleString(true)}″"
|
num >= denom -> "${value.toSimpleString(true)}″"
|
||||||
num != 1L && num != 0L -> Rational(1, (denom / num.toDouble()).roundToLong()).toString()
|
num != 1L && num != 0L -> Rational(1, (denom / num.toDouble()).roundToLong()).toString()
|
||||||
else -> it.toString()
|
else -> value.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -223,7 +223,9 @@ object ExifInterfaceHelper {
|
||||||
val dirs = DirType.values().map { Pair(it, it.createDirectory()) }.toMap()
|
val dirs = DirType.values().map { Pair(it, it.createDirectory()) }.toMap()
|
||||||
|
|
||||||
// exclude Exif directory when it only includes image size
|
// exclude Exif directory when it only includes image size
|
||||||
val isUselessExif: (Map<String, String>) -> Boolean = { it.size == 2 && it.containsKey("Image Height") && it.containsKey("Image Width") }
|
val isUselessExif = fun(it: Map<String, String>): Boolean {
|
||||||
|
return it.size == 2 && it.containsKey("Image Height") && it.containsKey("Image Width")
|
||||||
|
}
|
||||||
|
|
||||||
return HashMap<String, Map<String, String>>().apply {
|
return HashMap<String, Map<String, String>>().apply {
|
||||||
put("Exif", describeDir(exif, dirs, baseTags).takeUnless(isUselessExif) ?: hashMapOf())
|
put("Exif", describeDir(exif, dirs, baseTags).takeUnless(isUselessExif) ?: hashMapOf())
|
||||||
|
|
|
@ -45,15 +45,15 @@ class MediaStoreImageProvider : ImageProvider() {
|
||||||
fetchFrom(context, isModified, handleNewEntry, VIDEO_CONTENT_URI, VIDEO_PROJECTION)
|
fetchFrom(context, isModified, handleNewEntry, VIDEO_CONTENT_URI, VIDEO_PROJECTION)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the provided URI can point to the wrong media collection,
|
||||||
|
// e.g. a GIF image with the URI `content://media/external/video/media/[ID]`
|
||||||
|
// so the effective entry URI may not match the provided URI
|
||||||
override fun fetchSingle(context: Context, uri: Uri, sourceMimeType: String?, callback: ImageOpCallback) {
|
override fun fetchSingle(context: Context, uri: Uri, sourceMimeType: String?, callback: ImageOpCallback) {
|
||||||
var found = false
|
var found = false
|
||||||
val fetched = arrayListOf<FieldMap>()
|
val fetched = arrayListOf<FieldMap>()
|
||||||
val id = uri.tryParseId()
|
val id = uri.tryParseId()
|
||||||
val onSuccess = fun(entry: FieldMap) {
|
val alwaysValid: NewEntryChecker = fun(_: Int, _: Int): Boolean = true
|
||||||
entry["uri"] = uri.toString()
|
val onSuccess: NewEntryHandler = fun(entry: FieldMap) { fetched.add(entry) }
|
||||||
fetched.add(entry)
|
|
||||||
}
|
|
||||||
val alwaysValid = { _: Int, _: Int -> true }
|
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
if (!found && (sourceMimeType == null || isImage(sourceMimeType))) {
|
if (!found && (sourceMimeType == null || isImage(sourceMimeType))) {
|
||||||
val contentUri = ContentUris.withAppendedId(IMAGE_CONTENT_URI, id)
|
val contentUri = ContentUris.withAppendedId(IMAGE_CONTENT_URI, id)
|
||||||
|
|
Loading…
Reference in a new issue