Fixed invisible bottom navbar sometimes and a crash

This commit is contained in:
Prathamesh More 2021-10-13 16:53:53 +05:30
parent c2647b9160
commit 9b376a2f4f
4 changed files with 13 additions and 8 deletions

View file

@ -26,6 +26,7 @@ import androidx.navigation.ui.setupWithNavController
import code.name.monkey.retromusic.*
import code.name.monkey.retromusic.activities.base.AbsCastActivity
import code.name.monkey.retromusic.databinding.SlidingMusicPanelLayoutBinding
import code.name.monkey.retromusic.extensions.currentFragment
import code.name.monkey.retromusic.extensions.extra
import code.name.monkey.retromusic.extensions.findNavController
import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewFragment
@ -91,9 +92,7 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
getBottomNavigationView().setupWithNavController(navController)
// Scroll Fragment to top
getBottomNavigationView().setOnItemReselectedListener {
supportFragmentManager.findFragmentById(R.id.fragment_container)?.childFragmentManager?.fragments?.get(
0
)
currentFragment(R.id.fragment_container)
.also {
if (it is AbsRecyclerViewFragment<*, *>) {
it.scrollToTop()

View file

@ -14,6 +14,7 @@
*/
package code.name.monkey.retromusic.activities.base
import android.animation.Animator
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
@ -65,6 +66,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
}
private var windowInsets: WindowInsetsCompat? = null
private var bottomNavAnimator: Animator? = null
protected val libraryViewModel by viewModel<LibraryViewModel>()
private lateinit var bottomSheetBehavior: RetroBottomSheetBehavior<FrameLayout>
private var playerFragment: AbsPlayerFragment? = null
@ -274,8 +276,9 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
}
fun setBottomBarVisibility(visible: Boolean) {
bottomNavAnimator?.end()
if (!(visible && binding.bottomNavigationView.isVisible)) {
if (visible) {
bottomNavAnimator = if (visible) {
binding.bottomNavigationView.translateYAnimate(0F)
} else {
binding.bottomNavigationView.translateYAnimate(dip(R.dimen.bottom_nav_height).toFloat())