From f5eb3c931eca83b9ed2648be30c10b53051205af Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 21 May 2017 20:16:45 +0200 Subject: [PATCH] hide folders whose parent contains .nomedia when appropriate --- .../asynctasks/GetDirectoriesAsynctask.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 67cde8e04..2ba94ceee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -74,12 +74,29 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va return if (isThisOrParentExcluded(path, excludedPaths)) false else if (!config.shouldShowHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) { - !(file.containsNoMedia() || path.contains("/.")) + var containsNoMediaOrDot = file.containsNoMedia() || path.contains("/.") + if (!containsNoMediaOrDot) { + containsNoMediaOrDot = checkParentHasNoMedia(file.parentFile) + } + !containsNoMediaOrDot } else { true } } + private fun checkParentHasNoMedia(file: File): Boolean { + var curFile = file + while (true) { + if (curFile.containsNoMedia()) { + return true + } + curFile = curFile.parentFile + if (curFile.absolutePath == "/") + break + } + return false + } + private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet) = excludedPaths.any { path.startsWith(it) } private fun movePinnedToFront(dirs: ArrayList): ArrayList {