From c495c66a38a23a588c1c1ed28a82e61aa4895d13 Mon Sep 17 00:00:00 2001 From: Hemanth S Date: Tue, 22 Sep 2020 13:50:43 +0530 Subject: [PATCH] Added animation collapse when navigating to details --- .../base/AbsSlidingMusicPanelActivity.kt | 29 +++++++------------ .../retromusic/extensions/ViewExtensions.kt | 20 +++++++++++++ .../artists/ArtistDetailsFragment.kt | 1 - .../fragments/library/LibraryFragment.kt | 7 ++++- .../fragments/search/SearchFragment.kt | 7 +++-- 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt index c78c75da..e7b2355e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt @@ -9,12 +9,13 @@ import android.widget.FrameLayout import androidx.annotation.LayoutRes import androidx.core.view.ViewCompat import androidx.core.view.isVisible -import androidx.transition.TransitionManager import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.retromusic.R import code.name.monkey.retromusic.RetroBottomSheetBehavior import code.name.monkey.retromusic.extensions.hide +import code.name.monkey.retromusic.extensions.peekHeightAnimate +import code.name.monkey.retromusic.extensions.translateXAnimate import code.name.monkey.retromusic.extensions.whichFragment import code.name.monkey.retromusic.fragments.LibraryViewModel import code.name.monkey.retromusic.fragments.MiniPlayerFragment @@ -217,7 +218,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { libraryViewModel.setPanelState(HIDE) } else { if (bottomNavigationView.isVisible) { - libraryViewModel.setPanelState(EXPAND) + libraryViewModel.setPanelState(COLLAPSED_WITH) } else { libraryViewModel.setPanelState(COLLAPSED_WITHOUT) } @@ -301,12 +302,6 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { } } - fun hideBottomNavigation() { - behavior.isHideable = true - behavior.peekHeight = 0 - hideBottomBarVisibility(false) - } - fun updateTabs() { bottomNavigationView.menu.clear() val currentTabs: List = PreferenceUtil.libraryCategory @@ -330,6 +325,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { private fun updatePanelState() { libraryViewModel.panelState.observe(this, { state -> + val isQueueEmpty = MusicPlayerRemote.playingQueue.isEmpty() when (state) { EXPAND -> { println("EXPAND") @@ -337,32 +333,29 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { } HIDE -> { println("HIDE") - behavior.isHideable = true - behavior.peekHeight = 0 - collapsePanel() ViewCompat.setElevation(slidingPanel, 0f) ViewCompat.setElevation(bottomNavigationView, 10f) + behavior.isHideable = true + behavior.peekHeightAnimate(0) + collapsePanel() } COLLAPSED_WITH -> { println("COLLAPSED_WITH") - TransitionManager.beginDelayedTransition(mainContent) - bottomNavigationView.isVisible = true val heightOfBar = bottomNavigationView.height ViewCompat.setElevation(bottomNavigationView, 10f) ViewCompat.setElevation(slidingPanel, 10f) behavior.isHideable = false - behavior.peekHeight = (heightOfBar * 2) - 24 + behavior.peekHeightAnimate(if(isQueueEmpty) 0 else (heightOfBar * 2) - 24) + bottomNavigationView.translateXAnimate(0f) } COLLAPSED_WITHOUT -> { println("COLLAPSED_WITHOUT") - TransitionManager.beginDelayedTransition(mainContent) - TransitionManager.beginDelayedTransition(slidingPanel) val heightOfBar = bottomNavigationView.height - bottomNavigationView.isVisible = false ViewCompat.setElevation(bottomNavigationView, 10f) ViewCompat.setElevation(slidingPanel, 10f) behavior.isHideable = false - behavior.peekHeight = heightOfBar - 24 + behavior.peekHeightAnimate(if(isQueueEmpty) 0 else heightOfBar - 24) + bottomNavigationView.translateXAnimate(heightOfBar.toFloat()) } else -> { println("ELSE") diff --git a/app/src/main/java/code/name/monkey/retromusic/extensions/ViewExtensions.kt b/app/src/main/java/code/name/monkey/retromusic/extensions/ViewExtensions.kt index 0f9e30e8..3c224ed6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/extensions/ViewExtensions.kt +++ b/app/src/main/java/code/name/monkey/retromusic/extensions/ViewExtensions.kt @@ -14,6 +14,7 @@ package code.name.monkey.retromusic.extensions +import android.animation.ObjectAnimator import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -21,6 +22,7 @@ import android.widget.EditText import androidx.annotation.LayoutRes import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.TintHelper +import com.google.android.material.bottomsheet.BottomSheetBehavior @Suppress("UNCHECKED_CAST") fun ViewGroup.inflate(@LayoutRes layout: Int): T { @@ -45,3 +47,21 @@ fun EditText.appHandleColor(): EditText { TintHelper.colorHandles(this, ThemeStore.accentColor(context)) return this } + + +fun View.translateXAnimate(value: Float) { + ObjectAnimator.ofFloat(this, "translationY", value) + .apply { + duration = 300 + start() + } +} + +fun BottomSheetBehavior<*>.peekHeightAnimate(value: Int) { + ObjectAnimator.ofInt(this, "peekHeight", value) + .apply { + duration = 300 + start() + } +} + diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt index 65cc18c2..1caec7e6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt @@ -73,7 +73,6 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d setHasOptionsMenu(true) libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT) mainActivity.setSupportActionBar(toolbar) - toolbar.title = null setupRecyclerView() diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/library/LibraryFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/library/LibraryFragment.kt index 086e0a09..545f06c4 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/library/LibraryFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/library/LibraryFragment.kt @@ -14,17 +14,22 @@ import code.name.monkey.retromusic.R import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog import code.name.monkey.retromusic.dialogs.ImportPlaylistDialog import code.name.monkey.retromusic.extensions.findNavController +import code.name.monkey.retromusic.fragments.LibraryViewModel import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment +import code.name.monkey.retromusic.state.NowPlayingPanelState import kotlinx.android.synthetic.main.fragment_library.* +import org.koin.androidx.viewmodel.ext.android.sharedViewModel import java.lang.String class LibraryFragment : AbsMainActivityFragment(R.layout.fragment_library) { + private val libraryViewModel by sharedViewModel() + override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) setHasOptionsMenu(true) retainInstance = true - mainActivity.hideBottomBarVisibility(true) + libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITH) mainActivity.setSupportActionBar(toolbar) mainActivity.supportActionBar?.title = null toolbar.setNavigationOnClickListener { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchFragment.kt index a900341e..14fdc80e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchFragment.kt @@ -20,10 +20,13 @@ import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.SearchAdapter import code.name.monkey.retromusic.extensions.accentColor import code.name.monkey.retromusic.extensions.showToast +import code.name.monkey.retromusic.fragments.LibraryViewModel import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment +import code.name.monkey.retromusic.state.NowPlayingPanelState import com.google.android.material.textfield.TextInputEditText import kotlinx.android.synthetic.main.fragment_search.* import org.koin.android.ext.android.inject +import org.koin.androidx.viewmodel.ext.android.sharedViewModel import java.util.* import kotlin.collections.ArrayList @@ -33,6 +36,7 @@ class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWa const val REQ_CODE_SPEECH_INPUT = 9001 } + private val libraryViewModel by sharedViewModel() private val viewModel: SearchViewModel by inject() private lateinit var searchAdapter: SearchAdapter private var query: String? = null @@ -40,8 +44,7 @@ class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWa override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) mainActivity.setSupportActionBar(toolbar) - mainActivity.hideBottomBarVisibility(false) - + libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT) setupRecyclerView() keyboardPopup.accentColor() searchView.addTextChangedListener(this)