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 ac1a0669e..e4ee2ee21 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -8,7 +8,7 @@ import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.SORT_DESCENDING import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.extensions.containsNoMedia +import com.simplemobiletools.gallery.extensions.doesParentHaveNoMedia import com.simplemobiletools.gallery.extensions.sumByLong import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.models.Directory @@ -62,7 +62,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va } } - if (File(parentDir).containsNoMedia() || File(parentDir).parentFile?.containsNoMedia() == true || File(parentDir).parentFile?.parentFile?.containsNoMedia() == true) { + if (File(parentDir).doesParentHaveNoMedia()) { dirName += " $hidden" } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/File.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/File.kt index 2f05233c9..df5aaf241 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/File.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/File.kt @@ -4,3 +4,17 @@ import com.simplemobiletools.gallery.helpers.NOMEDIA import java.io.File fun File.containsNoMedia() = isDirectory && File(this, NOMEDIA).exists() + +fun File.doesParentHaveNoMedia(): Boolean { + var curFile = this + while (true) { + if (curFile.containsNoMedia()) { + return true + } + curFile = curFile.parentFile + if (curFile.absolutePath == "/") { + break + } + } + return false +} 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 f223a3b08..d4016c36b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -8,6 +8,7 @@ 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.doesParentHaveNoMedia import com.simplemobiletools.gallery.models.Medium import java.io.File import java.util.LinkedHashMap @@ -244,7 +245,7 @@ class MediaFetcher(val context: Context) { } else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) { var containsNoMediaOrDot = file.containsNoMedia() || path.contains("/.") if (!containsNoMediaOrDot) { - containsNoMediaOrDot = checkParentHasNoMedia(file.parentFile) + containsNoMediaOrDot = file.doesParentHaveNoMedia() } !containsNoMediaOrDot } else { @@ -252,19 +253,6 @@ class MediaFetcher(val context: Context) { } } - 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, includedPaths: MutableSet) = includedPaths.none { path.startsWith(it) } && excludedPaths.any { path.startsWith(it) }