From 98a5b7144b8d24f715a91152e296d7db3783af13 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 15 Dec 2018 21:23:00 +0100 Subject: [PATCH] fix subfolder counting at "Group direct subfolders" --- .../gallery/pro/activities/MainActivity.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 651576201..3a06fc215 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -967,19 +967,27 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { val newDirs = dirs.filter { foldersToShow.contains(it.path) } as ArrayList // update the directory media counts, add all subfolder media counts to it - dirs.forEach { - val mainDir = it + for (dir in dirs) { var longestSharedPath = "" - newDirs.forEach { - if (it.path != mainDir.path && mainDir.path.startsWith(it.path, true) && it.path.length > longestSharedPath.length) { - it.subfoldersCount += 1 - longestSharedPath = it.path + for (newDir in newDirs) { + if (newDir.path == dir.path) { + longestSharedPath = dir.path + continue } + + if (dir.path.startsWith(newDir.path, true) && newDir.path.length > longestSharedPath.length) { + longestSharedPath = newDir.path + } + } + + val parentFolder = newDirs.firstOrNull { it.path == longestSharedPath } + parentFolder?.apply { + subfoldersCount++ } val mainFolder = newDirs.firstOrNull { it.path == longestSharedPath } if (mainFolder != null) { - mainFolder.subfoldersMediaCount += mainDir.mediaCnt + mainFolder.subfoldersMediaCount += dir.mediaCnt } }