Re-add BottomNavigationView animation
Readd the navigation animation that occurs when an item is selected by the BottomNavigationView.
This commit is contained in:
parent
d46b99400f
commit
cc9a952b9a
2 changed files with 25 additions and 20 deletions
|
@ -23,7 +23,7 @@ import org.oxycblt.auxio.ui.accent
|
||||||
import org.oxycblt.auxio.ui.getInactiveAlpha
|
import org.oxycblt.auxio.ui.getInactiveAlpha
|
||||||
import org.oxycblt.auxio.ui.getTransparentAccent
|
import org.oxycblt.auxio.ui.getTransparentAccent
|
||||||
import org.oxycblt.auxio.ui.toColor
|
import org.oxycblt.auxio.ui.toColor
|
||||||
import java.lang.IllegalArgumentException
|
import kotlin.IllegalArgumentException
|
||||||
|
|
||||||
class MainFragment : Fragment() {
|
class MainFragment : Fragment() {
|
||||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||||
|
@ -72,8 +72,12 @@ class MainFragment : Fragment() {
|
||||||
binding.navBar.itemIconTintList = navTints
|
binding.navBar.itemIconTintList = navTints
|
||||||
binding.navBar.itemTextColor = navTints
|
binding.navBar.itemTextColor = navTints
|
||||||
|
|
||||||
|
// TODO: Add the navigation
|
||||||
|
// Do the trick to test if the memleak is real: Nav to songs, nav to playing, nav out of playing, nav to playing album, nav to songs
|
||||||
navController?.let { controller ->
|
navController?.let { controller ->
|
||||||
binding.navBar.setupWithNavController(controller)
|
binding.navBar.setOnNavigationItemSelectedListener {
|
||||||
|
navigateWithItem(controller, it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- VIEWMODEL SETUP ---
|
// --- VIEWMODEL SETUP ---
|
||||||
|
@ -96,10 +100,13 @@ class MainFragment : Fragment() {
|
||||||
playbackModel.navToSong.observe(viewLifecycleOwner) {
|
playbackModel.navToSong.observe(viewLifecycleOwner) {
|
||||||
if (it) {
|
if (it) {
|
||||||
if (binding.navBar.selectedItemId != R.id.library_fragment ||
|
if (binding.navBar.selectedItemId != R.id.library_fragment ||
|
||||||
navController!!.currentDestination?.id == R.id.artist_detail_fragment ||
|
(navController!!.currentDestination?.id == R.id.album_detail_fragment
|
||||||
navController.currentDestination?.id == R.id.genre_detail_fragment ||
|
&& detailModel.currentAlbum.value == null
|
||||||
detailModel.currentAlbum.value == null ||
|
|| detailModel.currentAlbum.value?.id
|
||||||
detailModel.currentAlbum.value?.id != playbackModel.song.value!!.album.id
|
!= playbackModel.song.value!!.album.id
|
||||||
|
) ||
|
||||||
|
navController.currentDestination?.id == R.id.artist_detail_fragment ||
|
||||||
|
navController.currentDestination?.id == R.id.genre_detail_fragment
|
||||||
) {
|
) {
|
||||||
binding.navBar.selectedItemId = R.id.library_fragment
|
binding.navBar.selectedItemId = R.id.library_fragment
|
||||||
}
|
}
|
||||||
|
@ -113,17 +120,15 @@ class MainFragment : Fragment() {
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private fun navigateWithItem(navController: NavController, item: MenuItem): Boolean {
|
||||||
* Some custom navigator code based off [NavigationUI] that makes animations function
|
if (navController.currentDestination!!.id != item.itemId) {
|
||||||
*/
|
// Create custom NavOptions myself so that animations work
|
||||||
private fun navigateWithItem(item: MenuItem, navController: NavController): Boolean {
|
val options = NavOptions.Builder()
|
||||||
if (item.itemId != navController.currentDestination!!.id) {
|
.setLaunchSingleTop(true)
|
||||||
val builder = NavOptions.Builder().setLaunchSingleTop(true)
|
.setEnterAnim(R.animator.nav_default_enter_anim)
|
||||||
|
.setExitAnim(R.animator.nav_default_exit_anim)
|
||||||
val options = builder.setEnterAnim(R.anim.nav_default_enter_anim)
|
.setPopEnterAnim(R.animator.nav_default_pop_enter_anim)
|
||||||
.setExitAnim(R.anim.nav_default_exit_anim)
|
.setPopExitAnim(R.animator.nav_default_pop_exit_anim)
|
||||||
.setPopEnterAnim(R.anim.nav_default_enter_anim)
|
|
||||||
.setPopExitAnim(R.anim.nav_default_exit_anim)
|
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
|
@ -134,6 +139,6 @@ class MainFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,10 +124,12 @@ class AlbumDetailFragment : DetailFragment() {
|
||||||
|
|
||||||
playbackModel.navToSong.observe(viewLifecycleOwner) {
|
playbackModel.navToSong.observe(viewLifecycleOwner) {
|
||||||
if (it) {
|
if (it) {
|
||||||
|
// Calculate where the item for the currently played song is, and navigate to there.
|
||||||
val pos = detailModel.currentAlbum.value!!.songs.indexOf(playbackModel.song.value)
|
val pos = detailModel.currentAlbum.value!!.songs.indexOf(playbackModel.song.value)
|
||||||
|
|
||||||
if (pos != -1) {
|
if (pos != -1) {
|
||||||
binding.albumSongRecycler.post {
|
binding.albumSongRecycler.post {
|
||||||
|
// Only scroll after UI creation
|
||||||
val y = binding.albumSongRecycler.y +
|
val y = binding.albumSongRecycler.y +
|
||||||
binding.albumSongRecycler.getChildAt(pos).y
|
binding.albumSongRecycler.getChildAt(pos).y
|
||||||
|
|
||||||
|
@ -135,8 +137,6 @@ class AlbumDetailFragment : DetailFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
playbackModel.doneWithNavToPlayingSong()
|
playbackModel.doneWithNavToPlayingSong()
|
||||||
} else {
|
|
||||||
findNavController().navigateUp()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue