get proper file last modified value only when actually needed
This commit is contained in:
parent
6f565f5828
commit
8d5a47ce6c
4 changed files with 33 additions and 13 deletions
|
@ -893,6 +893,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
val tempFolderPath = config.tempFolderPath
|
||||
val isSortingAscending = config.directorySorting and SORT_DESCENDING == 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 favoritePaths = getFavoritePaths()
|
||||
val dirPathsToRemove = ArrayList<String>()
|
||||
|
@ -903,7 +904,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
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()) {
|
||||
if (directory.path != tempFolderPath) {
|
||||
dirPathsToRemove.add(directory.path)
|
||||
|
@ -976,7 +977,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
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()) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.pro.asynctasks
|
|||
|
||||
import android.content.Context
|
||||
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_SIZE
|
||||
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> {
|
||||
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 getProperFileSize = context.config.getFileSorting(pathToUse) and SORT_BY_SIZE != 0
|
||||
val folderGrouping = context.config.getFolderGrouping(pathToUse)
|
||||
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 getVideoDurations = context.config.showThumbnailVideoDuration
|
||||
val media = if (showAll) {
|
||||
val foldersToScan = mediaFetcher.getFoldersToScan().filter { it != RECYCLE_BIN && it != FAVORITES && !context.config.isFolderProtected(it) }
|
||||
val media = ArrayList<Medium>()
|
||||
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)
|
||||
}
|
||||
|
||||
mediaFetcher.sortMedia(media, context.config.getFileSorting(SHOW_ALL))
|
||||
media
|
||||
} 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)
|
||||
}
|
||||
|
|
|
@ -888,9 +888,10 @@ fun Context.updateDirectoryPath(path: String) {
|
|||
val includedFolders = config.includedFolders
|
||||
val isSortingAscending = config.directorySorting and SORT_DESCENDING == 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 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)
|
||||
updateDBDirectory(directory)
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ import java.util.*
|
|||
class MediaFetcher(val context: Context) {
|
||||
var shouldStop = false
|
||||
|
||||
fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean, getProperDateTaken: Boolean, getProperFileSize: Boolean,
|
||||
favoritePaths: ArrayList<String>, getVideoDurations: Boolean, sortMedia: Boolean = true): ArrayList<Medium> {
|
||||
fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean, getProperDateTaken: Boolean, getProperLastModified: Boolean,
|
||||
getProperFileSize: Boolean, favoritePaths: ArrayList<String>, getVideoDurations: Boolean, sortMedia: Boolean = true): ArrayList<Medium> {
|
||||
val filterMedia = context.config.filterMedia
|
||||
if (filterMedia == 0) {
|
||||
return ArrayList()
|
||||
|
@ -34,7 +34,7 @@ class MediaFetcher(val context: Context) {
|
|||
curMedia.addAll(newMedia)
|
||||
}
|
||||
} 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)
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,7 @@ class MediaFetcher(val context: Context) {
|
|||
}
|
||||
|
||||
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 isRecycleBin = folder == RECYCLE_BIN
|
||||
val deletedMedia = if (isRecycleBin) {
|
||||
|
@ -297,12 +297,20 @@ class MediaFetcher(val context: Context) {
|
|||
media.add(this)
|
||||
}
|
||||
} else {
|
||||
val lastModified = file.lastModified()
|
||||
val lastModified = if (getProperLastModified) file.lastModified() else 0L
|
||||
var dateTaken = lastModified
|
||||
val videoDuration = if (getVideoDurations && isVideo) path.getVideoDuration() else 0
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue