From a20cc9aa0818f1a8b53b2fdce8efbd57988de992 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 5 Mar 2019 10:37:44 +0100 Subject: [PATCH] properly handle grouping by some numeric values, like dates --- .../gallery/pro/helpers/MediaFetcher.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 ff6eeec88..785627944 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 @@ -324,7 +324,16 @@ class MediaFetcher(val context: Context) { } val sortDescending = currentGrouping and GROUP_DESCENDING != 0 - val sorted = mediumGroups.toSortedMap(if (sortDescending) compareByDescending { it } else compareBy { it }) + val sorted = if (currentGrouping and GROUP_BY_DATE_TAKEN != 0 || currentGrouping and GROUP_BY_LAST_MODIFIED != 0) { + mediumGroups.toSortedMap(if (sortDescending) compareByDescending { + it.toLongOrNull() ?: 0L + } else { + compareBy { it.toLongOrNull() ?: 0L } + }) + } else { + mediumGroups.toSortedMap(if (sortDescending) compareByDescending { it } else compareBy { it }) + } + mediumGroups.clear() for ((key, value) in sorted) { mediumGroups[key] = value