From b2130669abae38b2a3b0d7d2fd6cff8619076f4c Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 3 May 2022 10:14:18 +0200 Subject: [PATCH] use "Fix Date Taken values" on Android 11+ file fetching --- app/build.gradle | 2 +- .../gallery/pro/activities/MainActivity.kt | 2 +- .../gallery/pro/helpers/MediaFetcher.kt | 23 ++++++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5e64a9d07..7123bcdc8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -77,7 +77,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:e8ad6a9128' + implementation 'com.github.SimpleMobileTools:Simple-Commons:b9178c4702' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 92fec6d91..2b535ccd8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -929,7 +929,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } } - val android11Files = mLastMediaFetcher?.getAndroid11FolderMedia(getImagesOnly, getVideosOnly, favoritePaths, false) + val android11Files = mLastMediaFetcher?.getAndroid11FolderMedia(getImagesOnly, getVideosOnly, favoritePaths, false, true, dateTakens) try { for (directory in dirs) { if (mShouldStopFetching || isDestroyed || isFinishing) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt index f27dc0005..f2cf702a8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt @@ -46,7 +46,7 @@ class MediaFetcher(val context: Context) { if (android11Files?.containsKey(curPath.toLowerCase()) == true) { curMedia.addAll(android11Files[curPath.toLowerCase()]!!) } else if (android11Files == null) { - val files = getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, false) + val files = getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, false, getProperDateTaken, dateTakens) if (files.containsKey(curPath.toLowerCase())) { curMedia.addAll(files[curPath.toLowerCase()]!!) } @@ -60,7 +60,8 @@ class MediaFetcher(val context: Context) { ) if (curPath == FAVORITES && isRPlus()) { - val files = getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, true) + val files = + getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, true, getProperDateTaken, dateTakens.clone() as HashMap) newMedia.forEach { newMedium -> for ((folder, media) in files) { media.forEach { medium -> @@ -423,7 +424,9 @@ class MediaFetcher(val context: Context) { isPickImage: Boolean, isPickVideo: Boolean, favoritePaths: ArrayList, - getFavoritePathsOnly: Boolean + getFavoritePathsOnly: Boolean, + getProperDateTaken: Boolean, + dateTakens: HashMap ): HashMap> { val media = HashMap>() if (!isRPlus()) { @@ -458,11 +461,6 @@ class MediaFetcher(val context: Context) { return@queryCursor } - val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000 - var dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN) - val size = cursor.getLongValue(Images.Media.SIZE) - val videoDuration = Math.round(cursor.getIntValue(MediaStore.MediaColumns.DURATION) / 1000.toDouble()).toInt() - val isPortrait = false val isImage = path.isImageFast() val isVideo = if (isImage) false else path.isVideoFast() @@ -492,6 +490,7 @@ class MediaFetcher(val context: Context) { if (!showHidden && filename.startsWith('.')) return@queryCursor + val size = cursor.getLongValue(Images.Media.SIZE) if (size <= 0L) { return@queryCursor } @@ -505,10 +504,18 @@ class MediaFetcher(val context: Context) { else -> TYPE_IMAGES } + val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000 + var dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN) + + if (getProperDateTaken) { + dateTaken = dateTakens.remove(path) ?: lastModified + } + if (dateTaken == 0L) { dateTaken = lastModified } + val videoDuration = Math.round(cursor.getIntValue(MediaStore.MediaColumns.DURATION) / 1000.toDouble()).toInt() val isFavorite = favoritePaths.contains(path) val medium = Medium(null, filename, path, path.getParentPath(), lastModified, dateTaken, size, type, videoDuration, isFavorite, 0L, mediaStoreId)