filter out hidden folders asap, if appropriate

This commit is contained in:
tibbi 2017-01-13 23:49:56 +01:00
parent 289e82cc1e
commit a48358bef3

View file

@ -26,6 +26,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
val showMedia = config.showMedia val showMedia = config.showMedia
val fileSorting = config.fileSorting val fileSorting = config.fileSorting
val parents = context.getParents(isPickImage, isPickVideo) val parents = context.getParents(isPickImage, isPickVideo)
filterDirectories(parents)
parents.mapNotNull { File(it).listFiles() } parents.mapNotNull { File(it).listFiles() }
.forEach { .forEach {
@ -74,8 +75,6 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
} }
val dirs = ArrayList(directories.values.filter { File(it.path).exists() }) val dirs = ArrayList(directories.values.filter { File(it.path).exists() })
filterDirectories(dirs)
Directory.sorting = config.directorySorting Directory.sorting = config.directorySorting
dirs.sort() dirs.sort()
@ -97,30 +96,30 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
callback.invoke(dirs) callback.invoke(dirs)
} }
private fun filterDirectories(dirs: MutableList<Directory>) { private fun filterDirectories(dirs: MutableList<String>) {
if (!config.showHiddenFolders) { if (!config.showHiddenFolders) {
removeHiddenFolders(dirs) removeHiddenFolders(dirs)
removeNoMediaFolders(dirs) removeNoMediaFolders(dirs)
} }
} }
private fun removeHiddenFolders(dirs: MutableList<Directory>) { private fun removeHiddenFolders(paths: MutableList<String>) {
val hiddenDirs = config.hiddenFolders val hiddenPaths = config.hiddenFolders
val ignoreDirs = dirs.filter { hiddenDirs.contains(it.path) } val ignorePaths = paths.filter { hiddenPaths.contains(it) }
dirs.removeAll(ignoreDirs) paths.removeAll(ignorePaths)
} }
private fun removeNoMediaFolders(dirs: MutableList<Directory>) { private fun removeNoMediaFolders(paths: MutableList<String>) {
val ignoreDirs = ArrayList<Directory>() val ignorePaths = ArrayList<String>()
for (d in dirs) { for (path in paths) {
val dir = File(d.path) val dir = File(path)
if (dir.exists() && dir.isDirectory) { if (dir.exists() && dir.isDirectory) {
val res = dir.list { file, filename -> filename == ".nomedia" } val res = dir.list { file, filename -> filename == ".nomedia" }
if (res?.isNotEmpty() == true) if (res?.isNotEmpty() == true)
ignoreDirs.add(d) ignorePaths.add(path)
} }
} }
dirs.removeAll(ignoreDirs) paths.removeAll(ignorePaths)
} }
} }