From 58bea1dda503e38235c34891049982fac10c0f12 Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Fri, 30 Jul 2021 19:59:18 -0600 Subject: [PATCH] sort: fix sort bug with same-year album songs Fix a problem where given two albums with the same year, like this: Album 1 [2018] - Song 1 - Song 2 Album 2 [2018] - Song 3 - Song 4 getSortedArtistSongs would incorrectly drop songs that came from any albums that came after Album 1, resulting in this: Song 1 [Album 1] Song 2 [Album 1] This was caused by a quirk in toSortedMap that would drop any map entries that corresponded to a previous sorted entry. We now get and sort the entries directly instead, which fixes the issue. --- app/src/main/java/org/oxycblt/auxio/recycler/SortMode.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/recycler/SortMode.kt b/app/src/main/java/org/oxycblt/auxio/recycler/SortMode.kt index a91ed3cf9..96ddd4dbb 100644 --- a/app/src/main/java/org/oxycblt/auxio/recycler/SortMode.kt +++ b/app/src/main/java/org/oxycblt/auxio/recycler/SortMode.kt @@ -144,8 +144,8 @@ enum class SortMode(@DrawableRes val iconRes: Int) { NUMERIC_UP -> { val list = mutableListOf() - songs.groupBy { it.album }.toSortedMap(compareBy { it.year }).values.forEach { items -> - list.addAll(items.sortedWith(compareBy { it.track })) + songs.groupBy { it.album }.entries.sortedBy { it.key.year }.forEach { entry -> + list.addAll(entry.value.sortedWith(compareBy { it.track })) } list @@ -154,8 +154,8 @@ enum class SortMode(@DrawableRes val iconRes: Int) { NUMERIC_DOWN -> { val list = mutableListOf() - songs.groupBy { it.album }.toSortedMap(compareByDescending { it.year }).values.forEach { items -> - list.addAll(items.sortedWith(compareBy { it.track })) + songs.groupBy { it.album }.entries.sortedWith(compareByDescending { it.key.year }).forEach { entry -> + list.addAll(entry.value.sortedWith(compareBy { it.track })) } list