diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptiveFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptiveFragment.kt
index a7fe6d3e..122bf7ab 100644
--- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptiveFragment.kt
+++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptiveFragment.kt
@@ -4,18 +4,107 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.FrameLayout
+import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.R
-import code.name.monkey.retromusic.helper.MusicPlayerRemote
-import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
+import code.name.monkey.retromusic.helper.MusicPlayerRemote
+import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
+import code.name.monkey.retromusic.model.Song
+import code.name.monkey.retromusic.model.lyrics.AbsSynchronizedLyrics
+import code.name.monkey.retromusic.model.lyrics.Lyrics
import kotlinx.android.synthetic.main.fragment_adaptive_player.*
-class AdaptiveFragment : AbsPlayerFragment(), PlayerAlbumCoverFragment.Callbacks {
+class AdaptiveFragment : AbsPlayerFragment(), PlayerAlbumCoverFragment.Callbacks, MusicProgressViewUpdateHelper.Callback {
+
+ private lateinit var lyricsLayout: FrameLayout
+ private lateinit var lyricsLine1: TextView
+ private lateinit var lyricsLine2: TextView
+
+ private var lyrics: Lyrics? = null
+ private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper
+
+ override fun onUpdateProgressViews(progress: Int, total: Int) {
+ if (!isLyricsLayoutBound()) return
+
+ if (!isLyricsLayoutVisible()) {
+ hideLyricsLayout()
+ return
+ }
+
+ if (lyrics !is AbsSynchronizedLyrics) return
+ val synchronizedLyrics = lyrics as AbsSynchronizedLyrics
+
+ lyricsLayout.visibility = View.VISIBLE
+ lyricsLayout.alpha = 1f
+
+ val oldLine = lyricsLine2.text.toString()
+ val line = synchronizedLyrics.getLine(progress)
+
+ if (oldLine != line || oldLine.isEmpty()) {
+ lyricsLine1.text = oldLine
+ lyricsLine2.text = line
+
+ lyricsLine1.visibility = View.VISIBLE
+ lyricsLine2.visibility = View.VISIBLE
+
+ lyricsLine2.measure(View.MeasureSpec.makeMeasureSpec(lyricsLine2.measuredWidth, View.MeasureSpec.EXACTLY), View.MeasureSpec.UNSPECIFIED)
+ val h: Float = lyricsLine2.measuredHeight.toFloat()
+
+ lyricsLine1.alpha = 1f
+ lyricsLine1.translationY = 0f
+ lyricsLine1.animate().alpha(0f).translationY(-h).duration = VISIBILITY_ANIM_DURATION
+
+ lyricsLine2.alpha = 0f
+ lyricsLine2.translationY = h
+ lyricsLine2.animate().alpha(1f).translationY(0f).duration = VISIBILITY_ANIM_DURATION
+ }
+ }
+
+ private fun isLyricsLayoutVisible(): Boolean {
+ return lyrics != null && lyrics!!.isSynchronized && lyrics!!.isValid
+ }
+
+ private fun isLyricsLayoutBound(): Boolean {
+ return lyricsLayout != null && lyricsLine1 != null && lyricsLine2 != null
+ }
+
+ private fun hideLyricsLayout() {
+ lyricsLayout.animate().alpha(0f).setDuration(VISIBILITY_ANIM_DURATION).withEndAction(Runnable {
+ if (!isLyricsLayoutBound()) return@Runnable
+ lyricsLayout.visibility = View.GONE
+ lyricsLine1.text = null
+ lyricsLine2.text = null
+ })
+ }
+
+ override fun setLyrics(l: Lyrics?) {
+ lyrics = l
+
+ if (!isLyricsLayoutBound()) return
+
+ if (!isLyricsLayoutVisible()) {
+ hideLyricsLayout()
+ return
+ }
+
+ lyricsLine1.text = null
+ lyricsLine2.text = null
+
+ lyricsLayout.visibility = View.VISIBLE
+ lyricsLayout.animate().alpha(1f).duration = VISIBILITY_ANIM_DURATION
+ }
+
+ override fun onDestroyView() {
+ super.onDestroyView()
+ progressViewUpdateHelper.stop()
+ }
+
override fun playerToolbar(): Toolbar {
return playerToolbar
}
@@ -29,8 +118,15 @@ class AdaptiveFragment : AbsPlayerFragment(), PlayerAlbumCoverFragment.Callbacks
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
+ lyricsLayout = view.findViewById(R.id.player_lyrics)
+ lyricsLine1 = view.findViewById(R.id.player_lyrics_line1)
+ lyricsLine2 = view.findViewById(R.id.player_lyrics_line2)
+
setUpSubFragments()
setUpPlayerToolbar()
+
+ progressViewUpdateHelper = MusicProgressViewUpdateHelper(this, 500, 1000)
+ progressViewUpdateHelper.start()
}
private fun setUpSubFragments() {
diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorFragment.kt
index 3529b55c..b2f617e4 100644
--- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorFragment.kt
+++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorFragment.kt
@@ -19,6 +19,8 @@ import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.R
+import code.name.monkey.retromusic.activities.LyricsActivity
+import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.glide.GlideApp
import code.name.monkey.retromusic.glide.RetroGlideExtension
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
@@ -26,8 +28,6 @@ import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.model.lyrics.Lyrics
-import code.name.monkey.retromusic.activities.LyricsActivity
-import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.RetroColorUtil
import code.name.monkey.retromusic.util.ViewUtil
@@ -133,7 +133,8 @@ class ColorFragment : AbsPlayerFragment() {
private fun updateSong() {
- GlideApp.with(activity!!).asBitmapPalette()
+ GlideApp.with(activity!!)
+ .asBitmapPalette()
.load(RetroGlideExtension.getSongModel(MusicPlayerRemote.currentSong))
.songOptions(MusicPlayerRemote.currentSong)
.transition(RetroGlideExtension.getDefaultTransition())
diff --git a/app/src/main/res/layout/fragment_adaptive_player.xml b/app/src/main/res/layout/fragment_adaptive_player.xml
index cb921c05..7b82382f 100644
--- a/app/src/main/res/layout/fragment_adaptive_player.xml
+++ b/app/src/main/res/layout/fragment_adaptive_player.xml
@@ -58,6 +58,42 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file