Improve navigation
Finally make parent navigation possible from artist albums and the like, along with heavily streamlining the main navigation code.
This commit is contained in:
parent
e236eff997
commit
fafaa0bf1f
9 changed files with 29 additions and 50 deletions
|
@ -20,6 +20,7 @@ import org.oxycblt.auxio.ui.isEdgeOn
|
|||
* The single [AppCompatActivity] for Auxio.
|
||||
*/
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.oxycblt.auxio.ui.toColor
|
|||
|
||||
/**
|
||||
* The primary "Home" [Fragment] for Auxio.
|
||||
* TODO: Make navigation stack instead of artificially rerouting to LibraryFragment
|
||||
*/
|
||||
class MainFragment : Fragment() {
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
|
@ -91,18 +92,19 @@ class MainFragment : Fragment() {
|
|||
}
|
||||
|
||||
detailModel.navToItem.observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
// If the current destination isn't even LibraryFragment, then navigate there first
|
||||
if (binding.navBar.selectedItemId != R.id.library_fragment) {
|
||||
if (it != null && navController != null) {
|
||||
val curDest = navController.currentDestination?.id
|
||||
|
||||
val isOk = when (it) {
|
||||
is Song -> (detailModel.currentAlbum.value?.id == it.album.id) magic (curDest != R.id.album_detail_fragment)
|
||||
is Album -> (detailModel.currentAlbum.value?.id == it.id) magic (curDest != R.id.album_detail_fragment)
|
||||
is Artist -> (detailModel.currentArtist.value?.id == it.id) magic (curDest != R.id.artist_detail_fragment)
|
||||
|
||||
else -> false
|
||||
}
|
||||
|
||||
if (isOk) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,29 +117,14 @@ class MainFragment : Fragment() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Whether its okay to navigate to the album detail fragment when the playing song/album needs to
|
||||
* be navigated to
|
||||
* Magic boolean logic that gets navigation working.
|
||||
* true true -> true |
|
||||
* true false -> false |
|
||||
* false true -> true |
|
||||
* false false -> false |
|
||||
*/
|
||||
private fun shouldGoToAlbum(controller: NavController): Boolean {
|
||||
return (
|
||||
controller.currentDestination!!.id == R.id.album_detail_fragment &&
|
||||
detailModel.currentAlbum.value?.id != playbackModel.song.value!!.album.id
|
||||
) ||
|
||||
controller.currentDestination!!.id == R.id.artist_detail_fragment ||
|
||||
controller.currentDestination!!.id == R.id.genre_detail_fragment
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether its okay to go to the artist detail fragment when the current playing artist
|
||||
* is selected.
|
||||
*/
|
||||
private fun shouldGoToArtist(controller: NavController): Boolean {
|
||||
return (
|
||||
controller.currentDestination!!.id == R.id.artist_detail_fragment &&
|
||||
detailModel.currentArtist.value?.id != playbackModel.song.value!!.album.artist.id
|
||||
) ||
|
||||
controller.currentDestination!!.id == R.id.album_detail_fragment ||
|
||||
controller.currentDestination!!.id == R.id.genre_detail_fragment
|
||||
private infix fun Boolean.magic(other: Boolean): Boolean {
|
||||
return if (!this && !other) false else !(this && !other)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -86,13 +86,11 @@ class AlbumDetailFragment : DetailFragment() {
|
|||
|
||||
detailModel.navToParent.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
if (!args.fromArtist) {
|
||||
findNavController().navigate(
|
||||
AlbumDetailFragmentDirections.actionShowParentArtist(
|
||||
detailModel.currentAlbum.value!!.artist.id
|
||||
)
|
||||
findNavController().navigate(
|
||||
AlbumDetailFragmentDirections.actionShowParentArtist(
|
||||
detailModel.currentAlbum.value!!.artist.id
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
detailModel.doneWithNavToParent()
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class ArtistDetailFragment : DetailFragment() {
|
|||
detailModel.updateNavigationStatus(true)
|
||||
|
||||
findNavController().navigate(
|
||||
ArtistDetailFragmentDirections.actionShowAlbum(it.id, true)
|
||||
ArtistDetailFragmentDirections.actionShowAlbum(it.id)
|
||||
)
|
||||
}
|
||||
},
|
||||
|
|
|
@ -77,7 +77,7 @@ class GenreDetailFragment : DetailFragment() {
|
|||
)
|
||||
} else if (it is Album) {
|
||||
findNavController().navigate(
|
||||
GenreDetailFragmentDirections.actionGoAlbum(it.id, false)
|
||||
GenreDetailFragmentDirections.actionGoAlbum(it.id)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ class LibraryFragment : Fragment() {
|
|||
when (baseModel) {
|
||||
is Genre -> LibraryFragmentDirections.actionShowGenre(baseModel.id)
|
||||
is Artist -> LibraryFragmentDirections.actionShowArtist(baseModel.id)
|
||||
is Album -> LibraryFragmentDirections.actionShowAlbum(baseModel.id, false)
|
||||
is Album -> LibraryFragmentDirections.actionShowAlbum(baseModel.id)
|
||||
|
||||
// If given model wasn't valid, then reset the navigation status
|
||||
// and abort the navigation.
|
||||
|
|
|
@ -163,7 +163,7 @@ class SearchFragment : Fragment() {
|
|||
when (baseModel) {
|
||||
is Genre -> SearchFragmentDirections.actionShowGenre(baseModel.id)
|
||||
is Artist -> SearchFragmentDirections.actionShowArtist(baseModel.id)
|
||||
is Album -> SearchFragmentDirections.actionShowAlbum(baseModel.id, false)
|
||||
is Album -> SearchFragmentDirections.actionShowAlbum(baseModel.id)
|
||||
|
||||
// If given model wasn't valid, then reset the navigation status
|
||||
// and abort the navigation.
|
||||
|
|
|
@ -7,16 +7,12 @@ import android.content.res.Configuration
|
|||
import android.content.res.Resources
|
||||
import android.graphics.Point
|
||||
import android.os.Build
|
||||
import android.text.SpannableString
|
||||
import android.text.Spanned
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.MenuItem
|
||||
import android.view.WindowManager
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.annotation.PluralsRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
|
|
@ -56,9 +56,6 @@
|
|||
<argument
|
||||
android:name="albumId"
|
||||
app:argType="long" />
|
||||
<argument
|
||||
android:name="fromArtist"
|
||||
app:argType="boolean" />
|
||||
<action
|
||||
android:id="@+id/action_show_parent_artist"
|
||||
app:destination="@id/artist_detail_fragment"
|
||||
|
|
Loading…
Reference in a new issue