diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 4a29e4996..0d6d3b764 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -591,9 +591,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { val isSortingAscending = config.directorySorting and SORT_DESCENDING == 0 val mediumDao = galleryDB.MediumDao() val directoryDao = galleryDB.DirectoryDao() + val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 for (directory in dirs) { - val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, config.directorySorting) + val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, config.directorySorting, getProperDateTaken) val newDir = if (curMedia.isEmpty()) { directory } else { @@ -634,7 +635,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } for (folder in foldersToScan) { - val newMedia = mediaFetcher.getFilesFrom(folder, getImagesOnly, getVideosOnly, config.directorySorting) + val newMedia = mediaFetcher.getFilesFrom(folder, getImagesOnly, getVideosOnly, config.directorySorting, getProperDateTaken) if (newMedia.isEmpty()) { continue } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index bd82fdac3..d7e17dd43 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.asynctasks import android.content.Context import android.os.AsyncTask +import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.models.Medium @@ -14,18 +15,19 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage override fun doInBackground(vararg params: Void): ArrayList { val sorting = context.config.getFileSorting(mPath) + val getProperDateTaken = sorting and SORT_BY_DATE_TAKEN != 0 return if (showAll) { val foldersToScan = mediaFetcher.getFoldersToScan() val media = ArrayList() foldersToScan.forEach { - val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, sorting) + val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, sorting, getProperDateTaken) media.addAll(newMedia) } MediaFetcher(context).sortMedia(media, context.config.getFileSorting("")) media } else { - mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, sorting) + mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, sorting, getProperDateTaken) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index d6b93814e..8221d01ef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -16,7 +16,7 @@ import java.io.File class MediaFetcher(val context: Context) { var shouldStop = false - fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean, sorting: Int): ArrayList { + fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean, sorting: Int, getProperDateTaken: Boolean): ArrayList { val filterMedia = context.config.filterMedia if (filterMedia == 0) { return ArrayList() @@ -27,7 +27,7 @@ class MediaFetcher(val context: Context) { val newMedia = getMediaOnOTG(curPath, isPickImage, isPickVideo, filterMedia) curMedia.addAll(newMedia) } else { - val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia) + val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken) curMedia.addAll(newMedia) } @@ -143,13 +143,12 @@ class MediaFetcher(val context: Context) { } } - private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int): ArrayList { + private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, getProperDateTaken: Boolean): ArrayList { val media = ArrayList() val files = File(folder).listFiles() ?: return media val doExtraCheck = context.config.doExtraCheck val showHidden = context.config.shouldShowHidden - val sorting = context.config.getFileSorting(folder) - val dateTakens = if (sorting and SORT_BY_DATE_TAKEN != 0) getFolderDateTakens(folder) else HashMap() + val dateTakens = if (getProperDateTaken) getFolderDateTakens(folder) else HashMap() for (file in files) { if (shouldStop) { @@ -183,7 +182,7 @@ class MediaFetcher(val context: Context) { val lastModified = file.lastModified() var dateTaken = lastModified - if (sorting and SORT_BY_DATE_TAKEN != 0) { + if (getProperDateTaken) { dateTaken = dateTakens.remove(filename) ?: lastModified }