Fix playing item highlighting issue

Fix an issue if one plays a song from all songs and then attempts to play a song from its genre/album, the song will not highlight despite it supposely playing.
This commit is contained in:
OxygenCobalt 2021-01-11 12:28:13 -07:00
parent 4f8ddb793f
commit e029785181
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 42 additions and 18 deletions

View file

@ -112,15 +112,12 @@ class AlbumDetailFragment : DetailFragment() {
// --- PLAYBACKVIEWMODEL SETUP ---
playbackModel.song.observe(viewLifecycleOwner) { song ->
if (playbackModel.mode.value == PlaybackMode.IN_ALBUM &&
playbackModel.parent.value?.id == detailModel.currentAlbum.value!!.id
) {
detailAdapter.highlightSong(song, binding.detailRecycler)
} else {
// Clear the viewholders if the mode isn't ALL_SONGS
detailAdapter.highlightSong(null, binding.detailRecycler)
}
playbackModel.song.observe(viewLifecycleOwner) {
handlePlayingItem(detailAdapter)
}
playbackModel.mode.observe(viewLifecycleOwner) {
handlePlayingItem(detailAdapter)
}
playbackModel.isInUserQueue.observe(viewLifecycleOwner) {
@ -134,6 +131,21 @@ class AlbumDetailFragment : DetailFragment() {
return binding.root
}
/**
* Handle an update to the mode or the song and determine whether to highlight a song
* item based off that
*/
private fun handlePlayingItem(detailAdapter: AlbumDetailAdapter) {
if (playbackModel.mode.value == PlaybackMode.IN_ALBUM &&
playbackModel.parent.value?.id == detailModel.currentAlbum.value!!.id
) {
detailAdapter.highlightSong(playbackModel.song.value, binding.detailRecycler)
} else {
// Clear the viewholders if the mode isn't ALL_SONGS
detailAdapter.highlightSong(null, binding.detailRecycler)
}
}
/**
* Scroll to the currently playing item.
*/

View file

@ -87,15 +87,12 @@ class GenreDetailFragment : DetailFragment() {
// --- PLAYBACKVIEWMODEL SETUP ---
playbackModel.song.observe(viewLifecycleOwner) { song ->
if (playbackModel.mode.value == PlaybackMode.IN_GENRE &&
playbackModel.parent.value?.id == detailModel.currentGenre.value!!.id
) {
detailAdapter.highlightSong(song, binding.detailRecycler)
} else {
// Clear the viewholders if the mode isn't ALL_SONGS
detailAdapter.highlightSong(null, binding.detailRecycler)
}
playbackModel.song.observe(viewLifecycleOwner) {
handlePlayingItem(detailAdapter)
}
playbackModel.mode.observe(viewLifecycleOwner) {
handlePlayingItem(detailAdapter)
}
playbackModel.isInUserQueue.observe(viewLifecycleOwner) {
@ -108,4 +105,19 @@ class GenreDetailFragment : DetailFragment() {
return binding.root
}
/**
* Handle an update to the mode or the song and determine whether to highlight a song
* item based off that
*/
private fun handlePlayingItem(detailAdapter: GenreDetailAdapter) {
if (playbackModel.mode.value == PlaybackMode.IN_GENRE &&
playbackModel.parent.value?.id == detailModel.currentGenre.value!!.id
) {
detailAdapter.highlightSong(playbackModel.song.value, binding.detailRecycler)
} else {
// Clear the viewholders if the mode isn't ALL_SONGS
detailAdapter.highlightSong(null, binding.detailRecycler)
}
}
}