From 7f2c76bf2727589c29264f442ca92196dc550c96 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 5 May 2019 11:01:10 +0200 Subject: [PATCH] tweaking folder grouping code, no functionality change --- .../gallery/pro/extensions/Context.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 } }