music: fix crash on adding to new playlist
Apparently dialog fragments do not change the state of the fragment it is overlaid on, resulting in it still having active StateFlow collectors that will intercept new playlist requests before AddToPlaylistDialog. Once again sharing StateFlows across views has bit me. In the future I may try to preserve the navigation idioms by not stacking NewPlaylistDialog on AddToPlaylistDialog and instead simply swap them out. I think this would also be better design too (It's not like I'm allowing other decision dialogs to be exitable back to their prior dialog).
This commit is contained in:
parent
d297c10b0a
commit
20c34fd888
1 changed files with 10 additions and 22 deletions
|
@ -32,10 +32,8 @@ import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.databinding.DialogMusicChoicesBinding
|
import org.oxycblt.auxio.databinding.DialogMusicChoicesBinding
|
||||||
import org.oxycblt.auxio.list.ClickableListListener
|
import org.oxycblt.auxio.list.ClickableListListener
|
||||||
import org.oxycblt.auxio.music.MusicViewModel
|
import org.oxycblt.auxio.music.MusicViewModel
|
||||||
import org.oxycblt.auxio.music.PlaylistDecision
|
|
||||||
import org.oxycblt.auxio.music.Song
|
import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.ui.ViewBindingMaterialDialogFragment
|
import org.oxycblt.auxio.ui.ViewBindingMaterialDialogFragment
|
||||||
import org.oxycblt.auxio.util.collect
|
|
||||||
import org.oxycblt.auxio.util.collectImmediately
|
import org.oxycblt.auxio.util.collectImmediately
|
||||||
import org.oxycblt.auxio.util.logD
|
import org.oxycblt.auxio.util.logD
|
||||||
import org.oxycblt.auxio.util.navigateSafe
|
import org.oxycblt.auxio.util.navigateSafe
|
||||||
|
@ -93,26 +91,16 @@ class AddToPlaylistDialog :
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNewPlaylist() {
|
override fun onNewPlaylist() {
|
||||||
musicModel.createPlaylist(songs = pickerModel.currentSongsToAdd.value ?: return)
|
// TODO: This is a temporary fix. Eventually I want to make this navigate away and
|
||||||
}
|
// instead have primary fragments launch navigation to the new playlist dialog.
|
||||||
|
// This should be better design (dialog layering is uh... probably not good) and
|
||||||
private fun handleDecision(decision: PlaylistDecision?) {
|
// preserves the existing navigation system.
|
||||||
when (decision) {
|
// I could also roll some kind of new playlist textbox into the dialog, but that's
|
||||||
is PlaylistDecision.Add -> {
|
// a lot harder.
|
||||||
logD("Navigated to playlist add dialog")
|
val songs = pickerModel.currentSongsToAdd.value ?: return
|
||||||
musicModel.playlistDecision.consume()
|
findNavController()
|
||||||
}
|
.navigateSafe(
|
||||||
is PlaylistDecision.New -> {
|
AddToPlaylistDialogDirections.newPlaylist(songs.map { it.uid }.toTypedArray()))
|
||||||
logD("Navigating to new playlist dialog")
|
|
||||||
findNavController()
|
|
||||||
.navigateSafe(
|
|
||||||
AddToPlaylistDialogDirections.newPlaylist(
|
|
||||||
decision.songs.map { it.uid }.toTypedArray()))
|
|
||||||
}
|
|
||||||
is PlaylistDecision.Rename,
|
|
||||||
is PlaylistDecision.Delete -> error("Unexpected decision $decision")
|
|
||||||
null -> {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePendingSongs(songs: List<Song>?) {
|
private fun updatePendingSongs(songs: List<Song>?) {
|
||||||
|
|
Loading…
Reference in a new issue