mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
fix #319, show a folder if its both excluded and included
This commit is contained in:
parent
9398c9be76
commit
bd03e4a176
2 changed files with 17 additions and 7 deletions
|
@ -27,8 +27,11 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
|
|
||||||
val media = context.getFilesFrom("", isPickImage, isPickVideo)
|
val media = context.getFilesFrom("", isPickImage, isPickVideo)
|
||||||
val excludedPaths = config.excludedFolders
|
val excludedPaths = config.excludedFolders
|
||||||
|
val includedPaths = config.includedFolders
|
||||||
val directories = groupDirectories(media)
|
val directories = groupDirectories(media)
|
||||||
val dirs = ArrayList(directories.values.filter { File(it.path).exists() }).filter { shouldFolderBeVisible(it.path, excludedPaths) } as ArrayList<Directory>
|
val dirs = ArrayList(directories.values
|
||||||
|
.filter { File(it.path).exists() })
|
||||||
|
.filter { shouldFolderBeVisible(it.path, excludedPaths, includedPaths) } as ArrayList<Directory>
|
||||||
Directory.sorting = config.directorySorting
|
Directory.sorting = config.directorySorting
|
||||||
dirs.sort()
|
dirs.sort()
|
||||||
return movePinnedToFront(dirs)
|
return movePinnedToFront(dirs)
|
||||||
|
@ -77,11 +80,11 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
return directories
|
return directories
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun shouldFolderBeVisible(path: String, excludedPaths: MutableSet<String>): Boolean {
|
private fun shouldFolderBeVisible(path: String, excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>): Boolean {
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
return if (isThisOrParentExcluded(path, excludedPaths))
|
return if (isThisOrParentExcluded(path, excludedPaths, includedPaths)) {
|
||||||
false
|
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("/.")
|
var containsNoMediaOrDot = file.containsNoMedia() || path.contains("/.")
|
||||||
if (!containsNoMediaOrDot) {
|
if (!containsNoMediaOrDot) {
|
||||||
containsNoMediaOrDot = checkParentHasNoMedia(file.parentFile)
|
containsNoMediaOrDot = checkParentHasNoMedia(file.parentFile)
|
||||||
|
@ -105,7 +108,8 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet<String>) = excludedPaths.any { path.startsWith(it) }
|
private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>) =
|
||||||
|
includedPaths.none { path.startsWith(it) } && excludedPaths.any { path.startsWith(it) }
|
||||||
|
|
||||||
private fun movePinnedToFront(dirs: ArrayList<Directory>): ArrayList<Directory> {
|
private fun movePinnedToFront(dirs: ArrayList<Directory>): ArrayList<Directory> {
|
||||||
val foundFolders = ArrayList<Directory>()
|
val foundFolders = ArrayList<Directory>()
|
||||||
|
|
|
@ -75,6 +75,7 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
|
||||||
val config = context.config
|
val config = context.config
|
||||||
val showMedia = config.showMedia
|
val showMedia = config.showMedia
|
||||||
val showHidden = config.shouldShowHidden
|
val showHidden = config.shouldShowHidden
|
||||||
|
val includedFolders = config.includedFolders
|
||||||
val excludedFolders = config.excludedFolders
|
val excludedFolders = config.excludedFolders
|
||||||
val noMediaFolders = context.getNoMediaFolders()
|
val noMediaFolders = context.getNoMediaFolders()
|
||||||
|
|
||||||
|
@ -113,14 +114,19 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
|
||||||
|
|
||||||
var isExcluded = false
|
var isExcluded = false
|
||||||
excludedFolders.forEach {
|
excludedFolders.forEach {
|
||||||
if (path.startsWith(it)) {
|
if (path.startsWith("$it/")) {
|
||||||
isExcluded = true
|
isExcluded = true
|
||||||
|
includedFolders.forEach {
|
||||||
|
if (path.startsWith("$it/")) {
|
||||||
|
isExcluded = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isExcluded && !showHidden) {
|
if (!isExcluded && !showHidden) {
|
||||||
noMediaFolders.forEach {
|
noMediaFolders.forEach {
|
||||||
if (path.startsWith(it)) {
|
if (path.startsWith("$it/")) {
|
||||||
isExcluded = true
|
isExcluded = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue