Fixed lyrics crash
This commit is contained in:
parent
9fc25b71ce
commit
ff2574fffc
9 changed files with 249 additions and 279 deletions
|
@ -85,6 +85,10 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
|||
showLyricsIcon(item)
|
||||
return true
|
||||
}
|
||||
R.id.action_go_to_lyrics -> {
|
||||
goToLyrics(requireActivity())
|
||||
return true
|
||||
}
|
||||
R.id.action_toggle_favorite -> {
|
||||
toggleFavorite(song)
|
||||
return true
|
||||
|
|
|
@ -231,13 +231,7 @@ class LyricsFragment : AbsMusicServiceFragment(R.layout.fragment_lyrics) {
|
|||
|
||||
@SuppressLint("CheckResult")
|
||||
private fun editSyncedLyrics() {
|
||||
var lrcFile: File? = null
|
||||
if (LyricUtil.isLrcOriginalFileExist(song.data)) {
|
||||
lrcFile = LyricUtil.getLocalLyricOriginalFile(song.data)
|
||||
} else if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
|
||||
lrcFile = LyricUtil.getLocalLyricFile(song.title, song.artistName)
|
||||
}
|
||||
val content: String = LyricUtil.getStringFromLrc(lrcFile)
|
||||
val content: String = LyricUtil.getStringFromLrc(LyricUtil.getSyncedLyricsFile(song))
|
||||
|
||||
MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
||||
title(res = R.string.edit_synced_lyrics)
|
||||
|
@ -332,11 +326,8 @@ class LyricsFragment : AbsMusicServiceFragment(R.layout.fragment_lyrics) {
|
|||
|
||||
fun loadLRCLyrics() {
|
||||
binding.lyricsView.setLabel("Empty")
|
||||
val song = MusicPlayerRemote.currentSong
|
||||
if (LyricUtil.isLrcOriginalFileExist(song.data)) {
|
||||
binding.lyricsView.loadLrc(LyricUtil.getLocalLyricOriginalFile(song.data))
|
||||
} else if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
|
||||
binding.lyricsView.loadLrc(LyricUtil.getLocalLyricFile(song.title, song.artistName))
|
||||
LyricUtil.getSyncedLyricsFile(MusicPlayerRemote.currentSong)?.let {
|
||||
binding.lyricsView.loadLrc(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ import code.name.monkey.retromusic.extensions.surfaceColor
|
|||
import code.name.monkey.retromusic.fragments.NowPlayingScreen.*
|
||||
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment
|
||||
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
|
||||
import code.name.monkey.retromusic.fragments.base.goToLyrics
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
|
||||
import code.name.monkey.retromusic.lyrics.CoverLrcView
|
||||
|
@ -74,18 +73,16 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
|
|||
}
|
||||
|
||||
private fun updateLyrics() {
|
||||
binding.lyricsView.setLabel("Empty")
|
||||
binding.lyricsView.setLabel(context?.getString(R.string.no_lyrics_found))
|
||||
val song = MusicPlayerRemote.currentSong
|
||||
when {
|
||||
LyricUtil.isLrcOriginalFileExist(song.data) -> {
|
||||
LyricUtil.getLocalLyricOriginalFile(song.data)
|
||||
?.let { binding.lyricsView.loadLrc(it) }
|
||||
}
|
||||
LyricUtil.isLrcFileExist(song.title, song.artistName) -> {
|
||||
LyricUtil.getLocalLyricFile(song.title, song.artistName)
|
||||
?.let { binding.lyricsView.loadLrc(it) }
|
||||
}
|
||||
else -> {
|
||||
val lrcFile = LyricUtil.getSyncedLyricsFile(song)
|
||||
if (lrcFile != null) {
|
||||
binding.lyricsView.loadLrc(lrcFile)
|
||||
} else {
|
||||
val embeddedLyrics = LyricUtil.getEmbeddedSyncedLyrics(song.data)
|
||||
if (embeddedLyrics != null) {
|
||||
binding.lyricsView.loadLrc(embeddedLyrics)
|
||||
} else {
|
||||
binding.lyricsView.reset()
|
||||
}
|
||||
}
|
||||
|
@ -126,16 +123,7 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
|
|||
)
|
||||
}
|
||||
progressViewUpdateHelper = MusicProgressViewUpdateHelper(this, 500, 1000)
|
||||
// Don't show lyrics container for below conditions
|
||||
if (!(nps == Circle || nps == Peak || nps == Tiny || !PreferenceUtil.showLyrics)) {
|
||||
lrcView.isVisible = false
|
||||
viewPager.isInvisible = false
|
||||
progressViewUpdateHelper?.stop()
|
||||
} else {
|
||||
lrcView.isVisible = true
|
||||
viewPager.isInvisible = true
|
||||
progressViewUpdateHelper?.start()
|
||||
}
|
||||
maybeInitLyrics()
|
||||
lrcView.apply {
|
||||
setDraggable(true, object : CoverLrcView.OnPlayClickListener {
|
||||
override fun onPlayClick(time: Long): Boolean {
|
||||
|
@ -145,25 +133,11 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
|
|||
}
|
||||
})
|
||||
}
|
||||
// Go to lyrics activity when clicked lyrics
|
||||
lrcView.setOnClickListener {
|
||||
goToLyrics(requireActivity())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val nps = PreferenceUtil.nowPlayingScreen
|
||||
// Don't show lyrics container for below conditions
|
||||
if (nps == Circle || nps == Peak || nps == Tiny || !PreferenceUtil.showLyrics) {
|
||||
lrcView.isVisible = false
|
||||
viewPager.isInvisible = false
|
||||
progressViewUpdateHelper?.stop()
|
||||
} else {
|
||||
lrcView.isVisible = true
|
||||
viewPager.isInvisible = true
|
||||
progressViewUpdateHelper?.start()
|
||||
}
|
||||
maybeInitLyrics()
|
||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
.registerOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
@ -194,22 +168,9 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
|
|||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
|
||||
if (key == SHOW_LYRICS) {
|
||||
if (sharedPreferences.getBoolean(key, false)) {
|
||||
val nps = PreferenceUtil.nowPlayingScreen
|
||||
// Don't show lyrics container for below conditions
|
||||
if (!(nps == Circle || nps == Peak || nps == Tiny || !PreferenceUtil.showLyrics)) {
|
||||
lrcView.isVisible = true
|
||||
viewPager.isInvisible = true
|
||||
progressViewUpdateHelper?.start()
|
||||
lrcView.animate().alpha(1f).duration =
|
||||
AbsPlayerFragment.VISIBILITY_ANIM_DURATION
|
||||
} else {
|
||||
lrcView.isVisible = false
|
||||
viewPager.isInvisible = false
|
||||
progressViewUpdateHelper?.stop()
|
||||
}
|
||||
maybeInitLyrics()
|
||||
} else {
|
||||
lrcView.isVisible = false
|
||||
viewPager.isInvisible = false
|
||||
showLyrics(false)
|
||||
progressViewUpdateHelper?.stop()
|
||||
}
|
||||
}
|
||||
|
@ -233,6 +194,25 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
|
|||
}
|
||||
}
|
||||
|
||||
private fun showLyrics(visible: Boolean) {
|
||||
lrcView.isVisible = visible
|
||||
viewPager.isInvisible = visible
|
||||
}
|
||||
|
||||
private fun maybeInitLyrics() {
|
||||
val nps = PreferenceUtil.nowPlayingScreen
|
||||
// Don't show lyrics container for below conditions
|
||||
if (nps != Circle && nps != Peak && nps != Tiny && PreferenceUtil.showLyrics) {
|
||||
showLyrics(true)
|
||||
progressViewUpdateHelper?.start()
|
||||
lrcView.animate().alpha(1f).duration =
|
||||
AbsPlayerFragment.VISIBILITY_ANIM_DURATION
|
||||
} else {
|
||||
showLyrics(false)
|
||||
progressViewUpdateHelper?.stop()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updatePlayingQueue() {
|
||||
binding.viewPager.apply {
|
||||
adapter = AlbumCoverPagerAdapter(childFragmentManager, MusicPlayerRemote.playingQueue)
|
||||
|
@ -266,15 +246,17 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
|
|||
callbacks?.onColorChanged(color)
|
||||
setLRCViewColors(
|
||||
when (PreferenceUtil.nowPlayingScreen) {
|
||||
Adaptive, Fit, Plain, Simple -> surfaceColor()
|
||||
Flat, Normal -> if (PreferenceUtil.isAdaptiveColor) {
|
||||
color.backgroundColor
|
||||
} else {
|
||||
surfaceColor()
|
||||
}
|
||||
Color, Gradient, Full ->color.backgroundColor
|
||||
Color -> color.backgroundColor
|
||||
Blur -> Color.BLACK
|
||||
else -> surfaceColor()
|
||||
})
|
||||
else -> color.backgroundColor
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun setCallbacks(listener: Callbacks) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue