Code Cleanup
This commit is contained in:
parent
41039bcdd5
commit
21a45163a7
3 changed files with 9 additions and 15 deletions
|
@ -75,34 +75,34 @@ class RealAlbumRepository(private val songRepository: RealSongRepository) :
|
||||||
songs: List<Song>
|
songs: List<Song>
|
||||||
): List<Album> {
|
): List<Album> {
|
||||||
val grouped = songs.groupBy { it.albumId }.map { Album(it.key, it.value) }
|
val grouped = songs.groupBy { it.albumId }.map { Album(it.key, it.value) }
|
||||||
|
val collator = Collator.getInstance()
|
||||||
return when (PreferenceUtil.albumSortOrder) {
|
return when (PreferenceUtil.albumSortOrder) {
|
||||||
SortOrder.AlbumSortOrder.ALBUM_A_Z -> {
|
SortOrder.AlbumSortOrder.ALBUM_A_Z -> {
|
||||||
val collator = Collator.getInstance()
|
|
||||||
grouped.sortedWith { a1, a2 -> collator.compare(a1.title, a2.title) }
|
grouped.sortedWith { a1, a2 -> collator.compare(a1.title, a2.title) }
|
||||||
}
|
}
|
||||||
SortOrder.AlbumSortOrder.ALBUM_Z_A -> {
|
SortOrder.AlbumSortOrder.ALBUM_Z_A -> {
|
||||||
val collator = Collator.getInstance()
|
|
||||||
grouped.sortedWith { a1, a2 -> collator.compare(a2.title, a1.title) }
|
grouped.sortedWith { a1, a2 -> collator.compare(a2.title, a1.title) }
|
||||||
}
|
}
|
||||||
SortOrder.AlbumSortOrder.ALBUM_ARTIST -> {
|
SortOrder.AlbumSortOrder.ALBUM_ARTIST -> {
|
||||||
val collator = Collator.getInstance()
|
|
||||||
grouped.sortedWith { a1, a2 -> collator.compare(a1.albumArtist, a2.albumArtist) }
|
grouped.sortedWith { a1, a2 -> collator.compare(a1.albumArtist, a2.albumArtist) }
|
||||||
}
|
}
|
||||||
|
SortOrder.AlbumSortOrder.ALBUM_NUMBER_OF_SONGS -> {
|
||||||
|
grouped.sortedByDescending { it.songCount }
|
||||||
|
}
|
||||||
else -> grouped
|
else -> grouped
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sortAlbumSongs(album: Album): Album {
|
private fun sortAlbumSongs(album: Album): Album {
|
||||||
|
val collator = Collator.getInstance()
|
||||||
val songs = when (PreferenceUtil.albumDetailSongSortOrder) {
|
val songs = when (PreferenceUtil.albumDetailSongSortOrder) {
|
||||||
SortOrder.AlbumSongSortOrder.SONG_TRACK_LIST -> album.songs.sortedWith { o1, o2 ->
|
SortOrder.AlbumSongSortOrder.SONG_TRACK_LIST -> album.songs.sortedWith { o1, o2 ->
|
||||||
o1.trackNumber.compareTo(o2.trackNumber)
|
o1.trackNumber.compareTo(o2.trackNumber)
|
||||||
}
|
}
|
||||||
SortOrder.AlbumSongSortOrder.SONG_A_Z -> {
|
SortOrder.AlbumSongSortOrder.SONG_A_Z -> {
|
||||||
val collator = Collator.getInstance()
|
|
||||||
album.songs.sortedWith { o1, o2 -> collator.compare(o1.title, o2.title) }
|
album.songs.sortedWith { o1, o2 -> collator.compare(o1.title, o2.title) }
|
||||||
}
|
}
|
||||||
SortOrder.AlbumSongSortOrder.SONG_Z_A -> {
|
SortOrder.AlbumSongSortOrder.SONG_Z_A -> {
|
||||||
val collator = Collator.getInstance()
|
|
||||||
album.songs.sortedWith { o1, o2 -> collator.compare(o2.title, o1.title) }
|
album.songs.sortedWith { o1, o2 -> collator.compare(o2.title, o1.title) }
|
||||||
}
|
}
|
||||||
SortOrder.AlbumSongSortOrder.SONG_DURATION -> album.songs.sortedWith { o1, o2 ->
|
SortOrder.AlbumSongSortOrder.SONG_DURATION -> album.songs.sortedWith { o1, o2 ->
|
||||||
|
|
|
@ -172,14 +172,13 @@ class RealArtistRepository(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sortArtists(artists: List<Artist>): List<Artist> {
|
private fun sortArtists(artists: List<Artist>): List<Artist> {
|
||||||
|
val collator = Collator.getInstance()
|
||||||
return when (PreferenceUtil.artistSortOrder) {
|
return when (PreferenceUtil.artistSortOrder) {
|
||||||
SortOrder.ArtistSortOrder.ARTIST_A_Z -> {
|
SortOrder.ArtistSortOrder.ARTIST_A_Z -> {
|
||||||
val collator = Collator.getInstance()
|
artists.sortedWith { a1, a2 -> collator.compare(a1.name, a2.name) }
|
||||||
artists.sortedWith{ a1, a2 -> collator.compare(a1.name, a2.name) }
|
|
||||||
}
|
}
|
||||||
SortOrder.ArtistSortOrder.ARTIST_Z_A -> {
|
SortOrder.ArtistSortOrder.ARTIST_Z_A -> {
|
||||||
val collator = Collator.getInstance()
|
artists.sortedWith { a1, a2 -> collator.compare(a2.name, a1.name) }
|
||||||
artists.sortedWith{ a1, a2 -> collator.compare(a2.name, a1.name) }
|
|
||||||
}
|
}
|
||||||
else -> artists
|
else -> artists
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,29 +68,24 @@ class RealSongRepository(private val context: Context) : SongRepository {
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
|
val collator = Collator.getInstance()
|
||||||
return when (PreferenceUtil.songSortOrder) {
|
return when (PreferenceUtil.songSortOrder) {
|
||||||
SortOrder.SongSortOrder.SONG_A_Z -> {
|
SortOrder.SongSortOrder.SONG_A_Z -> {
|
||||||
val collator = Collator.getInstance()
|
|
||||||
songs.sortedWith{ s1, s2 -> collator.compare(s1.title, s2.title) }
|
songs.sortedWith{ s1, s2 -> collator.compare(s1.title, s2.title) }
|
||||||
}
|
}
|
||||||
SortOrder.SongSortOrder.SONG_Z_A -> {
|
SortOrder.SongSortOrder.SONG_Z_A -> {
|
||||||
val collator = Collator.getInstance()
|
|
||||||
songs.sortedWith{ s1, s2 -> collator.compare(s2.title, s1.title) }
|
songs.sortedWith{ s1, s2 -> collator.compare(s2.title, s1.title) }
|
||||||
}
|
}
|
||||||
SortOrder.SongSortOrder.SONG_ALBUM -> {
|
SortOrder.SongSortOrder.SONG_ALBUM -> {
|
||||||
val collator = Collator.getInstance()
|
|
||||||
songs.sortedWith{ s1, s2 -> collator.compare(s1.albumName, s2.albumName) }
|
songs.sortedWith{ s1, s2 -> collator.compare(s1.albumName, s2.albumName) }
|
||||||
}
|
}
|
||||||
SortOrder.SongSortOrder.SONG_ALBUM_ARTIST -> {
|
SortOrder.SongSortOrder.SONG_ALBUM_ARTIST -> {
|
||||||
val collator = Collator.getInstance()
|
|
||||||
songs.sortedWith{ s1, s2 -> collator.compare(s1.albumArtist, s2.albumArtist) }
|
songs.sortedWith{ s1, s2 -> collator.compare(s1.albumArtist, s2.albumArtist) }
|
||||||
}
|
}
|
||||||
SortOrder.SongSortOrder.SONG_ARTIST -> {
|
SortOrder.SongSortOrder.SONG_ARTIST -> {
|
||||||
val collator = Collator.getInstance()
|
|
||||||
songs.sortedWith{ s1, s2 -> collator.compare(s1.artistName, s2.artistName) }
|
songs.sortedWith{ s1, s2 -> collator.compare(s1.artistName, s2.artistName) }
|
||||||
}
|
}
|
||||||
SortOrder.SongSortOrder.COMPOSER -> {
|
SortOrder.SongSortOrder.COMPOSER -> {
|
||||||
val collator = Collator.getInstance()
|
|
||||||
songs.sortedWith{ s1, s2 -> collator.compare(s1.composer, s2.composer) }
|
songs.sortedWith{ s1, s2 -> collator.compare(s1.composer, s2.composer) }
|
||||||
}
|
}
|
||||||
else -> songs
|
else -> songs
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue