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 e780d62c4..b58652a18 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 @@ -931,7 +931,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { taken = newDir.taken this@apply.size = newDir.size types = newDir.types - sortValue = getDirectorySortingValue(curMedia) + sortValue = getDirectorySortingValue(curMedia, path, name, size) } setupAdapter(dirs) 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 adbc6c957..8da181faf 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 @@ -879,30 +879,28 @@ fun Context.createDirectoryFromMedia(path: String, curMedia: ArrayList, val dateTaken = if (isSortingAscending) Math.min(firstItem.taken, lastItem.taken) else Math.max(firstItem.taken, lastItem.taken) 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, getDirectorySortingValue(curMedia)) + val sortValue = getDirectorySortingValue(curMedia, path, dirName, size) + return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, getPathLocation(path), mediaTypes, sortValue) } -fun Context.getDirectorySortingValue(media: ArrayList): String { +fun Context.getDirectorySortingValue(media: ArrayList, path: String, name: String, size: Long): String { val sorting = config.directorySorting val sorted = when { - sorting and SORT_BY_NAME != 0 -> media.sortedBy { it.name } - sorting and SORT_BY_PATH != 0 -> media.sortedBy { it.path } - sorting and SORT_BY_SIZE != 0 -> media.sortedBy { it.size } + sorting and SORT_BY_NAME != 0 -> return name + sorting and SORT_BY_PATH != 0 -> return path + sorting and SORT_BY_SIZE != 0 -> return size.toString() sorting and SORT_BY_DATE_MODIFIED != 0 -> media.sortedBy { it.modified } sorting and SORT_BY_DATE_TAKEN != 0 -> media.sortedBy { it.taken } else -> media } val relevantMedium = if (sorting.isSortingAscending()) { - sorted.first() + sorted.firstOrNull() ?: return "" } else { - sorted.last() + sorted.lastOrNull() ?: return "" } val result: Any = when { - sorting and SORT_BY_NAME != 0 -> relevantMedium.name - sorting and SORT_BY_PATH != 0 -> relevantMedium.path - sorting and SORT_BY_SIZE != 0 -> relevantMedium.size sorting and SORT_BY_DATE_MODIFIED != 0 -> relevantMedium.modified sorting and SORT_BY_DATE_TAKEN != 0 -> relevantMedium.taken else -> 0