minor
This commit is contained in:
parent
cdfd7808dd
commit
4b4d444884
5 changed files with 83 additions and 56 deletions
|
@ -18,6 +18,7 @@ import deckers.thibault.aves.metadata.xmp.GoogleDeviceContainer
|
|||
import deckers.thibault.aves.metadata.xmp.GoogleXMP
|
||||
import deckers.thibault.aves.metadata.xmp.XMP.getSafeStructField
|
||||
import deckers.thibault.aves.metadata.xmp.XMPPropName
|
||||
import deckers.thibault.aves.model.EntryFields
|
||||
import deckers.thibault.aves.model.FieldMap
|
||||
import deckers.thibault.aves.model.provider.ImageProvider
|
||||
import deckers.thibault.aves.model.provider.ImageProviderFactory.getProvider
|
||||
|
@ -329,8 +330,8 @@ class EmbeddedDataHandler(private val context: Context) : MethodCallHandler {
|
|||
FileProvider.getUriForFile(context, authority, targetFile)
|
||||
}
|
||||
val resultFields: FieldMap = hashMapOf(
|
||||
"uri" to uri.toString(),
|
||||
"mimeType" to mimeType,
|
||||
EntryFields.URI to uri.toString(),
|
||||
EntryFields.MIME_TYPE to mimeType,
|
||||
)
|
||||
if (isImage(mimeType) || isVideo(mimeType)) {
|
||||
val provider = getProvider(context, uri)
|
||||
|
|
|
@ -4,17 +4,17 @@ import android.net.Uri
|
|||
import androidx.core.net.toUri
|
||||
|
||||
class AvesEntry(map: FieldMap) {
|
||||
val uri: Uri = (map["uri"] as String).toUri() // content or file URI
|
||||
val path = map["path"] as String? // best effort to get local path
|
||||
val pageId = map["pageId"] as Int? // null means the main entry
|
||||
val mimeType = map["mimeType"] as String
|
||||
val width = map["width"] as Int
|
||||
val height = map["height"] as Int
|
||||
val rotationDegrees = map["rotationDegrees"] as Int
|
||||
val isFlipped = map["isFlipped"] as Boolean
|
||||
val sizeBytes = toLong(map["sizeBytes"])
|
||||
val trashed = map["trashed"] as Boolean
|
||||
val trashPath = map["trashPath"] as String?
|
||||
val uri: Uri = (map[EntryFields.URI] as String).toUri() // content or file URI
|
||||
val path = map[EntryFields.PATH] as String? // best effort to get local path
|
||||
val pageId = map[EntryFields.PAGE_ID] as Int? // null means the main entry
|
||||
val mimeType = map[EntryFields.MIME_TYPE] as String
|
||||
val width = map[EntryFields.WIDTH] as Int
|
||||
val height = map[EntryFields.HEIGHT] as Int
|
||||
val rotationDegrees = map[EntryFields.ROTATION_DEGREES] as Int
|
||||
val isFlipped = map[EntryFields.IS_FLIPPED] as Boolean
|
||||
val sizeBytes = toLong(map[EntryFields.SIZE_BYTES])
|
||||
val trashed = map[EntryFields.TRASHED] as Boolean
|
||||
val trashPath = map[EntryFields.TRASH_PATH] as String?
|
||||
|
||||
private val isRotated: Boolean
|
||||
get() = rotationDegrees % 180 == 90
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package deckers.thibault.aves.model
|
||||
|
||||
// entry fields exported and imported from/to the platform side
|
||||
object EntryFields {
|
||||
const val ORIGIN = "origin" // int
|
||||
const val URI = "uri" // string
|
||||
const val PATH = "path" // string
|
||||
const val PAGE_ID = "pageId" // int
|
||||
const val SOURCE_MIME_TYPE = "sourceMimeType" // string
|
||||
const val MIME_TYPE = "mimeType" // string
|
||||
const val WIDTH = "width" // int
|
||||
const val HEIGHT = "height" // int
|
||||
const val SOURCE_ROTATION_DEGREES = "sourceRotationDegrees" // int
|
||||
const val ROTATION_DEGREES = "rotationDegrees" // int
|
||||
const val IS_FLIPPED = "isFlipped" // boolean
|
||||
const val SIZE_BYTES = "sizeBytes" // long
|
||||
const val TRASHED = "trashed" // boolean
|
||||
const val TRASH_PATH = "trashPath" // string
|
||||
const val TITLE = "title" // string
|
||||
const val DATE_ADDED_SECS = "dateAddedSecs" // long
|
||||
const val DATE_MODIFIED_SECS = "dateModifiedSecs" // long
|
||||
const val SOURCE_DATE_TAKEN_MILLIS = "sourceDateTakenMillis" // long
|
||||
const val DURATION_MILLIS = "durationMillis" // long
|
||||
const val CONTENT_ID = "contentId" // long
|
||||
}
|
|
@ -55,19 +55,19 @@ class SourceEntry {
|
|||
}
|
||||
|
||||
constructor(map: FieldMap) {
|
||||
origin = map["origin"] as Int
|
||||
uri = (map["uri"] as String).toUri()
|
||||
path = map["path"] as String?
|
||||
sourceMimeType = map["sourceMimeType"] as String
|
||||
width = map["width"] as Int?
|
||||
height = map["height"] as Int?
|
||||
sourceRotationDegrees = map["sourceRotationDegrees"] as Int?
|
||||
sizeBytes = toLong(map["sizeBytes"])
|
||||
title = map["title"] as String?
|
||||
dateAddedSecs = toLong(map["dateAddedSecs"])
|
||||
dateModifiedSecs = toLong(map["dateModifiedSecs"])
|
||||
sourceDateTakenMillis = toLong(map["sourceDateTakenMillis"])
|
||||
durationMillis = toLong(map["durationMillis"])
|
||||
origin = map[EntryFields.ORIGIN] as Int
|
||||
uri = (map[EntryFields.URI] as String).toUri()
|
||||
path = map[EntryFields.PATH] as String?
|
||||
sourceMimeType = map[EntryFields.SOURCE_MIME_TYPE] as String
|
||||
width = map[EntryFields.WIDTH] as Int?
|
||||
height = map[EntryFields.HEIGHT] as Int?
|
||||
sourceRotationDegrees = map[EntryFields.SOURCE_ROTATION_DEGREES] as Int?
|
||||
sizeBytes = toLong(map[EntryFields.SIZE_BYTES])
|
||||
title = map[EntryFields.TITLE] as String?
|
||||
dateAddedSecs = toLong(map[EntryFields.DATE_ADDED_SECS])
|
||||
dateModifiedSecs = toLong(map[EntryFields.DATE_MODIFIED_SECS])
|
||||
sourceDateTakenMillis = toLong(map[EntryFields.SOURCE_DATE_TAKEN_MILLIS])
|
||||
durationMillis = toLong(map[EntryFields.DURATION_MILLIS])
|
||||
}
|
||||
|
||||
fun initFromFile(path: String, title: String, sizeBytes: Long, dateModifiedSecs: Long) {
|
||||
|
@ -79,21 +79,21 @@ class SourceEntry {
|
|||
|
||||
fun toMap(): FieldMap {
|
||||
return hashMapOf(
|
||||
"origin" to origin,
|
||||
"uri" to uri.toString(),
|
||||
"path" to path,
|
||||
"sourceMimeType" to sourceMimeType,
|
||||
"width" to width,
|
||||
"height" to height,
|
||||
"sourceRotationDegrees" to (sourceRotationDegrees ?: 0),
|
||||
"sizeBytes" to sizeBytes,
|
||||
"title" to title,
|
||||
"dateAddedSecs" to dateAddedSecs,
|
||||
"dateModifiedSecs" to dateModifiedSecs,
|
||||
"sourceDateTakenMillis" to sourceDateTakenMillis,
|
||||
"durationMillis" to durationMillis,
|
||||
EntryFields.ORIGIN to origin,
|
||||
EntryFields.URI to uri.toString(),
|
||||
EntryFields.PATH to path,
|
||||
EntryFields.SOURCE_MIME_TYPE to sourceMimeType,
|
||||
EntryFields.WIDTH to width,
|
||||
EntryFields.HEIGHT to height,
|
||||
EntryFields.SOURCE_ROTATION_DEGREES to (sourceRotationDegrees ?: 0),
|
||||
EntryFields.SIZE_BYTES to sizeBytes,
|
||||
EntryFields.TITLE to title,
|
||||
EntryFields.DATE_ADDED_SECS to dateAddedSecs,
|
||||
EntryFields.DATE_MODIFIED_SECS to dateModifiedSecs,
|
||||
EntryFields.SOURCE_DATE_TAKEN_MILLIS to sourceDateTakenMillis,
|
||||
EntryFields.DURATION_MILLIS to durationMillis,
|
||||
// only for map export
|
||||
"contentId" to contentId,
|
||||
EntryFields.CONTENT_ID to contentId,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.commonsware.cwac.document.DocumentFileCompat
|
|||
import deckers.thibault.aves.MainActivity
|
||||
import deckers.thibault.aves.MainActivity.Companion.DELETE_SINGLE_PERMISSION_REQUEST
|
||||
import deckers.thibault.aves.model.AvesEntry
|
||||
import deckers.thibault.aves.model.EntryFields
|
||||
import deckers.thibault.aves.model.FieldMap
|
||||
import deckers.thibault.aves.model.NameConflictStrategy
|
||||
import deckers.thibault.aves.model.SourceEntry
|
||||
|
@ -76,7 +77,7 @@ class MediaStoreImageProvider : ImageProvider() {
|
|||
val parentCheckDirectory = removeTrailingSeparator(directory)
|
||||
handleNew = { entry ->
|
||||
// skip entries in subfolders
|
||||
val path = entry["path"] as String?
|
||||
val path = entry[EntryFields.PATH] as String?
|
||||
if (path != null && File(path).parent == parentCheckDirectory) {
|
||||
handleNewEntry(entry)
|
||||
}
|
||||
|
@ -255,20 +256,20 @@ class MediaStoreImageProvider : ImageProvider() {
|
|||
Log.w(LOG_TAG, "failed to make entry from uri=$itemUri because of null MIME type")
|
||||
} else {
|
||||
var entryMap: FieldMap = hashMapOf(
|
||||
"origin" to SourceEntry.ORIGIN_MEDIA_STORE_CONTENT,
|
||||
"uri" to itemUri.toString(),
|
||||
"path" to cursor.getString(pathColumn),
|
||||
"sourceMimeType" to mimeType,
|
||||
"width" to width,
|
||||
"height" to height,
|
||||
"sourceRotationDegrees" to if (orientationColumn != -1) cursor.getInt(orientationColumn) else 0,
|
||||
"sizeBytes" to cursor.getLong(sizeColumn),
|
||||
"dateAddedSecs" to cursor.getInt(dateAddedColumn),
|
||||
"dateModifiedSecs" to dateModifiedSecs,
|
||||
"sourceDateTakenMillis" to if (dateTakenColumn != -1) cursor.getLong(dateTakenColumn) else null,
|
||||
"durationMillis" to durationMillis,
|
||||
EntryFields.ORIGIN to SourceEntry.ORIGIN_MEDIA_STORE_CONTENT,
|
||||
EntryFields.URI to itemUri.toString(),
|
||||
EntryFields.PATH to cursor.getString(pathColumn),
|
||||
EntryFields.SOURCE_MIME_TYPE to mimeType,
|
||||
EntryFields.WIDTH to width,
|
||||
EntryFields.HEIGHT to height,
|
||||
EntryFields.SOURCE_ROTATION_DEGREES to if (orientationColumn != -1) cursor.getInt(orientationColumn) else 0,
|
||||
EntryFields.SIZE_BYTES to cursor.getLong(sizeColumn),
|
||||
EntryFields.DATE_ADDED_SECS to cursor.getInt(dateAddedColumn),
|
||||
EntryFields.DATE_MODIFIED_SECS to dateModifiedSecs,
|
||||
EntryFields.SOURCE_DATE_TAKEN_MILLIS to if (dateTakenColumn != -1) cursor.getLong(dateTakenColumn) else null,
|
||||
EntryFields.DURATION_MILLIS to durationMillis,
|
||||
// only for map export
|
||||
"contentId" to id,
|
||||
EntryFields.CONTENT_ID to id,
|
||||
)
|
||||
|
||||
if (MimeTypes.isHeic(mimeType)) {
|
||||
|
@ -284,8 +285,8 @@ class MediaStoreImageProvider : ImageProvider() {
|
|||
if (outWidth > 0 && outHeight > 0) {
|
||||
width = outWidth
|
||||
height = outHeight
|
||||
entryMap["width"] = width
|
||||
entryMap["height"] = height
|
||||
entryMap[EntryFields.WIDTH] = width
|
||||
entryMap[EntryFields.HEIGHT] = height
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
|
|
Loading…
Reference in a new issue