mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
move subfolder count updating in an own function
This commit is contained in:
parent
98a5b7144b
commit
59c6f91100
1 changed files with 27 additions and 29 deletions
|
@ -958,46 +958,44 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
private fun getDirsToShow(dirs: ArrayList<Directory>): ArrayList<Directory> {
|
private fun getDirsToShow(dirs: ArrayList<Directory>): ArrayList<Directory> {
|
||||||
return if (config.groupDirectSubfolders) {
|
return if (config.groupDirectSubfolders) {
|
||||||
dirs.forEach {
|
dirs.forEach {
|
||||||
it.subfoldersCount = 1
|
it.subfoldersCount = 0
|
||||||
it.subfoldersMediaCount = it.mediaCnt
|
it.subfoldersMediaCount = it.mediaCnt
|
||||||
}
|
}
|
||||||
|
|
||||||
val dirFolders = dirs.map { it.path }.sorted().toMutableSet() as HashSet<String>
|
val dirFolders = dirs.map { it.path }.sorted().toMutableSet() as HashSet<String>
|
||||||
val foldersToShow = getDirectParentSubfolders(dirFolders)
|
val foldersToShow = getDirectParentSubfolders(dirFolders)
|
||||||
val newDirs = dirs.filter { foldersToShow.contains(it.path) } as ArrayList<Directory>
|
val parentDirs = dirs.filter { foldersToShow.contains(it.path) } as ArrayList<Directory>
|
||||||
|
updateSubfolderCounts(dirs, parentDirs)
|
||||||
// update the directory media counts, add all subfolder media counts to it
|
parentDirs
|
||||||
for (dir in dirs) {
|
|
||||||
var longestSharedPath = ""
|
|
||||||
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 += dir.mediaCnt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newDirs
|
|
||||||
} else {
|
} else {
|
||||||
dirs.forEach { it.subfoldersMediaCount = it.mediaCnt }
|
dirs.forEach { it.subfoldersMediaCount = it.mediaCnt }
|
||||||
dirs
|
dirs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateSubfolderCounts(children: ArrayList<Directory>, parentDirs: ArrayList<Directory>) {
|
||||||
|
for (child in children) {
|
||||||
|
var longestSharedPath = ""
|
||||||
|
for (parentDir in parentDirs) {
|
||||||
|
if (parentDir.path == child.path) {
|
||||||
|
longestSharedPath = child.path
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child.path.startsWith(parentDir.path, true) && parentDir.path.length > longestSharedPath.length) {
|
||||||
|
longestSharedPath = parentDir.path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parentDirs.firstOrNull { it.path == longestSharedPath }?.apply {
|
||||||
|
subfoldersCount++
|
||||||
|
if (path != child.path) {
|
||||||
|
subfoldersMediaCount += child.mediaCnt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createDirectoryFromMedia(path: String, curMedia: ArrayList<Medium>, albumCovers: ArrayList<AlbumCover>, hiddenString: String,
|
private fun createDirectoryFromMedia(path: String, curMedia: ArrayList<Medium>, albumCovers: ArrayList<AlbumCover>, hiddenString: String,
|
||||||
includedFolders: MutableSet<String>, isSortingAscending: Boolean): Directory {
|
includedFolders: MutableSet<String>, isSortingAscending: Boolean): Directory {
|
||||||
var thumbnail = curMedia.firstOrNull { getDoesFilePathExist(it.path) }?.path ?: ""
|
var thumbnail = curMedia.firstOrNull { getDoesFilePathExist(it.path) }?.path ?: ""
|
||||||
|
|
Loading…
Reference in a new issue