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.
This commit is contained in:
OxygenCobalt 2022-07-13 15:44:21 -06:00
parent e8f94564b7
commit a2afd3a4b7
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -260,19 +260,6 @@ data class Sort(val mode: Mode, val isAscending: Boolean) {
compareBy(BasicComparator.SONG)) 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<Song> =
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 * 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 * 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)) 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<Song> =
MultiComparator(
compareByDynamic(ascending) { it.dateAdded }, compareBy(BasicComparator.SONG))
override fun getAlbumComparator(ascending: Boolean): Comparator<Album> =
MultiComparator(
compareByDynamic(ascending) { album -> album.songs.minOf { it.dateAdded } },
compareBy(BasicComparator.ALBUM))
}
protected inline fun <T : Music, K> compareByDynamic( protected inline fun <T : Music, K> compareByDynamic(
ascending: Boolean, ascending: Boolean,
comparator: Comparator<in K>, comparator: Comparator<in K>,