mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 13:08:00 +01:00
filter out hidden folders asap, if appropriate
This commit is contained in:
parent
289e82cc1e
commit
a48358bef3
1 changed files with 12 additions and 13 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue