Cleanup the rewind and forward animation

This commit is contained in:
Bnyro 2023-01-12 18:42:51 +01:00
parent 62566ff527
commit 48776977ea
2 changed files with 35 additions and 29 deletions

View File

@ -10,6 +10,9 @@ import android.os.Looper
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.github.libretube.R
import com.github.libretube.databinding.DoubleTapOverlayBinding
@ -256,9 +259,9 @@ internal class CustomExoPlayerView(
R.drawable.ic_speed,
{
"${
player?.playbackParameters?.speed
.toString()
.replace(".0", "")
player?.playbackParameters?.speed
.toString()
.replace(".0", "")
}x"
}
) {
@ -341,19 +344,8 @@ internal class CustomExoPlayerView(
player?.seekTo((player?.currentPosition ?: 0L) - PlayerHelper.seekIncrement)
// show the rewind button
doubleTapOverlayBinding?.rewindBTN.apply {
this!!.visibility = View.VISIBLE
// clear previous animation
this.animate().rotation(0F).setDuration(0).start()
// start new animation
this.animate()
.rotation(-30F)
.setDuration(100)
.withEndAction {
// reset the animation when finished
animate().rotation(0F).setDuration(100).start()
}
.start()
doubleTapOverlayBinding?.apply {
animateSeeking(rewindBTN, rewindIV, rewindTV, true)
runnableHandler.removeCallbacks(hideRewindButtonRunnable)
// start callback to hide the button
@ -365,19 +357,8 @@ internal class CustomExoPlayerView(
player?.seekTo(player!!.currentPosition + PlayerHelper.seekIncrement)
// show the forward button
doubleTapOverlayBinding?.forwardBTN.apply {
this!!.visibility = View.VISIBLE
// clear previous animation
this.animate().rotation(0F).setDuration(0).start()
// start new animation
this.animate()
.rotation(30F)
.setDuration(100)
.withEndAction {
// reset the animation when finished
animate().rotation(0F).setDuration(100).start()
}
.start()
doubleTapOverlayBinding?.apply {
animateSeeking(forwardBTN, forwardIV, forwardTV, false)
// start callback to hide the button
runnableHandler.removeCallbacks(hideForwardButtonRunnable)
@ -385,6 +366,28 @@ internal class CustomExoPlayerView(
}
}
private fun animateSeeking(container: FrameLayout, imageView: ImageView, textView: TextView, isRewind: Boolean) {
container.visibility = View.VISIBLE
// clear previous animation
imageView.animate()
.rotation(0F)
.setDuration(0)
.start()
// start the rotate animation of the drawable
imageView.animate()
.rotation(if (isRewind) -30F else 30F)
.setDuration(ANIMATION_DURATION)
.withEndAction {
// reset the animation when finished
imageView.animate()
.rotation(0F)
.setDuration(ANIMATION_DURATION)
.start()
}
.start()
}
private val hideForwardButtonRunnable = Runnable {
doubleTapOverlayBinding?.forwardBTN.apply {
this!!.visibility = View.GONE
@ -607,6 +610,7 @@ internal class CustomExoPlayerView(
companion object {
private const val SUBTITLE_BOTTOM_PADDING_FRACTION = 0.158f
private const val ANIMATION_DURATION = 100L
private val LANDSCAPE_MARGIN_HORIZONTAL = (30).toPixel().toInt()
}
}

View File

@ -22,6 +22,7 @@
android:visibility="invisible">
<ImageView
android:id="@+id/rewindIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_rewind"
@ -61,6 +62,7 @@
android:visibility="invisible">
<ImageView
android:id="@+id/forwardIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_forward"