Skip to content

Commit

Permalink
music: add date added to albums [#181]
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OxygenCobalt committed Jul 13, 2022
1 parent e8f9456 commit a2afd3a
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions app/src/main/java/org/oxycblt/auxio/ui/Sort.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>,
Expand Down

0 comments on commit a2afd3a

Please sign in to comment.