From e86e6986c0b935d38f0de7bc90a82ac65911d29d Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 14 Jan 2021 11:03:24 +0100 Subject: [PATCH] get MediaStore last modified values in more cases, not just on R+ --- .../gallery/pro/activities/MainActivity.kt | 2 +- .../gallery/pro/asynctasks/GetMediaAsynctask.kt | 2 +- .../gallery/pro/extensions/Context.kt | 2 +- .../gallery/pro/helpers/MediaFetcher.kt | 16 ++++++---------- 4 files changed, 9 insertions(+), 13 deletions(-) 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 9234794c1..282f355a0 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 @@ -936,7 +936,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0 val favoritePaths = getFavoritePaths() val dirPathsToRemove = ArrayList() - val lastModifieds = if (isRPlus()) mLastMediaFetcher!!.getLastModifieds() else HashMap() + val lastModifieds = mLastMediaFetcher!!.getLastModifieds() val dateTakens = mLastMediaFetcher!!.getDateTakens() try { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt index 9817db535..07cfd49f1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt @@ -30,7 +30,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage val getProperFileSize = fileSorting and SORT_BY_SIZE != 0 val favoritePaths = context.getFavoritePaths() val getVideoDurations = context.config.showThumbnailVideoDuration - val lastModifieds = if (isRPlus() && getProperLastModified) mediaFetcher.getLastModifieds() else HashMap() + val lastModifieds = if (getProperLastModified) mediaFetcher.getLastModifieds() else HashMap() val dateTakens = if (getProperDateTaken) mediaFetcher.getDateTakens() else HashMap() val media = if (showAll) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index 099c80e3a..5adeba44e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -931,7 +931,7 @@ fun Context.updateDirectoryPath(path: String) { val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0 - val lastModifieds = if (isRPlus() && getProperLastModified) mediaFetcher.getFolderLastModifieds(path) else HashMap() + val lastModifieds = if (getProperLastModified) mediaFetcher.getFolderLastModifieds(path) else HashMap() val dateTakens = mediaFetcher.getFolderDateTakens(path) val favoritePaths = getFavoritePaths() val curMedia = mediaFetcher.getFilesFrom(path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, getProperFileSize, 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 4c4daa180..00fda35a9 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 @@ -321,15 +321,11 @@ class MediaFetcher(val context: Context) { } else { var lastModified = 0L if (getProperLastModified) { - if (isRPlus()) { - var newLastModified = lastModifieds.remove(path) - if (newLastModified == null) { - newLastModified = file.lastModified() - } - lastModified = newLastModified - } else { - lastModified = file.lastModified() + var newLastModified = lastModifieds.remove(path) + if (newLastModified == null) { + newLastModified = file.lastModified() } + lastModified = newLastModified } var dateTaken = lastModified @@ -590,7 +586,7 @@ class MediaFetcher(val context: Context) { return } - media.sortWith(Comparator { o1, o2 -> + media.sortWith { o1, o2 -> o1 as Medium o2 as Medium var result = when { @@ -617,7 +613,7 @@ class MediaFetcher(val context: Context) { result *= -1 } result - }) + } } fun groupMedia(media: ArrayList, path: String): ArrayList {