music: add playlist song sorting
Add the internal sort modes for playlist songs. Theoretically this might be better as playlist-specific, but it's harder to integrate that currently.
This commit is contained in:
parent
f846a08b01
commit
f3a2d94086
3 changed files with 21 additions and 6 deletions
|
@ -60,9 +60,11 @@ interface MusicSettings : Settings<MusicSettings.Listener> {
|
||||||
var albumSongSort: Sort
|
var albumSongSort: Sort
|
||||||
/** The [Sort] mode used in an [Artist]'s [Song] list. */
|
/** The [Sort] mode used in an [Artist]'s [Song] list. */
|
||||||
var artistSongSort: Sort
|
var artistSongSort: Sort
|
||||||
/** The [Sort] mode used in an [Genre]'s [Song] list. */
|
/** The [Sort] mode used in a [Genre]'s [Song] list. */
|
||||||
var genreSongSort: Sort
|
var genreSongSort: Sort
|
||||||
/** The [] */
|
/** The [Sort] mode used in a [Playlist]'s [Song] list, or null if sorting by original ordering. */
|
||||||
|
var playlistSongSort: Sort?
|
||||||
|
|
||||||
interface Listener {
|
interface Listener {
|
||||||
/** Called when a setting controlling how music is loaded has changed. */
|
/** Called when a setting controlling how music is loaded has changed. */
|
||||||
fun onIndexingSettingChanged() {}
|
fun onIndexingSettingChanged() {}
|
||||||
|
@ -222,6 +224,16 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext context: Context
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override var playlistSongSort: Sort?
|
||||||
|
get() = Sort.fromIntCode(sharedPreferences.getInt(
|
||||||
|
getString(R.string.set_key_playlist_songs_sort), Int.MIN_VALUE))
|
||||||
|
set(value) {
|
||||||
|
sharedPreferences.edit {
|
||||||
|
putInt(getString(R.string.lbl_playlist), value?.intCode ?: -1)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onSettingChanged(key: String, listener: MusicSettings.Listener) {
|
override fun onSettingChanged(key: String, listener: MusicSettings.Listener) {
|
||||||
// TODO: Differentiate "hard reloads" (Need the cache) and "Soft reloads"
|
// TODO: Differentiate "hard reloads" (Need the cache) and "Soft reloads"
|
||||||
// (just need to manipulate data)
|
// (just need to manipulate data)
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.oxycblt.auxio.playback
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import androidx.room.util.query
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
@ -288,10 +289,11 @@ constructor(
|
||||||
is Genre -> musicSettings.genreSongSort
|
is Genre -> musicSettings.genreSongSort
|
||||||
is Artist -> musicSettings.artistSongSort
|
is Artist -> musicSettings.artistSongSort
|
||||||
is Album -> musicSettings.albumSongSort
|
is Album -> musicSettings.albumSongSort
|
||||||
is Playlist -> TODO("handle this")
|
is Playlist -> musicSettings.playlistSongSort
|
||||||
null -> musicSettings.songSort
|
null -> musicSettings.songSort
|
||||||
}
|
}
|
||||||
val queue = sort.songs(parent?.songs ?: deviceLibrary.songs)
|
val songs = parent?.songs ?: deviceLibrary.songs
|
||||||
|
val queue = sort?.songs(songs) ?: songs
|
||||||
playbackManager.play(song, parent, queue, shuffled)
|
playbackManager.play(song, parent, queue, shuffled)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,11 +491,11 @@ constructor(
|
||||||
private fun selectionToSongs(selection: List<Music>): List<Song> {
|
private fun selectionToSongs(selection: List<Music>): List<Song> {
|
||||||
return selection.flatMap {
|
return selection.flatMap {
|
||||||
when (it) {
|
when (it) {
|
||||||
|
is Song -> listOf(it)
|
||||||
is Album -> musicSettings.albumSongSort.songs(it.songs)
|
is Album -> musicSettings.albumSongSort.songs(it.songs)
|
||||||
is Artist -> musicSettings.artistSongSort.songs(it.songs)
|
is Artist -> musicSettings.artistSongSort.songs(it.songs)
|
||||||
is Genre -> musicSettings.genreSongSort.songs(it.songs)
|
is Genre -> musicSettings.genreSongSort.songs(it.songs)
|
||||||
is Song -> listOf(it)
|
is Playlist -> musicSettings.playlistSongSort?.songs(it.songs) ?: it.songs
|
||||||
is Playlist -> TODO("handle this")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
<string name="set_key_album_songs_sort" translatable="false">auxio_album_sort</string>
|
<string name="set_key_album_songs_sort" translatable="false">auxio_album_sort</string>
|
||||||
<string name="set_key_artist_songs_sort" translatable="false">auxio_artist_sort</string>
|
<string name="set_key_artist_songs_sort" translatable="false">auxio_artist_sort</string>
|
||||||
<string name="set_key_genre_songs_sort" translatable="false">auxio_genre_sort</string>
|
<string name="set_key_genre_songs_sort" translatable="false">auxio_genre_sort</string>
|
||||||
|
<string name="set_key_playlist_songs_sort" translatable="false">auxio_playlist_sort</string>
|
||||||
|
|
||||||
<string-array name="entries_theme">
|
<string-array name="entries_theme">
|
||||||
<item>@string/set_theme_auto</item>
|
<item>@string/set_theme_auto</item>
|
||||||
|
|
Loading…
Reference in a new issue