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.android.ext.android.get
|
||||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||||
import org.koin.core.parameter.parametersOf
|
import org.koin.core.parameter.parametersOf
|
||||||
|
import java.text.Collator
|
||||||
|
|
||||||
class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_details),
|
class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_details),
|
||||||
IAlbumClickListener, ICabHolder {
|
IAlbumClickListener, ICabHolder {
|
||||||
|
@ -437,15 +438,13 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
|
||||||
o2.trackNumber
|
o2.trackNumber
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
SONG_A_Z -> album.songs.sortedWith { o1, o2 ->
|
SONG_A_Z -> {
|
||||||
o1.title.compareTo(
|
val collator = Collator.getInstance()
|
||||||
o2.title
|
album.songs.sortedWith { o1, o2 -> collator.compare(o1.title, o2.title) }
|
||||||
)
|
|
||||||
}
|
}
|
||||||
SONG_Z_A -> album.songs.sortedWith { o1, o2 ->
|
SONG_Z_A -> {
|
||||||
o2.title.compareTo(
|
val collator = Collator.getInstance()
|
||||||
o1.title
|
album.songs.sortedWith { o1, o2 -> collator.compare(o2.title, o1.title) }
|
||||||
)
|
|
||||||
}
|
}
|
||||||
SONG_DURATION -> album.songs.sortedWith { o1, o2 ->
|
SONG_DURATION -> album.songs.sortedWith { o1, o2 ->
|
||||||
o1.duration.compareTo(
|
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.Album
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
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 songs = songRepository.songs(cursor)
|
||||||
val album = Album(albumId, songs)
|
val album = Album(albumId, songs)
|
||||||
sortAlbumSongs(album)
|
return sortAlbumSongs(album)
|
||||||
return album
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't need sorted list of songs (with sortAlbumSongs())
|
// We don't need sorted list of songs (with sortAlbumSongs())
|
||||||
|
@ -74,11 +74,22 @@ class RealAlbumRepository(private val songRepository: RealSongRepository) :
|
||||||
fun splitIntoAlbums(
|
fun splitIntoAlbums(
|
||||||
songs: List<Song>
|
songs: List<Song>
|
||||||
): List<Album> {
|
): List<Album> {
|
||||||
return if (PreferenceUtil.albumSortOrder != SortOrder.AlbumSortOrder.ALBUM_NUMBER_OF_SONGS) songs.groupBy { it.albumId }
|
val grouped = songs.groupBy { it.albumId }.map { Album(it.key, it.value) }
|
||||||
.map { Album(it.key, it.value) }
|
return when (PreferenceUtil.albumSortOrder) {
|
||||||
// We can't sort Album with the help of MediaStore so a hack
|
SortOrder.AlbumSortOrder.ALBUM_A_Z -> {
|
||||||
else songs.groupBy { it.albumId }.map { Album(it.key, it.value) }
|
val collator = Collator.getInstance()
|
||||||
.sortedByDescending { it.songCount }
|
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 {
|
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 ->
|
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 -> album.songs.sortedWith { o1, o2 ->
|
SortOrder.AlbumSongSortOrder.SONG_A_Z -> {
|
||||||
o1.title.compareTo(o2.title)
|
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 ->
|
SortOrder.AlbumSongSortOrder.SONG_Z_A -> {
|
||||||
o2.title.compareTo(o1.title)
|
val collator = Collator.getInstance()
|
||||||
|
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 ->
|
||||||
o1.duration.compareTo(o2.duration)
|
o1.duration.compareTo(o2.duration)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue