From c2741f6dcb8e4288f6eeedcd7f85250717c1aae1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 13 Jan 2017 23:52:04 +0100 Subject: [PATCH] move folder filtering to getParents() --- .../asynctasks/GetDirectoriesAsynctask.kt | 26 ---------------- .../gallery/extensions/context.kt | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 788067499..d19cdc9ee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -26,7 +26,6 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va val showMedia = config.showMedia val fileSorting = config.fileSorting val parents = context.getParents(isPickImage, isPickVideo) - filterDirectories(parents) parents.mapNotNull { File(it).listFiles() } .forEach { @@ -96,30 +95,5 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va callback.invoke(dirs) } - private fun filterDirectories(dirs: MutableList) { - if (!config.showHiddenFolders) { - removeHiddenFolders(dirs) - removeNoMediaFolders(dirs) - } - } - private fun removeHiddenFolders(paths: MutableList) { - val hiddenPaths = config.hiddenFolders - val ignorePaths = paths.filter { hiddenPaths.contains(it) } - paths.removeAll(ignorePaths) - } - - private fun removeNoMediaFolders(paths: MutableList) { - val ignorePaths = ArrayList() - 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) - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index 52cc053e4..0dfc9826f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -61,6 +61,8 @@ fun Context.getParents(isPickImage: Boolean, isPickVideo: Boolean): ArrayList { } } +fun Context.filterDirectories(dirs: MutableList) { + if (!config.showHiddenFolders) { + removeHiddenFolders(dirs) + removeNoMediaFolders(dirs) + } +} + +fun Context.removeHiddenFolders(paths: MutableList) { + val hiddenPaths = config.hiddenFolders + val ignorePaths = paths.filter { hiddenPaths.contains(it) } + paths.removeAll(ignorePaths) +} + +private fun removeNoMediaFolders(paths: MutableList) { + val ignorePaths = ArrayList() + 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) +