Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
8efc17c98c
4 changed files with 29 additions and 26 deletions
|
@ -6,6 +6,7 @@ import android.content.ContextWrapper
|
|||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import android.webkit.MimeTypeMap
|
||||
import deckers.thibault.aves.model.EntryFields
|
||||
import deckers.thibault.aves.model.FieldMap
|
||||
import deckers.thibault.aves.model.SourceEntry
|
||||
import deckers.thibault.aves.utils.LogUtils
|
||||
|
@ -88,9 +89,9 @@ internal class FileImageProvider : ImageProvider() {
|
|||
}
|
||||
|
||||
return hashMapOf(
|
||||
"uri" to Uri.fromFile(newFile).toString(),
|
||||
"path" to newFile.path,
|
||||
"dateModifiedSecs" to newFile.lastModified() / 1000,
|
||||
EntryFields.URI to Uri.fromFile(newFile).toString(),
|
||||
EntryFields.PATH to newFile.path,
|
||||
EntryFields.DATE_MODIFIED_SECS to newFile.lastModified() / 1000,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -98,8 +99,8 @@ internal class FileImageProvider : ImageProvider() {
|
|||
try {
|
||||
val file = File(path)
|
||||
if (file.exists()) {
|
||||
newFields["dateModifiedSecs"] = file.lastModified() / 1000
|
||||
newFields["sizeBytes"] = file.length()
|
||||
newFields[EntryFields.DATE_MODIFIED_SECS] = file.lastModified() / 1000
|
||||
newFields[EntryFields.SIZE_BYTES] = file.length()
|
||||
}
|
||||
callback.onSuccess(newFields)
|
||||
} catch (e: SecurityException) {
|
||||
|
|
|
@ -64,6 +64,7 @@ import java.util.TimeZone
|
|||
import kotlin.math.absoluteValue
|
||||
import androidx.exifinterface.media.ExifInterfaceFork as ExifInterface
|
||||
import androidx.core.net.toUri
|
||||
import deckers.thibault.aves.model.EntryFields
|
||||
|
||||
abstract class ImageProvider {
|
||||
open fun fetchSingle(context: Context, uri: Uri, sourceMimeType: String?, allowUnsized: Boolean, callback: ImageOpCallback) {
|
||||
|
@ -74,10 +75,10 @@ abstract class ImageProvider {
|
|||
return if (StorageUtils.isInVault(context, path)) {
|
||||
val uri = Uri.fromFile(File(path))
|
||||
hashMapOf(
|
||||
"origin" to SourceEntry.ORIGIN_VAULT,
|
||||
"uri" to uri.toString(),
|
||||
"contentId" to null,
|
||||
"path" to path,
|
||||
EntryFields.ORIGIN to SourceEntry.ORIGIN_VAULT,
|
||||
EntryFields.URI to uri.toString(),
|
||||
EntryFields.CONTENT_ID to null,
|
||||
EntryFields.PATH to path,
|
||||
)
|
||||
} else {
|
||||
MediaStoreImageProvider().scanNewPathByMediaStore(context, path, mimeType)
|
||||
|
@ -361,7 +362,7 @@ abstract class ImageProvider {
|
|||
)
|
||||
|
||||
val newFields = scanNewPath(activity, targetPath, exportMimeType)
|
||||
val targetUri = (newFields["uri"] as String).toUri()
|
||||
val targetUri = (newFields[EntryFields.URI] as String).toUri()
|
||||
if (writeMetadata) {
|
||||
copyMetadata(
|
||||
context = activity,
|
||||
|
|
|
@ -598,8 +598,8 @@ class MediaStoreImageProvider : ImageProvider() {
|
|||
}
|
||||
return if (toBin) {
|
||||
hashMapOf(
|
||||
"trashed" to true,
|
||||
"trashPath" to targetPath,
|
||||
EntryFields.TRASHED to true,
|
||||
EntryFields.TRASH_PATH to targetPath,
|
||||
)
|
||||
} else {
|
||||
scanNewPath(activity, targetPath, mimeType)
|
||||
|
@ -912,13 +912,13 @@ class MediaStoreImageProvider : ImageProvider() {
|
|||
val cursor = context.contentResolver.query(uri, projection, null, null, null)
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
val newFields = hashMapOf<String, Any?>(
|
||||
"origin" to SourceEntry.ORIGIN_MEDIA_STORE_CONTENT,
|
||||
"uri" to uri.toString(),
|
||||
"contentId" to uri.tryParseId(),
|
||||
"path" to path,
|
||||
EntryFields.ORIGIN to SourceEntry.ORIGIN_MEDIA_STORE_CONTENT,
|
||||
EntryFields.URI to uri.toString(),
|
||||
EntryFields.CONTENT_ID to uri.tryParseId(),
|
||||
EntryFields.PATH to path,
|
||||
)
|
||||
cursor.getColumnIndex(MediaStore.MediaColumns.DATE_ADDED).let { if (it != -1) newFields["dateAddedSecs"] = cursor.getInt(it) }
|
||||
cursor.getColumnIndex(MediaStore.MediaColumns.DATE_MODIFIED).let { if (it != -1) newFields["dateModifiedSecs"] = cursor.getInt(it) }
|
||||
cursor.getColumnIndex(MediaStore.MediaColumns.DATE_ADDED).let { if (it != -1) newFields[EntryFields.DATE_ADDED_SECS] = cursor.getInt(it) }
|
||||
cursor.getColumnIndex(MediaStore.MediaColumns.DATE_MODIFIED).let { if (it != -1) newFields[EntryFields.DATE_MODIFIED_SECS] = cursor.getInt(it) }
|
||||
cursor.close()
|
||||
return newFields
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.provider.OpenableColumns
|
|||
import android.util.Log
|
||||
import deckers.thibault.aves.metadata.Metadata
|
||||
import deckers.thibault.aves.metadata.metadataextractor.Helper
|
||||
import deckers.thibault.aves.model.EntryFields
|
||||
import deckers.thibault.aves.model.FieldMap
|
||||
import deckers.thibault.aves.model.SourceEntry
|
||||
import deckers.thibault.aves.utils.LogUtils
|
||||
|
@ -43,9 +44,9 @@ open class UnknownContentProvider : ImageProvider() {
|
|||
}
|
||||
|
||||
val fields: FieldMap = hashMapOf(
|
||||
"origin" to SourceEntry.ORIGIN_UNKNOWN_CONTENT,
|
||||
"uri" to uri.toString(),
|
||||
"sourceMimeType" to mimeType,
|
||||
EntryFields.ORIGIN to SourceEntry.ORIGIN_UNKNOWN_CONTENT,
|
||||
EntryFields.URI to uri.toString(),
|
||||
EntryFields.SOURCE_MIME_TYPE to mimeType,
|
||||
)
|
||||
try {
|
||||
// some providers do not provide the mandatory `OpenableColumns`
|
||||
|
@ -53,11 +54,11 @@ open class UnknownContentProvider : ImageProvider() {
|
|||
// e.g. `content://mms/part/[id]` on Android KitKat
|
||||
val cursor = context.contentResolver.query(uri, null, null, null, null)
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME).let { if (it != -1) fields["title"] = cursor.getString(it) }
|
||||
cursor.getColumnIndex(OpenableColumns.SIZE).let { if (it != -1) fields["sizeBytes"] = cursor.getLong(it) }
|
||||
cursor.getColumnIndex(MediaStore.MediaColumns.DATA).let { if (it != -1) fields["path"] = cursor.getString(it) }
|
||||
cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME).let { if (it != -1) fields[EntryFields.TITLE] = cursor.getString(it) }
|
||||
cursor.getColumnIndex(OpenableColumns.SIZE).let { if (it != -1) fields[EntryFields.SIZE_BYTES] = cursor.getLong(it) }
|
||||
cursor.getColumnIndex(MediaStore.MediaColumns.DATA).let { if (it != -1) fields[EntryFields.PATH] = cursor.getString(it) }
|
||||
// mime type fallback if it was not provided and not found via `metadata-extractor`
|
||||
cursor.getColumnIndex(MediaStore.MediaColumns.MIME_TYPE).let { if (it != -1 && mimeType == null) fields["sourceMimeType"] = cursor.getString(it) }
|
||||
cursor.getColumnIndex(MediaStore.MediaColumns.MIME_TYPE).let { if (it != -1 && mimeType == null) fields[EntryFields.SOURCE_MIME_TYPE] = cursor.getString(it) }
|
||||
cursor.close()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
@ -65,7 +66,7 @@ open class UnknownContentProvider : ImageProvider() {
|
|||
return
|
||||
}
|
||||
|
||||
if (fields["sourceMimeType"] == null) {
|
||||
if (fields[EntryFields.SOURCE_MIME_TYPE] == null) {
|
||||
callback.onFailure(Exception("Failed to find MIME type for uri=$uri"))
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue