Skip to content

Commit

Permalink
Sort tracks on artist view alphabetically (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp authored Sep 4, 2021
1 parent 95dea5a commit 7738a3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/src/main/java/me/vanpetegem/accentor/data/tracks/Track.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ data class Track(
return this.number - other.number
}

fun compareAlphabetically(other: Track, albums: SparseArray<Album>): Int {
var order = normalizedTitle.compareTo(other.normalizedTitle)
if (order != 0) { return order }
order = this.number - other.number
if (order != 0) { return order }
return compareTo(other, albums)
}

companion object {
const val ALBUMARTIST = "me.vanpetegem.accentor.data.tracks.Track.ALBUMARTIST"
const val ARTIST = "me.vanpetegem.accentor.data.tracks.Track.ARTIST"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ArtistViewModel @Inject constructor(
fun tracksForArtist(artist: Artist): LiveData<List<Track>> = switchMap(trackRepository.findByArtist(artist)) { tracks ->
map(albumRepository.allAlbumsById) { albums ->
val copy = tracks.toMutableList()
copy.sortWith({ t1, t2 -> t1.compareTo(t2, albums) })
copy.sortWith({ t1, t2 -> t1.compareAlphabetically(t2, albums) })
copy
}
}
Expand Down

0 comments on commit 7738a3a

Please sign in to comment.