mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-18 06:17:59 +01:00
move folder filtering to getParents()
This commit is contained in:
parent
a48358bef3
commit
c2741f6dcb
2 changed files with 30 additions and 26 deletions
|
@ -26,7 +26,6 @@ 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 {
|
||||||
|
@ -96,30 +95,5 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
callback.invoke(dirs)
|
callback.invoke(dirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun filterDirectories(dirs: MutableList<String>) {
|
|
||||||
if (!config.showHiddenFolders) {
|
|
||||||
removeHiddenFolders(dirs)
|
|
||||||
removeNoMediaFolders(dirs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun removeHiddenFolders(paths: MutableList<String>) {
|
|
||||||
val hiddenPaths = config.hiddenFolders
|
|
||||||
val ignorePaths = paths.filter { hiddenPaths.contains(it) }
|
|
||||||
paths.removeAll(ignorePaths)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun removeNoMediaFolders(paths: MutableList<String>) {
|
|
||||||
val ignorePaths = ArrayList<String>()
|
|
||||||
for (path in paths) {
|
|
||||||
val dir = File(path)
|
|
||||||
if (dir.exists() && dir.isDirectory) {
|
|
||||||
val res = dir.list { file, filename -> filename == ".nomedia" }
|
|
||||||
if (res?.isNotEmpty() == true)
|
|
||||||
ignorePaths.add(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
paths.removeAll(ignorePaths)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,8 @@ fun Context.getParents(isPickImage: Boolean, isPickVideo: Boolean): ArrayList<St
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filterDirectories(parents)
|
||||||
return parents
|
return parents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,4 +86,32 @@ fun Context.getArgs(isPickImage: Boolean, isPickVideo: Boolean): Array<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.filterDirectories(dirs: MutableList<String>) {
|
||||||
|
if (!config.showHiddenFolders) {
|
||||||
|
removeHiddenFolders(dirs)
|
||||||
|
removeNoMediaFolders(dirs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.removeHiddenFolders(paths: MutableList<String>) {
|
||||||
|
val hiddenPaths = config.hiddenFolders
|
||||||
|
val ignorePaths = paths.filter { hiddenPaths.contains(it) }
|
||||||
|
paths.removeAll(ignorePaths)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun removeNoMediaFolders(paths: MutableList<String>) {
|
||||||
|
val ignorePaths = ArrayList<String>()
|
||||||
|
for (path in paths) {
|
||||||
|
val dir = File(path)
|
||||||
|
if (dir.exists() && dir.isDirectory) {
|
||||||
|
val res = dir.list { file, filename -> filename == ".nomedia" }
|
||||||
|
if (res?.isNotEmpty() == true)
|
||||||
|
ignorePaths.add(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
paths.removeAll(ignorePaths)
|
||||||
|
}
|
||||||
|
|
||||||
val Context.config: Config get() = Config.newInstance(this)
|
val Context.config: Config get() = Config.newInstance(this)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue