take selected file loading priority into consideration at loading files
This commit is contained in:
parent
ec5c902fb7
commit
f4ea041a8b
3 changed files with 19 additions and 11 deletions
|
@ -816,6 +816,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 getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0 || config.fileLoadingPriority == PRIORITY_COMPROMISE
|
||||
val favoritePaths = getFavoritePaths()
|
||||
val dirPathsToRemove = ArrayList<String>()
|
||||
|
||||
|
@ -825,7 +826,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
return
|
||||
}
|
||||
|
||||
val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, favoritePaths, false)
|
||||
val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperFileSize, favoritePaths, false)
|
||||
val newDir = if (curMedia.isEmpty()) {
|
||||
if (directory.path != tempFolderPath) {
|
||||
dirPathsToRemove.add(directory.path)
|
||||
|
@ -898,7 +899,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
|||
return
|
||||
}
|
||||
|
||||
val newMedia = mediaFetcher.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, favoritePaths, false)
|
||||
val newMedia = mediaFetcher.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperFileSize, favoritePaths, false)
|
||||
if (newMedia.isEmpty()) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simplemobiletools.gallery.pro.asynctasks
|
|||
import android.content.Context
|
||||
import android.os.AsyncTask
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
|
||||
import com.simplemobiletools.gallery.pro.extensions.config
|
||||
import com.simplemobiletools.gallery.pro.extensions.getFavoritePaths
|
||||
import com.simplemobiletools.gallery.pro.helpers.*
|
||||
|
@ -18,20 +19,21 @@ 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 != 0
|
||||
val getProperFileSize = context.config.getFileSorting(pathToUse) and SORT_BY_SIZE != 0 || context.config.fileLoadingPriority == PRIORITY_COMPROMISE
|
||||
val favoritePaths = context.getFavoritePaths()
|
||||
val getVideoDurations = context.config.showThumbnailVideoDuration
|
||||
val media = if (showAll) {
|
||||
val foldersToScan = mediaFetcher.getFoldersToScan().filter { it != RECYCLE_BIN && it != FAVORITES }
|
||||
val media = ArrayList<Medium>()
|
||||
foldersToScan.forEach {
|
||||
val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, getProperDateTaken, favoritePaths, getVideoDurations, false)
|
||||
val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, getProperDateTaken, getProperFileSize, favoritePaths, getVideoDurations, false)
|
||||
media.addAll(newMedia)
|
||||
}
|
||||
|
||||
mediaFetcher.sortMedia(media, context.config.getFileSorting(SHOW_ALL))
|
||||
media
|
||||
} else {
|
||||
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths, getVideoDurations)
|
||||
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, getProperFileSize, favoritePaths, getVideoDurations)
|
||||
}
|
||||
return mediaFetcher.groupMedia(media, pathToUse)
|
||||
}
|
||||
|
|
|
@ -17,15 +17,15 @@ import java.util.*
|
|||
class MediaFetcher(val context: Context) {
|
||||
var shouldStop = false
|
||||
|
||||
fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean, getProperDateTaken: Boolean, favoritePaths: ArrayList<String>,
|
||||
getVideoDurations: Boolean, sortMedia: Boolean = true): ArrayList<Medium> {
|
||||
fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean, getProperDateTaken: Boolean, getProperFileSize: Boolean,
|
||||
favoritePaths: ArrayList<String>, getVideoDurations: Boolean, sortMedia: Boolean = true): ArrayList<Medium> {
|
||||
val filterMedia = context.config.filterMedia
|
||||
if (filterMedia == 0) {
|
||||
return ArrayList()
|
||||
}
|
||||
|
||||
val curMedia = ArrayList<Medium>()
|
||||
val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken, favoritePaths, getVideoDurations)
|
||||
val newMedia = getMediaInFolder(curPath, isPickImage, isPickVideo, filterMedia, getProperDateTaken, getProperFileSize, favoritePaths, getVideoDurations)
|
||||
curMedia.addAll(newMedia)
|
||||
|
||||
if (sortMedia) {
|
||||
|
@ -155,7 +155,7 @@ class MediaFetcher(val context: Context) {
|
|||
}
|
||||
|
||||
private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, getProperDateTaken: Boolean,
|
||||
favoritePaths: ArrayList<String>, getVideoDurations: Boolean): ArrayList<Medium> {
|
||||
getProperFileSize: Boolean, favoritePaths: ArrayList<String>, getVideoDurations: Boolean): ArrayList<Medium> {
|
||||
val media = ArrayList<Medium>()
|
||||
|
||||
val isRecycleBin = folder == RECYCLE_BIN
|
||||
|
@ -209,9 +209,14 @@ class MediaFetcher(val context: Context) {
|
|||
if (!showHidden && filename.startsWith('.'))
|
||||
continue
|
||||
|
||||
val size = file.length()
|
||||
if (size <= 0L || (checkFileExistence && !file.exists()))
|
||||
val size = if (getProperFileSize || checkFileExistence) file.length() else 1L
|
||||
if ((getProperFileSize || checkFileExistence) && size <= 0L) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (checkFileExistence && !file.exists()) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (isRecycleBin) {
|
||||
deletedMedia.firstOrNull { it.path == path }?.apply {
|
||||
|
@ -356,7 +361,7 @@ class MediaFetcher(val context: Context) {
|
|||
return if (timestamp.areDigitsOnly()) {
|
||||
val cal = Calendar.getInstance(Locale.ENGLISH)
|
||||
cal.timeInMillis = timestamp.toLong()
|
||||
return DateFormat.format("dd MMM yyyy", cal).toString()
|
||||
DateFormat.format("dd MMM yyyy", cal).toString()
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue