Fixed Lyrics icon not updating for Full & Gradient theme
This commit is contained in:
parent
48950922fb
commit
1c50903f5c
6 changed files with 43 additions and 57 deletions
|
@ -25,7 +25,6 @@ import android.media.MediaMetadataRetriever
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.text.TextUtils
|
|
||||||
import android.view.GestureDetector
|
import android.view.GestureDetector
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
@ -33,6 +32,7 @@ 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.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
@ -57,7 +57,6 @@ import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.interfaces.IPaletteColorHolder
|
import code.name.monkey.retromusic.interfaces.IPaletteColorHolder
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.model.lyrics.Lyrics
|
|
||||||
import code.name.monkey.retromusic.repository.RealRepository
|
import code.name.monkey.retromusic.repository.RealRepository
|
||||||
import code.name.monkey.retromusic.service.MusicService
|
import code.name.monkey.retromusic.service.MusicService
|
||||||
import code.name.monkey.retromusic.util.*
|
import code.name.monkey.retromusic.util.*
|
||||||
|
@ -67,7 +66,6 @@ import kotlinx.coroutines.Dispatchers.Main
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.koin.android.ext.android.get
|
import org.koin.android.ext.android.get
|
||||||
import java.io.FileNotFoundException
|
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragment(layout),
|
abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragment(layout),
|
||||||
|
@ -81,8 +79,8 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
||||||
val song = MusicPlayerRemote.currentSong
|
val song = MusicPlayerRemote.currentSong
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.action_toggle_lyrics -> {
|
R.id.action_toggle_lyrics -> {
|
||||||
PreferenceUtil.showLyrics = !PreferenceUtil.showLyrics
|
PreferenceUtil.showLyrics = !item.isChecked
|
||||||
showLyricsIcon(item)
|
item.isChecked = !item.isChecked
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_go_to_lyrics -> {
|
R.id.action_go_to_lyrics -> {
|
||||||
|
@ -195,18 +193,6 @@ 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()
|
||||||
|
@ -223,7 +209,6 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
||||||
|
|
||||||
override fun onPlayingMetaChanged() {
|
override fun onPlayingMetaChanged() {
|
||||||
updateIsFavorite()
|
updateIsFavorite()
|
||||||
updateLyrics()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFavoriteStateChanged() {
|
override fun onFavoriteStateChanged() {
|
||||||
|
@ -279,32 +264,6 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateLyrics() {
|
|
||||||
setLyrics(null)
|
|
||||||
lifecycleScope.launch(IO) {
|
|
||||||
val song = MusicPlayerRemote.currentSong
|
|
||||||
val lyrics = try {
|
|
||||||
var data: String? = LyricUtil.getStringFromFile(song.title, song.artistName)
|
|
||||||
if (TextUtils.isEmpty(data)) {
|
|
||||||
data = MusicUtil.getLyrics(song)
|
|
||||||
if (TextUtils.isEmpty(data)) {
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
Lyrics.parse(song, data)
|
|
||||||
}
|
|
||||||
} else Lyrics.parse(song, data!!)
|
|
||||||
} catch (err: FileNotFoundException) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
withContext(Main) {
|
|
||||||
setLyrics(lyrics)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun setLyrics(l: Lyrics?) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
if (PreferenceUtil.isFullScreenMode &&
|
if (PreferenceUtil.isFullScreenMode &&
|
||||||
|
@ -320,8 +279,19 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onStart() {
|
override fun onResume() {
|
||||||
super.onStart()
|
super.onResume()
|
||||||
|
val nps = PreferenceUtil.nowPlayingScreen
|
||||||
|
|
||||||
|
if (nps == NowPlayingScreen.Circle || nps == NowPlayingScreen.Peak || nps == NowPlayingScreen.Tiny) {
|
||||||
|
playerToolbar()?.menu?.removeItem(R.id.action_toggle_lyrics)
|
||||||
|
} else {
|
||||||
|
playerToolbar()?.menu?.findItem(R.id.action_toggle_lyrics)?.apply {
|
||||||
|
fixCheckStateOnIcon()
|
||||||
|
isCheckable = true
|
||||||
|
isChecked = PreferenceUtil.showLyrics
|
||||||
|
}
|
||||||
|
}
|
||||||
requireView().setOnTouchListener(
|
requireView().setOnTouchListener(
|
||||||
SwipeDetector(
|
SwipeDetector(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
|
@ -329,12 +299,6 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
||||||
requireView()
|
requireView()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val nps = PreferenceUtil.nowPlayingScreen
|
|
||||||
if (nps == NowPlayingScreen.Circle || nps == NowPlayingScreen.Peak || nps == NowPlayingScreen.Tiny) {
|
|
||||||
playerToolbar()?.menu?.removeItem(R.id.action_toggle_lyrics)
|
|
||||||
} else {
|
|
||||||
playerToolbar()?.menu?.findItem(R.id.action_toggle_lyrics)?.let { showLyricsIcon(it) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SwipeDetector(val context: Context, val viewPager: ViewPager?, val view: View) :
|
class SwipeDetector(val context: Context, val viewPager: ViewPager?, val view: View) :
|
||||||
|
@ -449,3 +413,14 @@ fun goToLyrics(activity: Activity) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/** 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) }
|
||||||
|
|
|
@ -202,7 +202,7 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
|
||||||
private fun maybeInitLyrics() {
|
private fun maybeInitLyrics() {
|
||||||
val nps = PreferenceUtil.nowPlayingScreen
|
val nps = PreferenceUtil.nowPlayingScreen
|
||||||
// Don't show lyrics container for below conditions
|
// Don't show lyrics container for below conditions
|
||||||
if (nps != Circle && nps != Peak && nps != Tiny && PreferenceUtil.showLyrics) {
|
if (lyricViewNpsList.contains(nps) && PreferenceUtil.showLyrics) {
|
||||||
showLyrics(true)
|
showLyrics(true)
|
||||||
progressViewUpdateHelper?.start()
|
progressViewUpdateHelper?.start()
|
||||||
lrcView.animate().alpha(1f).duration =
|
lrcView.animate().alpha(1f).duration =
|
||||||
|
@ -272,5 +272,9 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val TAG: String = PlayerAlbumCoverFragment::class.java.simpleName
|
val TAG: String = PlayerAlbumCoverFragment::class.java.simpleName
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val lyricViewNpsList =
|
||||||
|
listOf(Blur, Classic, Color, Flat, Material, Normal, Plain, Simple)
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,6 +204,7 @@ class FullPlaybackControlsFragment :
|
||||||
popupMenu.setOnMenuItemClickListener(this)
|
popupMenu.setOnMenuItemClickListener(this)
|
||||||
popupMenu.inflate(R.menu.menu_player)
|
popupMenu.inflate(R.menu.menu_player)
|
||||||
popupMenu.menu.findItem(R.id.action_toggle_favorite).isVisible = false
|
popupMenu.menu.findItem(R.id.action_toggle_favorite).isVisible = false
|
||||||
|
popupMenu.menu.findItem(R.id.action_toggle_lyrics).isChecked = PreferenceUtil.showLyrics
|
||||||
popupMenu.show()
|
popupMenu.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,7 @@ class GradientPlayerFragment : AbsPlayerFragment(R.layout.fragment_gradient_play
|
||||||
popupMenu.setOnMenuItemClickListener(this)
|
popupMenu.setOnMenuItemClickListener(this)
|
||||||
popupMenu.inflate(R.menu.menu_player)
|
popupMenu.inflate(R.menu.menu_player)
|
||||||
popupMenu.menu.findItem(R.id.action_toggle_favorite).isVisible = false
|
popupMenu.menu.findItem(R.id.action_toggle_favorite).isVisible = false
|
||||||
|
popupMenu.menu.findItem(R.id.action_toggle_lyrics).isChecked = PreferenceUtil.showLyrics
|
||||||
popupMenu.show()
|
popupMenu.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +158,7 @@ class GradientPlayerFragment : AbsPlayerFragment(R.layout.fragment_gradient_play
|
||||||
}
|
}
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(
|
ViewCompat.setOnApplyWindowInsetsListener(
|
||||||
(binding.container)
|
(binding.container)
|
||||||
) { v: View, insets: WindowInsetsCompat ->
|
) { _: View, insets: WindowInsetsCompat ->
|
||||||
navBarHeight = insets.safeGetBottomInsets()
|
navBarHeight = insets.safeGetBottomInsets()
|
||||||
binding.recyclerView.updatePadding(top = navBarHeight)
|
binding.recyclerView.updatePadding(top = navBarHeight)
|
||||||
insets
|
insets
|
||||||
|
|
5
app/src/main/res/drawable/sld_lyrics.xml
Normal file
5
app/src/main/res/drawable/sld_lyrics.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:drawable="@drawable/ic_lyrics" android:state_checked="true" />
|
||||||
|
<item android:drawable="@drawable/ic_lyrics_outline" />
|
||||||
|
</selector>
|
|
@ -4,16 +4,16 @@
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_toggle_lyrics"
|
android:id="@+id/action_toggle_lyrics"
|
||||||
android:checkable="true"
|
android:checkable="true"
|
||||||
android:icon="@drawable/ic_lyrics_outline"
|
android:icon="@drawable/sld_lyrics"
|
||||||
android:orderInCategory="1"
|
android:orderInCategory="1"
|
||||||
android:title="@string/lyrics"
|
android:title="@string/lyrics"
|
||||||
app:showAsAction="always" />
|
app:showAsAction="always" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_toggle_favorite"
|
android:id="@+id/action_toggle_favorite"
|
||||||
|
android:checkable="true"
|
||||||
android:icon="@drawable/ic_favorite"
|
android:icon="@drawable/ic_favorite"
|
||||||
android:orderInCategory="2"
|
android:orderInCategory="2"
|
||||||
android:title="@string/favorites"
|
android:title="@string/favorites"
|
||||||
android:checkable="true"
|
|
||||||
app:showAsAction="always" />
|
app:showAsAction="always" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/now_playing"
|
android:id="@+id/now_playing"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue