Sort album repository in a localized way
This commit is contained in:
parent
2471a14690
commit
76be5a784a
2 changed files with 31 additions and 19 deletions
|
@ -80,6 +80,7 @@ import kotlinx.coroutines.withContext
|
|||
import org.koin.android.ext.android.get
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.koin.core.parameter.parametersOf
|
||||
import java.text.Collator
|
||||
|
||||
class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_details),
|
||||
IAlbumClickListener, ICabHolder {
|
||||
|
@ -437,15 +438,13 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
|
|||
o2.trackNumber
|
||||
)
|
||||
}
|
||||
SONG_A_Z -> album.songs.sortedWith { o1, o2 ->
|
||||
o1.title.compareTo(
|
||||
o2.title
|
||||
)
|
||||
SONG_A_Z -> {
|
||||
val collator = Collator.getInstance()
|
||||
album.songs.sortedWith { o1, o2 -> collator.compare(o1.title, o2.title) }
|
||||
}
|
||||
SONG_Z_A -> album.songs.sortedWith { o1, o2 ->
|
||||
o2.title.compareTo(
|
||||
o1.title
|
||||
)
|
||||
SONG_Z_A -> {
|
||||
val collator = Collator.getInstance()
|
||||
album.songs.sortedWith { o1, o2 -> collator.compare(o2.title, o1.title) }
|
||||
}
|
||||
SONG_DURATION -> album.songs.sortedWith { o1, o2 ->
|
||||
o1.duration.compareTo(
|
||||
|
|
|
@ -19,6 +19,7 @@ import code.name.monkey.retromusic.helper.SortOrder
|
|||
import code.name.monkey.retromusic.model.Album
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import java.text.Collator
|
||||
|
||||
|
||||
/**
|
||||
|
@ -65,8 +66,7 @@ class RealAlbumRepository(private val songRepository: RealSongRepository) :
|
|||
)
|
||||
val songs = songRepository.songs(cursor)
|
||||
val album = Album(albumId, songs)
|
||||
sortAlbumSongs(album)
|
||||
return album
|
||||
return sortAlbumSongs(album)
|
||||
}
|
||||
|
||||
// We don't need sorted list of songs (with sortAlbumSongs())
|
||||
|
@ -74,11 +74,22 @@ class RealAlbumRepository(private val songRepository: RealSongRepository) :
|
|||
fun splitIntoAlbums(
|
||||
songs: List<Song>
|
||||
): List<Album> {
|
||||
return if (PreferenceUtil.albumSortOrder != SortOrder.AlbumSortOrder.ALBUM_NUMBER_OF_SONGS) songs.groupBy { it.albumId }
|
||||
.map { Album(it.key, it.value) }
|
||||
// We can't sort Album with the help of MediaStore so a hack
|
||||
else songs.groupBy { it.albumId }.map { Album(it.key, it.value) }
|
||||
.sortedByDescending { it.songCount }
|
||||
val grouped = songs.groupBy { it.albumId }.map { Album(it.key, it.value) }
|
||||
return when (PreferenceUtil.albumSortOrder) {
|
||||
SortOrder.AlbumSortOrder.ALBUM_A_Z -> {
|
||||
val collator = Collator.getInstance()
|
||||
grouped.sortedWith { a1, a2 -> collator.compare(a1.title, a2.title) }
|
||||
}
|
||||
SortOrder.AlbumSortOrder.ALBUM_Z_A -> {
|
||||
val collator = Collator.getInstance()
|
||||
grouped.sortedWith { a1, a2 -> collator.compare(a2.title, a1.title) }
|
||||
}
|
||||
SortOrder.AlbumSortOrder.ALBUM_ARTIST -> {
|
||||
val collator = Collator.getInstance()
|
||||
grouped.sortedWith { a1, a2 -> collator.compare(a1.albumArtist, a2.albumArtist) }
|
||||
}
|
||||
else -> grouped
|
||||
}
|
||||
}
|
||||
|
||||
private fun sortAlbumSongs(album: Album): Album {
|
||||
|
@ -86,11 +97,13 @@ class RealAlbumRepository(private val songRepository: RealSongRepository) :
|
|||
SortOrder.AlbumSongSortOrder.SONG_TRACK_LIST -> album.songs.sortedWith { o1, o2 ->
|
||||
o1.trackNumber.compareTo(o2.trackNumber)
|
||||
}
|
||||
SortOrder.AlbumSongSortOrder.SONG_A_Z -> album.songs.sortedWith { o1, o2 ->
|
||||
o1.title.compareTo(o2.title)
|
||||
SortOrder.AlbumSongSortOrder.SONG_A_Z -> {
|
||||
val collator = Collator.getInstance()
|
||||
album.songs.sortedWith { o1, o2 -> collator.compare(o1.title, o2.title) }
|
||||
}
|
||||
SortOrder.AlbumSongSortOrder.SONG_Z_A -> album.songs.sortedWith { o1, o2 ->
|
||||
o2.title.compareTo(o1.title)
|
||||
SortOrder.AlbumSongSortOrder.SONG_Z_A -> {
|
||||
val collator = Collator.getInstance()
|
||||
album.songs.sortedWith { o1, o2 -> collator.compare(o2.title, o1.title) }
|
||||
}
|
||||
SortOrder.AlbumSongSortOrder.SONG_DURATION -> album.songs.sortedWith { o1, o2 ->
|
||||
o1.duration.compareTo(o2.duration)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue