From df3a0724d47f72187a7e7c7555d75c1270188d39 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Feb 2019 20:31:12 +0100 Subject: [PATCH] calculate proper folder size only if needed --- .../gallery/pro/activities/MainActivity.kt | 10 +++++----- .../gallery/pro/asynctasks/GetMediaAsynctask.kt | 2 +- .../gallery/pro/helpers/MediaFetcher.kt | 10 ++++++---- 3 files changed, 12 insertions(+), 10 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 7ccbbc379..dd1ed3ac1 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 @@ -816,7 +816,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { val tempFolderPath = config.tempFolderPath val isSortingAscending = config.directorySorting and SORT_DESCENDING == 0 val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 - val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0 || config.fileLoadingPriority == PRIORITY_COMPROMISE + val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0 val favoritePaths = getFavoritePaths() val dirPathsToRemove = ArrayList() @@ -833,7 +833,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } directory } else { - createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) + createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, isSortingAscending, getProperFileSize) } // we are looping through the already displayed folders looking for changes, do not do anything if nothing changed @@ -913,7 +913,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } } - val newDir = createDirectoryFromMedia(folder, newMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) + val newDir = createDirectoryFromMedia(folder, newMedia, albumCovers, hiddenString, includedFolders, isSortingAscending, getProperFileSize) dirs.add(newDir) setupAdapter(dirs) try { @@ -956,7 +956,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } private fun createDirectoryFromMedia(path: String, curMedia: ArrayList, albumCovers: ArrayList, hiddenString: String, - includedFolders: MutableSet, isSortingAscending: Boolean): Directory { + includedFolders: MutableSet, isSortingAscending: Boolean, getProperFileSize: Boolean): Directory { var thumbnail = curMedia.firstOrNull { File(it.path).exists() }?.path ?: "" albumCovers.forEach { if (it.path == path && File(it.tmb).exists()) { @@ -969,7 +969,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { val dirName = checkAppendingHidden(path, hiddenString, includedFolders) val lastModified = if (isSortingAscending) Math.min(firstItem.modified, lastItem.modified) else Math.max(firstItem.modified, lastItem.modified) val dateTaken = if (isSortingAscending) Math.min(firstItem.taken, lastItem.taken) else Math.max(firstItem.taken, lastItem.taken) - val size = curMedia.sumByLong { it.size } + val size = if (getProperFileSize) curMedia.sumByLong { it.size } else 0L val mediaTypes = curMedia.getDirMediaTypes() return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, getPathLocation(path), mediaTypes) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt index 76537076d..d382422a4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/asynctasks/GetMediaAsynctask.kt @@ -19,7 +19,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage override fun doInBackground(vararg params: Void): ArrayList { val pathToUse = if (showAll) SHOW_ALL else mPath val getProperDateTaken = context.config.getFileSorting(pathToUse) and SORT_BY_DATE_TAKEN != 0 || context.config.getFolderGrouping(pathToUse) and GROUP_BY_DATE_TAKEN != 0 - val getProperFileSize = context.config.getFileSorting(pathToUse) and SORT_BY_SIZE != 0 || context.config.fileLoadingPriority == PRIORITY_COMPROMISE + val getProperFileSize = context.config.getFileSorting(pathToUse) and SORT_BY_SIZE != 0 val favoritePaths = context.getFavoritePaths() val getVideoDurations = context.config.showThumbnailVideoDuration val media = if (showAll) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt index 98a399c4d..ff6eeec88 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt @@ -165,8 +165,10 @@ class MediaFetcher(val context: Context) { ArrayList() } - val checkFileExistence = context.config.fileLoadingPriority == PRIORITY_VALIDITY - val showHidden = context.config.shouldShowHidden + val config = context.config + val checkProperFileSize = getProperFileSize || config.fileLoadingPriority == PRIORITY_COMPROMISE + val checkFileExistence = config.fileLoadingPriority == PRIORITY_VALIDITY + val showHidden = config.shouldShowHidden val dateTakens = if (getProperDateTaken && folder != FAVORITES && !isRecycleBin) getFolderDateTakens(folder) else HashMap() val files = when (folder) { @@ -209,8 +211,8 @@ class MediaFetcher(val context: Context) { if (!showHidden && filename.startsWith('.')) continue - val size = if (getProperFileSize || checkFileExistence) file.length() else 1L - if ((getProperFileSize || checkFileExistence) && size <= 0L) { + val size = if (checkProperFileSize || checkFileExistence) file.length() else 1L + if ((checkProperFileSize || checkFileExistence) && size <= 0L) { continue }