get proper file Date Taken only when needed

This commit is contained in:
tibbi 2018-05-25 17:40:38 +02:00
parent a03c19172c
commit 17a55bd606
3 changed files with 12 additions and 10 deletions

View file

@ -591,9 +591,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
val isSortingAscending = config.directorySorting and SORT_DESCENDING == 0 val isSortingAscending = config.directorySorting and SORT_DESCENDING == 0
val mediumDao = galleryDB.MediumDao() val mediumDao = galleryDB.MediumDao()
val directoryDao = galleryDB.DirectoryDao() val directoryDao = galleryDB.DirectoryDao()
val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0
for (directory in dirs) { 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()) { val newDir = if (curMedia.isEmpty()) {
directory directory
} else { } else {
@ -634,7 +635,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
} }
for (folder in foldersToScan) { 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()) { if (newMedia.isEmpty()) {
continue continue
} }

View file

@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.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_TAKEN
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.helpers.MediaFetcher
import com.simplemobiletools.gallery.models.Medium 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> { override fun doInBackground(vararg params: Void): ArrayList<Medium> {
val sorting = context.config.getFileSorting(mPath) val sorting = context.config.getFileSorting(mPath)
val getProperDateTaken = sorting and SORT_BY_DATE_TAKEN != 0
return if (showAll) { return if (showAll) {
val foldersToScan = mediaFetcher.getFoldersToScan() val foldersToScan = mediaFetcher.getFoldersToScan()
val media = ArrayList<Medium>() val media = ArrayList<Medium>()
foldersToScan.forEach { foldersToScan.forEach {
val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, sorting) val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, sorting, getProperDateTaken)
media.addAll(newMedia) media.addAll(newMedia)
} }
MediaFetcher(context).sortMedia(media, context.config.getFileSorting("")) MediaFetcher(context).sortMedia(media, context.config.getFileSorting(""))
media media
} else { } else {
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, sorting) mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, sorting, getProperDateTaken)
} }
} }

View file

@ -16,7 +16,7 @@ import java.io.File
class MediaFetcher(val context: Context) { class MediaFetcher(val context: Context) {
var shouldStop = false 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 val filterMedia = context.config.filterMedia
if (filterMedia == 0) { if (filterMedia == 0) {
return ArrayList() return ArrayList()
@ -27,7 +27,7 @@ class MediaFetcher(val context: Context) {
val newMedia = getMediaOnOTG(curPath, isPickImage, isPickVideo, filterMedia) val newMedia = getMediaOnOTG(curPath, isPickImage, isPickVideo, filterMedia)
curMedia.addAll(newMedia) curMedia.addAll(newMedia)
} else { } else {
val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia) val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken)
curMedia.addAll(newMedia) 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 media = ArrayList<Medium>()
val files = File(folder).listFiles() ?: return media val files = File(folder).listFiles() ?: return media
val doExtraCheck = context.config.doExtraCheck val doExtraCheck = context.config.doExtraCheck
val showHidden = context.config.shouldShowHidden val showHidden = context.config.shouldShowHidden
val sorting = context.config.getFileSorting(folder) val dateTakens = if (getProperDateTaken) getFolderDateTakens(folder) else HashMap()
val dateTakens = if (sorting and SORT_BY_DATE_TAKEN != 0) getFolderDateTakens(folder) else HashMap()
for (file in files) { for (file in files) {
if (shouldStop) { if (shouldStop) {
@ -183,7 +182,7 @@ class MediaFetcher(val context: Context) {
val lastModified = file.lastModified() val lastModified = file.lastModified()
var dateTaken = lastModified var dateTaken = lastModified
if (sorting and SORT_BY_DATE_TAKEN != 0) { if (getProperDateTaken) {
dateTaken = dateTakens.remove(filename) ?: lastModified dateTaken = dateTakens.remove(filename) ?: lastModified
} }