music: re-add add -> new playlist route
Re-add the add to playlist -> new playlist route that was accidentally removed at some point.
This commit is contained in:
parent
14107c9444
commit
a6a3eceb7b
4 changed files with 39 additions and 4 deletions
|
@ -33,12 +33,13 @@ import org.oxycblt.auxio.util.logD
|
|||
import org.oxycblt.auxio.util.logW
|
||||
|
||||
/**
|
||||
* A [ViewModel] that stores the current information required for navigation picker dialogs
|
||||
* A [ViewModel] that stores choice information for [ShowArtistDialog], and possibly others in the
|
||||
* future.
|
||||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
@HiltViewModel
|
||||
class NavigationPickerViewModel @Inject constructor(private val musicRepository: MusicRepository) :
|
||||
class DetailPickerViewModel @Inject constructor(private val musicRepository: MusicRepository) :
|
||||
ViewModel(), MusicRepository.UpdateListener {
|
||||
private val _artistChoices = MutableStateFlow<ArtistShowChoices?>(null)
|
||||
/** The current set of [Artist] choices to show in the picker, or null if to show nothing. */
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.oxycblt.auxio.util.logD
|
|||
class ShowArtistDialog :
|
||||
ViewBindingMaterialDialogFragment<DialogMusicChoicesBinding>(), ClickableListListener<Artist> {
|
||||
private val detailModel: DetailViewModel by activityViewModels()
|
||||
private val pickerModel: NavigationPickerViewModel by viewModels()
|
||||
private val pickerModel: DetailPickerViewModel by viewModels()
|
||||
// Information about what artists to show choices for is initially within the navigation
|
||||
// arguments as UIDs, as that is the only safe way to parcel an artist.
|
||||
private val args: ShowArtistDialogArgs by navArgs()
|
||||
|
|
|
@ -32,10 +32,13 @@ import org.oxycblt.auxio.R
|
|||
import org.oxycblt.auxio.databinding.DialogMusicChoicesBinding
|
||||
import org.oxycblt.auxio.list.ClickableListListener
|
||||
import org.oxycblt.auxio.music.MusicViewModel
|
||||
import org.oxycblt.auxio.music.PlaylistDecision
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.ui.ViewBindingMaterialDialogFragment
|
||||
import org.oxycblt.auxio.util.collect
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.navigateSafe
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
|
||||
/**
|
||||
|
@ -72,8 +75,8 @@ class AddToPlaylistDialog :
|
|||
}
|
||||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
musicModel.playlistDecision.consume()
|
||||
pickerModel.setSongsToAdd(args.songUids)
|
||||
collect(musicModel.playlistDecision.flow, ::handleDecision)
|
||||
collectImmediately(pickerModel.currentSongsToAdd, ::updatePendingSongs)
|
||||
collectImmediately(pickerModel.playlistAddChoices, ::updatePlaylistChoices)
|
||||
}
|
||||
|
@ -93,6 +96,25 @@ class AddToPlaylistDialog :
|
|||
musicModel.createPlaylist(songs = pickerModel.currentSongsToAdd.value ?: return)
|
||||
}
|
||||
|
||||
private fun handleDecision(decision: PlaylistDecision?) {
|
||||
when (decision) {
|
||||
is PlaylistDecision.Add -> {
|
||||
logD("Navigated to playlist add dialog")
|
||||
musicModel.playlistDecision.consume()
|
||||
}
|
||||
is PlaylistDecision.New -> {
|
||||
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>?) {
|
||||
if (songs == null) {
|
||||
logD("No songs to show choices for, navigating away")
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.oxycblt.auxio.databinding.DialogPlaylistNameBinding
|
|||
import org.oxycblt.auxio.music.MusicViewModel
|
||||
import org.oxycblt.auxio.ui.ViewBindingMaterialDialogFragment
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||
|
||||
|
@ -84,9 +85,20 @@ class NewPlaylistDialog : ViewBindingMaterialDialogFragment<DialogPlaylistNameBi
|
|||
// --- VIEWMODEL SETUP ---
|
||||
musicModel.playlistDecision.consume()
|
||||
pickerModel.setPendingPlaylist(requireContext(), args.songUids)
|
||||
collectImmediately(pickerModel.currentPendingPlaylist, ::updatePendingPlaylist)
|
||||
collectImmediately(pickerModel.chosenName, ::updateChosenName)
|
||||
}
|
||||
|
||||
private fun updatePendingPlaylist(pendingPlaylist: PendingPlaylist?) {
|
||||
if (pendingPlaylist == null) {
|
||||
logD("No playlist to create, leaving")
|
||||
findNavController().navigateUp()
|
||||
return
|
||||
}
|
||||
|
||||
requireBinding().playlistName.hint = pendingPlaylist.preferredName
|
||||
}
|
||||
|
||||
private fun updateChosenName(chosenName: ChosenName) {
|
||||
(dialog as AlertDialog).getButton(AlertDialog.BUTTON_POSITIVE)?.isEnabled =
|
||||
chosenName is ChosenName.Valid || chosenName is ChosenName.Empty
|
||||
|
|
Loading…
Reference in a new issue