Added favorite button for miniplayer
This commit is contained in:
parent
005d8ee6e8
commit
850036e5cc
3 changed files with 37 additions and 13 deletions
|
@ -3,6 +3,7 @@ package code.name.monkey.retromusic.fragments
|
||||||
import android.animation.ObjectAnimator
|
import android.animation.ObjectAnimator
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.AsyncTask
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
import android.text.SpannableStringBuilder
|
import android.text.SpannableStringBuilder
|
||||||
|
@ -11,14 +12,12 @@ import android.view.*
|
||||||
import android.view.animation.DecelerateInterpolator
|
import android.view.animation.DecelerateInterpolator
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
|
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
|
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
|
||||||
import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler
|
import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.util.NavigationUtil
|
import code.name.monkey.retromusic.util.*
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
|
||||||
import code.name.monkey.retromusic.util.RetroUtil
|
|
||||||
import code.name.monkey.retromusic.util.ViewUtil
|
|
||||||
import kotlinx.android.synthetic.main.fragment_mini_player.*
|
import kotlinx.android.synthetic.main.fragment_mini_player.*
|
||||||
|
|
||||||
open class MiniPlayerFragment : AbsMusicServiceFragment(), MusicProgressViewUpdateHelper.Callback, View.OnClickListener {
|
open class MiniPlayerFragment : AbsMusicServiceFragment(), MusicProgressViewUpdateHelper.Callback, View.OnClickListener {
|
||||||
|
@ -92,10 +91,12 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(), MusicProgressViewUpda
|
||||||
override fun onServiceConnected() {
|
override fun onServiceConnected() {
|
||||||
updateSongTitle()
|
updateSongTitle()
|
||||||
updatePlayPauseDrawableState()
|
updatePlayPauseDrawableState()
|
||||||
|
updateIsFavorite()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPlayingMetaChanged() {
|
override fun onPlayingMetaChanged() {
|
||||||
updateSongTitle()
|
updateSongTitle()
|
||||||
|
updateIsFavorite()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPlayStateChanged() {
|
override fun onPlayStateChanged() {
|
||||||
|
@ -128,11 +129,6 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(), MusicProgressViewUpda
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setColor(playerFragmentColor: Int) {
|
|
||||||
view!!.setBackgroundColor(playerFragmentColor)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class FlingPlayBackController(context: Context) : View.OnTouchListener {
|
class FlingPlayBackController(context: Context) : View.OnTouchListener {
|
||||||
|
|
||||||
private var flingPlayBackController: GestureDetector
|
private var flingPlayBackController: GestureDetector
|
||||||
|
@ -161,4 +157,33 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(), MusicProgressViewUpda
|
||||||
return flingPlayBackController.onTouchEvent(event)
|
return flingPlayBackController.onTouchEvent(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var updateIsFavoriteTask: AsyncTask<*, *, *>? = null
|
||||||
|
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
fun updateIsFavorite() {
|
||||||
|
if (updateIsFavoriteTask != null) {
|
||||||
|
updateIsFavoriteTask!!.cancel(false)
|
||||||
|
}
|
||||||
|
updateIsFavoriteTask = object : AsyncTask<Song, Void, Boolean>() {
|
||||||
|
override fun doInBackground(vararg params: Song): Boolean? {
|
||||||
|
val activity = activity
|
||||||
|
return if (activity != null) {
|
||||||
|
MusicUtil.isFavorite(requireActivity(), params[0])
|
||||||
|
} else {
|
||||||
|
cancel(false)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPostExecute(isFavorite: Boolean?) {
|
||||||
|
val res = if (isFavorite!!)
|
||||||
|
R.drawable.ic_favorite_white_24dp
|
||||||
|
else
|
||||||
|
R.drawable.ic_favorite_border_white_24dp
|
||||||
|
val drawable = RetroUtil.getTintedVectorDrawable(requireActivity(), res, ThemeStore.accentColor(requireActivity()))
|
||||||
|
miniPlayerImage.setImageDrawable(drawable)
|
||||||
|
}
|
||||||
|
}.execute(MusicPlayerRemote.currentSong)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<code.name.monkey.retromusic.views.IconImageView
|
<code.name.monkey.retromusic.views.IconImageView
|
||||||
android:id="@+id/mini_player_image"
|
android:id="@+id/miniPlayerImage"
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
android:paddingEnd="8dp">
|
android:paddingEnd="8dp">
|
||||||
|
|
||||||
<code.name.monkey.retromusic.views.IconImageView
|
<code.name.monkey.retromusic.views.IconImageView
|
||||||
android:id="@+id/mini_player_image"
|
android:id="@+id/miniPlayerImage"
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
@ -42,7 +42,6 @@
|
||||||
android:scrollHorizontally="true"
|
android:scrollHorizontally="true"
|
||||||
android:singleLine="true" />
|
android:singleLine="true" />
|
||||||
|
|
||||||
|
|
||||||
<code.name.monkey.retromusic.views.IconImageView
|
<code.name.monkey.retromusic.views.IconImageView
|
||||||
android:id="@+id/actionPrevious"
|
android:id="@+id/actionPrevious"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
|
|
Loading…
Reference in a new issue