music: simplify picker closing

Simplify picker closing navigation by avoiding weird communication via
state change and instead simply navigate twice from NewPlaylistDialog.

This is probably really stupid. But so is the other way.
This commit is contained in:
Alexander Capehart 2023-05-17 12:08:31 -06:00
parent 6cfb50a10f
commit d0a68353a7
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 12 additions and 5 deletions

View file

@ -127,7 +127,7 @@ class PlaylistDetailFragment :
true true
} }
R.id.action_delete -> { R.id.action_delete -> {
musicModel.deletePlaylist(currentPlaylist) musicModel.createPlaylist()
true true
} }
else -> false else -> false

View file

@ -36,6 +36,7 @@ import org.oxycblt.auxio.util.update
// TODO: Entirely rework music equality such that it's not completely UID-focused and actually // TODO: Entirely rework music equality such that it's not completely UID-focused and actually
// takes metadata into account // takes metadata into account
// TODO: Reduce need for raw objects to save some memory
/** /**
* Library-backed implementation of [Song]. * Library-backed implementation of [Song].

View file

@ -22,6 +22,7 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.ConcatAdapter import androidx.recyclerview.widget.ConcatAdapter
@ -47,7 +48,7 @@ class AddToPlaylistDialog :
ClickableListListener<PlaylistChoice>, ClickableListListener<PlaylistChoice>,
NewPlaylistFooterAdapter.Listener { NewPlaylistFooterAdapter.Listener {
private val musicModel: MusicViewModel by activityViewModels() private val musicModel: MusicViewModel by activityViewModels()
private val pickerModel: PlaylistPickerViewModel by activityViewModels() private val pickerModel: PlaylistPickerViewModel by viewModels()
// Information about what playlist to name for is initially within the navigation arguments // Information about what playlist to name for is initially within the navigation arguments
// as UIDs, as that is the only safe way to parcel playlist information. // as UIDs, as that is the only safe way to parcel playlist information.
private val args: AddToPlaylistDialogArgs by navArgs() private val args: AddToPlaylistDialogArgs by navArgs()

View file

@ -23,6 +23,7 @@ import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.widget.addTextChangedListener import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs import androidx.navigation.fragment.navArgs
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
@ -42,7 +43,7 @@ import org.oxycblt.auxio.util.unlikelyToBeNull
@AndroidEntryPoint @AndroidEntryPoint
class NewPlaylistDialog : ViewBindingDialogFragment<DialogPlaylistNameBinding>() { class NewPlaylistDialog : ViewBindingDialogFragment<DialogPlaylistNameBinding>() {
private val musicModel: MusicViewModel by activityViewModels() private val musicModel: MusicViewModel by activityViewModels()
private val pickerModel: PlaylistPickerViewModel by activityViewModels() private val pickerModel: PlaylistPickerViewModel by viewModels()
// Information about what playlist to name for is initially within the navigation arguments // Information about what playlist to name for is initially within the navigation arguments
// as UIDs, as that is the only safe way to parcel playlist information. // as UIDs, as that is the only safe way to parcel playlist information.
private val args: NewPlaylistDialogArgs by navArgs() private val args: NewPlaylistDialogArgs by navArgs()
@ -62,6 +63,12 @@ class NewPlaylistDialog : ViewBindingDialogFragment<DialogPlaylistNameBinding>()
musicModel.createPlaylist(name, pendingPlaylist.songs) musicModel.createPlaylist(name, pendingPlaylist.songs)
pickerModel.dropPendingAddition() pickerModel.dropPendingAddition()
requireContext().showToast(R.string.lng_playlist_created) requireContext().showToast(R.string.lng_playlist_created)
findNavController().apply {
navigateUp()
// Do an additional navigation away from the playlist addition dialog, if
// needed. If that dialog isn't present, this should be a no-op. Hopefully.
navigateUp()
}
} }
.setNegativeButton(R.string.lbl_cancel, null) .setNegativeButton(R.string.lbl_cancel, null)
} }

View file

@ -8,8 +8,6 @@
android:background="?attr/colorSurface" android:background="?attr/colorSurface"
android:transitionGroup="true"> android:transitionGroup="true">
<!-- TODO: Try to align the queue bar with the playback bar. -->
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
android:id="@+id/explore_nav_host" android:id="@+id/explore_nav_host"
android:name="androidx.navigation.fragment.NavHostFragment" android:name="androidx.navigation.fragment.NavHostFragment"