use the animated play/pause button at the Current Track bar too

This commit is contained in:
tibbi 2021-03-01 15:29:51 +01:00
parent d7845ddd51
commit 8f97587c84
2 changed files with 34 additions and 10 deletions

View file

@ -1,15 +1,21 @@
package com.simplemobiletools.musicplayer.views package com.simplemobiletools.musicplayer.views
import android.content.Context import android.content.Context
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.provider.MediaStore import android.provider.MediaStore
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.RelativeLayout import android.widget.RelativeLayout
import com.airbnb.lottie.LottieProperty
import com.airbnb.lottie.model.KeyPath
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.fadeIn
import com.simplemobiletools.commons.extensions.fadeOut
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
import com.simplemobiletools.musicplayer.R import com.simplemobiletools.musicplayer.R
import com.simplemobiletools.musicplayer.extensions.config import com.simplemobiletools.musicplayer.extensions.config
import com.simplemobiletools.musicplayer.extensions.sendIntent import com.simplemobiletools.musicplayer.extensions.sendIntent
@ -54,8 +60,22 @@ class CurrentTrackBar(context: Context, attributeSet: AttributeSet) : RelativeLa
} }
fun updateTrackState(isPlaying: Boolean) { fun updateTrackState(isPlaying: Boolean) {
val drawableId = if (isPlaying) R.drawable.ic_pause_vector else R.drawable.ic_play_vector val wasNull = current_track_play_pause.tag == null
val drawable = context.resources.getColoredDrawableWithColor(drawableId, context.config.textColor) if (current_track_play_pause.tag != isPlaying) {
current_track_play_pause.setImageDrawable(drawable) current_track_play_pause.speed = if (isPlaying) 2.5f else -2.5f
if (wasNull) {
current_track_play_pause.progress = if (isPlaying) 1f else 0f
} else {
current_track_play_pause.playAnimation()
}
current_track_play_pause.addValueCallback(
KeyPath("**"),
LottieProperty.COLOR_FILTER,
{ PorterDuffColorFilter(context.config.textColor, PorterDuff.Mode.SRC_IN) }
)
current_track_play_pause.tag = isPlaying
}
} }
} }

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.musicplayer.views.CurrentTrackBar xmlns:android="http://schemas.android.com/apk/res/android" <com.simplemobiletools.musicplayer.views.CurrentTrackBar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/current_track_bar" android:id="@+id/current_track_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -37,17 +38,20 @@
android:textSize="@dimen/bigger_text_size" android:textSize="@dimen/bigger_text_size"
tools:text="My Track" /> tools:text="My Track" />
<ImageView <com.airbnb.lottie.LottieAnimationView
android:id="@+id/current_track_play_pause" android:id="@+id/current_track_play_pause"
android:layout_width="wrap_content" android:layout_width="@dimen/smaller_icon_size"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignTop="@+id/current_track_image" android:layout_alignTop="@+id/current_track_image"
android:layout_alignBottom="@+id/current_track_image" android:layout_alignBottom="@+id/current_track_image"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_marginEnd="@dimen/medium_margin" android:layout_marginEnd="@dimen/normal_margin"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:paddingStart="@dimen/medium_margin" android:paddingStart="@dimen/smaller_margin"
android:paddingEnd="@dimen/medium_margin" android:paddingEnd="@dimen/smaller_margin"
android:src="@drawable/ic_pause_vector" /> android:scaleType="fitCenter"
app:lottie_autoPlay="false"
app:lottie_loop="false"
app:lottie_rawRes="@raw/playpause" />
</com.simplemobiletools.musicplayer.views.CurrentTrackBar> </com.simplemobiletools.musicplayer.views.CurrentTrackBar>