diff --git a/app/src/main/java/me/vanpetegem/accentor/data/tracks/Track.kt b/app/src/main/java/me/vanpetegem/accentor/data/tracks/Track.kt index 753d9468..256f2fd3 100644 --- a/app/src/main/java/me/vanpetegem/accentor/data/tracks/Track.kt +++ b/app/src/main/java/me/vanpetegem/accentor/data/tracks/Track.kt @@ -33,6 +33,14 @@ data class Track( return this.number - other.number } + fun compareAlphabetically(other: Track, albums: SparseArray): 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" diff --git a/app/src/main/java/me/vanpetegem/accentor/ui/artists/ArtistViewModel.kt b/app/src/main/java/me/vanpetegem/accentor/ui/artists/ArtistViewModel.kt index 12568535..ddc186ec 100644 --- a/app/src/main/java/me/vanpetegem/accentor/ui/artists/ArtistViewModel.kt +++ b/app/src/main/java/me/vanpetegem/accentor/ui/artists/ArtistViewModel.kt @@ -34,7 +34,7 @@ class ArtistViewModel @Inject constructor( fun tracksForArtist(artist: Artist): LiveData> = 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 } }