[Now Playing] Fixed lyrics and overflow icon color in Color theme

This commit is contained in:
Prathamesh More 2022-01-21 18:52:44 +05:30
parent 1c94e4d18a
commit db97705f67
3 changed files with 27 additions and 20 deletions

View file

@ -32,7 +32,6 @@ import android.view.View
import android.widget.RelativeLayout
import android.widget.Toast
import androidx.annotation.LayoutRes
import androidx.appcompat.graphics.drawable.DrawableWrapper
import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
@ -86,8 +85,8 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
return true
}
R.id.action_toggle_lyrics -> {
PreferenceUtil.showLyrics = !item.isChecked
item.isChecked = !item.isChecked
PreferenceUtil.showLyrics = !PreferenceUtil.showLyrics
showLyricsIcon(item)
if (PreferenceUtil.lyricsScreenOn && PreferenceUtil.showLyrics) {
mainActivity.keepScreenOn(true)
} else if (!PreferenceUtil.isScreenOnEnabled && !PreferenceUtil.showLyrics) {
@ -205,6 +204,18 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
return false
}
private fun showLyricsIcon(item: MenuItem) {
val icon =
if (PreferenceUtil.showLyrics) R.drawable.ic_lyrics else R.drawable.ic_lyrics_outline
val drawable: Drawable = RetroUtil.getTintedVectorDrawable(
requireContext(),
icon,
toolbarIconColor()
)
item.isChecked = PreferenceUtil.showLyrics
item.icon = drawable
}
abstract fun playerToolbar(): Toolbar?
abstract fun onShow()
@ -299,7 +310,6 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
playerToolbar()?.menu?.removeItem(R.id.action_toggle_lyrics)
} else {
playerToolbar()?.menu?.findItem(R.id.action_toggle_lyrics)?.apply {
fixCheckStateOnIcon()
isCheckable = true
isChecked = PreferenceUtil.showLyrics
}
@ -424,16 +434,4 @@ fun goToLyrics(activity: Activity) {
null
)
}
}
/** Fixes checked state being ignored by injecting checked state directly into drawable */
@SuppressLint("RestrictedApi")
class CheckDrawableWrapper(val menuItem: MenuItem) : DrawableWrapper(menuItem.icon) {
// inject checked state into drawable state set
override fun setState(stateSet: IntArray) = super.setState(
if (menuItem.isChecked) stateSet + android.R.attr.state_checked else stateSet
)
}
/** Wrap icon drawable with [CheckDrawableWrapper]. */
fun MenuItem.fixCheckStateOnIcon() = apply { icon = CheckDrawableWrapper(this) }
}

View file

@ -16,7 +16,6 @@ package code.name.monkey.retromusic.fragments.player.color
import android.animation.ValueAnimator
import android.os.Bundle
import android.os.Handler
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.core.animation.doOnEnd
@ -61,7 +60,7 @@ class ColorFragment : AbsPlayerFragment(R.layout.fragment_color_player) {
_binding?.root?.setBackgroundColor(color.backgroundColor)
}
animator.start()
Handler().post {
binding.playerToolbar.post {
ToolbarContentTintHelper.colorizeToolbar(
binding.playerToolbar,
color.secondaryTextColor,