Skip to content

Commit

Permalink
home: handle playback decision event
Browse files Browse the repository at this point in the history
Forgot to add this.

Resolves #734.
  • Loading branch information
OxygenCobalt committed Apr 4, 2024
1 parent 13a3a57 commit 6e05ef3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## dev

#### What's Fixed
- Fixed crash when using play next on the end of a queue or with a single-song queue
- Fixed weird behavior if using play next on the end of a queue with repeat all enabled
- Fixed artist choice dialog not showing up on home screen if playing from artist/genre was enabled

## 3.4.2

#### What's Fixed
Expand Down
22 changes: 19 additions & 3 deletions app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -487,7 +489,7 @@ class HomeFragment :
}
}

private fun handleDecision(decision: PlaylistDecision?) {
private fun handlePlaylistDecision(decision: PlaylistDecision?) {
if (decision == null) return
val directions =
when (decision) {
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PlayFromArtistDialog :
}

playbackModel.playbackDecision.consume()
pickerModel.setPickerSongUid(args.artistUid)
pickerModel.setPickerSongUid(args.songUid)
collectImmediately(pickerModel.currentPickerSong, ::updateSong)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PlayFromGenreDialog :
}

playbackModel.playbackDecision.consume()
pickerModel.setPickerSongUid(args.genreUid)
pickerModel.setPickerSongUid(args.songUid)
collectImmediately(pickerModel.currentPickerSong, ::updateSong)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,7 @@ class PlaybackService :
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) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/navigation/inner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@
android:label="play_from_artist_dialog"
tools:layout="@layout/dialog_music_choices">
<argument
android:name="artistUid"
android:name="songUid"
app:argType="org.oxycblt.auxio.music.Music$UID" />
</dialog>

Expand All @@ -501,7 +501,7 @@
android:label="play_from_genre_dialog"
tools:layout="@layout/dialog_music_choices">
<argument
android:name="genreUid"
android:name="songUid"
app:argType="org.oxycblt.auxio.music.Music$UID" />
</dialog>

Expand Down

0 comments on commit 6e05ef3

Please sign in to comment.