2019-04-20 05:29:45 +00:00
|
|
|
package code.name.monkey.retromusic.activities.base
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2019-12-01 11:28:57 +00:00
|
|
|
import android.graphics.Color
|
2018-11-30 01:06:16 +00:00
|
|
|
import android.os.Bundle
|
2019-12-01 11:28:57 +00:00
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.view.ViewTreeObserver
|
2020-05-11 09:51:22 +00:00
|
|
|
import android.widget.FrameLayout
|
2019-02-23 17:39:02 +00:00
|
|
|
import androidx.annotation.LayoutRes
|
2020-07-28 19:18:34 +00:00
|
|
|
import androidx.lifecycle.Observer
|
2019-12-01 11:28:57 +00:00
|
|
|
import code.name.monkey.appthemehelper.util.ATHUtil
|
|
|
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
2019-02-23 17:39:02 +00:00
|
|
|
import code.name.monkey.retromusic.R
|
2020-05-09 05:55:42 +00:00
|
|
|
import code.name.monkey.retromusic.RetroBottomSheetBehavior
|
2020-08-11 18:29:44 +00:00
|
|
|
import code.name.monkey.retromusic.extensions.*
|
2020-07-28 19:18:34 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
2019-12-01 11:28:57 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.MiniPlayerFragment
|
|
|
|
import code.name.monkey.retromusic.fragments.NowPlayingScreen
|
2020-02-26 16:49:24 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.NowPlayingScreen.*
|
2019-05-19 17:10:21 +00:00
|
|
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
2019-12-01 15:27:01 +00:00
|
|
|
import code.name.monkey.retromusic.model.CategoryInfo
|
2020-06-06 18:57:28 +00:00
|
|
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
2019-02-23 17:39:02 +00:00
|
|
|
import code.name.monkey.retromusic.views.BottomNavigationBarTinted
|
2019-10-04 12:59:37 +00:00
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
2020-02-26 16:49:24 +00:00
|
|
|
import kotlinx.android.synthetic.main.sliding_music_panel_layout.*
|
2020-07-28 19:18:34 +00:00
|
|
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
2019-02-23 17:39:02 +00:00
|
|
|
|
2020-07-28 19:18:34 +00:00
|
|
|
abstract class AbsSlidingMusicPanelActivity() : AbsMusicServiceActivity() {
|
2019-12-01 11:28:57 +00:00
|
|
|
companion object {
|
|
|
|
val TAG: String = AbsSlidingMusicPanelActivity::class.java.simpleName
|
|
|
|
}
|
|
|
|
|
2020-07-28 19:18:34 +00:00
|
|
|
private val libraryViewModel by viewModel<LibraryViewModel>()
|
2020-05-11 09:51:22 +00:00
|
|
|
private lateinit var behavior: RetroBottomSheetBehavior<FrameLayout>
|
2019-12-01 11:28:57 +00:00
|
|
|
private var miniPlayerFragment: MiniPlayerFragment? = null
|
2020-05-09 14:45:07 +00:00
|
|
|
private var cps: NowPlayingScreen? = null
|
2019-12-01 11:28:57 +00:00
|
|
|
private var navigationBarColor: Int = 0
|
|
|
|
private var taskColor: Int = 0
|
|
|
|
private var lightStatusBar: Boolean = false
|
|
|
|
private var lightNavigationBar: Boolean = false
|
2020-07-28 19:18:34 +00:00
|
|
|
private var paletteColor: Int = Color.WHITE
|
2019-12-01 11:28:57 +00:00
|
|
|
protected abstract fun createContentView(): View
|
|
|
|
private val panelState: Int
|
2020-05-11 09:51:22 +00:00
|
|
|
get() = behavior.state
|
2019-12-01 11:28:57 +00:00
|
|
|
|
|
|
|
private val bottomSheetCallbackList = object : BottomSheetBehavior.BottomSheetCallback() {
|
|
|
|
|
|
|
|
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
|
|
|
setMiniPlayerAlphaProgress(slideOffset)
|
|
|
|
dimBackground.show()
|
|
|
|
dimBackground.alpha = slideOffset
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
|
|
|
when (newState) {
|
|
|
|
BottomSheetBehavior.STATE_EXPANDED -> {
|
|
|
|
onPanelExpanded()
|
|
|
|
}
|
|
|
|
BottomSheetBehavior.STATE_COLLAPSED -> {
|
|
|
|
onPanelCollapsed()
|
|
|
|
dimBackground.hide()
|
|
|
|
}
|
|
|
|
else -> {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 07:42:09 +00:00
|
|
|
|
2019-12-01 11:28:57 +00:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(createContentView())
|
|
|
|
chooseFragmentForTheme()
|
|
|
|
setupSlidingUpPanel()
|
2020-07-28 19:18:34 +00:00
|
|
|
addMusicServiceEventListener(libraryViewModel)
|
|
|
|
|
|
|
|
setupBottomSheet()
|
2019-12-01 11:28:57 +00:00
|
|
|
|
2020-07-28 19:18:34 +00:00
|
|
|
val themeColor = ATHUtil.resolveColor(this, android.R.attr.windowBackground, Color.GRAY)
|
|
|
|
dimBackground.setBackgroundColor(ColorUtil.withAlpha(themeColor, 0.5f))
|
|
|
|
|
|
|
|
libraryViewModel.paletteColorLiveData.observe(this, Observer {
|
|
|
|
this.paletteColor = it
|
|
|
|
onPaletteColorChanged()
|
|
|
|
})
|
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
|
2020-07-28 19:18:34 +00:00
|
|
|
fun getBottomSheetBehavior() = behavior
|
2020-05-11 09:51:22 +00:00
|
|
|
|
2020-07-28 19:18:34 +00:00
|
|
|
private fun setupBottomSheet() {
|
2020-05-11 09:51:22 +00:00
|
|
|
behavior = BottomSheetBehavior.from(slidingPanel) as RetroBottomSheetBehavior
|
2020-07-28 19:18:34 +00:00
|
|
|
behavior.addBottomSheetCallback(bottomSheetCallbackList)
|
2019-12-01 11:28:57 +00:00
|
|
|
|
2020-07-28 19:18:34 +00:00
|
|
|
if (behavior.state == BottomSheetBehavior.STATE_EXPANDED) {
|
|
|
|
setMiniPlayerAlphaProgress(1f)
|
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2020-06-06 18:57:28 +00:00
|
|
|
if (cps != PreferenceUtil.nowPlayingScreen) {
|
2019-12-01 11:28:57 +00:00
|
|
|
postRecreate()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
super.onDestroy()
|
2020-05-11 09:51:22 +00:00
|
|
|
behavior.removeBottomSheetCallback(bottomSheetCallbackList)
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected fun wrapSlidingMusicPanel(@LayoutRes resId: Int): View {
|
2020-02-26 16:49:24 +00:00
|
|
|
val slidingMusicPanelLayout =
|
|
|
|
layoutInflater.inflate(R.layout.sliding_music_panel_layout, null)
|
2020-07-28 19:18:34 +00:00
|
|
|
val contentContainer: ViewGroup =
|
|
|
|
slidingMusicPanelLayout.findViewById(R.id.mainContentFrame)
|
2019-12-01 11:28:57 +00:00
|
|
|
layoutInflater.inflate(resId, contentContainer)
|
|
|
|
return slidingMusicPanelLayout
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun collapsePanel() {
|
2020-05-11 09:51:22 +00:00
|
|
|
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fun expandPanel() {
|
2020-05-11 09:51:22 +00:00
|
|
|
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
2019-12-01 11:28:57 +00:00
|
|
|
setMiniPlayerAlphaProgress(1f)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setMiniPlayerAlphaProgress(progress: Float) {
|
|
|
|
if (miniPlayerFragment?.view == null) return
|
|
|
|
val alpha = 1 - progress
|
|
|
|
miniPlayerFragment?.view?.alpha = alpha
|
|
|
|
// necessary to make the views below clickable
|
|
|
|
miniPlayerFragment?.view?.visibility = if (alpha == 0f) View.GONE else View.VISIBLE
|
|
|
|
|
|
|
|
bottomNavigationView.translationY = progress * 500
|
2020-07-28 19:18:34 +00:00
|
|
|
bottomNavigationView.alpha = alpha
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
open fun onPanelCollapsed() {
|
|
|
|
// restore values
|
|
|
|
super.setLightStatusbar(lightStatusBar)
|
|
|
|
super.setTaskDescriptionColor(taskColor)
|
|
|
|
super.setNavigationbarColor(navigationBarColor)
|
|
|
|
super.setLightNavigationBar(lightNavigationBar)
|
|
|
|
}
|
|
|
|
|
|
|
|
open fun onPanelExpanded() {
|
|
|
|
onPaletteColorChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setupSlidingUpPanel() {
|
2020-02-26 16:49:24 +00:00
|
|
|
slidingPanel.viewTreeObserver.addOnGlobalLayoutListener(object :
|
|
|
|
ViewTreeObserver.OnGlobalLayoutListener {
|
2019-12-01 11:28:57 +00:00
|
|
|
override fun onGlobalLayout() {
|
|
|
|
slidingPanel.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
|
|
|
when (panelState) {
|
|
|
|
BottomSheetBehavior.STATE_EXPANDED -> onPanelExpanded()
|
|
|
|
BottomSheetBehavior.STATE_COLLAPSED -> onPanelCollapsed()
|
2020-07-28 19:18:34 +00:00
|
|
|
else -> {
|
|
|
|
//playerFragment!!.onHide()
|
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fun getBottomNavigationView(): BottomNavigationBarTinted {
|
|
|
|
return bottomNavigationView
|
|
|
|
}
|
|
|
|
|
2020-05-11 09:51:22 +00:00
|
|
|
fun setBottomBarVisibility(visible: Int) {
|
|
|
|
bottomNavigationView.visibility = visible
|
|
|
|
hideBottomBar(MusicPlayerRemote.playingQueue.isEmpty())
|
|
|
|
}
|
|
|
|
|
2019-12-01 11:28:57 +00:00
|
|
|
private fun hideBottomBar(hide: Boolean) {
|
2020-08-11 18:29:44 +00:00
|
|
|
val heightOfBar = dimToPixel(R.dimen.mini_player_height)
|
|
|
|
val heightOfBarWithTabs = dimToPixel(R.dimen.mini_player_height_expanded)
|
2019-12-01 11:28:57 +00:00
|
|
|
|
|
|
|
if (hide) {
|
2020-05-11 09:51:22 +00:00
|
|
|
behavior.isHideable = true
|
|
|
|
behavior.peekHeight = 0
|
2020-08-11 18:29:44 +00:00
|
|
|
bottomNavigationView.elevation = dipToPix(10f)
|
2020-05-11 19:39:44 +00:00
|
|
|
collapsePanel()
|
2019-12-01 11:28:57 +00:00
|
|
|
} else {
|
|
|
|
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
2020-08-11 18:29:44 +00:00
|
|
|
slidingPanel.elevation = dipToPix(10f)
|
|
|
|
bottomNavigationView.elevation = dipToPix(10f)
|
2020-05-11 09:51:22 +00:00
|
|
|
behavior.isHideable = false
|
|
|
|
behavior.peekHeight =
|
|
|
|
if (bottomNavigationView.visibility == View.VISIBLE) {
|
|
|
|
heightOfBarWithTabs
|
|
|
|
} else {
|
|
|
|
heightOfBar
|
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun chooseFragmentForTheme() {
|
2020-06-06 18:57:28 +00:00
|
|
|
cps = PreferenceUtil.nowPlayingScreen
|
2020-08-11 18:29:44 +00:00
|
|
|
miniPlayerFragment = whichFragment<MiniPlayerFragment>(R.id.miniPlayerFragment)
|
2019-12-01 11:28:57 +00:00
|
|
|
miniPlayerFragment?.view?.setOnClickListener { expandPanel() }
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onServiceConnected() {
|
|
|
|
super.onServiceConnected()
|
|
|
|
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
2020-02-26 16:49:24 +00:00
|
|
|
slidingPanel.viewTreeObserver.addOnGlobalLayoutListener(object :
|
|
|
|
ViewTreeObserver.OnGlobalLayoutListener {
|
2019-12-01 11:28:57 +00:00
|
|
|
override fun onGlobalLayout() {
|
|
|
|
slidingPanel.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
|
|
|
hideBottomBar(false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} // don't call hideBottomBar(true) here as it causes a bug with the SlidingUpPanelLayout
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onQueueChanged() {
|
|
|
|
super.onQueueChanged()
|
|
|
|
hideBottomBar(MusicPlayerRemote.playingQueue.isEmpty())
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBackPressed() {
|
|
|
|
if (!handleBackPress()) super.onBackPressed()
|
|
|
|
}
|
|
|
|
|
|
|
|
open fun handleBackPress(): Boolean {
|
|
|
|
if (panelState == BottomSheetBehavior.STATE_EXPANDED) {
|
|
|
|
collapsePanel()
|
|
|
|
return true
|
2020-01-24 17:27:43 +00:00
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-07-28 19:18:34 +00:00
|
|
|
private fun onPaletteColorChanged() {
|
2019-12-01 11:28:57 +00:00
|
|
|
if (panelState == BottomSheetBehavior.STATE_EXPANDED) {
|
|
|
|
super.setTaskDescriptionColor(paletteColor)
|
|
|
|
val isColorLight = ColorUtil.isColorLight(paletteColor)
|
2020-06-06 18:57:28 +00:00
|
|
|
if (PreferenceUtil.isAdaptiveColor && (cps == Normal || cps == Flat)) {
|
2019-12-01 11:28:57 +00:00
|
|
|
super.setLightNavigationBar(true)
|
|
|
|
super.setLightStatusbar(isColorLight)
|
2020-05-14 10:25:57 +00:00
|
|
|
} else if (cps == Card || cps == Blur || cps == BlurCard) {
|
2019-12-01 11:28:57 +00:00
|
|
|
super.setLightStatusbar(false)
|
|
|
|
super.setLightNavigationBar(true)
|
2020-02-02 12:44:16 +00:00
|
|
|
super.setNavigationbarColor(Color.BLACK)
|
2020-05-17 19:58:04 +00:00
|
|
|
} else if (cps == Color || cps == Tiny || cps == Gradient) {
|
2019-12-01 11:28:57 +00:00
|
|
|
super.setNavigationbarColor(paletteColor)
|
|
|
|
super.setLightNavigationBar(isColorLight)
|
|
|
|
super.setLightStatusbar(isColorLight)
|
2020-05-14 10:25:57 +00:00
|
|
|
} else if (cps == Full) {
|
2020-05-09 14:45:07 +00:00
|
|
|
super.setNavigationbarColor(paletteColor)
|
|
|
|
super.setLightNavigationBar(isColorLight)
|
|
|
|
super.setLightStatusbar(false)
|
2020-05-17 19:58:04 +00:00
|
|
|
} else if (cps == Classic) {
|
2020-05-09 05:55:42 +00:00
|
|
|
super.setLightStatusbar(false)
|
2020-05-14 15:27:42 +00:00
|
|
|
} else if (cps == Fit) {
|
2020-02-26 16:49:24 +00:00
|
|
|
super.setLightStatusbar(false)
|
2019-12-01 11:28:57 +00:00
|
|
|
} else {
|
2019-12-30 11:01:50 +00:00
|
|
|
super.setLightStatusbar(
|
|
|
|
ColorUtil.isColorLight(
|
|
|
|
ATHUtil.resolveColor(
|
|
|
|
this,
|
|
|
|
android.R.attr.windowBackground
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2019-12-01 11:28:57 +00:00
|
|
|
super.setLightNavigationBar(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun setLightStatusbar(enabled: Boolean) {
|
|
|
|
lightStatusBar = enabled
|
|
|
|
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
|
|
|
super.setLightStatusbar(enabled)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun setLightNavigationBar(enabled: Boolean) {
|
|
|
|
lightNavigationBar = enabled
|
|
|
|
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
|
|
|
super.setLightNavigationBar(enabled)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun setNavigationbarColor(color: Int) {
|
|
|
|
navigationBarColor = color
|
|
|
|
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
|
|
|
super.setNavigationbarColor(color)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun setTaskDescriptionColor(color: Int) {
|
|
|
|
taskColor = color
|
|
|
|
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
|
|
|
super.setTaskDescriptionColor(color)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 18:29:44 +00:00
|
|
|
fun hideBottomNavigation() {
|
|
|
|
behavior.isHideable = true
|
|
|
|
behavior.state == BottomSheetBehavior.STATE_HIDDEN
|
|
|
|
}
|
|
|
|
|
2020-05-11 09:51:22 +00:00
|
|
|
fun updateTabs() {
|
2019-12-01 11:28:57 +00:00
|
|
|
bottomNavigationView.menu.clear()
|
2020-06-06 18:57:28 +00:00
|
|
|
val currentTabs: List<CategoryInfo> = PreferenceUtil.libraryCategory
|
2019-12-01 11:28:57 +00:00
|
|
|
for (tab in currentTabs) {
|
|
|
|
if (tab.visible) {
|
|
|
|
val menu = tab.category
|
2019-12-01 15:27:01 +00:00
|
|
|
bottomNavigationView.menu.add(0, menu.id, 0, menu.stringRes).setIcon(menu.icon)
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-11 09:51:22 +00:00
|
|
|
if (bottomNavigationView.menu.size() == 1) {
|
|
|
|
bottomNavigationView.hide()
|
2019-12-01 15:27:01 +00:00
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
2019-03-25 12:43:43 +00:00
|
|
|
}
|