music: re-add picker reloading
Fix a regression where the music picker would not reload if the library changes.
This commit is contained in:
parent
fd61f5bb9f
commit
2242c413d8
5 changed files with 20 additions and 10 deletions
|
@ -116,6 +116,10 @@ class DetailViewModel(application: Application) :
|
||||||
currentGenre.value?.let(::refreshGenreData)
|
currentGenre.value?.let(::refreshGenreData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
musicStore.addCallback(this)
|
||||||
|
}
|
||||||
|
|
||||||
fun setSongUid(uid: Music.UID) {
|
fun setSongUid(uid: Music.UID) {
|
||||||
if (_currentSong.value?.run { song.uid } == uid) return
|
if (_currentSong.value?.run { song.uid } == uid) return
|
||||||
val library = unlikelyToBeNull(musicStore.library)
|
val library = unlikelyToBeNull(musicStore.library)
|
||||||
|
@ -153,10 +157,6 @@ class DetailViewModel(application: Application) :
|
||||||
refreshGenreData(genre)
|
refreshGenreData(genre)
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
|
||||||
musicStore.addCallback(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun generateDetailSong(song: Song) {
|
private fun generateDetailSong(song: Song) {
|
||||||
currentSongJob?.cancel()
|
currentSongJob?.cancel()
|
||||||
_currentSong.value = DetailSong(song, null)
|
_currentSong.value = DetailSong(song, null)
|
||||||
|
|
|
@ -107,9 +107,6 @@ class MusicStore private constructor() {
|
||||||
/** Sanitize an old item to find the corresponding item in a new library. */
|
/** Sanitize an old item to find the corresponding item in a new library. */
|
||||||
fun sanitize(song: Song) = find<Song>(song.uid)
|
fun sanitize(song: Song) = find<Song>(song.uid)
|
||||||
|
|
||||||
/** Sanitize an old item to find the corresponding item in a new library. */
|
|
||||||
fun sanitize(songs: List<Song>) = songs.mapNotNull { sanitize(it) }
|
|
||||||
|
|
||||||
/** Sanitize an old item to find the corresponding item in a new library. */
|
/** Sanitize an old item to find the corresponding item in a new library. */
|
||||||
fun sanitize(album: Album) = find<Album>(album.uid)
|
fun sanitize(album: Album) = find<Album>(album.uid)
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ abstract class ArtistPickerDialog :
|
||||||
override fun onBindingCreated(binding: DialogMusicPickerBinding, savedInstanceState: Bundle?) {
|
override fun onBindingCreated(binding: DialogMusicPickerBinding, savedInstanceState: Bundle?) {
|
||||||
binding.pickerRecycler.adapter = artistAdapter
|
binding.pickerRecycler.adapter = artistAdapter
|
||||||
collectImmediately(pickerModel.currentArtists) { artists ->
|
collectImmediately(pickerModel.currentArtists) { artists ->
|
||||||
if (artists != null) {
|
if (!artists.isNullOrEmpty()) {
|
||||||
artistAdapter.submitList(artists)
|
artistAdapter.submitList(artists)
|
||||||
} else {
|
} else {
|
||||||
findNavController().navigateUp()
|
findNavController().navigateUp()
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.oxycblt.auxio.music.MusicStore
|
||||||
import org.oxycblt.auxio.music.Song
|
import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||||
|
|
||||||
class MusicPickerViewModel : ViewModel() {
|
class MusicPickerViewModel : ViewModel(), MusicStore.Callback {
|
||||||
private val musicStore = MusicStore.getInstance()
|
private val musicStore = MusicStore.getInstance()
|
||||||
|
|
||||||
private val _currentSong = MutableStateFlow<Song?>(null)
|
private val _currentSong = MutableStateFlow<Song?>(null)
|
||||||
|
@ -28,4 +28,17 @@ class MusicPickerViewModel : ViewModel() {
|
||||||
val library = unlikelyToBeNull(musicStore.library)
|
val library = unlikelyToBeNull(musicStore.library)
|
||||||
_currentArtists.value = uids.mapNotNull { library.find<Artist>(it) }.ifEmpty { null }
|
_currentArtists.value = uids.mapNotNull { library.find<Artist>(it) }.ifEmpty { null }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onLibraryChanged(library: MusicStore.Library?) {
|
||||||
|
if (library != null) {
|
||||||
|
val song = _currentSong.value
|
||||||
|
val artists = _currentArtists.value
|
||||||
|
if (song != null) {
|
||||||
|
_currentSong.value = library.sanitize(song)
|
||||||
|
_currentArtists.value = _currentSong.value?.artists
|
||||||
|
} else if (artists != null){
|
||||||
|
_currentArtists.value = artists.mapNotNull { library.sanitize(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -456,7 +456,7 @@ class PlaybackStateManager private constructor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_queue = newLibrary.sanitize(_queue).toMutableList()
|
_queue = _queue.mapNotNullTo(mutableListOf()) { newLibrary.sanitize(it) }
|
||||||
|
|
||||||
while (song?.uid != oldSongUid && index > -1) {
|
while (song?.uid != oldSongUid && index > -1) {
|
||||||
index--
|
index--
|
||||||
|
|
Loading…
Reference in a new issue