optimize folder visibility checking

This commit is contained in:
tibbi 2019-02-27 19:33:28 +01:00
parent 1daa85e629
commit 633a1af644

View file

@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.pro.extensions
import android.media.MediaMetadataRetriever import android.media.MediaMetadataRetriever
import com.bumptech.glide.signature.ObjectKey import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.gallery.pro.helpers.NOMEDIA
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
@ -17,14 +18,19 @@ fun String.isThisOrParentIncluded(includedPaths: MutableSet<String>) = includedP
fun String.isThisOrParentExcluded(excludedPaths: MutableSet<String>) = excludedPaths.any { startsWith(it, true) } fun String.isThisOrParentExcluded(excludedPaths: MutableSet<String>) = excludedPaths.any { startsWith(it, true) }
fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>, showHidden: Boolean): Boolean { fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>, showHidden: Boolean): Boolean {
if (isEmpty()) {
return false
}
val file = File(this) val file = File(this)
return if (isEmpty()) { if (!showHidden && file.isHidden) {
false return false
} else if (!showHidden && file.isHidden) {
false
} else if (includedPaths.contains(this)) { } else if (includedPaths.contains(this)) {
true return true
} else if (!showHidden && file.containsNoMedia()) { }
val containsNoMedia = if (showHidden) false else File(this, NOMEDIA).exists()
return if (!showHidden && containsNoMedia) {
false false
} else if (excludedPaths.contains(this)) { } else if (excludedPaths.contains(this)) {
false false
@ -33,7 +39,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPath
} else if (isThisOrParentExcluded(excludedPaths)) { } else if (isThisOrParentExcluded(excludedPaths)) {
false false
} else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) { } else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) {
var containsNoMediaOrDot = file.containsNoMedia() || contains("/.") var containsNoMediaOrDot = containsNoMedia || contains("/.")
if (!containsNoMediaOrDot) { if (!containsNoMediaOrDot) {
containsNoMediaOrDot = file.doesThisOrParentHaveNoMedia() containsNoMediaOrDot = file.doesThisOrParentHaveNoMedia()
} }