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:
parent
e8f94564b7
commit
a2afd3a4b7
1 changed files with 18 additions and 13 deletions
|
@ -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<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
|
||||
* 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<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(
|
||||
ascending: Boolean,
|
||||
comparator: Comparator<in K>,
|
||||
|
|
Loading…
Reference in a new issue