mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 13:08:00 +01:00
get proper file Date Taken only when needed
This commit is contained in:
parent
a03c19172c
commit
17a55bd606
3 changed files with 12 additions and 10 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<Medium> {
|
||||
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<Medium>()
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Medium> {
|
||||
fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean, sorting: Int, getProperDateTaken: Boolean): ArrayList<Medium> {
|
||||
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<Medium> {
|
||||
private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, getProperDateTaken: Boolean): ArrayList<Medium> {
|
||||
val media = ArrayList<Medium>()
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue