From 633a1af644a4d6a46c99947c41d6a11dc1599fd6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Feb 2019 19:33:28 +0100 Subject: [PATCH] optimize folder visibility checking --- .../gallery/pro/extensions/String.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt index 70dfafa0d..e07e80657 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/String.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.pro.extensions import android.media.MediaMetadataRetriever import com.bumptech.glide.signature.ObjectKey +import com.simplemobiletools.gallery.pro.helpers.NOMEDIA import java.io.File import java.io.IOException @@ -17,14 +18,19 @@ fun String.isThisOrParentIncluded(includedPaths: MutableSet) = includedP fun String.isThisOrParentExcluded(excludedPaths: MutableSet) = excludedPaths.any { startsWith(it, true) } fun String.shouldFolderBeVisible(excludedPaths: MutableSet, includedPaths: MutableSet, showHidden: Boolean): Boolean { + if (isEmpty()) { + return false + } + val file = File(this) - return if (isEmpty()) { - false - } else if (!showHidden && file.isHidden) { - false + if (!showHidden && file.isHidden) { + return false } else if (includedPaths.contains(this)) { - true - } else if (!showHidden && file.containsNoMedia()) { + return true + } + + val containsNoMedia = if (showHidden) false else File(this, NOMEDIA).exists() + return if (!showHidden && containsNoMedia) { false } else if (excludedPaths.contains(this)) { false @@ -33,7 +39,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet, includedPath } else if (isThisOrParentExcluded(excludedPaths)) { false } else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) { - var containsNoMediaOrDot = file.containsNoMedia() || contains("/.") + var containsNoMediaOrDot = containsNoMedia || contains("/.") if (!containsNoMediaOrDot) { containsNoMediaOrDot = file.doesThisOrParentHaveNoMedia() }