2020-10-06 08:46:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Hemanth Savarla.
|
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License v3
|
|
|
|
*
|
|
|
|
* This is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
2019-04-20 05:29:45 +00:00
|
|
|
package code.name.monkey.retromusic.activities.base
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2021-11-11 14:54:05 +00:00
|
|
|
import android.content.res.ColorStateList
|
2021-10-25 13:53:46 +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
|
2021-10-22 15:52:57 +00:00
|
|
|
import androidx.core.animation.doOnEnd
|
2020-08-13 08:24:36 +00:00
|
|
|
import androidx.core.view.ViewCompat
|
2021-10-13 07:38:25 +00:00
|
|
|
import androidx.core.view.WindowInsetsCompat
|
2020-08-13 08:24:36 +00:00
|
|
|
import androidx.core.view.isVisible
|
2020-09-23 20:55:12 +00:00
|
|
|
import androidx.fragment.app.Fragment
|
2020-10-02 18:05:09 +00:00
|
|
|
import androidx.fragment.app.commit
|
2021-10-25 13:53:46 +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
|
2021-09-08 18:30:20 +00:00
|
|
|
import code.name.monkey.retromusic.databinding.SlidingMusicPanelLayoutBinding
|
2020-10-11 17:22:34 +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.NowPlayingScreen
|
2020-02-26 16:49:24 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.NowPlayingScreen.*
|
2020-09-23 20:55:12 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
|
2021-09-27 16:11:27 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.other.MiniPlayerFragment
|
2020-09-23 20:55:12 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.player.adaptive.AdaptiveFragment
|
|
|
|
import code.name.monkey.retromusic.fragments.player.blur.BlurPlayerFragment
|
|
|
|
import code.name.monkey.retromusic.fragments.player.card.CardFragment
|
|
|
|
import code.name.monkey.retromusic.fragments.player.cardblur.CardBlurFragment
|
|
|
|
import code.name.monkey.retromusic.fragments.player.circle.CirclePlayerFragment
|
2020-10-02 12:56:17 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.player.classic.ClassicPlayerFragment
|
2020-09-23 20:55:12 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.player.color.ColorFragment
|
|
|
|
import code.name.monkey.retromusic.fragments.player.fit.FitFragment
|
|
|
|
import code.name.monkey.retromusic.fragments.player.flat.FlatPlayerFragment
|
|
|
|
import code.name.monkey.retromusic.fragments.player.full.FullPlayerFragment
|
|
|
|
import code.name.monkey.retromusic.fragments.player.gradient.GradientPlayerFragment
|
|
|
|
import code.name.monkey.retromusic.fragments.player.material.MaterialFragment
|
|
|
|
import code.name.monkey.retromusic.fragments.player.normal.PlayerFragment
|
2020-09-23 21:10:16 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.player.peak.PeakPlayerFragment
|
2020-09-23 20:55:12 +00:00
|
|
|
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
|
2021-10-11 07:19:38 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.queue.PlayingQueueFragment
|
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
|
2021-10-22 14:53:23 +00:00
|
|
|
import code.name.monkey.retromusic.util.RetroUtil
|
2020-09-23 20:55:12 +00:00
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior.*
|
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-08-21 14:19:15 +00:00
|
|
|
abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
2019-12-01 11:28:57 +00:00
|
|
|
companion object {
|
|
|
|
val TAG: String = AbsSlidingMusicPanelActivity::class.java.simpleName
|
|
|
|
}
|
|
|
|
|
2021-10-13 07:38:25 +00:00
|
|
|
private var windowInsets: WindowInsetsCompat? = null
|
2020-08-29 18:53:15 +00:00
|
|
|
protected val libraryViewModel by viewModel<LibraryViewModel>()
|
2020-09-23 20:55:12 +00:00
|
|
|
private lateinit var bottomSheetBehavior: RetroBottomSheetBehavior<FrameLayout>
|
2020-10-02 12:56:17 +00:00
|
|
|
private var playerFragment: AbsPlayerFragment? = null
|
2019-12-01 11:28:57 +00:00
|
|
|
private var miniPlayerFragment: MiniPlayerFragment? = null
|
2020-09-23 20:55:12 +00:00
|
|
|
private var nowPlayingScreen: NowPlayingScreen? = null
|
2019-12-01 11:28:57 +00:00
|
|
|
private var taskColor: Int = 0
|
2021-10-25 13:53:46 +00:00
|
|
|
private var paletteColor: Int = Color.WHITE
|
2021-09-08 18:30:20 +00:00
|
|
|
protected abstract fun createContentView(): SlidingMusicPanelLayoutBinding
|
2019-12-01 11:28:57 +00:00
|
|
|
private val panelState: Int
|
2020-09-23 20:55:12 +00:00
|
|
|
get() = bottomSheetBehavior.state
|
2021-09-08 18:30:20 +00:00
|
|
|
private lateinit var binding: SlidingMusicPanelLayoutBinding
|
2020-09-23 20:55:12 +00:00
|
|
|
private val bottomSheetCallbackList = object : BottomSheetCallback() {
|
2019-12-01 11:28:57 +00:00
|
|
|
|
|
|
|
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
|
|
|
setMiniPlayerAlphaProgress(slideOffset)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
|
|
|
when (newState) {
|
2020-09-23 20:55:12 +00:00
|
|
|
STATE_EXPANDED -> {
|
2019-12-01 11:28:57 +00:00
|
|
|
onPanelExpanded()
|
|
|
|
}
|
2020-09-23 20:55:12 +00:00
|
|
|
STATE_COLLAPSED -> {
|
2019-12-01 11:28:57 +00:00
|
|
|
onPanelCollapsed()
|
|
|
|
}
|
|
|
|
else -> {
|
2020-09-23 20:55:12 +00:00
|
|
|
println("Do something")
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 21:10:16 +00:00
|
|
|
fun getBottomSheetBehavior() = bottomSheetBehavior
|
2020-05-05 07:42:09 +00:00
|
|
|
|
2019-12-01 11:28:57 +00:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2021-09-08 18:30:20 +00:00
|
|
|
binding = createContentView()
|
|
|
|
setContentView(binding.root)
|
2021-10-13 07:38:25 +00:00
|
|
|
ViewCompat.setOnApplyWindowInsetsListener(
|
|
|
|
binding.root
|
|
|
|
) { _, insets ->
|
|
|
|
windowInsets = insets
|
|
|
|
insets
|
|
|
|
}
|
2021-11-11 14:51:57 +00:00
|
|
|
bottomNavigationView.drawAboveSystemBarsWithPadding()
|
2021-10-22 14:53:23 +00:00
|
|
|
if (RetroUtil.isLandscape()) {
|
2021-10-22 15:01:43 +00:00
|
|
|
binding.slidingPanel.drawAboveSystemBarsWithPadding(true)
|
2021-10-22 14:53:23 +00:00
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
chooseFragmentForTheme()
|
|
|
|
setupSlidingUpPanel()
|
2020-07-28 19:18:34 +00:00
|
|
|
setupBottomSheet()
|
2021-10-25 13:53:46 +00:00
|
|
|
updateColor()
|
2021-11-11 14:54:05 +00:00
|
|
|
binding.slidingPanel.backgroundTintList = ColorStateList.valueOf(darkAccentColor())
|
|
|
|
bottomNavigationView.backgroundTintList = ColorStateList.valueOf(darkAccentColor())
|
2020-09-23 21:10:16 +00:00
|
|
|
}
|
2020-05-11 09:51:22 +00:00
|
|
|
|
2020-07-28 19:18:34 +00:00
|
|
|
private fun setupBottomSheet() {
|
2021-09-08 18:30:20 +00:00
|
|
|
bottomSheetBehavior = from(binding.slidingPanel) as RetroBottomSheetBehavior
|
2020-09-23 20:55:12 +00:00
|
|
|
bottomSheetBehavior.addBottomSheetCallback(bottomSheetCallbackList)
|
2021-10-25 12:38:10 +00:00
|
|
|
bottomSheetBehavior.isHideable = false
|
2021-10-11 06:16:29 +00:00
|
|
|
setMiniPlayerAlphaProgress(0F)
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2020-09-23 20:55:12 +00:00
|
|
|
if (nowPlayingScreen != PreferenceUtil.nowPlayingScreen) {
|
2019-12-01 11:28:57 +00:00
|
|
|
postRecreate()
|
|
|
|
}
|
2020-12-03 20:57:44 +00:00
|
|
|
if (bottomSheetBehavior.state == STATE_EXPANDED) {
|
2020-10-11 17:15:27 +00:00
|
|
|
setMiniPlayerAlphaProgress(1f)
|
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
super.onDestroy()
|
2020-09-23 20:55:12 +00:00
|
|
|
bottomSheetBehavior.removeBottomSheetCallback(bottomSheetCallbackList)
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
2021-09-08 18:30:20 +00:00
|
|
|
protected fun wrapSlidingMusicPanel(): SlidingMusicPanelLayoutBinding {
|
2021-09-12 14:20:33 +00:00
|
|
|
return SlidingMusicPanelLayoutBinding.inflate(layoutInflater)
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 21:31:09 +00:00
|
|
|
fun collapsePanel() {
|
2020-09-23 20:55:12 +00:00
|
|
|
bottomSheetBehavior.state = STATE_COLLAPSED
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fun expandPanel() {
|
2020-09-23 20:55:12 +00:00
|
|
|
bottomSheetBehavior.state = STATE_EXPANDED
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun setMiniPlayerAlphaProgress(progress: Float) {
|
2021-09-16 14:09:38 +00:00
|
|
|
if (progress < 0) return
|
2019-12-01 11:28:57 +00:00
|
|
|
val alpha = 1 - progress
|
2021-09-17 14:42:32 +00:00
|
|
|
miniPlayerFragment?.view?.alpha = 1 - (progress / 0.2F)
|
2019-12-01 11:28:57 +00:00
|
|
|
miniPlayerFragment?.view?.visibility = if (alpha == 0f) View.GONE else View.VISIBLE
|
2021-09-08 18:30:20 +00:00
|
|
|
binding.bottomNavigationView.translationY = progress * 500
|
|
|
|
binding.bottomNavigationView.alpha = alpha
|
2021-09-11 19:58:33 +00:00
|
|
|
binding.playerFragmentContainer.alpha = (progress - 0.2F) / 0.2F
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
open fun onPanelCollapsed() {
|
2021-10-27 04:16:33 +00:00
|
|
|
setMiniPlayerAlphaProgress(0F)
|
2019-12-01 11:28:57 +00:00
|
|
|
// restore values
|
2021-12-01 19:07:43 +00:00
|
|
|
setLightStatusBarAuto(surfaceColor())
|
|
|
|
setLightNavigationAuto()
|
|
|
|
setTaskDescriptionColor(taskColor)
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
open fun onPanelExpanded() {
|
2021-10-27 04:16:33 +00:00
|
|
|
setMiniPlayerAlphaProgress(1F)
|
2021-10-25 13:53:46 +00:00
|
|
|
onPaletteColorChanged()
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun setupSlidingUpPanel() {
|
2021-09-08 18:30:20 +00:00
|
|
|
binding.slidingPanel.viewTreeObserver.addOnGlobalLayoutListener(object :
|
2020-02-26 16:49:24 +00:00
|
|
|
ViewTreeObserver.OnGlobalLayoutListener {
|
2019-12-01 11:28:57 +00:00
|
|
|
override fun onGlobalLayout() {
|
2021-09-08 18:30:20 +00:00
|
|
|
binding.slidingPanel.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
2020-09-23 21:10:16 +00:00
|
|
|
if (nowPlayingScreen != Peak) {
|
2021-09-08 18:30:20 +00:00
|
|
|
val params = binding.slidingPanel.layoutParams as ViewGroup.LayoutParams
|
2020-09-23 21:10:16 +00:00
|
|
|
params.height = ViewGroup.LayoutParams.MATCH_PARENT
|
2021-09-08 18:30:20 +00:00
|
|
|
binding.slidingPanel.layoutParams = params
|
2020-09-23 21:10:16 +00:00
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
when (panelState) {
|
2020-09-23 20:55:12 +00:00
|
|
|
STATE_EXPANDED -> onPanelExpanded()
|
|
|
|
STATE_COLLAPSED -> onPanelCollapsed()
|
2020-07-28 19:18:34 +00:00
|
|
|
else -> {
|
2020-10-06 08:46:04 +00:00
|
|
|
// playerFragment!!.onHide()
|
2020-07-28 19:18:34 +00:00
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-11-11 14:51:57 +00:00
|
|
|
val bottomNavigationView get() = binding.bottomNavigationView
|
2019-12-01 11:28:57 +00:00
|
|
|
|
|
|
|
override fun onServiceConnected() {
|
|
|
|
super.onServiceConnected()
|
|
|
|
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
2021-09-08 18:30:20 +00:00
|
|
|
binding.slidingPanel.viewTreeObserver.addOnGlobalLayoutListener(object :
|
2020-02-26 16:49:24 +00:00
|
|
|
ViewTreeObserver.OnGlobalLayoutListener {
|
2019-12-01 11:28:57 +00:00
|
|
|
override fun onGlobalLayout() {
|
2021-09-08 18:30:20 +00:00
|
|
|
binding.slidingPanel.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
2021-10-25 12:38:10 +00:00
|
|
|
hideBottomSheet(false)
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
})
|
2021-10-25 12:38:10 +00:00
|
|
|
} // don't call hideBottomSheet(true) here as it causes a bug with the SlidingUpPanelLayout
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onQueueChanged() {
|
|
|
|
super.onQueueChanged()
|
2021-10-11 07:19:38 +00:00
|
|
|
// Mini player should be hidden in Playing Queue
|
2021-10-25 12:38:10 +00:00
|
|
|
// it may pop up if hideBottomSheet is called
|
2021-11-24 20:15:34 +00:00
|
|
|
if (currentFragment(R.id.fragment_container) !is PlayingQueueFragment &&
|
|
|
|
bottomSheetBehavior.state != STATE_EXPANDED
|
|
|
|
) {
|
2021-10-25 12:38:10 +00:00
|
|
|
hideBottomSheet(MusicPlayerRemote.playingQueue.isEmpty())
|
2021-10-11 07:19:38 +00:00
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBackPressed() {
|
|
|
|
if (!handleBackPress()) super.onBackPressed()
|
|
|
|
}
|
|
|
|
|
2020-09-23 20:55:12 +00:00
|
|
|
private fun handleBackPress(): Boolean {
|
|
|
|
if (bottomSheetBehavior.peekHeight != 0 && playerFragment!!.onBackPressed()) return true
|
|
|
|
if (panelState == STATE_EXPANDED) {
|
2019-12-01 11:28:57 +00:00
|
|
|
collapsePanel()
|
|
|
|
return true
|
2020-01-24 17:27:43 +00:00
|
|
|
}
|
2020-10-02 19:10:26 +00:00
|
|
|
|
2019-12-01 11:28:57 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-10-25 13:53:46 +00:00
|
|
|
private fun onPaletteColorChanged() {
|
|
|
|
if (panelState == STATE_EXPANDED) {
|
2021-12-01 19:07:43 +00:00
|
|
|
setTaskDescColor(paletteColor)
|
2021-10-25 13:53:46 +00:00
|
|
|
val isColorLight = ColorUtil.isColorLight(paletteColor)
|
|
|
|
if (PreferenceUtil.isAdaptiveColor && (nowPlayingScreen == Normal || nowPlayingScreen == Flat)) {
|
2021-12-01 19:07:43 +00:00
|
|
|
setLightNavigationBar(true)
|
|
|
|
setLightStatusBar(isColorLight)
|
2021-10-25 13:53:46 +00:00
|
|
|
} else if (nowPlayingScreen == Card || nowPlayingScreen == Blur || nowPlayingScreen == BlurCard) {
|
2021-12-01 19:07:43 +00:00
|
|
|
setLightStatusBar(false)
|
|
|
|
setLightNavigationBar(true)
|
2021-10-25 13:53:46 +00:00
|
|
|
} else if (nowPlayingScreen == Color || nowPlayingScreen == Tiny || nowPlayingScreen == Gradient) {
|
2021-12-01 19:07:43 +00:00
|
|
|
setLightNavigationBar(isColorLight)
|
|
|
|
setLightStatusBar(isColorLight)
|
2021-10-25 13:53:46 +00:00
|
|
|
} else if (nowPlayingScreen == Full) {
|
2021-12-01 19:07:43 +00:00
|
|
|
setLightNavigationBar(isColorLight)
|
|
|
|
setLightStatusBar(false)
|
2021-10-25 13:53:46 +00:00
|
|
|
} else if (nowPlayingScreen == Classic) {
|
2021-12-01 19:07:43 +00:00
|
|
|
setLightStatusBar(false)
|
2021-10-25 13:53:46 +00:00
|
|
|
} else if (nowPlayingScreen == Fit) {
|
2021-12-01 19:07:43 +00:00
|
|
|
setLightStatusBar(false)
|
2021-10-25 13:53:46 +00:00
|
|
|
} else {
|
2021-12-01 19:07:43 +00:00
|
|
|
setLightStatusBar(
|
2021-10-25 13:53:46 +00:00
|
|
|
ColorUtil.isColorLight(
|
|
|
|
ATHUtil.resolveColor(
|
|
|
|
this,
|
|
|
|
android.R.attr.windowBackground
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2021-12-01 19:07:43 +00:00
|
|
|
setLightNavigationBar(true)
|
2021-10-25 13:53:46 +00:00
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-01 19:07:43 +00:00
|
|
|
private fun setTaskDescColor(color: Int) {
|
2019-12-01 11:28:57 +00:00
|
|
|
taskColor = color
|
2020-09-23 20:55:12 +00:00
|
|
|
if (panelState == STATE_COLLAPSED) {
|
2021-12-01 19:07:43 +00:00
|
|
|
setTaskDescriptionColor(color)
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 09:51:22 +00:00
|
|
|
fun updateTabs() {
|
2021-09-08 18:30:20 +00:00
|
|
|
binding.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
|
2021-09-08 18:30:20 +00:00
|
|
|
binding.bottomNavigationView.menu.add(0, menu.id, 0, menu.stringRes)
|
|
|
|
.setIcon(menu.icon)
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-08 18:30:20 +00:00
|
|
|
if (binding.bottomNavigationView.menu.size() == 1) {
|
|
|
|
binding.bottomNavigationView.hide()
|
2019-12-01 15:27:01 +00:00
|
|
|
}
|
2019-12-01 11:28:57 +00:00
|
|
|
}
|
2020-09-17 17:56:59 +00:00
|
|
|
|
2021-10-25 13:53:46 +00:00
|
|
|
private fun updateColor() {
|
|
|
|
libraryViewModel.paletteColor.observe(this, { color ->
|
|
|
|
this.paletteColor = color
|
|
|
|
onPaletteColorChanged()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-25 12:38:10 +00:00
|
|
|
fun setBottomNavVisibility(visible: Boolean, animate: Boolean = false) {
|
2021-12-02 18:26:07 +00:00
|
|
|
binding.bottomNavigationView.translateYAnimate(if (visible) 0F else dip(R.dimen.bottom_nav_height).toFloat() + windowInsets.safeGetBottomInsets())
|
|
|
|
.apply {
|
|
|
|
doOnEnd {
|
|
|
|
binding.bottomNavigationView.bringToFront()
|
|
|
|
}
|
|
|
|
hideBottomSheet(
|
|
|
|
hide = MusicPlayerRemote.playingQueue.isEmpty(),
|
|
|
|
animate = animate,
|
|
|
|
isBottomNavVisible = visible
|
|
|
|
)
|
|
|
|
}
|
2020-10-11 17:15:27 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 18:26:07 +00:00
|
|
|
fun hideBottomSheet(
|
|
|
|
hide: Boolean,
|
|
|
|
animate: Boolean = false,
|
|
|
|
isBottomNavVisible: Boolean = bottomNavigationView.isVisible
|
|
|
|
) {
|
2021-10-13 07:38:25 +00:00
|
|
|
val heightOfBar =
|
|
|
|
windowInsets.safeGetBottomInsets() +
|
|
|
|
if (MusicPlayerRemote.isCasting) dip(R.dimen.cast_mini_player_height) else dip(R.dimen.mini_player_height)
|
2021-09-24 07:31:53 +00:00
|
|
|
val heightOfBarWithTabs = heightOfBar + dip(R.dimen.bottom_nav_height)
|
2020-10-11 17:15:27 +00:00
|
|
|
if (hide) {
|
2021-10-25 12:38:10 +00:00
|
|
|
bottomSheetBehavior.peekHeight = -windowInsets.safeGetBottomInsets()
|
|
|
|
bottomSheetBehavior.state = STATE_COLLAPSED
|
2021-12-02 18:26:07 +00:00
|
|
|
libraryViewModel.setFabMargin(if (isBottomNavVisible) dip(R.dimen.bottom_nav_height) else 0)
|
2021-09-08 18:30:20 +00:00
|
|
|
ViewCompat.setElevation(binding.slidingPanel, 0f)
|
|
|
|
ViewCompat.setElevation(binding.bottomNavigationView, 10f)
|
2020-10-11 17:15:27 +00:00
|
|
|
} else {
|
|
|
|
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
2021-09-08 18:30:20 +00:00
|
|
|
ViewCompat.setElevation(binding.slidingPanel, 10f)
|
|
|
|
ViewCompat.setElevation(binding.bottomNavigationView, 10f)
|
2021-12-02 18:26:07 +00:00
|
|
|
if (isBottomNavVisible) {
|
2020-12-03 20:57:44 +00:00
|
|
|
println("List")
|
2021-10-25 12:38:10 +00:00
|
|
|
if (animate) {
|
|
|
|
bottomSheetBehavior.peekHeightAnimate(heightOfBarWithTabs)
|
|
|
|
} else {
|
|
|
|
bottomSheetBehavior.peekHeight = heightOfBarWithTabs
|
|
|
|
}
|
2021-10-22 15:52:57 +00:00
|
|
|
binding.bottomNavigationView.bringToFront()
|
2021-11-23 09:22:46 +00:00
|
|
|
libraryViewModel.setFabMargin(dip(R.dimen.mini_player_height_expanded))
|
2020-10-11 17:15:27 +00:00
|
|
|
} else {
|
2020-12-03 20:57:44 +00:00
|
|
|
println("Details")
|
2021-10-25 12:38:10 +00:00
|
|
|
if (animate) {
|
2021-12-02 18:26:07 +00:00
|
|
|
bottomSheetBehavior.peekHeightAnimate(heightOfBar).doOnEnd {
|
2021-10-25 12:38:10 +00:00
|
|
|
binding.slidingPanel.bringToFront()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bottomSheetBehavior.peekHeight = heightOfBar
|
2021-10-22 15:52:57 +00:00
|
|
|
binding.slidingPanel.bringToFront()
|
|
|
|
}
|
2021-11-23 09:22:46 +00:00
|
|
|
libraryViewModel.setFabMargin(dip(R.dimen.mini_player_height))
|
2020-09-17 17:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-11 17:15:27 +00:00
|
|
|
}
|
2020-09-17 17:56:59 +00:00
|
|
|
}
|
2020-09-23 21:10:16 +00:00
|
|
|
|
2021-09-08 18:30:20 +00:00
|
|
|
fun setAllowDragging(allowDragging: Boolean) {
|
|
|
|
bottomSheetBehavior.setAllowDragging(allowDragging)
|
2021-10-25 12:38:10 +00:00
|
|
|
hideBottomSheet(false)
|
2021-09-08 18:30:20 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 20:55:12 +00:00
|
|
|
private fun chooseFragmentForTheme() {
|
|
|
|
nowPlayingScreen = PreferenceUtil.nowPlayingScreen
|
|
|
|
|
|
|
|
val fragment: Fragment = when (nowPlayingScreen) {
|
|
|
|
Blur -> BlurPlayerFragment()
|
|
|
|
Adaptive -> AdaptiveFragment()
|
|
|
|
Normal -> PlayerFragment()
|
|
|
|
Card -> CardFragment()
|
|
|
|
BlurCard -> CardBlurFragment()
|
|
|
|
Fit -> FitFragment()
|
|
|
|
Flat -> FlatPlayerFragment()
|
|
|
|
Full -> FullPlayerFragment()
|
|
|
|
Plain -> PlainPlayerFragment()
|
|
|
|
Simple -> SimplePlayerFragment()
|
|
|
|
Material -> MaterialFragment()
|
|
|
|
Color -> ColorFragment()
|
|
|
|
Gradient -> GradientPlayerFragment()
|
|
|
|
Tiny -> TinyPlayerFragment()
|
2020-09-23 21:10:16 +00:00
|
|
|
Peak -> PeakPlayerFragment()
|
2020-09-23 20:55:12 +00:00
|
|
|
Circle -> CirclePlayerFragment()
|
2020-10-02 12:56:17 +00:00
|
|
|
Classic -> ClassicPlayerFragment()
|
2020-09-23 20:55:12 +00:00
|
|
|
else -> PlayerFragment()
|
|
|
|
} // must implement AbsPlayerFragment
|
2020-10-02 18:05:09 +00:00
|
|
|
supportFragmentManager.commit {
|
|
|
|
replace(R.id.playerFragmentContainer, fragment)
|
|
|
|
}
|
2020-09-23 20:55:12 +00:00
|
|
|
supportFragmentManager.executePendingTransactions()
|
2020-10-02 18:05:09 +00:00
|
|
|
playerFragment = whichFragment<AbsPlayerFragment>(R.id.playerFragmentContainer)
|
2020-09-23 20:55:12 +00:00
|
|
|
miniPlayerFragment = whichFragment<MiniPlayerFragment>(R.id.miniPlayerFragment)
|
|
|
|
miniPlayerFragment?.view?.setOnClickListener { expandPanel() }
|
|
|
|
}
|
2020-10-06 08:46:04 +00:00
|
|
|
}
|