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