From a2afd3a4b744faf1cb5a930044810c7eef5e3c2c Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Wed, 13 Jul 2022 15:44:21 -0600 Subject: [PATCH] music: add date added to albums [#181] Added date added sorting to albums as well. This implementation picks the earliest song in an album that was added to the library and then uses that for sorting. --- .../main/java/org/oxycblt/auxio/ui/Sort.kt | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/ui/Sort.kt b/app/src/main/java/org/oxycblt/auxio/ui/Sort.kt index a83f23f42..bbe117059 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/Sort.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/Sort.kt @@ -260,19 +260,6 @@ data class Sort(val mode: Mode, val isAscending: Boolean) { compareBy(BasicComparator.SONG)) } - /** Sort by the time the item was added. Only supported by [Song] */ - object ByDateAdded : Mode() { - override val intCode: Int - get() = IntegerTable.SORT_BY_DATE_ADDED - - override val itemId: Int - get() = R.id.option_sort_date_added - - override fun getSongComparator(ascending: Boolean): Comparator = - MultiComparator( - compareByDynamic(ascending) { it.dateAdded }, compareBy(BasicComparator.SONG)) - } - /** * Sort by the disc, and then track number of an item. Only supported by [Song]. Do not use * this in a main sorting view, as it is not assigned to a particular item ID @@ -291,6 +278,24 @@ data class Sort(val mode: Mode, val isAscending: Boolean) { compareBy(BasicComparator.SONG)) } + /** Sort by the time the item was added. Only supported by [Song] */ + object ByDateAdded : Mode() { + override val intCode: Int + get() = IntegerTable.SORT_BY_DATE_ADDED + + override val itemId: Int + get() = R.id.option_sort_date_added + + override fun getSongComparator(ascending: Boolean): Comparator = + MultiComparator( + compareByDynamic(ascending) { it.dateAdded }, compareBy(BasicComparator.SONG)) + + override fun getAlbumComparator(ascending: Boolean): Comparator = + MultiComparator( + compareByDynamic(ascending) { album -> album.songs.minOf { it.dateAdded } }, + compareBy(BasicComparator.ALBUM)) + } + protected inline fun compareByDynamic( ascending: Boolean, comparator: Comparator,