From f6c6b402c6e04e5e19c3e67884eb3b6702f5b936 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 25 Dec 2021 21:02:45 +0100 Subject: [PATCH] properly fetch Favorite file sizes to avoid caching glitches --- app/build.gradle | 2 +- .../gallery/pro/activities/MainActivity.kt | 2 +- .../gallery/pro/helpers/MediaFetcher.kt | 26 ++++++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index bba613d9d..c8538a34c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,7 +78,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:da849e726f' + implementation 'com.github.SimpleMobileTools:Simple-Commons:7e0240b1e3' 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.23' 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 ebc4a0911..8ef303a5b 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 @@ -913,7 +913,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } } - val android11Files = mLastMediaFetcher?.getAndroid11FolderMedia(getImagesOnly, getVideosOnly, favoritePaths) + val android11Files = mLastMediaFetcher?.getAndroid11FolderMedia(getImagesOnly, getVideosOnly, favoritePaths, false) 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 aaa9312e7..5202cb767 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 @@ -42,11 +42,11 @@ class MediaFetcher(val context: Context) { curMedia.addAll(newMedia) } } else { - if (isRPlus() && curPath != FAVORITES && curPath != RECYCLE_BIN) { + if (curPath != FAVORITES && curPath != RECYCLE_BIN && isRPlus()) { if (android11Files?.containsKey(curPath.toLowerCase()) == true) { curMedia.addAll(android11Files[curPath.toLowerCase()]!!) } else if (android11Files == null) { - val files = getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths) + val files = getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, false) if (files.containsKey(curPath.toLowerCase())) { curMedia.addAll(files[curPath.toLowerCase()]!!) } @@ -58,6 +58,19 @@ class MediaFetcher(val context: Context) { curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, getVideoDurations, lastModifieds.clone() as HashMap, dateTakens.clone() as HashMap ) + + if (curPath == FAVORITES && isRPlus()) { + val files = getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, true) + newMedia.forEach { newMedium -> + for ((folder, media) in files) { + media.forEach { medium -> + if (medium.path == newMedium.path) { + newMedium.size = medium.size + } + } + } + } + } curMedia.addAll(newMedia) } } @@ -407,7 +420,10 @@ class MediaFetcher(val context: Context) { } fun getAndroid11FolderMedia( - isPickImage: Boolean, isPickVideo: Boolean, favoritePaths: ArrayList + isPickImage: Boolean, + isPickVideo: Boolean, + favoritePaths: ArrayList, + getFavoritePathsOnly: Boolean ): HashMap> { val media = HashMap>() if (!isRPlus()) { @@ -438,6 +454,10 @@ class MediaFetcher(val context: Context) { val mediaStoreId = cursor.getLongValue(Images.Media._ID) val filename = cursor.getStringValue(Images.Media.DISPLAY_NAME) val path = cursor.getStringValue(Images.Media.DATA) + if (getFavoritePathsOnly && !favoritePaths.contains(path)) { + 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)