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 1ac57208f..e8e19edcb 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 @@ -1,7 +1,6 @@ package com.simplemobiletools.gallery.pro.extensions import android.os.Environment -import com.simplemobiletools.commons.extensions.containsNoMedia import com.simplemobiletools.commons.helpers.NOMEDIA import java.io.File import java.io.IOException @@ -18,7 +17,8 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet, includedPath } val file = File(this) - if (file.name.startsWith("img_", true)) { + val filename = file.name + if (filename.startsWith("img_", true) && file.isDirectory) { val files = file.list() if (files != null) { if (files.any { it.contains("burst", true) }) { @@ -27,7 +27,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet, includedPath } } - if (!showHidden && file.isHidden) { + if (!showHidden && filename.startsWith('.')) { return false } else if (includedPaths.contains(this)) { return true @@ -36,7 +36,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet, includedPath val containsNoMedia = if (showHidden) { false } else { - file.containsNoMedia() + File(this, NOMEDIA).exists() } return if (!showHidden && containsNoMedia) { @@ -47,7 +47,7 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet, includedPath true } else if (isThisOrParentExcluded(excludedPaths)) { false - } else if (!showHidden && file.isDirectory && file.canonicalFile == file.absoluteFile) { + } else if (!showHidden) { var containsNoMediaOrDot = containsNoMedia || contains("/.") if (!containsNoMediaOrDot) { var curPath = this diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt index 0a30ae525..de905e3f8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt @@ -68,7 +68,20 @@ class MediaFetcher(val context: Context) { val includedPaths = config.includedFolders val folderNomediaStatuses = HashMap() - folders.distinctBy { it.getDistinctPath() }.filter { + val distinctPathsMap = HashMap() + val distinctPaths = folders.distinctBy { + when { + distinctPathsMap.containsKey(it) -> distinctPathsMap[it] + distinctPathsMap.contains(it.getParentPath()) -> distinctPathsMap[it.getParentPath()] + else -> { + val distinct = it.getDistinctPath() + distinctPathsMap[it.getParentPath()] = distinct.getParentPath() + distinct + } + } + } + + distinctPaths.filter { it.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden, folderNomediaStatuses) { path, hasNoMedia -> folderNomediaStatuses[path] = hasNoMedia }