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