properly filter cached directories by file type shown
This commit is contained in:
parent
7f17aeda71
commit
2eaff8568f
5 changed files with 43 additions and 12 deletions
|
@ -276,13 +276,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
mIsGettingDirs = true
|
mIsGettingDirs = true
|
||||||
if (!mLoadedInitialPhotos) {
|
if (!mLoadedInitialPhotos) {
|
||||||
getCachedDirectories {
|
getCachedDirectories {
|
||||||
val shouldShowHidden = config.shouldShowHidden
|
if (it.isNotEmpty()) {
|
||||||
val excludedPaths = config.excludedFolders
|
gotDirectories(it, true)
|
||||||
val includedPaths = config.includedFolders
|
|
||||||
val dirs = it.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) } as ArrayList<Directory>
|
|
||||||
|
|
||||||
if (dirs.isNotEmpty()) {
|
|
||||||
gotDirectories(dirs, true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,6 +307,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
|
|
||||||
private fun showFilterMediaDialog() {
|
private fun showFilterMediaDialog() {
|
||||||
FilterMediaDialog(this) {
|
FilterMediaDialog(this) {
|
||||||
|
mLoadedInitialPhotos = false
|
||||||
directories_refresh_layout.isRefreshing = true
|
directories_refresh_layout.isRefreshing = true
|
||||||
getDirectories()
|
getDirectories()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,10 @@ import com.simplemobiletools.commons.helpers.sumByLong
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.extensions.checkAppendingHidden
|
import com.simplemobiletools.gallery.extensions.checkAppendingHidden
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
|
import com.simplemobiletools.gallery.helpers.GIFS
|
||||||
|
import com.simplemobiletools.gallery.helpers.IMAGES
|
||||||
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
||||||
|
import com.simplemobiletools.gallery.helpers.VIDEOS
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -55,17 +58,36 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val mediaTypes = getDirMediaTypes(curMedia)
|
||||||
|
|
||||||
val dirName = context.checkAppendingHidden(parentDir, hidden, includedFolders)
|
val dirName = context.checkAppendingHidden(parentDir, hidden, includedFolders)
|
||||||
val lastModified = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified)
|
val lastModified = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.modified, lastItem.modified) else Math.min(firstItem.modified, lastItem.modified)
|
||||||
val dateTaken = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken)
|
val dateTaken = if (config.directorySorting and SORT_DESCENDING > 0) Math.max(firstItem.taken, lastItem.taken) else Math.min(firstItem.taken, lastItem.taken)
|
||||||
val size = curMedia.sumByLong { it.size }
|
val size = curMedia.sumByLong { it.size }
|
||||||
val directory = Directory(null, parentDir, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, context.isPathOnSD(parentDir))
|
val directory = Directory(null, parentDir, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, context.isPathOnSD(parentDir), mediaTypes)
|
||||||
directories.add(directory)
|
directories.add(directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
return directories
|
return directories
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getDirMediaTypes(media: ArrayList<Medium>): Int {
|
||||||
|
var types = 0
|
||||||
|
if (media.any { it.isImage() }) {
|
||||||
|
types += IMAGES
|
||||||
|
}
|
||||||
|
|
||||||
|
if (media.any { it.isVideo() }) {
|
||||||
|
types += VIDEOS
|
||||||
|
}
|
||||||
|
|
||||||
|
if (media.any { it.isGif() }) {
|
||||||
|
types += GIFS
|
||||||
|
}
|
||||||
|
|
||||||
|
return types
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPostExecute(dirs: ArrayList<Directory>) {
|
override fun onPostExecute(dirs: ArrayList<Directory>) {
|
||||||
super.onPostExecute(dirs)
|
super.onPostExecute(dirs)
|
||||||
callback(dirs)
|
callback(dirs)
|
||||||
|
|
|
@ -212,7 +212,7 @@ fun Context.addTempFolderIfNeeded(dirs: ArrayList<Directory>): ArrayList<Directo
|
||||||
val directories = ArrayList<Directory>()
|
val directories = ArrayList<Directory>()
|
||||||
val tempFolderPath = config.tempFolderPath
|
val tempFolderPath = config.tempFolderPath
|
||||||
if (tempFolderPath.isNotEmpty()) {
|
if (tempFolderPath.isNotEmpty()) {
|
||||||
val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, isPathOnSD(tempFolderPath))
|
val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, isPathOnSD(tempFolderPath), 0)
|
||||||
directories.add(newFolder)
|
directories.add(newFolder)
|
||||||
}
|
}
|
||||||
directories.addAll(dirs)
|
directories.addAll(dirs)
|
||||||
|
@ -249,7 +249,19 @@ fun Context.getCachedDirectories(callback: (ArrayList<Directory>) -> Unit) {
|
||||||
Thread {
|
Thread {
|
||||||
val directoryDao = galleryDB.DirectoryDao()
|
val directoryDao = galleryDB.DirectoryDao()
|
||||||
val directories = directoryDao.getAll() as ArrayList<Directory>
|
val directories = directoryDao.getAll() as ArrayList<Directory>
|
||||||
callback(directories)
|
val shouldShowHidden = config.shouldShowHidden
|
||||||
|
val excludedPaths = config.excludedFolders
|
||||||
|
val includedPaths = config.includedFolders
|
||||||
|
var filteredDirectories = directories.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) } as ArrayList<Directory>
|
||||||
|
val filterMedia = config.filterMedia
|
||||||
|
filteredDirectories = filteredDirectories.filter {
|
||||||
|
(filterMedia and IMAGES != 0 && it.types == TYPE_IMAGE) ||
|
||||||
|
(filterMedia and VIDEOS != 0 && it.types == TYPE_VIDEO) ||
|
||||||
|
(filterMedia and GIFS != 0 && it.types == TYPE_GIF)
|
||||||
|
} as ArrayList<Directory>
|
||||||
|
|
||||||
|
callback(filteredDirectories)
|
||||||
|
|
||||||
removeInvalidDirectories(directories, directoryDao)
|
removeInvalidDirectories(directories, directoryDao)
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import com.simplemobiletools.gallery.models.Directory
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface DirectoryDao {
|
interface DirectoryDao {
|
||||||
@Query("SELECT path, thumbnail, filename, media_count, last_modified, date_taken, size, is_on_sd_card FROM directories")
|
@Query("SELECT path, thumbnail, filename, media_count, last_modified, date_taken, size, is_on_sd_card, media_types FROM directories")
|
||||||
fun getAll(): List<Directory>
|
fun getAll(): List<Directory>
|
||||||
|
|
||||||
@Insert(onConflict = REPLACE)
|
@Insert(onConflict = REPLACE)
|
||||||
|
|
|
@ -19,7 +19,8 @@ data class Directory(
|
||||||
@ColumnInfo(name = "last_modified") val modified: Long,
|
@ColumnInfo(name = "last_modified") val modified: Long,
|
||||||
@ColumnInfo(name = "date_taken") val taken: Long,
|
@ColumnInfo(name = "date_taken") val taken: Long,
|
||||||
@ColumnInfo(name = "size") val size: Long,
|
@ColumnInfo(name = "size") val size: Long,
|
||||||
@ColumnInfo(name = "is_on_sd_card") val isOnSDCard: Boolean) : Serializable, Comparable<Directory> {
|
@ColumnInfo(name = "is_on_sd_card") val isOnSDCard: Boolean,
|
||||||
|
@ColumnInfo(name = "media_types") val types: Int) : Serializable, Comparable<Directory> {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val serialVersionUID = -6553345863555455L
|
private const val serialVersionUID = -6553345863555455L
|
||||||
|
|
Loading…
Reference in a new issue