[Now Playing] Fixed lyrics and overflow icon color in Color theme
This commit is contained in:
parent
1c94e4d18a
commit
db97705f67
3 changed files with 27 additions and 20 deletions
|
@ -32,7 +32,6 @@ import android.view.View
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.LayoutRes
|
import androidx.annotation.LayoutRes
|
||||||
import androidx.appcompat.graphics.drawable.DrawableWrapper
|
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
@ -86,8 +85,8 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_toggle_lyrics -> {
|
R.id.action_toggle_lyrics -> {
|
||||||
PreferenceUtil.showLyrics = !item.isChecked
|
PreferenceUtil.showLyrics = !PreferenceUtil.showLyrics
|
||||||
item.isChecked = !item.isChecked
|
showLyricsIcon(item)
|
||||||
if (PreferenceUtil.lyricsScreenOn && PreferenceUtil.showLyrics) {
|
if (PreferenceUtil.lyricsScreenOn && PreferenceUtil.showLyrics) {
|
||||||
mainActivity.keepScreenOn(true)
|
mainActivity.keepScreenOn(true)
|
||||||
} else if (!PreferenceUtil.isScreenOnEnabled && !PreferenceUtil.showLyrics) {
|
} else if (!PreferenceUtil.isScreenOnEnabled && !PreferenceUtil.showLyrics) {
|
||||||
|
@ -205,6 +204,18 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
||||||
return false
|
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 playerToolbar(): Toolbar?
|
||||||
|
|
||||||
abstract fun onShow()
|
abstract fun onShow()
|
||||||
|
@ -299,7 +310,6 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
||||||
playerToolbar()?.menu?.removeItem(R.id.action_toggle_lyrics)
|
playerToolbar()?.menu?.removeItem(R.id.action_toggle_lyrics)
|
||||||
} else {
|
} else {
|
||||||
playerToolbar()?.menu?.findItem(R.id.action_toggle_lyrics)?.apply {
|
playerToolbar()?.menu?.findItem(R.id.action_toggle_lyrics)?.apply {
|
||||||
fixCheckStateOnIcon()
|
|
||||||
isCheckable = true
|
isCheckable = true
|
||||||
isChecked = PreferenceUtil.showLyrics
|
isChecked = PreferenceUtil.showLyrics
|
||||||
}
|
}
|
||||||
|
@ -424,16 +434,4 @@ fun goToLyrics(activity: Activity) {
|
||||||
null
|
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) }
|
|
|
@ -16,7 +16,6 @@ package code.name.monkey.retromusic.fragments.player.color
|
||||||
|
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.animation.doOnEnd
|
import androidx.core.animation.doOnEnd
|
||||||
|
@ -61,7 +60,7 @@ class ColorFragment : AbsPlayerFragment(R.layout.fragment_color_player) {
|
||||||
_binding?.root?.setBackgroundColor(color.backgroundColor)
|
_binding?.root?.setBackgroundColor(color.backgroundColor)
|
||||||
}
|
}
|
||||||
animator.start()
|
animator.start()
|
||||||
Handler().post {
|
binding.playerToolbar.post {
|
||||||
ToolbarContentTintHelper.colorizeToolbar(
|
ToolbarContentTintHelper.colorizeToolbar(
|
||||||
binding.playerToolbar,
|
binding.playerToolbar,
|
||||||
color.secondaryTextColor,
|
color.secondaryTextColor,
|
||||||
|
|
|
@ -341,7 +341,7 @@ public final class ToolbarContentTintHelper {
|
||||||
.setSubtitleTextColor(ATHUtil.INSTANCE.resolveColor(activity, android.R.attr.textColorSecondary));
|
.setSubtitleTextColor(ATHUtil.INSTANCE.resolveColor(activity, android.R.attr.textColorSecondary));
|
||||||
|
|
||||||
//Step 4: Changing the color of the Overflow Menu icon.
|
//Step 4: Changing the color of the Overflow Menu icon.
|
||||||
setOverflowButtonColor(activity, toolbarView, toolbarIconsColor);
|
setOverflowButtonColor(toolbarView, toolbarIconsColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,6 +530,16 @@ public final class ToolbarContentTintHelper {
|
||||||
v.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
|
v.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setOverflowButtonColor(final Toolbar toolbar, final int color) {
|
||||||
|
Drawable drawable = toolbar.getOverflowIcon();
|
||||||
|
if (drawable != null) {
|
||||||
|
// If we don't mutate the drawable, then all drawables with this id will have the ColorFilter
|
||||||
|
drawable.mutate();
|
||||||
|
drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static void setOverflowButtonColor(final Activity activity, final Toolbar toolbar,
|
private static void setOverflowButtonColor(final Activity activity, final Toolbar toolbar,
|
||||||
final int toolbarIconsColor) {
|
final int toolbarIconsColor) {
|
||||||
final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
|
final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue