From 72db7e8070285ac02f9caa284eee7b92fa123cc1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 17 Dec 2018 12:47:22 +0100 Subject: [PATCH] improve the handling of direct subfolder grouping in some cases --- .../gallery/pro/extensions/Context.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 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 8fdb3ee20..fec3ae4df 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 @@ -211,16 +211,26 @@ fun Context.getDirectParentSubfolders(folders: HashSet, currentPathPrefi val internalPath = internalStoragePath val sdPath = sdCardPath val currentPaths = LinkedHashSet() + folders.forEach { val path = it - if (!path.equals(internalPath, true) && !path.equals(sdPath, true) && path != RECYCLE_BIN && path != FAVORITES) { + if (path != RECYCLE_BIN && path != FAVORITES && !path.equals(internalPath, true) && !path.equals(sdPath, true)) { if (currentPathPrefix.isNotEmpty()) { - if (File(path).parent.equals(currentPathPrefix, true) || path == currentPathPrefix) { + if (path == currentPathPrefix || File(path).parent.equals(currentPathPrefix, true)) { currentPaths.add(path) } } else if (folders.any { !it.equals(path, true) && (File(path).parent.equals(it, true) || File(it).parent.equals(File(path).parent, true)) }) { + // if we have folders like + // /storage/emulated/0/Pictures/Images and + // /storage/emulated/0/Pictures/Screenshots, + // but /storage/emulated/0/Pictures is empty, show Images and Screenshots as separate folders, do not group them at /Pictures + val parent = File(path).parent - currentPaths.add(parent) + if (folders.contains(parent)) { + currentPaths.add(parent) + } else { + currentPaths.add(path) + } } else { currentPaths.add(path) }