From d2a6d2cb88a1c16d648ee83592748a615445d7b8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 9 Apr 2018 21:51:28 +0200 Subject: [PATCH] properly make the Included folders check recursive --- .../simplemobiletools/gallery/extensions/Context.kt | 2 +- .../simplemobiletools/gallery/extensions/String.kt | 4 ++++ .../gallery/helpers/MediaFetcher.kt | 13 +++---------- 3 files changed, 8 insertions(+), 11 deletions(-) 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 be2eaed6b..66a7fbde5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -178,7 +178,7 @@ fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: } } - return if (File(path).doesThisOrParentHaveNoMedia() && !includedFolders.contains(path)) { + return if (File(path).doesThisOrParentHaveNoMedia() && !path.isThisOrParentIncluded(includedFolders)) { "$dirName $hidden" } else { dirName diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt index 47837c672..692256eec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt @@ -4,3 +4,7 @@ import com.bumptech.glide.signature.ObjectKey import java.io.File fun String.getFileSignature() = ObjectKey(File(this).lastModified().toString()) + +fun String.isThisOrParentIncluded(includedPaths: MutableSet) = includedPaths.any { startsWith(it, true) } + +fun String.isThisOrParentExcluded(excludedPaths: MutableSet) = excludedPaths.any { startsWith(it, true) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 196da0e6b..ce7d75453 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -7,10 +7,7 @@ import android.os.Environment import android.provider.MediaStore import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* -import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.extensions.containsNoMedia -import com.simplemobiletools.gallery.extensions.doesThisOrParentHaveNoMedia -import com.simplemobiletools.gallery.extensions.isPathInMediaStore +import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.models.Medium import java.io.File import java.util.LinkedHashMap @@ -246,9 +243,9 @@ class MediaFetcher(val context: Context) { private fun shouldFolderBeVisible(path: String, excludedPaths: MutableSet, includedPaths: MutableSet, showHidden: Boolean): Boolean { val file = File(path) - return if (includedPaths.contains(path)) { + return if (path.isThisOrParentIncluded(includedPaths)) { true - } else if (isThisOrParentExcluded(path, excludedPaths, includedPaths)) { + } else if (path.isThisOrParentExcluded(excludedPaths)) { false } else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) { var containsNoMediaOrDot = file.containsNoMedia() || path.contains("/.") @@ -261,9 +258,6 @@ class MediaFetcher(val context: Context) { } } - private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet, includedPaths: MutableSet) = - includedPaths.none { path.startsWith(it, true) } && excludedPaths.any { path.startsWith(it, true) } - private fun getMediaInFolder(folder: String, curMedia: ArrayList, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, allowRecursion: Boolean) { val files = File(folder).listFiles() ?: return for (file in files) { @@ -310,7 +304,6 @@ class MediaFetcher(val context: Context) { val isAlreadyAdded = curMedia.any { it.path == file.absolutePath } if (!isAlreadyAdded) { curMedia.add(medium) - //context.scanPath(file.absolutePath) } } }