WIP pure Follow system
This commit is contained in:
parent
4da1f68617
commit
bb72a16b84
73 changed files with 1135 additions and 1246 deletions
|
@ -16,7 +16,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
||||
|
@ -192,14 +191,16 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
|
|||
val themeColor = if (PreferenceUtil.getInstance(this).adaptiveColor) color
|
||||
else ThemeStore.accentColor(this)
|
||||
|
||||
songTitle.setTextColor(themeColor)
|
||||
moreTitle.setTextColor(themeColor)
|
||||
songTitle.setTextColor(ThemeStore.accentColor(this))
|
||||
moreTitle.setTextColor(ThemeStore.accentColor(this))
|
||||
|
||||
val buttonColor = if (PreferenceUtil.getInstance(this).adaptiveColor) color
|
||||
else ATHUtil.resolveColor(this, R.attr.cardBackgroundColor)
|
||||
val buttonColor = if (PreferenceUtil.getInstance(this).adaptiveColor)
|
||||
color
|
||||
else
|
||||
ATHUtil.resolveColor(this, R.attr.cardBackgroundColor)
|
||||
|
||||
MaterialUtil.setTint(button = shuffleAction, color = buttonColor)
|
||||
MaterialUtil.setTint(button = playAction, color = buttonColor)
|
||||
//MaterialUtil.setTint(button = shuffleAction, color = buttonColor)
|
||||
//MaterialUtil.setTint(button = playAction, color = buttonColor)
|
||||
|
||||
toolbar.setBackgroundColor(ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
setSupportActionBar(toolbar)
|
||||
|
|
|
@ -2,15 +2,22 @@ package code.name.monkey.retromusic.activities.base
|
|||
|
||||
import android.animation.ValueAnimator
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.*
|
||||
import android.graphics.Color
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewTreeObserver
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.fragment.app.Fragment
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
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.extensions.*
|
||||
import code.name.monkey.retromusic.fragments.*
|
||||
import code.name.monkey.retromusic.extensions.hide
|
||||
import code.name.monkey.retromusic.extensions.show
|
||||
import code.name.monkey.retromusic.fragments.MiniPlayerFragment
|
||||
import code.name.monkey.retromusic.fragments.NowPlayingScreen
|
||||
import code.name.monkey.retromusic.fragments.NowPlayingScreen.*
|
||||
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
|
||||
import code.name.monkey.retromusic.fragments.player.adaptive.AdaptiveFragment
|
||||
|
@ -28,330 +35,331 @@ 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.*
|
||||
import code.name.monkey.retromusic.util.DensityUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.views.BottomNavigationBarTinted
|
||||
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(), AbsPlayerFragment.Callbacks {
|
||||
companion object {
|
||||
val TAG: String = AbsSlidingMusicPanelActivity::class.java.simpleName
|
||||
}
|
||||
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
|
||||
private var navigationBarColor: Int = 0
|
||||
private var taskColor: Int = 0
|
||||
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 lateinit var bottomSheetBehavior: BottomSheetBehavior<MaterialCardView>
|
||||
private var miniPlayerFragment: MiniPlayerFragment? = null
|
||||
private var playerFragment: AbsPlayerFragment? = null
|
||||
private var currentNowPlayingScreen: NowPlayingScreen? = null
|
||||
private var navigationBarColor: Int = 0
|
||||
private var taskColor: Int = 0
|
||||
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() {
|
||||
private val bottomSheetCallbackList = object : BottomSheetBehavior.BottomSheetCallback() {
|
||||
|
||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {
|
||||
setMiniPlayerAlphaProgress(slideOffset)
|
||||
dimBackground.show()
|
||||
dimBackground.alpha = slideOffset
|
||||
}
|
||||
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 -> {
|
||||
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
||||
when (newState) {
|
||||
BottomSheetBehavior.STATE_EXPANDED -> {
|
||||
onPanelExpanded()
|
||||
}
|
||||
BottomSheetBehavior.STATE_COLLAPSED -> {
|
||||
onPanelCollapsed()
|
||||
dimBackground.hide()
|
||||
}
|
||||
else -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(createContentView())
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(createContentView())
|
||||
|
||||
chooseFragmentForTheme()
|
||||
setupSlidingUpPanel()
|
||||
chooseFragmentForTheme()
|
||||
setupSlidingUpPanel()
|
||||
|
||||
updateTabs()
|
||||
updateTabs()
|
||||
|
||||
bottomSheetBehavior = BottomSheetBehavior.from(slidingPanel)
|
||||
bottomSheetBehavior = BottomSheetBehavior.from(slidingPanel)
|
||||
|
||||
val themeColor = ATHUtil.resolveColor(this, R.attr.colorPrimary, Color.GRAY)
|
||||
dimBackground.setBackgroundColor(ColorUtil.withAlpha(themeColor, 0.5f))
|
||||
}
|
||||
val themeColor = ATHUtil.resolveColor(this, android.R.attr.windowBackground, Color.GRAY)
|
||||
dimBackground.setBackgroundColor(ColorUtil.withAlpha(themeColor, 0.5f))
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (currentNowPlayingScreen != PreferenceUtil.getInstance(this).nowPlayingScreen) {
|
||||
postRecreate()
|
||||
}
|
||||
bottomSheetBehavior.addBottomSheetCallback(bottomSheetCallbackList)
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (currentNowPlayingScreen != PreferenceUtil.getInstance(this).nowPlayingScreen) {
|
||||
postRecreate()
|
||||
}
|
||||
bottomSheetBehavior.addBottomSheetCallback(bottomSheetCallbackList)
|
||||
|
||||
if (bottomSheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
setMiniPlayerAlphaProgress(1f)
|
||||
}
|
||||
}
|
||||
if (bottomSheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
setMiniPlayerAlphaProgress(1f)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
bottomSheetBehavior.removeBottomSheetCallback(bottomSheetCallbackList)
|
||||
if (navigationBarColorAnimator != null) navigationBarColorAnimator!!.cancel() // just in case
|
||||
}
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
bottomSheetBehavior.removeBottomSheetCallback(bottomSheetCallbackList)
|
||||
if (navigationBarColorAnimator != null) navigationBarColorAnimator!!.cancel() // just in case
|
||||
}
|
||||
|
||||
protected fun wrapSlidingMusicPanel(@LayoutRes resId: Int): View {
|
||||
@SuppressLint("InflateParams") val slidingMusicPanelLayout = layoutInflater.inflate(
|
||||
R.layout.sliding_music_panel_layout, null
|
||||
)
|
||||
val contentContainer = slidingMusicPanelLayout.findViewById<ViewGroup>(R.id.mainContentFrame)
|
||||
layoutInflater.inflate(resId, contentContainer)
|
||||
return slidingMusicPanelLayout
|
||||
}
|
||||
protected fun wrapSlidingMusicPanel(@LayoutRes resId: Int): View {
|
||||
@SuppressLint("InflateParams") val slidingMusicPanelLayout = layoutInflater.inflate(
|
||||
R.layout.sliding_music_panel_layout, null
|
||||
)
|
||||
val contentContainer = slidingMusicPanelLayout.findViewById<ViewGroup>(R.id.mainContentFrame)
|
||||
layoutInflater.inflate(resId, contentContainer)
|
||||
return slidingMusicPanelLayout
|
||||
}
|
||||
|
||||
private fun collapsePanel() {
|
||||
bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
}
|
||||
private fun collapsePanel() {
|
||||
bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
}
|
||||
|
||||
fun expandPanel() {
|
||||
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
setMiniPlayerAlphaProgress(1f)
|
||||
}
|
||||
fun expandPanel() {
|
||||
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
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
|
||||
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
|
||||
bottomNavigationView.alpha = alpha
|
||||
}
|
||||
bottomNavigationView.translationY = progress * 500
|
||||
bottomNavigationView.alpha = alpha
|
||||
}
|
||||
|
||||
open fun onPanelCollapsed() {
|
||||
// restore values
|
||||
super.setLightStatusbar(lightStatusBar)
|
||||
super.setTaskDescriptionColor(taskColor)
|
||||
super.setNavigationbarColor(navigationBarColor)
|
||||
super.setLightNavigationBar(lightNavigationBar)
|
||||
open fun onPanelCollapsed() {
|
||||
// restore values
|
||||
super.setLightStatusbar(lightStatusBar)
|
||||
super.setTaskDescriptionColor(taskColor)
|
||||
super.setNavigationbarColor(navigationBarColor)
|
||||
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)
|
||||
open fun onPanelExpanded() {
|
||||
val playerFragmentColor = playerFragment!!.paletteColor
|
||||
super.setTaskDescriptionColor(playerFragmentColor)
|
||||
|
||||
playerFragment?.setMenuVisibility(true)
|
||||
playerFragment?.userVisibleHint = true
|
||||
playerFragment?.onShow()
|
||||
onPaletteColorChanged()
|
||||
}
|
||||
playerFragment?.setMenuVisibility(true)
|
||||
playerFragment?.userVisibleHint = true
|
||||
playerFragment?.onShow()
|
||||
onPaletteColorChanged()
|
||||
}
|
||||
|
||||
private fun setupSlidingUpPanel() {
|
||||
slidingPanel.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
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) {
|
||||
BottomSheetBehavior.STATE_EXPANDED -> onPanelExpanded()
|
||||
BottomSheetBehavior.STATE_COLLAPSED -> onPanelCollapsed()
|
||||
else -> playerFragment!!.onHide()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
private fun setupSlidingUpPanel() {
|
||||
slidingPanel.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
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) {
|
||||
BottomSheetBehavior.STATE_EXPANDED -> onPanelExpanded()
|
||||
BottomSheetBehavior.STATE_COLLAPSED -> onPanelCollapsed()
|
||||
else -> playerFragment!!.onHide()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun toggleBottomNavigationView(toggle: Boolean) {
|
||||
bottomNavigationView.visibility = if (toggle) View.GONE else View.VISIBLE
|
||||
}
|
||||
fun toggleBottomNavigationView(toggle: Boolean) {
|
||||
bottomNavigationView.visibility = if (toggle) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
fun getBottomNavigationView(): BottomNavigationBarTinted {
|
||||
return bottomNavigationView
|
||||
}
|
||||
fun getBottomNavigationView(): BottomNavigationBarTinted {
|
||||
return bottomNavigationView
|
||||
}
|
||||
|
||||
private fun hideBottomBar(hide: Boolean) {
|
||||
val heightOfBar = resources.getDimensionPixelSize(R.dimen.mini_player_height)
|
||||
val heightOfBarWithTabs = resources.getDimensionPixelSize(R.dimen.mini_player_height_expanded)
|
||||
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) {
|
||||
bottomSheetBehavior.isHideable = true
|
||||
bottomSheetBehavior.peekHeight = 0
|
||||
collapsePanel()
|
||||
bottomNavigationView.elevation = DensityUtil.dip2px(this, 10f).toFloat()
|
||||
} else {
|
||||
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
||||
slidingPanel.cardElevation = DensityUtil.dip2px(this, 10f).toFloat()
|
||||
bottomNavigationView.elevation = DensityUtil.dip2px(this, 10f).toFloat()
|
||||
bottomSheetBehavior.isHideable = false
|
||||
bottomSheetBehavior.peekHeight = if (bottomNavigationView.visibility == View.VISIBLE) heightOfBarWithTabs else heightOfBar
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hide) {
|
||||
bottomSheetBehavior.isHideable = true
|
||||
bottomSheetBehavior.peekHeight = 0
|
||||
collapsePanel()
|
||||
bottomNavigationView.elevation = DensityUtil.dip2px(this, 10f).toFloat()
|
||||
} else {
|
||||
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
||||
slidingPanel.cardElevation = DensityUtil.dip2px(this, 10f).toFloat()
|
||||
bottomNavigationView.elevation = DensityUtil.dip2px(this, 10f).toFloat()
|
||||
bottomSheetBehavior.isHideable = false
|
||||
bottomSheetBehavior.peekHeight = if (bottomNavigationView.visibility == View.VISIBLE) heightOfBarWithTabs else heightOfBar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setBottomBarVisibility(gone: Int) {
|
||||
bottomNavigationView.visibility = gone
|
||||
hideBottomBar(false)
|
||||
}
|
||||
fun setBottomBarVisibility(gone: Int) {
|
||||
bottomNavigationView.visibility = gone
|
||||
hideBottomBar(false)
|
||||
}
|
||||
|
||||
private fun chooseFragmentForTheme() {
|
||||
currentNowPlayingScreen = PreferenceUtil.getInstance(this).nowPlayingScreen
|
||||
private fun chooseFragmentForTheme() {
|
||||
currentNowPlayingScreen = PreferenceUtil.getInstance(this).nowPlayingScreen
|
||||
|
||||
val fragment: Fragment = when (currentNowPlayingScreen) {
|
||||
BLUR -> BlurPlayerFragment()
|
||||
ADAPTIVE -> AdaptiveFragment()
|
||||
NORMAL -> PlayerFragment()
|
||||
CARD -> CardFragment()
|
||||
BLUR_CARD -> CardBlurFragment()
|
||||
FIT -> FitFragment()
|
||||
FLAT -> FlatPlayerFragment()
|
||||
FULL -> FullPlayerFragment()
|
||||
PLAIN -> PlainPlayerFragment()
|
||||
SIMPLE -> SimplePlayerFragment()
|
||||
MATERIAL -> MaterialFragment()
|
||||
COLOR -> ColorFragment()
|
||||
TINY -> TinyPlayerFragment()
|
||||
PEAK -> PeakPlayerFragment()
|
||||
else -> PlayerFragment()
|
||||
} // must implement AbsPlayerFragment
|
||||
supportFragmentManager.beginTransaction().replace(R.id.playerFragmentContainer, fragment)
|
||||
.commit()
|
||||
supportFragmentManager.executePendingTransactions()
|
||||
val fragment: Fragment = when (currentNowPlayingScreen) {
|
||||
BLUR -> BlurPlayerFragment()
|
||||
ADAPTIVE -> AdaptiveFragment()
|
||||
NORMAL -> PlayerFragment()
|
||||
CARD -> CardFragment()
|
||||
BLUR_CARD -> CardBlurFragment()
|
||||
FIT -> FitFragment()
|
||||
FLAT -> FlatPlayerFragment()
|
||||
FULL -> FullPlayerFragment()
|
||||
PLAIN -> PlainPlayerFragment()
|
||||
SIMPLE -> SimplePlayerFragment()
|
||||
MATERIAL -> MaterialFragment()
|
||||
COLOR -> ColorFragment()
|
||||
TINY -> TinyPlayerFragment()
|
||||
PEAK -> PeakPlayerFragment()
|
||||
else -> PlayerFragment()
|
||||
} // must implement AbsPlayerFragment
|
||||
supportFragmentManager.beginTransaction().replace(R.id.playerFragmentContainer, fragment)
|
||||
.commit()
|
||||
supportFragmentManager.executePendingTransactions()
|
||||
|
||||
playerFragment = supportFragmentManager.findFragmentById(R.id.playerFragmentContainer) as AbsPlayerFragment
|
||||
miniPlayerFragment = supportFragmentManager.findFragmentById(R.id.miniPlayerFragment) as MiniPlayerFragment
|
||||
miniPlayerFragment?.view?.setOnClickListener { expandPanel() }
|
||||
}
|
||||
playerFragment = supportFragmentManager.findFragmentById(R.id.playerFragmentContainer) as AbsPlayerFragment
|
||||
miniPlayerFragment = supportFragmentManager.findFragmentById(R.id.miniPlayerFragment) as MiniPlayerFragment
|
||||
miniPlayerFragment?.view?.setOnClickListener { expandPanel() }
|
||||
}
|
||||
|
||||
override fun onServiceConnected() {
|
||||
super.onServiceConnected()
|
||||
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
||||
slidingPanel.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
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 onServiceConnected() {
|
||||
super.onServiceConnected()
|
||||
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
||||
slidingPanel.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
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 onQueueChanged() {
|
||||
super.onQueueChanged()
|
||||
hideBottomBar(MusicPlayerRemote.playingQueue.isEmpty())
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (!handleBackPress()) super.onBackPressed()
|
||||
}
|
||||
override fun onBackPressed() {
|
||||
if (!handleBackPress()) super.onBackPressed()
|
||||
}
|
||||
|
||||
open fun handleBackPress(): Boolean {
|
||||
if (bottomSheetBehavior.peekHeight != 0 && playerFragment!!.onBackPressed()) return true
|
||||
if (panelState == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
collapsePanel()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
open fun handleBackPress(): Boolean {
|
||||
if (bottomSheetBehavior.peekHeight != 0 && playerFragment!!.onBackPressed()) return true
|
||||
if (panelState == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
collapsePanel()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onPaletteColorChanged() {
|
||||
if (panelState == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
val paletteColor = playerFragment!!.paletteColor
|
||||
super.setTaskDescriptionColor(paletteColor)
|
||||
override fun onPaletteColorChanged() {
|
||||
if (panelState == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
val paletteColor = playerFragment!!.paletteColor
|
||||
super.setTaskDescriptionColor(paletteColor)
|
||||
|
||||
val isColorLight = ColorUtil.isColorLight(paletteColor)
|
||||
val isColorLight = ColorUtil.isColorLight(paletteColor)
|
||||
|
||||
if (PreferenceUtil.getInstance(this).adaptiveColor && (currentNowPlayingScreen == NORMAL || currentNowPlayingScreen == FLAT)) {
|
||||
super.setLightNavigationBar(true)
|
||||
super.setLightStatusbar(isColorLight)
|
||||
} else if (currentNowPlayingScreen == FULL || currentNowPlayingScreen == CARD || currentNowPlayingScreen == FIT || currentNowPlayingScreen == BLUR || currentNowPlayingScreen == BLUR_CARD) {
|
||||
super.setLightStatusbar(false)
|
||||
super.setLightNavigationBar(true)
|
||||
} else if (currentNowPlayingScreen == COLOR || currentNowPlayingScreen == TINY) {
|
||||
super.setNavigationbarColor(paletteColor)
|
||||
super.setLightNavigationBar(isColorLight)
|
||||
super.setLightStatusbar(isColorLight)
|
||||
} else {
|
||||
super.setLightStatusbar(
|
||||
ColorUtil.isColorLight(
|
||||
ATHUtil.resolveColor(
|
||||
this, R.attr.colorPrimary
|
||||
)
|
||||
)
|
||||
)
|
||||
super.setLightNavigationBar(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (PreferenceUtil.getInstance(this).adaptiveColor && (currentNowPlayingScreen == NORMAL || currentNowPlayingScreen == FLAT)) {
|
||||
super.setLightNavigationBar(true)
|
||||
super.setLightStatusbar(isColorLight)
|
||||
} else if (currentNowPlayingScreen == FULL || currentNowPlayingScreen == CARD || currentNowPlayingScreen == FIT || currentNowPlayingScreen == BLUR || currentNowPlayingScreen == BLUR_CARD) {
|
||||
super.setLightStatusbar(false)
|
||||
super.setLightNavigationBar(true)
|
||||
} else if (currentNowPlayingScreen == COLOR || currentNowPlayingScreen == TINY) {
|
||||
super.setNavigationbarColor(paletteColor)
|
||||
super.setLightNavigationBar(isColorLight)
|
||||
super.setLightStatusbar(isColorLight)
|
||||
} else {
|
||||
super.setLightStatusbar(
|
||||
ColorUtil.isColorLight(
|
||||
ATHUtil.resolveColor(
|
||||
this, R.attr.colorPrimary
|
||||
)
|
||||
)
|
||||
)
|
||||
super.setLightNavigationBar(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setLightStatusbar(enabled: Boolean) {
|
||||
lightStatusBar = enabled
|
||||
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
super.setLightStatusbar(enabled)
|
||||
}
|
||||
}
|
||||
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 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) {
|
||||
if (navigationBarColorAnimator != null) navigationBarColorAnimator!!.cancel()
|
||||
super.setNavigationbarColor(color)
|
||||
}
|
||||
}
|
||||
override fun setNavigationbarColor(color: Int) {
|
||||
navigationBarColor = color
|
||||
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
if (navigationBarColorAnimator != null) navigationBarColorAnimator!!.cancel()
|
||||
super.setNavigationbarColor(color)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setTaskDescriptionColor(color: Int) {
|
||||
taskColor = color
|
||||
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
super.setTaskDescriptionColor(color)
|
||||
}
|
||||
}
|
||||
override fun setTaskDescriptionColor(color: Int) {
|
||||
taskColor = color
|
||||
if (panelState == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
super.setTaskDescriptionColor(color)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateTabs() {
|
||||
bottomNavigationView.menu.clear()
|
||||
val currentTabs = PreferenceUtil.getInstance(this).libraryCategoryInfos
|
||||
for (tab in currentTabs) {
|
||||
if (tab.visible) {
|
||||
val menu = tab.category
|
||||
bottomNavigationView.menu.add(
|
||||
0, menu.id, 0, menu.stringRes
|
||||
).setIcon(menu.icon)
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun updateTabs() {
|
||||
bottomNavigationView.menu.clear()
|
||||
val currentTabs = PreferenceUtil.getInstance(this).libraryCategoryInfos
|
||||
for (tab in currentTabs) {
|
||||
if (tab.visible) {
|
||||
val menu = tab.category
|
||||
bottomNavigationView.menu.add(
|
||||
0, menu.id, 0, menu.stringRes
|
||||
).setIcon(menu.icon)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
|
||||
if (ev?.action == MotionEvent.ACTION_DOWN) {
|
||||
if (panelState == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
val outRect = Rect()
|
||||
slidingPanel.getGlobalVisibleRect(outRect)
|
||||
if (!outRect.contains(ev.rawX.toInt(), ev.rawY.toInt())) {
|
||||
bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.dispatchTouchEvent(ev)
|
||||
}
|
||||
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
|
||||
if (ev?.action == MotionEvent.ACTION_DOWN) {
|
||||
if (panelState == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
val outRect = Rect()
|
||||
slidingPanel.getGlobalVisibleRect(outRect)
|
||||
if (!outRect.contains(ev.rawX.toInt(), ev.rawY.toInt())) {
|
||||
bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.dispatchTouchEvent(ev)
|
||||
}
|
||||
}
|
|
@ -2,199 +2,201 @@ package code.name.monkey.retromusic.activities.base
|
|||
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.*
|
||||
import android.view.*
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.content.ContextCompat
|
||||
import code.name.monkey.appthemehelper.*
|
||||
import code.name.monkey.appthemehelper.ATH
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.common.ATHToolbarActivity
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.appthemehelper.util.TintHelper
|
||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.util.*
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.RetroUtil
|
||||
import code.name.monkey.retromusic.util.ThemeManager
|
||||
|
||||
abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
|
||||
|
||||
private val handler = Handler()
|
||||
private val handler = Handler()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(ThemeManager.getThemeResValue(this))
|
||||
hideStatusBar()
|
||||
super.onCreate(savedInstanceState)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(ThemeManager.getThemeResValue(this))
|
||||
hideStatusBar()
|
||||
super.onCreate(savedInstanceState)
|
||||
setImmersiveFullscreen()
|
||||
registerSystemUiVisibility()
|
||||
toggleScreenOn()
|
||||
}
|
||||
|
||||
changeBackgroundShape()
|
||||
setImmersiveFullscreen()
|
||||
registerSystemUiVisibility()
|
||||
toggleScreenOn()
|
||||
}
|
||||
private fun toggleScreenOn() {
|
||||
if (PreferenceUtil.getInstance(this).isScreenOnEnabled) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
} else {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
}
|
||||
|
||||
private fun toggleScreenOn() {
|
||||
if (PreferenceUtil.getInstance(this).isScreenOnEnabled) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
} else {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
}
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
if (hasFocus) {
|
||||
hideStatusBar()
|
||||
handler.removeCallbacks(this)
|
||||
handler.postDelayed(this, 300)
|
||||
} else {
|
||||
handler.removeCallbacks(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
if (hasFocus) {
|
||||
hideStatusBar()
|
||||
handler.removeCallbacks(this)
|
||||
handler.postDelayed(this, 300)
|
||||
} else {
|
||||
handler.removeCallbacks(this)
|
||||
}
|
||||
}
|
||||
fun hideStatusBar() {
|
||||
hideStatusBar(PreferenceUtil.getInstance(this).fullScreenMode)
|
||||
}
|
||||
|
||||
fun hideStatusBar() {
|
||||
hideStatusBar(PreferenceUtil.getInstance(this).fullScreenMode)
|
||||
}
|
||||
private fun hideStatusBar(fullscreen: Boolean) {
|
||||
val statusBar = window.decorView.rootView.findViewById<View>(R.id.status_bar)
|
||||
if (statusBar != null) {
|
||||
statusBar.visibility = if (fullscreen) View.GONE else View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
private fun hideStatusBar(fullscreen: Boolean) {
|
||||
val statusBar = window.decorView.rootView.findViewById<View>(R.id.status_bar)
|
||||
if (statusBar != null) {
|
||||
statusBar.visibility = if (fullscreen) View.GONE else View.VISIBLE
|
||||
}
|
||||
}
|
||||
private fun changeBackgroundShape() {
|
||||
var background: Drawable? = if (PreferenceUtil.getInstance(this).isRoundCorners)
|
||||
ContextCompat.getDrawable(this, R.drawable.round_window)
|
||||
else ContextCompat.getDrawable(this, R.drawable.square_window)
|
||||
background = TintHelper.createTintedDrawable(background, ATHUtil.resolveColor(this, android.R.attr.windowBackground))
|
||||
window.setBackgroundDrawable(background)
|
||||
}
|
||||
|
||||
private fun changeBackgroundShape() {
|
||||
var background: Drawable? = if (PreferenceUtil.getInstance(this).isRoundCorners) ContextCompat.getDrawable(
|
||||
this,
|
||||
R.drawable.round_window
|
||||
)
|
||||
else ContextCompat.getDrawable(this, R.drawable.square_window)
|
||||
background = TintHelper.createTintedDrawable(
|
||||
background,
|
||||
ATHUtil.resolveColor(this, R.attr.colorPrimary)
|
||||
)
|
||||
window.setBackgroundDrawable(background)
|
||||
}
|
||||
fun setDrawUnderStatusBar() {
|
||||
RetroUtil.setAllowDrawUnderStatusBar(window)
|
||||
}
|
||||
|
||||
fun setDrawUnderStatusBar() {
|
||||
RetroUtil.setAllowDrawUnderStatusBar(window)
|
||||
}
|
||||
fun setDrawUnderNavigationBar() {
|
||||
RetroUtil.setAllowDrawUnderNavigationBar(window)
|
||||
}
|
||||
|
||||
fun setDrawUnderNavigationBar() {
|
||||
RetroUtil.setAllowDrawUnderNavigationBar(window)
|
||||
}
|
||||
/**
|
||||
* This will set the color of the view with the id "status_bar" on KitKat and Lollipop. On
|
||||
* Lollipop if no such view is found it will set the statusbar color using the native method.
|
||||
*
|
||||
* @param color the new statusbar color (will be shifted down on Lollipop and above)
|
||||
*/
|
||||
fun setStatusbarColor(color: Int) {
|
||||
val statusBar = window.decorView.rootView.findViewById<View>(R.id.status_bar)
|
||||
if (statusBar != null) {
|
||||
when {
|
||||
VersionUtils.hasMarshmallow() -> window.statusBarColor = color
|
||||
VersionUtils.hasLollipop() -> statusBar.setBackgroundColor(
|
||||
ColorUtil.darkenColor(
|
||||
color
|
||||
)
|
||||
)
|
||||
else -> statusBar.setBackgroundColor(color)
|
||||
}
|
||||
} else {
|
||||
when {
|
||||
VersionUtils.hasMarshmallow() -> window.statusBarColor = color
|
||||
else -> window.statusBarColor = ColorUtil.darkenColor(color)
|
||||
}
|
||||
}
|
||||
setLightStatusbarAuto(color)
|
||||
}
|
||||
|
||||
/**
|
||||
* This will set the color of the view with the id "status_bar" on KitKat and Lollipop. On
|
||||
* Lollipop if no such view is found it will set the statusbar color using the native method.
|
||||
*
|
||||
* @param color the new statusbar color (will be shifted down on Lollipop and above)
|
||||
*/
|
||||
fun setStatusbarColor(color: Int) {
|
||||
val statusBar = window.decorView.rootView.findViewById<View>(R.id.status_bar)
|
||||
if (statusBar != null) {
|
||||
when {
|
||||
VersionUtils.hasMarshmallow() -> window.statusBarColor = color
|
||||
VersionUtils.hasLollipop() -> statusBar.setBackgroundColor(
|
||||
ColorUtil.darkenColor(
|
||||
color
|
||||
)
|
||||
)
|
||||
else -> statusBar.setBackgroundColor(color)
|
||||
}
|
||||
} else {
|
||||
when {
|
||||
VersionUtils.hasMarshmallow() -> window.statusBarColor = color
|
||||
else -> window.statusBarColor = ColorUtil.darkenColor(color)
|
||||
}
|
||||
}
|
||||
setLightStatusbarAuto(color)
|
||||
}
|
||||
fun setStatusbarColorAuto() {
|
||||
// we don't want to use statusbar color because we are doing the color darkening on our own to support KitKat
|
||||
//setStatusbarColor(ATHUtil.resolveColor(this, android.R.attr.windowBackground))
|
||||
}
|
||||
|
||||
fun setStatusbarColorAuto() {
|
||||
// we don't want to use statusbar color because we are doing the color darkening on our own to support KitKat
|
||||
setStatusbarColor(ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
}
|
||||
open fun setTaskDescriptionColor(@ColorInt color: Int) {
|
||||
ATH.setTaskDescriptionColor(this, color)
|
||||
}
|
||||
|
||||
open fun setTaskDescriptionColor(@ColorInt color: Int) {
|
||||
ATH.setTaskDescriptionColor(this, color)
|
||||
}
|
||||
fun setTaskDescriptionColorAuto() {
|
||||
setTaskDescriptionColor(ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
}
|
||||
|
||||
fun setTaskDescriptionColorAuto() {
|
||||
setTaskDescriptionColor(ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
}
|
||||
open fun setNavigationbarColor(color: Int) {
|
||||
if (ThemeStore.coloredNavigationBar(this)) {
|
||||
ATH.setNavigationbarColor(this, color)
|
||||
} else {
|
||||
ATH.setNavigationbarColor(this, Color.BLACK)
|
||||
}
|
||||
}
|
||||
|
||||
open fun setNavigationbarColor(color: Int) {
|
||||
if (ThemeStore.coloredNavigationBar(this)) {
|
||||
ATH.setNavigationbarColor(this, color)
|
||||
} else {
|
||||
ATH.setNavigationbarColor(this, Color.BLACK)
|
||||
}
|
||||
}
|
||||
open fun setNavigationBarColorPrimary() {
|
||||
ATH.setNavigationbarColor(this, ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
}
|
||||
|
||||
open fun setNavigationBarColorPrimary() {
|
||||
ATH.setNavigationbarColor(this, ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
}
|
||||
fun setNavigationbarColorAuto() {
|
||||
setNavigationbarColor(ATHUtil.resolveColor(this, R.attr.colorSecondary))
|
||||
}
|
||||
|
||||
fun setNavigationbarColorAuto() {
|
||||
setNavigationbarColor(ATHUtil.resolveColor(this, R.attr.colorSecondary))
|
||||
}
|
||||
open fun setLightStatusbar(enabled: Boolean) {
|
||||
ATH.setLightStatusbar(this, enabled)
|
||||
}
|
||||
|
||||
open fun setLightStatusbar(enabled: Boolean) {
|
||||
ATH.setLightStatusbar(this, enabled)
|
||||
}
|
||||
fun setLightStatusbarAuto(bgColor: Int) {
|
||||
setLightStatusbar(ColorUtil.isColorLight(bgColor))
|
||||
}
|
||||
|
||||
fun setLightStatusbarAuto(bgColor: Int) {
|
||||
setLightStatusbar(ColorUtil.isColorLight(bgColor))
|
||||
}
|
||||
open fun setLightNavigationBar(enabled: Boolean) {
|
||||
if (!ATHUtil.isWindowBackgroundDark(this) and ThemeStore.coloredNavigationBar(this)) {
|
||||
ATH.setLightNavigationbar(this, enabled)
|
||||
}
|
||||
}
|
||||
|
||||
open fun setLightNavigationBar(enabled: Boolean) {
|
||||
if (!ATHUtil.isWindowBackgroundDark(this) and ThemeStore.coloredNavigationBar(this)) {
|
||||
ATH.setLightNavigationbar(this, enabled)
|
||||
}
|
||||
}
|
||||
private fun registerSystemUiVisibility() {
|
||||
val decorView = window.decorView
|
||||
decorView.setOnSystemUiVisibilityChangeListener { visibility ->
|
||||
if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
|
||||
setImmersiveFullscreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerSystemUiVisibility() {
|
||||
val decorView = window.decorView
|
||||
decorView.setOnSystemUiVisibilityChangeListener { visibility ->
|
||||
if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
|
||||
setImmersiveFullscreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun unregisterSystemUiVisibility() {
|
||||
val decorView = window.decorView
|
||||
decorView.setOnSystemUiVisibilityChangeListener(null)
|
||||
}
|
||||
|
||||
private fun unregisterSystemUiVisibility() {
|
||||
val decorView = window.decorView
|
||||
decorView.setOnSystemUiVisibilityChangeListener(null)
|
||||
}
|
||||
private fun setImmersiveFullscreen() {
|
||||
val flags = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
|
||||
|
||||
private fun setImmersiveFullscreen() {
|
||||
val flags = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
|
||||
if (PreferenceUtil.getInstance(this).fullScreenMode) {
|
||||
window.decorView.systemUiVisibility = flags
|
||||
}
|
||||
}
|
||||
|
||||
if (PreferenceUtil.getInstance(this).fullScreenMode) {
|
||||
window.decorView.systemUiVisibility = flags
|
||||
}
|
||||
}
|
||||
private fun exitFullscreen() {
|
||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
||||
}
|
||||
|
||||
private fun exitFullscreen() {
|
||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
||||
}
|
||||
override fun run() {
|
||||
setImmersiveFullscreen()
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
setImmersiveFullscreen()
|
||||
}
|
||||
override fun onStop() {
|
||||
handler.removeCallbacks(this)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
handler.removeCallbacks(this)
|
||||
super.onStop()
|
||||
}
|
||||
public override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
unregisterSystemUiVisibility()
|
||||
exitFullscreen()
|
||||
}
|
||||
|
||||
public override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
unregisterSystemUiVisibility()
|
||||
exitFullscreen()
|
||||
}
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||
handler.removeCallbacks(this)
|
||||
handler.postDelayed(this, 500)
|
||||
}
|
||||
return super.onKeyDown(keyCode, event)
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||
handler.removeCallbacks(this)
|
||||
handler.postDelayed(this, 500)
|
||||
}
|
||||
return super.onKeyDown(keyCode, event)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,210 +1,201 @@
|
|||
package code.name.monkey.retromusic.adapter
|
||||
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.IntDef
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.recyclerview.widget.*
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.adapter.album.AlbumFullWidthAdapter
|
||||
import code.name.monkey.retromusic.adapter.artist.ArtistAdapter
|
||||
import code.name.monkey.retromusic.adapter.song.SongAdapter
|
||||
import code.name.monkey.retromusic.extensions.show
|
||||
import code.name.monkey.retromusic.loaders.PlaylistSongsLoader
|
||||
import code.name.monkey.retromusic.model.*
|
||||
import code.name.monkey.retromusic.model.Album
|
||||
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.textview.MaterialTextView
|
||||
|
||||
class HomeAdapter(
|
||||
private val activity: AppCompatActivity, private val displayMetrics: DisplayMetrics
|
||||
private val activity: AppCompatActivity, private val displayMetrics: DisplayMetrics
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
||||
private var list = ArrayList<Home>()
|
||||
private var list = ArrayList<Home>()
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return list[position].homeSection
|
||||
}
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return list[position].homeSection
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
val layout = LayoutInflater.from(activity)
|
||||
.inflate(R.layout.section_recycler_view, parent, false)
|
||||
return when (viewType) {
|
||||
RECENT_ARTISTS, TOP_ARTISTS -> ArtistViewHolder(layout)
|
||||
PLAYLISTS -> PlaylistViewHolder(layout)
|
||||
else -> {
|
||||
AlbumViewHolder(
|
||||
LayoutInflater.from(activity).inflate(
|
||||
R.layout.metal_section_recycler_view, parent, false
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
val layout = LayoutInflater.from(activity)
|
||||
.inflate(R.layout.section_recycler_view, parent, false)
|
||||
return when (viewType) {
|
||||
RECENT_ARTISTS, TOP_ARTISTS -> ArtistViewHolder(layout)
|
||||
PLAYLISTS -> PlaylistViewHolder(layout)
|
||||
else -> {
|
||||
AlbumViewHolder(LayoutInflater.from(activity).inflate(R.layout.metal_section_recycler_view, parent, false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
println("ViewType ${getItemViewType(position)}")
|
||||
when (getItemViewType(position)) {
|
||||
RECENT_ALBUMS -> {
|
||||
val viewHolder = holder as AlbumViewHolder
|
||||
viewHolder.bindView(
|
||||
list[position].arrayList.toAlbums(),
|
||||
R.string.recent_albums,
|
||||
R.string.recent_added_albums
|
||||
)
|
||||
}
|
||||
TOP_ALBUMS -> {
|
||||
val viewHolder = holder as AlbumViewHolder
|
||||
viewHolder.bindView(
|
||||
list[position].arrayList.toAlbums(),
|
||||
R.string.top_albums,
|
||||
R.string.most_played_albums
|
||||
)
|
||||
}
|
||||
RECENT_ARTISTS -> {
|
||||
val viewHolder = holder as ArtistViewHolder
|
||||
viewHolder.bindView(
|
||||
list[position].arrayList.toArtists(),
|
||||
R.string.recent_artists,
|
||||
R.string.recent_added_artists
|
||||
)
|
||||
}
|
||||
TOP_ARTISTS -> {
|
||||
val viewHolder = holder as ArtistViewHolder
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
println("ViewType ${getItemViewType(position)}")
|
||||
when (getItemViewType(position)) {
|
||||
RECENT_ALBUMS -> {
|
||||
val viewHolder = holder as AlbumViewHolder
|
||||
viewHolder.bindView(
|
||||
list[position].arrayList.toAlbums(),
|
||||
R.string.recent_albums,
|
||||
R.string.recent_added_albums
|
||||
)
|
||||
}
|
||||
TOP_ALBUMS -> {
|
||||
val viewHolder = holder as AlbumViewHolder
|
||||
viewHolder.bindView(
|
||||
list[position].arrayList.toAlbums(),
|
||||
R.string.top_albums,
|
||||
R.string.most_played_albums
|
||||
)
|
||||
}
|
||||
RECENT_ARTISTS -> {
|
||||
val viewHolder = holder as ArtistViewHolder
|
||||
viewHolder.bindView(
|
||||
list[position].arrayList.toArtists(),
|
||||
R.string.recent_artists,
|
||||
R.string.recent_added_artists
|
||||
)
|
||||
}
|
||||
TOP_ARTISTS -> {
|
||||
val viewHolder = holder as ArtistViewHolder
|
||||
|
||||
viewHolder.bindView(
|
||||
list[position].arrayList.toArtists(),
|
||||
R.string.top_artists,
|
||||
R.string.most_played_artists
|
||||
)
|
||||
}
|
||||
PLAYLISTS -> {
|
||||
val viewHolder = holder as PlaylistViewHolder
|
||||
viewHolder.bindView(
|
||||
list[position].arrayList.toPlaylist(),
|
||||
R.string.favorites,
|
||||
R.string.favorites_songs
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
viewHolder.bindView(
|
||||
list[position].arrayList.toArtists(),
|
||||
R.string.top_artists,
|
||||
R.string.most_played_artists
|
||||
)
|
||||
}
|
||||
PLAYLISTS -> {
|
||||
val viewHolder = holder as PlaylistViewHolder
|
||||
viewHolder.bindView(
|
||||
list[position].arrayList.toPlaylist(),
|
||||
R.string.favorites,
|
||||
R.string.favorites_songs
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return list.size
|
||||
}
|
||||
override fun getItemCount(): Int {
|
||||
return list.size
|
||||
}
|
||||
|
||||
fun swapData(sections: ArrayList<Home>) {
|
||||
list = sections
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
fun swapData(sections: ArrayList<Home>) {
|
||||
list = sections
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
companion object {
|
||||
companion object {
|
||||
|
||||
@IntDef(RECENT_ALBUMS, TOP_ALBUMS, RECENT_ARTISTS, TOP_ARTISTS, PLAYLISTS)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class HomeSection
|
||||
@IntDef(RECENT_ALBUMS, TOP_ALBUMS, RECENT_ARTISTS, TOP_ARTISTS, PLAYLISTS)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class HomeSection
|
||||
|
||||
const val RECENT_ALBUMS = 3
|
||||
const val TOP_ALBUMS = 1
|
||||
const val RECENT_ARTISTS = 2
|
||||
const val TOP_ARTISTS = 0
|
||||
const val PLAYLISTS = 4
|
||||
const val RECENT_ALBUMS = 3
|
||||
const val TOP_ALBUMS = 1
|
||||
const val RECENT_ARTISTS = 2
|
||||
const val TOP_ARTISTS = 0
|
||||
const val PLAYLISTS = 4
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private inner class AlbumViewHolder(view: View) : AbsHomeViewItem(view) {
|
||||
fun bindView(list: ArrayList<Album>, titleRes: Int, subtitleRes: Int) {
|
||||
if (list.isNotEmpty()) {
|
||||
recyclerView.apply {
|
||||
show()
|
||||
adapter = AlbumFullWidthAdapter(activity, list, displayMetrics)
|
||||
}
|
||||
titleContainer.show()
|
||||
title.text = activity.getString(titleRes)
|
||||
text.text = activity.getString(subtitleRes)
|
||||
}
|
||||
}
|
||||
private inner class AlbumViewHolder(view: View) : AbsHomeViewItem(view) {
|
||||
fun bindView(list: ArrayList<Album>, titleRes: Int, subtitleRes: Int) {
|
||||
if (list.isNotEmpty()) {
|
||||
recyclerView.apply {
|
||||
show()
|
||||
adapter = AlbumFullWidthAdapter(activity, list, displayMetrics)
|
||||
}
|
||||
title.text = activity.getString(titleRes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class ArtistViewHolder(view: View) : AbsHomeViewItem(view) {
|
||||
fun bindView(list: ArrayList<Artist>, titleRes: Int, subtitleRes: Int) {
|
||||
if (list.isNotEmpty()) {
|
||||
recyclerView.apply {
|
||||
show()
|
||||
layoutManager = GridLayoutManager(
|
||||
activity, 1, GridLayoutManager.HORIZONTAL, false
|
||||
)
|
||||
val artistAdapter = ArtistAdapter(
|
||||
activity,
|
||||
list,
|
||||
PreferenceUtil.getInstance(activity).getHomeGridStyle(activity),
|
||||
false,
|
||||
null
|
||||
)
|
||||
adapter = artistAdapter
|
||||
}
|
||||
title.text = activity.getString(titleRes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private inner class PlaylistViewHolder(view: View) : AbsHomeViewItem(view) {
|
||||
fun bindView(arrayList: ArrayList<Playlist>, titleRes: Int, subtitleRes: Int) {
|
||||
if (arrayList.isNotEmpty()) {
|
||||
val songs = PlaylistSongsLoader.getPlaylistSongList(activity, arrayList[0])
|
||||
if (songs.isNotEmpty()) {
|
||||
recyclerView.apply {
|
||||
show()
|
||||
val songAdapter = SongAdapter(
|
||||
activity, songs, R.layout.item_album_card, false, null
|
||||
)
|
||||
layoutManager = GridLayoutManager(
|
||||
activity, 1, GridLayoutManager.HORIZONTAL, false
|
||||
)
|
||||
adapter = songAdapter
|
||||
|
||||
inner class ArtistViewHolder(view: View) : AbsHomeViewItem(view) {
|
||||
fun bindView(list: ArrayList<Artist>, titleRes: Int, subtitleRes: Int) {
|
||||
if (list.isNotEmpty()) {
|
||||
recyclerView.apply {
|
||||
show()
|
||||
layoutManager = GridLayoutManager(
|
||||
activity, 1, GridLayoutManager.HORIZONTAL, false
|
||||
)
|
||||
val artistAdapter = ArtistAdapter(
|
||||
activity,
|
||||
list,
|
||||
PreferenceUtil.getInstance(activity).getHomeGridStyle(activity),
|
||||
false,
|
||||
null
|
||||
)
|
||||
adapter = artistAdapter
|
||||
}
|
||||
titleContainer.show()
|
||||
title.text = activity.getString(titleRes)
|
||||
text.text = activity.getString(subtitleRes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
title.text = activity.getString(titleRes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inner class PlaylistViewHolder(view: View) : AbsHomeViewItem(view) {
|
||||
fun bindView(arrayList: ArrayList<Playlist>, titleRes: Int, subtitleRes: Int) {
|
||||
if (arrayList.isNotEmpty()) {
|
||||
val songs = PlaylistSongsLoader.getPlaylistSongList(activity, arrayList[0])
|
||||
if (songs.isNotEmpty()) {
|
||||
recyclerView.apply {
|
||||
show()
|
||||
val songAdapter = SongAdapter(
|
||||
activity, songs, R.layout.item_album_card, false, null
|
||||
)
|
||||
layoutManager = GridLayoutManager(
|
||||
activity, 1, GridLayoutManager.HORIZONTAL, false
|
||||
)
|
||||
adapter = songAdapter
|
||||
|
||||
}
|
||||
titleContainer.show()
|
||||
title.text = activity.getString(titleRes)
|
||||
text.text = activity.getString(subtitleRes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open inner class AbsHomeViewItem(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val recyclerView: RecyclerView = itemView.findViewById(R.id.recyclerView)
|
||||
val titleContainer: View = itemView.findViewById(R.id.titleContainer)
|
||||
val title: AppCompatTextView = itemView.findViewById(R.id.title)
|
||||
val text: MaterialTextView = itemView.findViewById(R.id.text)
|
||||
}
|
||||
open inner class AbsHomeViewItem(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val recyclerView: RecyclerView = itemView.findViewById(R.id.recyclerView)
|
||||
val title: AppCompatTextView = itemView.findViewById(R.id.title)
|
||||
}
|
||||
}
|
||||
|
||||
private fun <E> ArrayList<E>.toAlbums(): ArrayList<Album> {
|
||||
val arrayList = ArrayList<Album>()
|
||||
for (x in this) {
|
||||
arrayList.add(x as Album)
|
||||
}
|
||||
return arrayList;
|
||||
val arrayList = ArrayList<Album>()
|
||||
for (x in this) {
|
||||
arrayList.add(x as Album)
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
private fun <E> ArrayList<E>.toArtists(): ArrayList<Artist> {
|
||||
val arrayList = ArrayList<Artist>()
|
||||
for (x in this) {
|
||||
arrayList.add(x as Artist)
|
||||
}
|
||||
return arrayList;
|
||||
val arrayList = ArrayList<Artist>()
|
||||
for (x in this) {
|
||||
arrayList.add(x as Artist)
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
private fun <E> ArrayList<E>.toPlaylist(): ArrayList<Playlist> {
|
||||
val arrayList = ArrayList<Playlist>()
|
||||
for (x in this) {
|
||||
arrayList.add(x as Playlist)
|
||||
}
|
||||
return arrayList;
|
||||
val arrayList = ArrayList<Playlist>()
|
||||
for (x in this) {
|
||||
arrayList.add(x as Playlist)
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,95 +2,94 @@ package code.name.monkey.retromusic.adapter.song
|
|||
|
||||
import android.app.ActivityOptions
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.*
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.*
|
||||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import java.util.*
|
||||
|
||||
open class PlaylistSongAdapter(
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>,
|
||||
itemLayoutRes: Int,
|
||||
usePalette: Boolean,
|
||||
cabHolder: CabHolder?
|
||||
activity: AppCompatActivity,
|
||||
dataSet: ArrayList<Song>,
|
||||
itemLayoutRes: Int,
|
||||
usePalette: Boolean,
|
||||
cabHolder: CabHolder?
|
||||
) : AbsOffsetSongAdapter(activity, dataSet, itemLayoutRes, usePalette, cabHolder, false) {
|
||||
|
||||
init {
|
||||
this.setMultiSelectMenuRes(R.menu.menu_cannot_delete_single_songs_playlist_songs_selection)
|
||||
}
|
||||
init {
|
||||
this.setMultiSelectMenuRes(R.menu.menu_cannot_delete_single_songs_playlist_songs_selection)
|
||||
}
|
||||
|
||||
override fun createViewHolder(view: View): SongAdapter.ViewHolder {
|
||||
return ViewHolder(view)
|
||||
}
|
||||
override fun createViewHolder(view: View): SongAdapter.ViewHolder {
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SongAdapter.ViewHolder, position: Int) {
|
||||
override fun onBindViewHolder(holder: SongAdapter.ViewHolder, position: Int) {
|
||||
|
||||
if (holder.itemViewType == OFFSET_ITEM) {
|
||||
if (holder.itemViewType == OFFSET_ITEM) {
|
||||
|
||||
val buttonColor = RetroColorUtil.toolbarColor(activity)
|
||||
val textColor = MaterialValueHelper.getPrimaryTextColor(
|
||||
activity, ColorUtil.isColorLight(
|
||||
buttonColor
|
||||
)
|
||||
)
|
||||
val viewHolder = holder as ViewHolder
|
||||
val buttonColor = RetroColorUtil.toolbarColor(activity)
|
||||
val textColor = MaterialValueHelper.getPrimaryTextColor(activity, ColorUtil.isColorLight(buttonColor))
|
||||
val viewHolder = holder as ViewHolder
|
||||
|
||||
viewHolder.playAction?.let {
|
||||
it.backgroundTintList = ColorStateList.valueOf(buttonColor)
|
||||
it.setTextColor(textColor)
|
||||
it.iconTint = ColorStateList.valueOf(textColor)
|
||||
it.setOnClickListener {
|
||||
MusicPlayerRemote.openQueue(dataSet, 0, true)
|
||||
}
|
||||
}
|
||||
viewHolder.shuffleAction?.let {
|
||||
it.backgroundTintList = ColorStateList.valueOf(buttonColor)
|
||||
it.setTextColor(textColor)
|
||||
it.iconTint = ColorStateList.valueOf(textColor)
|
||||
it.setOnClickListener {
|
||||
MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
|
||||
}
|
||||
}
|
||||
viewHolder.playAction?.let {
|
||||
it.backgroundTintList = ColorStateList.valueOf(buttonColor)
|
||||
it.setTextColor(textColor)
|
||||
it.iconTint = ColorStateList.valueOf(textColor)
|
||||
it.setOnClickListener {
|
||||
MusicPlayerRemote.openQueue(dataSet, 0, true)
|
||||
}
|
||||
}
|
||||
viewHolder.shuffleAction?.let {
|
||||
it.backgroundTintList = ColorStateList.valueOf(buttonColor)
|
||||
it.setTextColor(textColor)
|
||||
it.iconTint = ColorStateList.valueOf(textColor)
|
||||
it.setOnClickListener {
|
||||
MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
super.onBindViewHolder(holder, position - 1)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.onBindViewHolder(holder, position - 1)
|
||||
}
|
||||
}
|
||||
|
||||
open inner class ViewHolder(itemView: View) : AbsOffsetSongAdapter.ViewHolder(itemView) {
|
||||
open inner class ViewHolder(itemView: View) : AbsOffsetSongAdapter.ViewHolder(itemView) {
|
||||
|
||||
val playAction: MaterialButton? = itemView.findViewById(R.id.playAction)
|
||||
val shuffleAction: MaterialButton? = itemView.findViewById(R.id.shuffleAction)
|
||||
val playAction: MaterialButton? = itemView.findViewById(R.id.playAction)
|
||||
val shuffleAction: MaterialButton? = itemView.findViewById(R.id.shuffleAction)
|
||||
|
||||
override var songMenuRes: Int
|
||||
get() = R.menu.menu_item_cannot_delete_single_songs_playlist_song
|
||||
set(value) {
|
||||
super.songMenuRes = value
|
||||
}
|
||||
override var songMenuRes: Int
|
||||
get() = R.menu.menu_item_cannot_delete_single_songs_playlist_song
|
||||
set(value) {
|
||||
super.songMenuRes = value
|
||||
}
|
||||
|
||||
override fun onSongMenuItemClick(item: MenuItem): Boolean {
|
||||
if (item.itemId == R.id.action_go_to_album) {
|
||||
val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
|
||||
activity, image, activity.getString(
|
||||
R.string.transition_album_art
|
||||
)
|
||||
)
|
||||
NavigationUtil.goToAlbumOptions(
|
||||
activity, dataSet[adapterPosition - 1].albumId, activityOptions
|
||||
)
|
||||
return true
|
||||
}
|
||||
return super.onSongMenuItemClick(item)
|
||||
}
|
||||
}
|
||||
override fun onSongMenuItemClick(item: MenuItem): Boolean {
|
||||
if (item.itemId == R.id.action_go_to_album) {
|
||||
val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
|
||||
activity, image, activity.getString(
|
||||
R.string.transition_album_art
|
||||
)
|
||||
)
|
||||
NavigationUtil.goToAlbumOptions(
|
||||
activity, dataSet[adapterPosition - 1].albumId, activityOptions
|
||||
)
|
||||
return true
|
||||
}
|
||||
return super.onSongMenuItemClick(item)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TAG: String = PlaylistSongAdapter::class.java.simpleName
|
||||
}
|
||||
companion object {
|
||||
val TAG: String = PlaylistSongAdapter::class.java.simpleName
|
||||
}
|
||||
}
|
|
@ -2,17 +2,25 @@ package code.name.monkey.retromusic.adapter.song
|
|||
|
||||
import android.app.ActivityOptions
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.adapter.base.*
|
||||
import code.name.monkey.retromusic.glide.*
|
||||
import code.name.monkey.retromusic.helper.*
|
||||
import code.name.monkey.retromusic.helper.menu.*
|
||||
import code.name.monkey.retromusic.adapter.base.AbsMultiSelectAdapter
|
||||
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
|
||||
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
|
||||
import code.name.monkey.retromusic.glide.SongGlideRequest
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.helper.SortOrder
|
||||
import code.name.monkey.retromusic.helper.menu.SongMenuHelper
|
||||
import code.name.monkey.retromusic.helper.menu.SongsMenuHelper
|
||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.*
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.afollestad.materialcab.MaterialCab
|
||||
import com.bumptech.glide.Glide
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||
|
@ -79,20 +87,8 @@ open class SongAdapter(
|
|||
private fun setColors(color: Int, holder: ViewHolder) {
|
||||
if (holder.paletteColorContainer != null) {
|
||||
holder.paletteColorContainer?.setBackgroundColor(color)
|
||||
holder.title?.setTextColor(
|
||||
MaterialValueHelper.getPrimaryTextColor(
|
||||
activity, ColorUtil.isColorLight(
|
||||
color
|
||||
)
|
||||
)
|
||||
)
|
||||
holder.text?.setTextColor(
|
||||
MaterialValueHelper.getSecondaryTextColor(
|
||||
activity, ColorUtil.isColorLight(
|
||||
color
|
||||
)
|
||||
)
|
||||
)
|
||||
//holder.title?.setTextColor(MaterialValueHelper.getPrimaryTextColor(activity, ColorUtil.isColorLight(color)))
|
||||
//holder.text?.setTextColor(MaterialValueHelper.getSecondaryTextColor(activity, ColorUtil.isColorLight(color)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ fun AppCompatActivity.applyToolbar(toolbar: Toolbar) {
|
|||
setNavigationIcon(R.drawable.ic_keyboard_backspace_black_24dp)
|
||||
ToolbarContentTintHelper.colorBackButton(toolbar)
|
||||
setBackgroundColor(ATHUtil.resolveColor(this@applyToolbar, R.attr.colorPrimary))
|
||||
|
||||
}
|
||||
setSupportActionBar(toolbar)
|
||||
}
|
|
@ -49,18 +49,16 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(), MusicProgressViewUpda
|
|||
setUpMiniPlayer()
|
||||
|
||||
if (RetroUtil.isTablet()) {
|
||||
actionNext.visibility = View.VISIBLE
|
||||
actionPrevious.visibility = View.VISIBLE
|
||||
actionNext?.visibility = View.VISIBLE
|
||||
actionPrevious?.visibility = View.VISIBLE
|
||||
actionPlayingQueue.visibility = View.VISIBLE
|
||||
} else {
|
||||
actionNext.visibility = if (PreferenceUtil.getInstance(requireContext()).isExtraControls) View.VISIBLE else View.GONE
|
||||
actionPlayingQueue.visibility = if (PreferenceUtil.getInstance(requireContext()).isExtraControls) View.GONE else View.VISIBLE
|
||||
actionPrevious.visibility = if (PreferenceUtil.getInstance(requireContext()).isExtraControls) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
actionPlayingQueue.setOnClickListener(this)
|
||||
actionNext.setOnClickListener(this)
|
||||
actionPrevious.setOnClickListener(this)
|
||||
actionNext?.setOnClickListener(this)
|
||||
actionPrevious?.setOnClickListener(this)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,129 +1,127 @@
|
|||
package code.name.monkey.retromusic.fragments.base
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidx.annotation.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.NonNull
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.util.*
|
||||
import code.name.monkey.retromusic.util.DensityUtil
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||
import kotlinx.android.synthetic.main.fragment_main_activity_recycler_view.*
|
||||
|
||||
abstract class AbsLibraryPagerRecyclerViewFragment<A : RecyclerView.Adapter<*>, LM : RecyclerView.LayoutManager> : AbsLibraryPagerFragment(), AppBarLayout.OnOffsetChangedListener {
|
||||
|
||||
protected var adapter: A? = null
|
||||
protected var layoutManager: LM? = null
|
||||
protected var adapter: A? = null
|
||||
protected var layoutManager: LM? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val view = inflater.inflate(
|
||||
R.layout.fragment_main_activity_recycler_view, container, false
|
||||
);
|
||||
return view
|
||||
}
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View? {
|
||||
return inflater.inflate(R.layout.fragment_main_activity_recycler_view, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
libraryFragment.addOnAppBarOffsetChangedListener(this)
|
||||
initLayoutManager()
|
||||
initAdapter()
|
||||
setUpRecyclerView()
|
||||
}
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
libraryFragment.addOnAppBarOffsetChangedListener(this)
|
||||
initLayoutManager()
|
||||
initAdapter()
|
||||
setUpRecyclerView()
|
||||
}
|
||||
|
||||
private fun setUpRecyclerView() {
|
||||
if (recyclerView is FastScrollRecyclerView) {
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(
|
||||
requireActivity(), recyclerView as FastScrollRecyclerView
|
||||
)
|
||||
}
|
||||
recyclerView.layoutManager = layoutManager
|
||||
recyclerView.adapter = adapter
|
||||
}
|
||||
private fun setUpRecyclerView() {
|
||||
if (recyclerView is FastScrollRecyclerView) {
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(requireActivity(), recyclerView as FastScrollRecyclerView)
|
||||
}
|
||||
recyclerView.layoutManager = layoutManager
|
||||
recyclerView.adapter = adapter
|
||||
}
|
||||
|
||||
private fun initAdapter() {
|
||||
adapter = createAdapter()
|
||||
adapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onChanged() {
|
||||
super.onChanged()
|
||||
checkIsEmpty()
|
||||
checkForPadding()
|
||||
}
|
||||
})
|
||||
}
|
||||
private fun initAdapter() {
|
||||
adapter = createAdapter()
|
||||
adapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onChanged() {
|
||||
super.onChanged()
|
||||
checkIsEmpty()
|
||||
checkForPadding()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
protected open val emptyMessage: Int
|
||||
@StringRes get() = R.string.empty
|
||||
protected open val emptyMessage: Int
|
||||
@StringRes get() = R.string.empty
|
||||
|
||||
private fun getEmojiByUnicode(unicode: Int): String {
|
||||
return String(Character.toChars(unicode))
|
||||
}
|
||||
private fun getEmojiByUnicode(unicode: Int): String {
|
||||
return String(Character.toChars(unicode))
|
||||
}
|
||||
|
||||
private fun checkIsEmpty() {
|
||||
emptyEmoji.text = getEmojiByUnicode(0x1F631)
|
||||
emptyText.setText(emptyMessage)
|
||||
empty.visibility = if (adapter!!.itemCount == 0) View.VISIBLE else View.GONE
|
||||
}
|
||||
private fun checkIsEmpty() {
|
||||
emptyEmoji.text = getEmojiByUnicode(0x1F631)
|
||||
emptyText.setText(emptyMessage)
|
||||
empty.visibility = if (adapter!!.itemCount == 0) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
private fun checkForPadding() {
|
||||
val itemCount: Int = adapter?.itemCount ?: 0
|
||||
val params = container.layoutParams as ViewGroup.MarginLayoutParams
|
||||
if (itemCount > 0 && MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
||||
val height = DensityUtil.dip2px(requireContext(), 104f)
|
||||
params.bottomMargin = height
|
||||
} else {
|
||||
val height = DensityUtil.dip2px(requireContext(), 52f)
|
||||
params.bottomMargin = height
|
||||
}
|
||||
}
|
||||
private fun checkForPadding() {
|
||||
val itemCount: Int = adapter?.itemCount ?: 0
|
||||
val params = container.layoutParams as ViewGroup.MarginLayoutParams
|
||||
if (itemCount > 0 && MusicPlayerRemote.playingQueue.isNotEmpty()) {
|
||||
val height = DensityUtil.dip2px(requireContext(), 104f)
|
||||
params.bottomMargin = height
|
||||
} else {
|
||||
val height = DensityUtil.dip2px(requireContext(), 52f)
|
||||
params.bottomMargin = height
|
||||
}
|
||||
}
|
||||
|
||||
private fun initLayoutManager() {
|
||||
layoutManager = createLayoutManager()
|
||||
}
|
||||
private fun initLayoutManager() {
|
||||
layoutManager = createLayoutManager()
|
||||
}
|
||||
|
||||
protected abstract fun createLayoutManager(): LM
|
||||
protected abstract fun createLayoutManager(): LM
|
||||
|
||||
@NonNull
|
||||
protected abstract fun createAdapter(): A
|
||||
@NonNull
|
||||
protected abstract fun createAdapter(): A
|
||||
|
||||
override fun onOffsetChanged(p0: AppBarLayout?, i: Int) {
|
||||
container.setPadding(
|
||||
container.paddingLeft,
|
||||
container.paddingTop,
|
||||
container.paddingRight,
|
||||
libraryFragment.totalAppBarScrollingRange + i
|
||||
)
|
||||
}
|
||||
override fun onOffsetChanged(p0: AppBarLayout?, i: Int) {
|
||||
container.setPadding(
|
||||
container.paddingLeft,
|
||||
container.paddingTop,
|
||||
container.paddingRight,
|
||||
libraryFragment.totalAppBarScrollingRange + i)
|
||||
}
|
||||
|
||||
override fun onQueueChanged() {
|
||||
super.onQueueChanged()
|
||||
checkForPadding()
|
||||
}
|
||||
override fun onQueueChanged() {
|
||||
super.onQueueChanged()
|
||||
checkForPadding()
|
||||
}
|
||||
|
||||
override fun onServiceConnected() {
|
||||
super.onServiceConnected()
|
||||
checkForPadding()
|
||||
}
|
||||
override fun onServiceConnected() {
|
||||
super.onServiceConnected()
|
||||
checkForPadding()
|
||||
}
|
||||
|
||||
protected fun invalidateLayoutManager() {
|
||||
initLayoutManager()
|
||||
recyclerView.layoutManager = layoutManager
|
||||
}
|
||||
protected fun invalidateLayoutManager() {
|
||||
initLayoutManager()
|
||||
recyclerView.layoutManager = layoutManager
|
||||
}
|
||||
|
||||
protected fun invalidateAdapter() {
|
||||
initAdapter()
|
||||
checkIsEmpty()
|
||||
recyclerView.adapter = adapter
|
||||
}
|
||||
protected fun invalidateAdapter() {
|
||||
initAdapter()
|
||||
checkIsEmpty()
|
||||
recyclerView.adapter = adapter
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
libraryFragment.removeOnAppBarOffsetChangedListener(this)
|
||||
}
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
libraryFragment.removeOnAppBarOffsetChangedListener(this)
|
||||
}
|
||||
|
||||
fun recyclerView(): RecyclerView {
|
||||
return recyclerView
|
||||
}
|
||||
fun recyclerView(): RecyclerView {
|
||||
return recyclerView
|
||||
}
|
||||
}
|
|
@ -26,11 +26,11 @@ abstract class AbsMainActivityFragment : AbsMusicServiceFragment() {
|
|||
mainActivity.setBottomBarVisibility(View.VISIBLE)
|
||||
}
|
||||
|
||||
private fun setStatusbarColor(view: View, color: Int) {
|
||||
private fun setStatusBarColor(view: View, color: Int) {
|
||||
val statusBar = view.findViewById<View>(R.id.status_bar)
|
||||
if (statusBar != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
statusBar.setBackgroundColor(color)
|
||||
//statusBar.setBackgroundColor(color)
|
||||
mainActivity.setLightStatusbarAuto(color)
|
||||
} else {
|
||||
statusBar.setBackgroundColor(color)
|
||||
|
@ -38,13 +38,13 @@ abstract class AbsMainActivityFragment : AbsMusicServiceFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
fun setStatusbarColorAuto(view: View) {
|
||||
val colorPrimary = ATHUtil.resolveColor(requireContext(), R.attr.colorPrimary)
|
||||
fun setStatusBarColorAuto(view: View) {
|
||||
val colorPrimary = ATHUtil.resolveColor(requireContext(), android.R.attr.windowBackground)
|
||||
// we don't want to use statusbar color because we are doing the color darkening on our own to support KitKat
|
||||
if (VersionUtils.hasMarshmallow()) {
|
||||
setStatusbarColor(view, colorPrimary)
|
||||
setStatusBarColor(view, colorPrimary)
|
||||
} else {
|
||||
setStatusbarColor(view, ColorUtil.darkenColor(colorPrimary))
|
||||
setStatusBarColor(view, ColorUtil.darkenColor(colorPrimary))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
setStatusbarColorAuto(view);
|
||||
setStatusBarColorAuto(view);
|
||||
setupToolbar();
|
||||
inflateFragment();
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
getMainActivity().setSupportActionBar(toolbar);
|
||||
toolbar.setNavigationOnClickListener(v -> showMainMenu(OptionsSheetDialogFragment.LIBRARY));
|
||||
ToolbarContentTintHelper.colorBackButton(toolbar);
|
||||
toolbar.setTitleTextColor(ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorOnSecondary));
|
||||
//toolbar.setTitleTextColor(ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorOnSecondary));
|
||||
}
|
||||
|
||||
private Fragment getCurrentFragment() {
|
||||
|
|
|
@ -131,4 +131,4 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
|
|||
return fragment
|
||||
}
|
||||
}
|
||||
}// Required empty public constructor
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
setStatusbarColorAuto(view);
|
||||
setStatusBarColorAuto(view);
|
||||
setUpAppbarColor();
|
||||
setUpBreadCrumbs();
|
||||
setUpRecyclerView();
|
||||
|
|
|
@ -80,7 +80,7 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
|
|||
NavigationUtil.goToUserInfo(requireActivity(), options)
|
||||
}
|
||||
if (!PreferenceUtil.getInstance(requireContext()).isHomeBanner)
|
||||
setStatusbarColorAuto(view)
|
||||
setStatusBarColorAuto(view)
|
||||
|
||||
lastAdded.setOnClickListener {
|
||||
NavigationUtil.goToPlaylistNew(requireActivity(), LastAddedPlaylist(requireActivity()))
|
||||
|
|
|
@ -14,17 +14,17 @@ import code.name.monkey.appthemehelper.util.ColorUtil
|
|||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
import code.name.monkey.appthemehelper.util.TintHelper
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
|
||||
import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler
|
||||
import code.name.monkey.retromusic.misc.SimpleOnSeekbarChangeListener
|
||||
import code.name.monkey.retromusic.service.MusicService
|
||||
import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import kotlinx.android.synthetic.main.fragment_card_blur_player_playback_controls.*
|
||||
import kotlinx.android.synthetic.main.media_button.*
|
||||
import kotlinx.android.synthetic.main.player_time.*
|
||||
|
||||
|
||||
class CardBlurPlaybackControlsFragment : AbsPlayerControlsFragment() {
|
||||
|
||||
|
@ -33,7 +33,6 @@ class CardBlurPlaybackControlsFragment : AbsPlayerControlsFragment() {
|
|||
private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper
|
||||
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
progressViewUpdateHelper = MusicProgressViewUpdateHelper(this)
|
||||
|
|
|
@ -40,7 +40,7 @@ abstract class AbsSettingsFragment : ATEPreferenceFragmentCompat() {
|
|||
NavigationUtil.goToProVersion(requireActivity())
|
||||
}
|
||||
|
||||
internal fun setSummary(preference: Preference, value: Any) {
|
||||
internal fun setSummary(preference: Preference, value: Any?) {
|
||||
val stringValue = value.toString()
|
||||
if (preference is ListPreference) {
|
||||
val index = preference.findIndexOfValue(stringValue)
|
||||
|
@ -52,10 +52,12 @@ abstract class AbsSettingsFragment : ATEPreferenceFragmentCompat() {
|
|||
|
||||
abstract fun invalidateSettings()
|
||||
|
||||
protected fun setSummary(preference: Preference) {
|
||||
setSummary(preference, PreferenceManager
|
||||
.getDefaultSharedPreferences(preference.context)
|
||||
.getString(preference.key, "")!!)
|
||||
protected fun setSummary(preference: Preference?) {
|
||||
preference?.let {
|
||||
setSummary(it, PreferenceManager
|
||||
.getDefaultSharedPreferences(it.context)
|
||||
.getString(it.key, ""))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
|
|
@ -37,7 +37,7 @@ class MainSettingsFragment : Fragment(), View.OnClickListener {
|
|||
R.id.generalSettings -> inflateFragment(ThemeSettingsFragment(), R.string.general_settings_title)
|
||||
R.id.audioSettings -> inflateFragment(AudioSettings(), R.string.pref_header_audio)
|
||||
R.id.nowPlayingSettings -> inflateFragment(NowPlayingSettingsFragment(), R.string.now_playing)
|
||||
R.id.personalizeSettings -> inflateFragment(PersonaizeSettingsFragment(), R.string.personalize)
|
||||
R.id.personalizeSettings -> inflateFragment(PersonalizeSettingsFragment(), R.string.personalize)
|
||||
R.id.imageSettings -> inflateFragment(ImageSettingFragment(), R.string.pref_header_images)
|
||||
R.id.notificationSettings -> inflateFragment(NotificationSettingsFragment(), R.string.notification)
|
||||
R.id.otherSettings -> inflateFragment(OtherSettingsFragment(), R.string.others)
|
||||
|
|
|
@ -19,23 +19,14 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.TwoStatePreference
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
|
||||
|
||||
class PersonaizeSettingsFragment : AbsSettingsFragment(), SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
class PersonalizeSettingsFragment : AbsSettingsFragment(), SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
override fun invalidateSettings() {
|
||||
val cornerWindow: TwoStatePreference = findPreference("corner_window")!!
|
||||
cornerWindow.setOnPreferenceChangeListener { _, newValue ->
|
||||
if (newValue as Boolean && !App.isProVersion()) {
|
||||
showProToastAndNavigate(activity!!.getString(R.string.pref_title_round_corners))
|
||||
return@setOnPreferenceChangeListener false
|
||||
}
|
||||
requireActivity().recreate()
|
||||
return@setOnPreferenceChangeListener true
|
||||
}
|
||||
|
||||
val toggleFullScreen: TwoStatePreference = findPreference("toggle_full_screen")!!
|
||||
toggleFullScreen.setOnPreferenceChangeListener { _, _ ->
|
||||
requireActivity().recreate()
|
||||
|
@ -45,7 +36,6 @@ class PersonaizeSettingsFragment : AbsSettingsFragment(), SharedPreferences.OnSh
|
|||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.pref_ui)
|
||||
addPreferencesFromResource(R.xml.pref_window)
|
||||
addPreferencesFromResource(R.xml.pref_lockscreen)
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ object ThemeManager {
|
|||
@StyleRes
|
||||
fun getThemeResValue(context: Context): Int = when (PreferenceUtil.getInstance(context).generalThemeValue) {
|
||||
"light" -> R.style.Theme_RetroMusic_Light
|
||||
"auto" -> if (isSystemDarkModeEnabled(context)) R.style.Theme_RetroMusic else R.style.Theme_RetroMusic_Light
|
||||
"auto" -> R.style.Theme_RetroMusic_FollowSystem
|
||||
"black" -> R.style.Theme_RetroMusic_Black
|
||||
else -> R.style.Theme_RetroMusic
|
||||
/**
|
||||
|
|
|
@ -14,119 +14,107 @@
|
|||
|
||||
package code.name.monkey.retromusic.util
|
||||
|
||||
import android.animation.*
|
||||
import android.animation.Animator
|
||||
import android.animation.ArgbEvaluator
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.content.res.*
|
||||
import android.graphics.*
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.animation.PathInterpolator
|
||||
import android.widget.*
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.SeekBar
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.view.ViewCompat
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
import code.name.monkey.retromusic.R
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||
|
||||
object ViewUtil {
|
||||
|
||||
const val RETRO_MUSIC_ANIM_TIME = 1000
|
||||
const val RETRO_MUSIC_ANIM_TIME = 1000
|
||||
|
||||
fun setProgressDrawable(progressSlider: SeekBar, newColor: Int, thumbTint: Boolean = false) {
|
||||
fun setProgressDrawable(progressSlider: SeekBar, newColor: Int, thumbTint: Boolean = false) {
|
||||
|
||||
if (thumbTint) {
|
||||
progressSlider.thumbTintList = ColorStateList.valueOf(newColor)
|
||||
}
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
val layerDrawable = progressSlider.progressDrawable as LayerDrawable
|
||||
val progressDrawable = layerDrawable.findDrawableByLayerId(android.R.id.progress)
|
||||
progressDrawable.setColorFilter(newColor, PorterDuff.Mode.SRC_IN)
|
||||
} else {
|
||||
progressSlider.progressTintList = ColorStateList.valueOf(newColor)
|
||||
}
|
||||
}
|
||||
if (thumbTint) {
|
||||
progressSlider.thumbTintList = ColorStateList.valueOf(newColor)
|
||||
}
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
val layerDrawable = progressSlider.progressDrawable as LayerDrawable
|
||||
val progressDrawable = layerDrawable.findDrawableByLayerId(android.R.id.progress)
|
||||
progressDrawable.setColorFilter(newColor, PorterDuff.Mode.SRC_IN)
|
||||
} else {
|
||||
progressSlider.progressTintList = ColorStateList.valueOf(newColor)
|
||||
}
|
||||
}
|
||||
|
||||
fun setProgressDrawable(progressSlider: ProgressBar, newColor: Int) {
|
||||
fun setProgressDrawable(progressSlider: ProgressBar, newColor: Int) {
|
||||
|
||||
val ld = progressSlider.progressDrawable as LayerDrawable
|
||||
val ld = progressSlider.progressDrawable as LayerDrawable
|
||||
|
||||
val progress = ld.findDrawableByLayerId(android.R.id.progress)
|
||||
progress.setColorFilter(newColor, PorterDuff.Mode.SRC_IN)
|
||||
val progress = ld.findDrawableByLayerId(android.R.id.progress)
|
||||
progress.setColorFilter(newColor, PorterDuff.Mode.SRC_IN)
|
||||
|
||||
val background = ld.findDrawableByLayerId(android.R.id.background)
|
||||
val primaryColor = ATHUtil.resolveColor(progressSlider.context, R.attr.colorPrimary)
|
||||
background.setColorFilter(
|
||||
MaterialValueHelper.getPrimaryDisabledTextColor(
|
||||
progressSlider.context, ColorUtil.isColorLight(
|
||||
primaryColor
|
||||
)
|
||||
), PorterDuff.Mode.SRC_IN
|
||||
)
|
||||
val background = ld.findDrawableByLayerId(android.R.id.background)
|
||||
val primaryColor = ATHUtil.resolveColor(progressSlider.context, android.R.attr.windowBackground)
|
||||
background.setColorFilter(MaterialValueHelper.getPrimaryDisabledTextColor(progressSlider.context, ColorUtil.isColorLight(primaryColor)), PorterDuff.Mode.SRC_IN)
|
||||
|
||||
val secondaryProgress = ld.findDrawableByLayerId(android.R.id.secondaryProgress)
|
||||
secondaryProgress?.setColorFilter(
|
||||
ColorUtil.withAlpha(newColor, 0.65f), PorterDuff.Mode.SRC_IN
|
||||
)
|
||||
}
|
||||
val secondaryProgress = ld.findDrawableByLayerId(android.R.id.secondaryProgress)
|
||||
secondaryProgress?.setColorFilter(
|
||||
ColorUtil.withAlpha(newColor, 0.65f), PorterDuff.Mode.SRC_IN
|
||||
)
|
||||
}
|
||||
|
||||
private fun createColorAnimator(
|
||||
target: Any, propertyName: String, @ColorInt startColor: Int, @ColorInt endColor: Int
|
||||
): Animator {
|
||||
val animator: ObjectAnimator
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
animator = ObjectAnimator.ofArgb(target, propertyName, startColor, endColor)
|
||||
} else {
|
||||
animator = ObjectAnimator.ofInt(target, propertyName, startColor, endColor)
|
||||
animator.setEvaluator(ArgbEvaluator())
|
||||
}
|
||||
private fun createColorAnimator(
|
||||
target: Any, propertyName: String, @ColorInt startColor: Int, @ColorInt endColor: Int
|
||||
): Animator {
|
||||
val animator: ObjectAnimator
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
animator = ObjectAnimator.ofArgb(target, propertyName, startColor, endColor)
|
||||
} else {
|
||||
animator = ObjectAnimator.ofInt(target, propertyName, startColor, endColor)
|
||||
animator.setEvaluator(ArgbEvaluator())
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
animator.interpolator = PathInterpolator(0.4f, 0f, 1f, 1f)
|
||||
}
|
||||
animator.duration = RETRO_MUSIC_ANIM_TIME.toLong()
|
||||
return animator
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
animator.interpolator = PathInterpolator(0.4f, 0f, 1f, 1f)
|
||||
}
|
||||
animator.duration = RETRO_MUSIC_ANIM_TIME.toLong()
|
||||
return animator
|
||||
}
|
||||
|
||||
fun hitTest(v: View, x: Int, y: Int): Boolean {
|
||||
val tx = (ViewCompat.getTranslationX(v) + 0.5f).toInt()
|
||||
val ty = (ViewCompat.getTranslationY(v) + 0.5f).toInt()
|
||||
val left = v.left + tx
|
||||
val right = v.right + tx
|
||||
val top = v.top + ty
|
||||
val bottom = v.bottom + ty
|
||||
fun hitTest(v: View, x: Int, y: Int): Boolean {
|
||||
val tx = (ViewCompat.getTranslationX(v) + 0.5f).toInt()
|
||||
val ty = (ViewCompat.getTranslationY(v) + 0.5f).toInt()
|
||||
val left = v.left + tx
|
||||
val right = v.right + tx
|
||||
val top = v.top + ty
|
||||
val bottom = v.bottom + ty
|
||||
|
||||
return x in left..right && y >= top && y <= bottom
|
||||
}
|
||||
return x in left..right && y >= top && y <= bottom
|
||||
}
|
||||
|
||||
fun setUpFastScrollRecyclerViewColor(
|
||||
context: Context,
|
||||
recyclerView: FastScrollRecyclerView,
|
||||
accentColor: Int = ThemeStore.accentColor(context)
|
||||
) {
|
||||
recyclerView.setPopupBgColor(accentColor)
|
||||
recyclerView.setPopupTextColor(
|
||||
MaterialValueHelper.getPrimaryTextColor(
|
||||
context, ColorUtil.isColorLight(
|
||||
accentColor
|
||||
)
|
||||
)
|
||||
)
|
||||
recyclerView.setThumbColor(accentColor)
|
||||
recyclerView.setTrackColor(Color.TRANSPARENT)
|
||||
recyclerView.setTrackColor(
|
||||
ColorUtil.withAlpha(
|
||||
ATHUtil.resolveColor(
|
||||
context, R.attr.colorControlNormal
|
||||
), 0.12f
|
||||
)
|
||||
)
|
||||
fun setUpFastScrollRecyclerViewColor(
|
||||
context: Context,
|
||||
recyclerView: FastScrollRecyclerView,
|
||||
accentColor: Int = ThemeStore.accentColor(context)
|
||||
) {
|
||||
recyclerView.setPopupBgColor(accentColor)
|
||||
recyclerView.setPopupTextColor(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(accentColor)))
|
||||
recyclerView.setThumbColor(accentColor)
|
||||
recyclerView.setTrackColor(Color.TRANSPARENT)
|
||||
recyclerView.setTrackColor(ColorUtil.withAlpha(ATHUtil.resolveColor(context, R.attr.colorControlNormal), 0.12f))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun convertDpToPixel(dp: Float, resources: Resources): Float {
|
||||
val metrics = resources.displayMetrics
|
||||
return dp * metrics.density
|
||||
}
|
||||
fun convertDpToPixel(dp: Float, resources: Resources): Float {
|
||||
val metrics = resources.displayMetrics
|
||||
return dp * metrics.density
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue