Fixed bottom sheet animations
This commit is contained in:
parent
72aedb7e77
commit
3bfacaea77
8 changed files with 48 additions and 39 deletions
|
@ -27,7 +27,6 @@ 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.drawNextToNavbar
|
||||
import code.name.monkey.retromusic.extensions.extra
|
||||
import code.name.monkey.retromusic.extensions.findNavController
|
||||
import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewFragment
|
||||
|
@ -40,7 +39,6 @@ import code.name.monkey.retromusic.repository.PlaylistSongsLoader
|
|||
import code.name.monkey.retromusic.service.MusicService
|
||||
import code.name.monkey.retromusic.util.AppRater
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.android.ext.android.get
|
||||
|
@ -112,13 +110,13 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
|
|||
saveTab(destination.id)
|
||||
}
|
||||
// Show Bottom Navigation Bar
|
||||
setBottomBarVisibility(true)
|
||||
setBottomNavVisibility(visible = true, animate = true)
|
||||
}
|
||||
R.id.playing_queue_fragment -> {
|
||||
setBottomBarVisibility(false)
|
||||
hideBottomBar(true)
|
||||
setBottomNavVisibility(visible = false)
|
||||
hideBottomSheet(true)
|
||||
}
|
||||
else -> setBottomBarVisibility(false) // Hide Bottom Navigation Bar
|
||||
else -> setBottomNavVisibility(visible = false, animate = true) // Hide Bottom Navigation Bar
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -136,7 +134,7 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
|
|||
PreferenceUtil.registerOnSharedPreferenceChangedListener(this)
|
||||
val expand = extra<Boolean>(EXPAND_PANEL).value ?: false
|
||||
if (expand && PreferenceUtil.isExpandPanel) {
|
||||
setBottomBarVisibility(false)
|
||||
setBottomNavVisibility(false)
|
||||
fromNotification = true
|
||||
expandPanel()
|
||||
intent.removeExtra(EXPAND_PANEL)
|
||||
|
|
|
@ -94,7 +94,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
|||
STATE_COLLAPSED -> {
|
||||
onPanelCollapsed()
|
||||
if (fromNotification) {
|
||||
hideBottomBar(MusicPlayerRemote.playingQueue.isEmpty())
|
||||
hideBottomSheet(MusicPlayerRemote.playingQueue.isEmpty())
|
||||
fromNotification = false
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +123,6 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
|||
windowInsets = insets
|
||||
insets
|
||||
}
|
||||
//binding.fragmentContainer.drawAboveNavBar()
|
||||
binding.bottomNavigationView.drawAboveSystemBarsWithPadding()
|
||||
if (RetroUtil.isLandscape()) {
|
||||
binding.slidingPanel.drawAboveSystemBarsWithPadding(true)
|
||||
|
@ -137,6 +136,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
|||
private fun setupBottomSheet() {
|
||||
bottomSheetBehavior = from(binding.slidingPanel) as RetroBottomSheetBehavior
|
||||
bottomSheetBehavior.addBottomSheetCallback(bottomSheetCallbackList)
|
||||
bottomSheetBehavior.isHideable = false
|
||||
setMiniPlayerAlphaProgress(0F)
|
||||
}
|
||||
|
||||
|
@ -224,18 +224,18 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
|||
ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
binding.slidingPanel.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
hideBottomBar(false)
|
||||
hideBottomSheet(false)
|
||||
}
|
||||
})
|
||||
} // don't call hideBottomBar(true) here as it causes a bug with the SlidingUpPanelLayout
|
||||
} // don't call hideBottomSheet(true) here as it causes a bug with the SlidingUpPanelLayout
|
||||
}
|
||||
|
||||
override fun onQueueChanged() {
|
||||
super.onQueueChanged()
|
||||
// Mini player should be hidden in Playing Queue
|
||||
// it may pop up if hideBottomBar is called
|
||||
// it may pop up if hideBottomSheet is called
|
||||
if (currentFragment(R.id.fragment_container) !is PlayingQueueFragment) {
|
||||
hideBottomBar(MusicPlayerRemote.playingQueue.isEmpty())
|
||||
hideBottomSheet(MusicPlayerRemote.playingQueue.isEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,45 +282,54 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
fun setBottomBarVisibility(visible: Boolean) {
|
||||
fun setBottomNavVisibility(visible: Boolean, animate: Boolean = false) {
|
||||
binding.bottomNavigationView.isVisible = visible
|
||||
hideBottomBar(MusicPlayerRemote.playingQueue.isEmpty())
|
||||
hideBottomSheet(MusicPlayerRemote.playingQueue.isEmpty(), animate)
|
||||
}
|
||||
|
||||
fun hideBottomBar(hide: Boolean) {
|
||||
fun hideBottomSheet(hide: Boolean, animate: Boolean = false) {
|
||||
val heightOfBar =
|
||||
windowInsets.safeGetBottomInsets() +
|
||||
if (MusicPlayerRemote.isCasting) dip(R.dimen.cast_mini_player_height) else dip(R.dimen.mini_player_height)
|
||||
val heightOfBarWithTabs = heightOfBar + dip(R.dimen.bottom_nav_height)
|
||||
val isVisible = binding.bottomNavigationView.isVisible
|
||||
if (hide) {
|
||||
bottomSheetBehavior.isHideable = true
|
||||
bottomSheetBehavior.peekHeight = 0
|
||||
bottomSheetBehavior.state = STATE_HIDDEN
|
||||
bottomSheetBehavior.peekHeight = -windowInsets.safeGetBottomInsets()
|
||||
bottomSheetBehavior.state = STATE_COLLAPSED
|
||||
libraryViewModel.setFabMargin(if (isVisible) dip(R.dimen.bottom_nav_height) else 0)
|
||||
ViewCompat.setElevation(binding.slidingPanel, 0f)
|
||||
ViewCompat.setElevation(binding.bottomNavigationView, 10f)
|
||||
} else {
|
||||
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
||||
bottomSheetBehavior.isHideable = false
|
||||
if (bottomSheetBehavior.state == STATE_HIDDEN)
|
||||
bottomSheetBehavior.state = STATE_EXPANDED
|
||||
|
||||
ViewCompat.setElevation(binding.slidingPanel, 10f)
|
||||
ViewCompat.setElevation(binding.bottomNavigationView, 10f)
|
||||
if (isVisible) {
|
||||
println("List")
|
||||
bottomSheetBehavior.peekHeightAnimate(heightOfBarWithTabs)
|
||||
bottomNavAnimator?.end()
|
||||
bottomNavAnimator = binding.bottomNavigationView.translateYAnimate(0F)
|
||||
if (animate) {
|
||||
bottomNavAnimator?.end()
|
||||
bottomSheetBehavior.peekHeightAnimate(heightOfBarWithTabs)
|
||||
bottomNavAnimator = binding.bottomNavigationView.translateYAnimate(0F)
|
||||
} else {
|
||||
bottomSheetBehavior.peekHeight = heightOfBarWithTabs
|
||||
binding.bottomNavigationView.translationY = 0F
|
||||
}
|
||||
binding.bottomNavigationView.bringToFront()
|
||||
libraryViewModel.setFabMargin(heightOfBarWithTabs - 2 * windowInsets.safeGetBottomInsets())
|
||||
} else {
|
||||
println("Details")
|
||||
bottomSheetBehavior.peekHeightAnimate(heightOfBar)
|
||||
bottomNavAnimator?.end()
|
||||
bottomNavAnimator =
|
||||
getBottomNavigationView().translateYAnimate(dip(R.dimen.bottom_nav_height).toFloat())
|
||||
bottomNavAnimator?.doOnEnd {
|
||||
if (animate) {
|
||||
bottomSheetBehavior.peekHeightAnimate(heightOfBar)
|
||||
bottomNavAnimator?.end()
|
||||
bottomNavAnimator =
|
||||
getBottomNavigationView().translateYAnimate(dip(R.dimen.bottom_nav_height).toFloat())
|
||||
bottomNavAnimator?.doOnEnd {
|
||||
binding.slidingPanel.bringToFront()
|
||||
}
|
||||
} else {
|
||||
bottomSheetBehavior.peekHeight = heightOfBar
|
||||
binding.bottomNavigationView.translationY =
|
||||
dip(R.dimen.bottom_nav_height).toFloat()
|
||||
binding.slidingPanel.bringToFront()
|
||||
}
|
||||
libraryViewModel.setFabMargin(heightOfBar - 2 * windowInsets.safeGetBottomInsets())
|
||||
|
@ -331,7 +340,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
|||
|
||||
fun setAllowDragging(allowDragging: Boolean) {
|
||||
bottomSheetBehavior.setAllowDragging(allowDragging)
|
||||
hideBottomBar(false)
|
||||
hideBottomSheet(false)
|
||||
}
|
||||
|
||||
private fun chooseFragmentForTheme() {
|
||||
|
|
|
@ -131,7 +131,7 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
|||
}
|
||||
R.id.action_go_to_album -> {
|
||||
//Hide Bottom Bar First, else Bottom Sheet doesn't collapse fully
|
||||
mainActivity.setBottomBarVisibility(false)
|
||||
mainActivity.setBottomNavVisibility(false)
|
||||
mainActivity.collapsePanel()
|
||||
requireActivity().findNavController(R.id.fragment_container).navigate(
|
||||
R.id.albumDetailsFragment,
|
||||
|
@ -386,7 +386,7 @@ fun goToArtist(activity: Activity) {
|
|||
currentFragment(R.id.fragment_container)?.exitTransition = null
|
||||
|
||||
//Hide Bottom Bar First, else Bottom Sheet doesn't collapse fully
|
||||
setBottomBarVisibility(false)
|
||||
setBottomNavVisibility(false)
|
||||
if (getBottomSheetBehavior().state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
collapsePanel()
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ fun goToAlbum(activity: Activity) {
|
|||
currentFragment(R.id.fragment_container)?.exitTransition = null
|
||||
|
||||
//Hide Bottom Bar First, else Bottom Sheet doesn't collapse fully
|
||||
setBottomBarVisibility(false)
|
||||
setBottomNavVisibility(false)
|
||||
if (getBottomSheetBehavior().state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
collapsePanel()
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class LibraryFragment : AbsMainActivityFragment(R.layout.fragment_library) {
|
|||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
mainActivity.setBottomBarVisibility(true)
|
||||
mainActivity.setBottomNavVisibility(true)
|
||||
mainActivity.setSupportActionBar(binding.toolbar)
|
||||
mainActivity.supportActionBar?.title = null
|
||||
binding.toolbar.setNavigationOnClickListener {
|
||||
|
|
|
@ -101,12 +101,12 @@ class PlayingQueueRVFragment : AbsRecyclerViewFragment<PlayingQueueAdapter, Line
|
|||
override fun onQueueChanged() {
|
||||
super.onQueueChanged()
|
||||
updateQueue()
|
||||
mainActivity.hideBottomBar(true)
|
||||
mainActivity.hideBottomSheet(true)
|
||||
}
|
||||
|
||||
override fun onPlayingMetaChanged() {
|
||||
updateQueuePosition()
|
||||
mainActivity.hideBottomBar(true)
|
||||
mainActivity.hideBottomSheet(true)
|
||||
}
|
||||
|
||||
private fun updateQueuePosition() {
|
||||
|
|
|
@ -214,7 +214,7 @@ class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWa
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
mainActivity.setBottomBarVisibility(false)
|
||||
mainActivity.setBottomNavVisibility(false)
|
||||
}
|
||||
|
||||
private fun hideKeyboard(view: View?) {
|
||||
|
|
|
@ -44,7 +44,7 @@ object NavigationUtil {
|
|||
if (activity !is MainActivity) return
|
||||
activity.apply {
|
||||
//Hide Bottom Bar First, else Bottom Sheet doesn't collapse fully
|
||||
setBottomBarVisibility(false)
|
||||
setBottomNavVisibility(false)
|
||||
if (getBottomSheetBehavior().state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
collapsePanel()
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:behavior_hideable="true"
|
||||
app:behavior_peekHeight="0dp"
|
||||
app:gestureInsetBottomIgnored="true"
|
||||
app:enableEdgeToEdge="true"
|
||||
app:layout_behavior="code.name.monkey.retromusic.RetroBottomSheetBehavior">
|
||||
|
||||
<FrameLayout
|
||||
|
|
Loading…
Reference in a new issue