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 db9845f72..ebc8182f0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -27,8 +27,11 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va val media = context.getFilesFrom("", isPickImage, isPickVideo) val excludedPaths = config.excludedFolders + val includedPaths = config.includedFolders val directories = groupDirectories(media) - val dirs = ArrayList(directories.values.filter { File(it.path).exists() }).filter { shouldFolderBeVisible(it.path, excludedPaths) } as ArrayList + val dirs = ArrayList(directories.values + .filter { File(it.path).exists() }) + .filter { shouldFolderBeVisible(it.path, excludedPaths, includedPaths) } as ArrayList Directory.sorting = config.directorySorting dirs.sort() return movePinnedToFront(dirs) @@ -77,11 +80,11 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va return directories } - private fun shouldFolderBeVisible(path: String, excludedPaths: MutableSet): Boolean { + private fun shouldFolderBeVisible(path: String, excludedPaths: MutableSet, includedPaths: MutableSet): Boolean { val file = File(path) - return if (isThisOrParentExcluded(path, excludedPaths)) + return if (isThisOrParentExcluded(path, excludedPaths, includedPaths)) { false - else if (!config.shouldShowHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) { + } else if (!config.shouldShowHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) { var containsNoMediaOrDot = file.containsNoMedia() || path.contains("/.") if (!containsNoMediaOrDot) { containsNoMediaOrDot = checkParentHasNoMedia(file.parentFile) @@ -105,7 +108,8 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va return false } - private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet) = excludedPaths.any { path.startsWith(it) } + private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet, includedPaths: MutableSet) = + includedPaths.none { path.startsWith(it) } && excludedPaths.any { path.startsWith(it) } private fun movePinnedToFront(dirs: ArrayList): ArrayList { val foundFolders = ArrayList() 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 f13a021d3..1f57f026c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -75,6 +75,7 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP val config = context.config val showMedia = config.showMedia val showHidden = config.shouldShowHidden + val includedFolders = config.includedFolders val excludedFolders = config.excludedFolders val noMediaFolders = context.getNoMediaFolders() @@ -113,14 +114,19 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP var isExcluded = false excludedFolders.forEach { - if (path.startsWith(it)) { + if (path.startsWith("$it/")) { isExcluded = true + includedFolders.forEach { + if (path.startsWith("$it/")) { + isExcluded = false + } + } } } if (!isExcluded && !showHidden) { noMediaFolders.forEach { - if (path.startsWith(it)) { + if (path.startsWith("$it/")) { isExcluded = true } }