get proper file last modified value only when actually needed

This commit is contained in:
tibbi 2020-02-10 11:10:46 +01:00
parent 6f565f5828
commit 8d5a47ce6c
4 changed files with 33 additions and 13 deletions

View file

@ -893,6 +893,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
val tempFolderPath = config.tempFolderPath val tempFolderPath = config.tempFolderPath
val isSortingAscending = config.directorySorting and SORT_DESCENDING == 0 val isSortingAscending = config.directorySorting and SORT_DESCENDING == 0
val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0
val getProperLastModified = config.directorySorting and SORT_BY_DATE_MODIFIED != 0
val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0 val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0
val favoritePaths = getFavoritePaths() val favoritePaths = getFavoritePaths()
val dirPathsToRemove = ArrayList<String>() val dirPathsToRemove = ArrayList<String>()
@ -903,7 +904,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
return return
} }
val curMedia = mLastMediaFetcher!!.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperFileSize, favoritePaths, false) val curMedia = mLastMediaFetcher!!.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, false)
val newDir = if (curMedia.isEmpty()) { val newDir = if (curMedia.isEmpty()) {
if (directory.path != tempFolderPath) { if (directory.path != tempFolderPath) {
dirPathsToRemove.add(directory.path) dirPathsToRemove.add(directory.path)
@ -976,7 +977,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
return return
} }
val newMedia = mLastMediaFetcher!!.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperFileSize, favoritePaths, false) val newMedia = mLastMediaFetcher!!.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, false)
if (newMedia.isEmpty()) { if (newMedia.isEmpty()) {
continue continue
} }

View file

@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.pro.asynctasks
import android.content.Context import android.content.Context
import android.os.AsyncTask import android.os.AsyncTask
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
import com.simplemobiletools.gallery.pro.extensions.config import com.simplemobiletools.gallery.pro.extensions.config
@ -18,22 +19,31 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
override fun doInBackground(vararg params: Void): ArrayList<ThumbnailItem> { override fun doInBackground(vararg params: Void): ArrayList<ThumbnailItem> {
val pathToUse = if (showAll) SHOW_ALL else mPath val pathToUse = if (showAll) SHOW_ALL else mPath
val getProperDateTaken = context.config.getFileSorting(pathToUse) and SORT_BY_DATE_TAKEN != 0 || context.config.getFolderGrouping(pathToUse) and GROUP_BY_DATE_TAKEN_DAILY != 0 val folderGrouping = context.config.getFolderGrouping(pathToUse)
val getProperFileSize = context.config.getFileSorting(pathToUse) and SORT_BY_SIZE != 0 val fileSorting = context.config.getFileSorting(pathToUse)
val getProperDateTaken = fileSorting and SORT_BY_DATE_TAKEN != 0 ||
folderGrouping and GROUP_BY_DATE_TAKEN_DAILY != 0 ||
folderGrouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0
val getProperLastModified = fileSorting and SORT_BY_DATE_MODIFIED != 0 ||
folderGrouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 ||
folderGrouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0
val getProperFileSize = fileSorting and SORT_BY_SIZE != 0
val favoritePaths = context.getFavoritePaths() val favoritePaths = context.getFavoritePaths()
val getVideoDurations = context.config.showThumbnailVideoDuration val getVideoDurations = context.config.showThumbnailVideoDuration
val media = if (showAll) { val media = if (showAll) {
val foldersToScan = mediaFetcher.getFoldersToScan().filter { it != RECYCLE_BIN && it != FAVORITES && !context.config.isFolderProtected(it) } val foldersToScan = mediaFetcher.getFoldersToScan().filter { it != RECYCLE_BIN && it != FAVORITES && !context.config.isFolderProtected(it) }
val media = ArrayList<Medium>() val media = ArrayList<Medium>()
foldersToScan.forEach { foldersToScan.forEach {
val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, getProperDateTaken, getProperFileSize, favoritePaths, getVideoDurations, false) val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, getVideoDurations, false)
media.addAll(newMedia) media.addAll(newMedia)
} }
mediaFetcher.sortMedia(media, context.config.getFileSorting(SHOW_ALL)) mediaFetcher.sortMedia(media, context.config.getFileSorting(SHOW_ALL))
media media
} else { } else {
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, getProperFileSize, favoritePaths, getVideoDurations) mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, getVideoDurations)
} }
return mediaFetcher.groupMedia(media, pathToUse) return mediaFetcher.groupMedia(media, pathToUse)
} }

View file

@ -888,9 +888,10 @@ fun Context.updateDirectoryPath(path: String) {
val includedFolders = config.includedFolders val includedFolders = config.includedFolders
val isSortingAscending = config.directorySorting and SORT_DESCENDING == 0 val isSortingAscending = config.directorySorting and SORT_DESCENDING == 0
val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0
val getProperLastModified = config.directorySorting and SORT_BY_DATE_MODIFIED != 0
val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0 val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0
val favoritePaths = getFavoritePaths() val favoritePaths = getFavoritePaths()
val curMedia = mediaFetcher.getFilesFrom(path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperFileSize, favoritePaths, false) val curMedia = mediaFetcher.getFilesFrom(path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, false)
val directory = createDirectoryFromMedia(path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending, getProperFileSize) val directory = createDirectoryFromMedia(path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending, getProperFileSize)
updateDBDirectory(directory) updateDBDirectory(directory)
} }

View file

@ -20,8 +20,8 @@ import java.util.*
class MediaFetcher(val context: Context) { class MediaFetcher(val context: Context) {
var shouldStop = false var shouldStop = false
fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean, getProperDateTaken: Boolean, getProperFileSize: Boolean, fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean, getProperDateTaken: Boolean, getProperLastModified: Boolean,
favoritePaths: ArrayList<String>, getVideoDurations: Boolean, sortMedia: Boolean = true): ArrayList<Medium> { getProperFileSize: Boolean, favoritePaths: ArrayList<String>, getVideoDurations: Boolean, sortMedia: Boolean = true): ArrayList<Medium> {
val filterMedia = context.config.filterMedia val filterMedia = context.config.filterMedia
if (filterMedia == 0) { if (filterMedia == 0) {
return ArrayList() return ArrayList()
@ -34,7 +34,7 @@ class MediaFetcher(val context: Context) {
curMedia.addAll(newMedia) curMedia.addAll(newMedia)
} }
} else { } else {
val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken, getProperFileSize, favoritePaths, getVideoDurations) val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths, getVideoDurations)
curMedia.addAll(newMedia) curMedia.addAll(newMedia)
} }
@ -212,7 +212,7 @@ class MediaFetcher(val context: Context) {
} }
private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, getProperDateTaken: Boolean, private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, getProperDateTaken: Boolean,
getProperFileSize: Boolean, favoritePaths: ArrayList<String>, getVideoDurations: Boolean): ArrayList<Medium> { getProperLastModified: Boolean, getProperFileSize: Boolean, favoritePaths: ArrayList<String>, getVideoDurations: Boolean): ArrayList<Medium> {
val media = ArrayList<Medium>() val media = ArrayList<Medium>()
val isRecycleBin = folder == RECYCLE_BIN val isRecycleBin = folder == RECYCLE_BIN
val deletedMedia = if (isRecycleBin) { val deletedMedia = if (isRecycleBin) {
@ -297,12 +297,20 @@ class MediaFetcher(val context: Context) {
media.add(this) media.add(this)
} }
} else { } else {
val lastModified = file.lastModified() val lastModified = if (getProperLastModified) file.lastModified() else 0L
var dateTaken = lastModified var dateTaken = lastModified
val videoDuration = if (getVideoDurations && isVideo) path.getVideoDuration() else 0 val videoDuration = if (getVideoDurations && isVideo) path.getVideoDuration() else 0
if (getProperDateTaken) { if (getProperDateTaken) {
dateTaken = dateTakens.remove(path) ?: lastModified var newDateTaken = dateTakens.remove(path)
if (newDateTaken == null) {
newDateTaken = if (getProperLastModified) {
lastModified
} else {
file.lastModified()
}
}
dateTaken = newDateTaken
} }
val type = when { val type = when {