diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index 9a4235f70..bcb0b3300 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -188,9 +188,7 @@ fun Context.getDirsToShow(dirs: ArrayList, allDirs: ArrayList - val foldersToShow = getDirectParentSubfolders(dirFolders, currentPathPrefix) - val parentDirs = dirs.filter { foldersToShow.contains(it.path) } as ArrayList + val parentDirs = getDirectParentSubfolders(dirs, currentPathPrefix) updateSubfolderCounts(dirs, parentDirs) // show the current folder as an available option too, not just subfolders @@ -209,7 +207,8 @@ fun Context.getDirsToShow(dirs: ArrayList, allDirs: ArrayList, currentPathPrefix: String): HashSet { +fun Context.getDirectParentSubfolders(dirs: ArrayList, currentPathPrefix: String): ArrayList { + val folders = dirs.map { it.path }.sorted().toMutableSet() as HashSet val internalPath = internalStoragePath val sdPath = sdCardPath val currentPaths = LinkedHashSet() @@ -257,15 +256,17 @@ fun Context.getDirectParentSubfolders(folders: HashSet, currentPathPrefi } if (folders.size == currentPaths.size) { - return currentPaths + return dirs.filter { currentPaths.contains(it.path) } as ArrayList } folders.clear() folders.addAll(currentPaths) + + val dirsToShow = dirs.filter { folders.contains(it.path) } as ArrayList return if (areDirectSubfoldersAvailable) { - getDirectParentSubfolders(folders, currentPathPrefix) + getDirectParentSubfolders(dirsToShow, currentPathPrefix) } else { - folders + dirsToShow } }