home: handle playback decision event

Forgot to add this.

Resolves #734.
This commit is contained in:
Alexander Capehart
2024-04-07 23:25:53 -06:00
parent a920da3fbd
commit dc51c84c54
6 changed files with 31 additions and 11 deletions
@@ -75,6 +75,7 @@ import org.oxycblt.auxio.music.PlaylistDecision
import org.oxycblt.auxio.music.PlaylistMessage
import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.music.external.M3U
import org.oxycblt.auxio.playback.PlaybackDecision
import org.oxycblt.auxio.playback.PlaybackViewModel
import org.oxycblt.auxio.util.collect
import org.oxycblt.auxio.util.collectImmediately
@@ -214,12 +215,13 @@ class HomeFragment :
collectImmediately(homeModel.currentTabType, ::updateCurrentTab)
collectImmediately(homeModel.songList, homeModel.isFastScrolling, ::updateFab)
collect(homeModel.speedDialOpen, ::updateSpeedDial)
collect(detailModel.toShow.flow, ::handleShow)
collect(listModel.menu.flow, ::handleMenu)
collectImmediately(listModel.selected, ::updateSelection)
collectImmediately(musicModel.indexingState, ::updateIndexerState)
collect(musicModel.playlistDecision.flow, ::handleDecision)
collect(musicModel.playlistDecision.flow, ::handlePlaylistDecision)
collectImmediately(musicModel.playlistMessage.flow, ::handlePlaylistMessage)
collect(detailModel.toShow.flow, ::handleShow)
collect(playbackModel.playbackDecision.flow, ::handlePlaybackDecision)
}
override fun onResume() {
@@ -487,7 +489,7 @@ class HomeFragment :
}
}
private fun handleDecision(decision: PlaylistDecision?) {
private fun handlePlaylistDecision(decision: PlaylistDecision?) {
if (decision == null) return
val directions =
when (decision) {
@@ -539,6 +541,20 @@ class HomeFragment :
musicModel.playlistMessage.consume()
}
private fun handlePlaybackDecision(decision: PlaybackDecision?) {
when (decision) {
is PlaybackDecision.PlayFromArtist -> {
findNavController()
.navigateSafe(HomeFragmentDirections.playFromArtist(decision.song.uid))
}
is PlaybackDecision.PlayFromGenre -> {
findNavController()
.navigateSafe(HomeFragmentDirections.playFromGenre(decision.song.uid))
}
null -> {}
}
}
private fun updateFab(songs: List<Song>, isFastScrolling: Boolean) {
updateFabVisibility(songs, isFastScrolling, homeModel.currentTabType.value)
}
@@ -70,7 +70,7 @@ class PlayFromArtistDialog :
}
playbackModel.playbackDecision.consume()
pickerModel.setPickerSongUid(args.artistUid)
pickerModel.setPickerSongUid(args.songUid)
collectImmediately(pickerModel.currentPickerSong, ::updateSong)
}
@@ -70,7 +70,7 @@ class PlayFromGenreDialog :
}
playbackModel.playbackDecision.consume()
pickerModel.setPickerSongUid(args.genreUid)
pickerModel.setPickerSongUid(args.songUid)
collectImmediately(pickerModel.currentPickerSong, ::updateSong)
}
@@ -368,10 +368,7 @@ constructor(
C.INDEX_UNSET
} else {
currTimeline.getNextWindowIndex(
player.currentMediaItemIndex,
Player.REPEAT_MODE_OFF,
player.shuffleModeEnabled
)
player.currentMediaItemIndex, Player.REPEAT_MODE_OFF, player.shuffleModeEnabled)
}
if (nextIndex == C.INDEX_UNSET) {