From 3d47eac4e391fe87eba2cca53757ceb6b31368d0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 14 Dec 2018 22:02:03 +0100 Subject: [PATCH] show the sum of all subfolder media counts with "Group direct subfolders" --- .../gallery/pro/activities/MainActivity.kt | 22 ++++++++++++++++++- .../gallery/pro/adapters/DirectoryAdapter.kt | 2 +- .../gallery/pro/models/Directory.kt | 12 +++++----- 3 files changed, 28 insertions(+), 8 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 0b6bf1658..db11c197b 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 @@ -957,10 +957,30 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { private fun getDirsToShow(dirs: ArrayList): ArrayList { return if (config.groupDirectSubfolders) { + dirs.forEach { it.subfoldersMediaCount = it.mediaCnt } val dirFolders = dirs.map { it.path }.sorted().toMutableSet() as HashSet val foldersToShow = getDirectParentSubfolders(dirFolders) - dirs.filter { foldersToShow.contains(it.path) } as ArrayList + 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 + var longestSharedPath = "" + newDirs.forEach { + if (it.path != mainDir.path && mainDir.path.startsWith(it.path, true) && it.path.length > longestSharedPath.length) { + longestSharedPath = it.path + } + } + + val mainFolder = newDirs.firstOrNull { it.path == longestSharedPath } + if (mainFolder != null) { + mainFolder.subfoldersMediaCount += mainDir.mediaCnt + } + } + + newDirs } else { + dirs.forEach { it.subfoldersMediaCount = it.mediaCnt } dirs } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index b4241f18e..61b53d188 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -503,7 +503,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList TYPE_VIDEOS directory.tmb.isGif() -> TYPE_GIFS diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Directory.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Directory.kt index 8b90b8bdf..7c968ce44 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/models/Directory.kt @@ -1,9 +1,6 @@ package com.simplemobiletools.gallery.pro.models -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.Index -import androidx.room.PrimaryKey +import androidx.room.* import com.simplemobiletools.commons.extensions.formatDate import com.simplemobiletools.commons.extensions.formatSize import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED @@ -23,8 +20,11 @@ data class Directory( @ColumnInfo(name = "last_modified") var modified: Long, @ColumnInfo(name = "date_taken") var taken: Long, @ColumnInfo(name = "size") var size: Long, - @ColumnInfo(name = "location") val location: Int, - @ColumnInfo(name = "media_types") var types: Int) { + @ColumnInfo(name = "location") var location: Int, + @ColumnInfo(name = "media_types") var types: Int, + @Ignore var subfoldersMediaCount: Int = 0) { // used with "Group direct subfolders" enabled to count subfolder media counts + + constructor() : this(null, "", "", "", 0, 0L, 0L, 0L, 0, 0, 0) fun getBubbleText(sorting: Int) = when { sorting and SORT_BY_NAME != 0 -> name