Refactor from sliding uppanel to bottom sheet
This commit is contained in:
parent
6f362e1ab7
commit
a4f7c99f61
14 changed files with 241 additions and 142 deletions
|
@ -31,16 +31,20 @@ import code.name.monkey.retromusic.fragments.player.plain.PlainPlayerFragment
|
|||
import code.name.monkey.retromusic.fragments.player.simple.SimplePlayerFragment
|
||||
import code.name.monkey.retromusic.fragments.player.tiny.TinyPlayerFragment
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.util.DensityUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.views.BottomNavigationBarTinted
|
||||
import com.sothree.slidinguppanel.SlidingUpPanelLayout
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import kotlinx.android.synthetic.main.sliding_music_panel_layout.*
|
||||
|
||||
abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), SlidingUpPanelLayout.PanelSlideListener, AbsPlayerFragment.Callbacks {
|
||||
|
||||
abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), AbsPlayerFragment.Callbacks {
|
||||
companion object {
|
||||
val TAG: String = AbsSlidingMusicPanelActivity::class.java.simpleName
|
||||
}
|
||||
|
||||
private lateinit var bottomSheetBehavior: BottomSheetBehavior<MaterialCardView>
|
||||
private var miniPlayerFragment: MiniPlayerFragment? = null
|
||||
private var playerFragment: AbsPlayerFragment? = null
|
||||
private var currentNowPlayingScreen: NowPlayingScreen? = null
|
||||
|
@ -49,11 +53,37 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Sliding
|
|||
private var lightStatusBar: Boolean = false
|
||||
private var lightNavigationBar: Boolean = false
|
||||
private var navigationBarColorAnimator: ValueAnimator? = null
|
||||
|
||||
protected abstract fun createContentView(): View
|
||||
private val panelState: Int
|
||||
get() = bottomSheetBehavior.state
|
||||
|
||||
private val bottomSheetCallbackList = object : BottomSheetBehavior.BottomSheetCallback() {
|
||||
|
||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
||||
setMiniPlayerAlphaProgress(slideOffset)
|
||||
}
|
||||
|
||||
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
||||
when (newState) {
|
||||
BottomSheetBehavior.STATE_HIDDEN -> {
|
||||
}
|
||||
BottomSheetBehavior.STATE_EXPANDED -> {
|
||||
onPanelExpanded()
|
||||
}
|
||||
BottomSheetBehavior.STATE_COLLAPSED -> {
|
||||
onPanelCollapsed()
|
||||
}
|
||||
BottomSheetBehavior.STATE_DRAGGING -> {
|
||||
}
|
||||
BottomSheetBehavior.STATE_SETTLING -> {
|
||||
}
|
||||
else -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val panelState: SlidingUpPanelLayout.PanelState?
|
||||
get() = slidingLayout.panelState
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -63,6 +93,10 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Sliding
|
|||
setupSlidingUpPanel()
|
||||
|
||||
updateTabs()
|
||||
|
||||
bottomSheetBehavior = BottomSheetBehavior.from(slidingPanel)
|
||||
bottomSheetBehavior.bottomSheetCallback = bottomSheetCallbackList
|
||||
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -87,18 +121,19 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Sliding
|
|||
}
|
||||
|
||||
fun setAntiDragView(antiDragView: View) {
|
||||
slidingLayout.setAntiDragView(antiDragView)
|
||||
//slidingLayout.setAntiDragView(antiDragView)
|
||||
}
|
||||
|
||||
private fun collapsePanel() {
|
||||
slidingLayout.panelState = SlidingUpPanelLayout.PanelState.COLLAPSED
|
||||
bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
}
|
||||
|
||||
fun expandPanel() {
|
||||
slidingLayout.panelState = SlidingUpPanelLayout.PanelState.EXPANDED
|
||||
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
}
|
||||
|
||||
private fun setMiniPlayerAlphaProgress(progress: Float) {
|
||||
print("Sliding $progress")
|
||||
if (miniPlayerFragment?.view == null) return
|
||||
val alpha = 1 - progress
|
||||
miniPlayerFragment?.view?.alpha = alpha
|
||||
|
@ -117,44 +152,41 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Sliding
|
|||
super.setLightNavigationBar(lightNavigationBar)
|
||||
|
||||
|
||||
playerFragment!!.setMenuVisibility(false)
|
||||
playerFragment!!.userVisibleHint = false
|
||||
playerFragment!!.onHide()
|
||||
playerFragment?.setMenuVisibility(false)
|
||||
playerFragment?.userVisibleHint = false
|
||||
playerFragment?.onHide()
|
||||
}
|
||||
|
||||
open fun onPanelExpanded() {
|
||||
val playerFragmentColor = playerFragment!!.paletteColor
|
||||
super.setTaskDescriptionColor(playerFragmentColor)
|
||||
|
||||
playerFragment!!.setMenuVisibility(true)
|
||||
playerFragment!!.userVisibleHint = true
|
||||
playerFragment!!.onShow()
|
||||
playerFragment?.setMenuVisibility(true)
|
||||
playerFragment?.userVisibleHint = true
|
||||
playerFragment?.onShow()
|
||||
onPaletteColorChanged()
|
||||
}
|
||||
|
||||
private fun setupSlidingUpPanel() {
|
||||
slidingLayout.viewTreeObserver
|
||||
slidingPanel.viewTreeObserver
|
||||
.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
slidingLayout.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
slidingPanel.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
if (currentNowPlayingScreen != PEAK) {
|
||||
val params = slidingPanel.layoutParams as ViewGroup.LayoutParams
|
||||
params.height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||
slidingPanel.layoutParams = params
|
||||
}
|
||||
when (panelState) {
|
||||
SlidingUpPanelLayout.PanelState.EXPANDED -> {
|
||||
onPanelSlide(slidingLayout, 1f)
|
||||
onPanelExpanded()
|
||||
}
|
||||
SlidingUpPanelLayout.PanelState.COLLAPSED -> onPanelCollapsed()
|
||||
else -> playerFragment!!.onHide()
|
||||
}
|
||||
/* when (panelState) {
|
||||
SlidingUpPanelLayout.PanelState.EXPANDED -> {
|
||||
onPanelSlide(slidingLayout, 1f)
|
||||
onPanelExpanded()
|
||||
}
|
||||
SlidingUpPanelLayout.PanelState.COLLAPSED -> onPanelCollapsed()
|
||||
else -> playerFragment!!.onHide()
|
||||
}*/
|
||||
}
|
||||
})
|
||||
|
||||
slidingLayout.addPanelSlideListener(this)
|
||||
|
||||
}
|
||||
|
||||
fun toggleBottomNavigationView(toggle: Boolean) {
|
||||
|
@ -165,16 +197,20 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Sliding
|
|||
return bottomNavigationView
|
||||
}
|
||||
|
||||
fun hideBottomBar(hide: Boolean) {
|
||||
private fun hideBottomBar(hide: Boolean) {
|
||||
val heightOfBar = resources.getDimensionPixelSize(R.dimen.mini_player_height)
|
||||
val heightOfBarWithTabs = resources.getDimensionPixelSize(R.dimen.mini_player_height_expanded)
|
||||
|
||||
if (hide) {
|
||||
slidingLayout.panelHeight = 0
|
||||
bottomSheetBehavior.isHideable = true
|
||||
bottomSheetBehavior.peekHeight = 0
|
||||
collapsePanel()
|
||||
bottomNavigationView.elevation = DensityUtil.dip2px(this, 10f).toFloat()
|
||||
} else {
|
||||
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
||||
slidingLayout.panelHeight = if (bottomNavigationView.visibility == View.VISIBLE) heightOfBarWithTabs else heightOfBar
|
||||
bottomNavigationView.elevation = 0f
|
||||
bottomSheetBehavior.isHideable = false
|
||||
bottomSheetBehavior.peekHeight = if (bottomNavigationView.visibility == View.VISIBLE) heightOfBarWithTabs else heightOfBar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,10 +251,10 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Sliding
|
|||
|
||||
override fun onServiceConnected() {
|
||||
super.onServiceConnected()
|
||||
if (!MusicPlayerRemote.playingQueue.isEmpty()) {
|
||||
slidingLayout.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
||||
slidingPanel.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
slidingLayout.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
slidingPanel.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
hideBottomBar(false)
|
||||
}
|
||||
})
|
||||
|
@ -236,20 +272,17 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Sliding
|
|||
}
|
||||
|
||||
open fun handleBackPress(): Boolean {
|
||||
if (slidingLayout.panelHeight != 0 && playerFragment!!.onBackPressed())
|
||||
if (bottomSheetBehavior.peekHeight != 0 && playerFragment!!.onBackPressed())
|
||||
return true
|
||||
if (panelState == SlidingUpPanelLayout.PanelState.EXPANDED) {
|
||||
if (panelState == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
collapsePanel()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onPanelSlide(panel: View?, slideOffset: Float) {
|
||||
setMiniPlayerAlphaProgress(slideOffset)
|
||||
}
|
||||
|
||||
override fun onPanelStateChanged(panel: View, previousState: SlidingUpPanelLayout.PanelState, newState: SlidingUpPanelLayout.PanelState) {
|
||||
/*override fun onPanelStateChanged(panel: View, previousState: SlidingUpPanelLayout.PanelState, newState: SlidingUpPanelLayout.PanelState) {
|
||||
when (newState) {
|
||||
SlidingUpPanelLayout.PanelState.COLLAPSED -> onPanelCollapsed()
|
||||
SlidingUpPanelLayout.PanelState.EXPANDED -> onPanelExpanded()
|
||||
|
@ -257,16 +290,15 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Sliding
|
|||
else -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
override fun onPaletteColorChanged() {
|
||||
if (panelState == SlidingUpPanelLayout.PanelState.EXPANDED) {
|
||||
if (panelState == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
val paletteColor = playerFragment!!.paletteColor
|
||||
super.setTaskDescriptionColor(paletteColor)
|
||||
|
||||
val isColorLight = ColorUtil.isColorLight(paletteColor)
|
||||
|
||||
|
||||
if (PreferenceUtil.getInstance(this).adaptiveColor &&
|
||||
(currentNowPlayingScreen == NORMAL || currentNowPlayingScreen == FLAT)) {
|
||||
super.setLightNavigationBar(true)
|
||||
|
@ -289,21 +321,21 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Sliding
|
|||
|
||||
override fun setLightStatusbar(enabled: Boolean) {
|
||||
lightStatusBar = enabled
|
||||
if (panelState == SlidingUpPanelLayout.PanelState.COLLAPSED) {
|
||||
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
super.setLightStatusbar(enabled)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setLightNavigationBar(enabled: Boolean) {
|
||||
lightNavigationBar = enabled
|
||||
if (panelState == SlidingUpPanelLayout.PanelState.COLLAPSED) {
|
||||
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
super.setLightNavigationBar(enabled)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setNavigationbarColor(color: Int) {
|
||||
navigationBarColor = color
|
||||
if (panelState == SlidingUpPanelLayout.PanelState.COLLAPSED) {
|
||||
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
if (navigationBarColorAnimator != null) navigationBarColorAnimator!!.cancel()
|
||||
super.setNavigationbarColor(color)
|
||||
}
|
||||
|
@ -311,7 +343,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), Sliding
|
|||
|
||||
override fun setTaskDescriptionColor(color: Int) {
|
||||
taskColor = color
|
||||
if (panelState == SlidingUpPanelLayout.PanelState.COLLAPSED) {
|
||||
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
super.setTaskDescriptionColor(color)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package code.name.monkey.retromusic.adapter
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
@ -9,7 +8,6 @@ import androidx.annotation.IntDef
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.adapter.album.AlbumFullWidthAdapter
|
||||
import code.name.monkey.retromusic.adapter.artist.ArtistAdapter
|
||||
|
@ -20,7 +18,7 @@ import code.name.monkey.retromusic.model.Artist
|
|||
import code.name.monkey.retromusic.model.Home
|
||||
import code.name.monkey.retromusic.model.Playlist
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.textview.MaterialTextView
|
||||
|
||||
|
||||
class HomeAdapter(
|
||||
|
@ -92,8 +90,8 @@ class HomeAdapter(
|
|||
recyclerView.apply {
|
||||
adapter = AlbumFullWidthAdapter(activity, home.arrayList as ArrayList<Album>, displayMetrics)
|
||||
}
|
||||
chip.text = activity.getString(home.title)
|
||||
chip.setChipIconResource(home.icon)
|
||||
title.text = activity.getString(home.title)
|
||||
text.text = activity.getString(home.subTitle)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,8 +102,9 @@ class HomeAdapter(
|
|||
val artistAdapter = ArtistAdapter(activity, home.arrayList as ArrayList<Artist>, PreferenceUtil.getInstance(activity).getHomeGridStyle(context!!), false, null)
|
||||
adapter = artistAdapter
|
||||
}
|
||||
chip.text = activity.getString(home.title)
|
||||
chip.setChipIconResource(home.icon)
|
||||
|
||||
title.text = activity.getString(home.title)
|
||||
text.text = activity.getString(home.subTitle)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,17 +117,14 @@ class HomeAdapter(
|
|||
adapter = songAdapter
|
||||
|
||||
}
|
||||
chip.text = activity.getString(home.title)
|
||||
chip.setChipIconResource(home.icon)
|
||||
title.text = activity.getString(home.title)
|
||||
text.text = activity.getString(home.subTitle)
|
||||
}
|
||||
}
|
||||
|
||||
private open inner class AbsHomeViewItem(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val recyclerView: RecyclerView = itemView.findViewById(R.id.recyclerView)
|
||||
val chip: Chip = itemView.findViewById(R.id.chipHead)
|
||||
|
||||
init {
|
||||
chip.apply { chipBackgroundColor = ColorStateList.valueOf(ThemeStore.primaryColor(context)) }
|
||||
}
|
||||
val title: MaterialTextView = itemView.findViewById(R.id.title)
|
||||
val text: MaterialTextView = itemView.findViewById(R.id.text)
|
||||
}
|
||||
}
|
|
@ -9,7 +9,6 @@ import androidx.annotation.StringRes
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.util.DensityUtil
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
|
@ -64,10 +63,7 @@ abstract class AbsLibraryPagerRecyclerViewFragment<A : RecyclerView.Adapter<*>,
|
|||
}
|
||||
|
||||
private fun checkForPadding() {
|
||||
val height = if (MusicPlayerRemote.playingQueue.isEmpty())
|
||||
DensityUtil.dip2px(context!!, 52f)
|
||||
else
|
||||
0
|
||||
val height = DensityUtil.dip2px(requireContext(), 52f)
|
||||
recyclerView.setPadding(0, 0, 0, (height * 2.3).toInt())
|
||||
}
|
||||
|
||||
|
|
|
@ -151,11 +151,7 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
|
|||
}
|
||||
|
||||
private fun checkPadding() {
|
||||
val marginSpan = when {
|
||||
MusicPlayerRemote.playingQueue.isEmpty() -> RetroUtil.convertDpToPixel(52f, context!!).toInt()
|
||||
else -> RetroUtil.convertDpToPixel(0f, requireContext()).toInt()
|
||||
}
|
||||
|
||||
val marginSpan = DensityUtil.dip2px(requireContext(), 52f)
|
||||
(recyclerView.layoutParams as ViewGroup.MarginLayoutParams).bottomMargin = (marginSpan * 2.3f).toInt()
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ interface HomePresenter : Presenter<HomeView> {
|
|||
if (it.isNotEmpty()) hashSet.add(
|
||||
Home(0,
|
||||
R.string.recent_artists,
|
||||
0,
|
||||
R.string.recent_added_artists,
|
||||
it,
|
||||
RECENT_ARTISTS,
|
||||
R.drawable.ic_artist_white_24dp
|
||||
|
@ -87,7 +87,7 @@ interface HomePresenter : Presenter<HomeView> {
|
|||
if (it.isNotEmpty()) hashSet.add(
|
||||
Home(1,
|
||||
R.string.recent_albums,
|
||||
0,
|
||||
R.string.recent_added_albums,
|
||||
it,
|
||||
RECENT_ALBUMS,
|
||||
R.drawable.ic_album_white_24dp
|
||||
|
@ -102,7 +102,7 @@ interface HomePresenter : Presenter<HomeView> {
|
|||
if (it.isNotEmpty()) hashSet.add(
|
||||
Home(2,
|
||||
R.string.top_artists,
|
||||
0,
|
||||
R.string.most_played_artists,
|
||||
it,
|
||||
TOP_ARTISTS,
|
||||
R.drawable.ic_artist_white_24dp
|
||||
|
@ -117,7 +117,7 @@ interface HomePresenter : Presenter<HomeView> {
|
|||
if (it.isNotEmpty()) hashSet.add(
|
||||
Home(3,
|
||||
R.string.top_albums,
|
||||
0,
|
||||
R.string.most_played_albums,
|
||||
it,
|
||||
TOP_ALBUMS,
|
||||
R.drawable.ic_album_white_24dp
|
||||
|
@ -132,7 +132,7 @@ interface HomePresenter : Presenter<HomeView> {
|
|||
if (it.isNotEmpty()) hashSet.add(
|
||||
Home(4,
|
||||
R.string.favorites,
|
||||
0,
|
||||
R.string.favorites_songs,
|
||||
it,
|
||||
PLAYLISTS,
|
||||
R.drawable.ic_favorite_white_24dp
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue