Minor playback nav improvements
Change the playing nav system to rely off a single value, instead of multiple booleans.
This commit is contained in:
parent
206d8d1c1f
commit
6ac269b1df
8 changed files with 46 additions and 105 deletions
|
@ -15,7 +15,10 @@ import androidx.navigation.fragment.NavHostFragment
|
|||
import androidx.navigation.fragment.findNavController
|
||||
import org.oxycblt.auxio.databinding.FragmentMainBinding
|
||||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.ui.accent
|
||||
import org.oxycblt.auxio.ui.getInactiveAlpha
|
||||
|
@ -93,34 +96,21 @@ class MainFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingSong.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
if (binding.navBar.selectedItemId != R.id.library_fragment ||
|
||||
shouldGoToAlbum(navController!!)
|
||||
) {
|
||||
playbackModel.navToItem.observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
// If the current destination isnt even LibraryFragment, then navigate there first
|
||||
if (binding.navBar.selectedItemId != R.id.library_fragment) {
|
||||
binding.navBar.selectedItemId = R.id.library_fragment
|
||||
} else {
|
||||
// If the user currently is in library, check if its valid to navigate to the
|
||||
// item in question.
|
||||
if ((it is Album || it is Song) && shouldGoToAlbum(navController!!)) {
|
||||
binding.navBar.selectedItemId = R.id.library_fragment
|
||||
} else if (it is Artist && shouldGoToArtist(navController!!)) {
|
||||
binding.navBar.selectedItemId = R.id.library_fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingAlbum.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
if (binding.navBar.selectedItemId != R.id.library_fragment ||
|
||||
shouldGoToAlbum(navController!!)
|
||||
) {
|
||||
binding.navBar.selectedItemId = R.id.library_fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingArtist.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
if (binding.navBar.selectedItemId != R.id.library_fragment ||
|
||||
shouldGoToArtist(navController!!)
|
||||
) {
|
||||
binding.navBar.selectedItemId = R.id.library_fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
playbackModel.restorePlaybackIfNeeded(requireContext())
|
||||
|
@ -130,7 +120,6 @@ class MainFragment : Fragment() {
|
|||
return binding.root
|
||||
}
|
||||
|
||||
// I have no idea what these things even do
|
||||
private fun shouldGoToAlbum(controller: NavController): Boolean {
|
||||
return (
|
||||
controller.currentDestination!!.id == R.id.album_detail_fragment &&
|
||||
|
|
|
@ -122,8 +122,9 @@ class AlbumDetailFragment : DetailFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingSong.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
playbackModel.navToItem.observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
/*
|
||||
// Calculate where the item for the currently played song is, and navigate to there.
|
||||
val pos = detailModel.albumSortMode.value!!.getSortedSongList(
|
||||
detailModel.currentAlbum.value!!.songs
|
||||
|
@ -135,17 +136,14 @@ class AlbumDetailFragment : DetailFragment() {
|
|||
val y = binding.albumSongRecycler.y +
|
||||
binding.albumSongRecycler.getChildAt(pos).y
|
||||
|
||||
binding.nestedScroll.smoothScrollTo(0, y.toInt())
|
||||
binding.nestedScroll.scrollTo(0, y.toInt())
|
||||
}
|
||||
|
||||
playbackModel.doneWithNavToPlayingSong()
|
||||
playbackModel.doneWithNavToItem()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingAlbum.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
playbackModel.doneWithNavToPlayingAlbum()
|
||||
TODO: Re-add scroll if you find a way to implement the playing indicators on song items
|
||||
*/
|
||||
playbackModel.doneWithNavToItem()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import androidx.navigation.fragment.navArgs
|
|||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentArtistDetailBinding
|
||||
import org.oxycblt.auxio.detail.adapters.DetailAlbumAdapter
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.ui.disable
|
||||
|
@ -108,9 +109,9 @@ class ArtistDetailFragment : DetailFragment() {
|
|||
)
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingArtist.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
playbackModel.doneWithNavToPlayingArtist()
|
||||
playbackModel.navToItem.observe(viewLifecycleOwner) {
|
||||
if (it != null && it is Artist) {
|
||||
playbackModel.doneWithNavToItem()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -151,28 +151,16 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
|||
}
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingSong.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
playbackModel.navToItem.observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
libraryModel.updateNavigationStatus(false)
|
||||
|
||||
navToItem(playbackModel.song.value!!.album)
|
||||
if (it is Song) {
|
||||
navToItem(it.album)
|
||||
} else {
|
||||
navToItem(it)
|
||||
}
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingAlbum.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
libraryModel.updateNavigationStatus(false)
|
||||
|
||||
navToItem(playbackModel.song.value!!.album)
|
||||
}
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingArtist.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
libraryModel.updateNavigationStatus(false)
|
||||
|
||||
navToItem(playbackModel.song.value!!.album.artist)
|
||||
}
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
|
|
|
@ -51,7 +51,7 @@ class CompactPlaybackFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.root.setOnLongClickListener {
|
||||
playbackModel.navToPlayingSong()
|
||||
playbackModel.navToItem(playbackModel.song.value!!)
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
@ -187,20 +187,8 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
}
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingSong.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingAlbum.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
}
|
||||
|
||||
playbackModel.navToPlayingArtist.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
playbackModel.navToItem.observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
|||
|
||||
/**
|
||||
* The ViewModel that provides a UI-Focused frontend for [PlaybackStateManager].
|
||||
* TODO: Implement navigation to playing album/artist
|
||||
* @author OxygenCobalt
|
||||
*/
|
||||
class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||
|
@ -62,14 +61,8 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
private val mIsSeeking = MutableLiveData(false)
|
||||
val isSeeking: LiveData<Boolean> get() = mIsSeeking
|
||||
|
||||
private val mNavToPlayingSong = MutableLiveData(false)
|
||||
val navToPlayingSong: LiveData<Boolean> get() = mNavToPlayingSong
|
||||
|
||||
private val mNavToPlayingAlbum = MutableLiveData(false)
|
||||
val navToPlayingAlbum: LiveData<Boolean> get() = mNavToPlayingAlbum
|
||||
|
||||
private val mNavToPlayingArtist = MutableLiveData(false)
|
||||
val navToPlayingArtist: LiveData<Boolean> get() = mNavToPlayingArtist
|
||||
private val mNavToItem = MutableLiveData<BaseModel?>()
|
||||
val navToItem: LiveData<BaseModel?> get() = mNavToItem
|
||||
|
||||
private var mCanAnimate = false
|
||||
val canAnimate: Boolean get() = mCanAnimate
|
||||
|
@ -288,28 +281,12 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
}
|
||||
}
|
||||
|
||||
fun navToPlayingSong() {
|
||||
mNavToPlayingSong.value = true
|
||||
fun navToItem(item: BaseModel) {
|
||||
mNavToItem.value = item
|
||||
}
|
||||
|
||||
fun doneWithNavToPlayingSong() {
|
||||
mNavToPlayingSong.value = false
|
||||
}
|
||||
|
||||
fun navToPlayingAlbum() {
|
||||
mNavToPlayingAlbum.value = true
|
||||
}
|
||||
|
||||
fun doneWithNavToPlayingAlbum() {
|
||||
mNavToPlayingAlbum.value = false
|
||||
}
|
||||
|
||||
fun navToPlayingArtist() {
|
||||
mNavToPlayingArtist.value = true
|
||||
}
|
||||
|
||||
fun doneWithNavToPlayingArtist() {
|
||||
mNavToPlayingArtist.value = false
|
||||
fun doneWithNavToItem() {
|
||||
mNavToItem.value = null
|
||||
}
|
||||
|
||||
fun enableAnimation() {
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
android:layout_marginStart="@dimen/margin_mid_large"
|
||||
android:layout_marginEnd="@dimen/margin_mid_large"
|
||||
android:text="@{song.name}"
|
||||
android:onClick="@{() -> playbackModel.navToPlayingSong()}"
|
||||
android:onClick="@{() -> playbackModel.navToItem(playbackModel.song)}"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
|
||||
app:layout_constraintBottom_toTopOf="@+id/playback_artist"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
@ -84,7 +84,7 @@
|
|||
android:layout_marginStart="@dimen/margin_mid_large"
|
||||
android:layout_marginEnd="@dimen/margin_mid_large"
|
||||
android:text="@{song.album.artist.name}"
|
||||
android:onClick="@{() -> playbackModel.navToPlayingArtist()}"
|
||||
android:onClick="@{() -> playbackModel.navToItem(playbackModel.song.album.artist)}"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
app:layout_constraintBottom_toTopOf="@+id/playback_album"
|
||||
|
@ -102,7 +102,7 @@
|
|||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:text="@{song.album.name}"
|
||||
android:onClick="@{() -> playbackModel.navToPlayingAlbum()}"
|
||||
android:onClick="@{() -> playbackModel.navToItem(playbackModel.song.album)}"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
app:layout_constraintBottom_toTopOf="@+id/playback_seek_bar"
|
||||
|
|
Loading…
Reference in a new issue