Skip to content

Commit 452fe3a

Browse files
committed
Respect disabled animations
1 parent c25e523 commit 452fe3a

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

app/src/main/java/org/schabi/newpipe/views/player/PlayerFastSeekOverlay.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
5858

5959
initTap = false
6060

61-
secondsView.stop()
61+
secondsView.stopAnimation()
6262
}
6363

6464
override fun onDoubleTapProgressDown(portion: DisplayPortion) {
@@ -86,8 +86,6 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
8686
wasForwarding = shouldForward
8787

8888
if (!initTap) {
89-
// Start animation
90-
secondsView.start()
9189
initTap = true
9290
}
9391
}
@@ -104,6 +102,8 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
104102

105103
if (initTap) performListener?.onDoubleTabEnd()
106104
initTap = false
105+
106+
secondsView.stopAnimation()
107107
}
108108

109109
private fun changeConstraints(forward: Boolean) {
@@ -115,7 +115,7 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
115115
secondsView.id, if (forward) END else START,
116116
PARENT_ID, if (forward) END else START
117117
)
118-
secondsView.start()
118+
secondsView.startAnimation()
119119
applyTo(rootConstraintLayout)
120120
}
121121
}

app/src/main/java/org/schabi/newpipe/views/player/SecondsView.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.view.LayoutInflater
88
import android.widget.LinearLayout
99
import org.schabi.newpipe.R
1010
import org.schabi.newpipe.databinding.PlayerFastSeekSecondsViewBinding
11+
import org.schabi.newpipe.util.DeviceUtils
1112

1213
class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs) {
1314

@@ -33,6 +34,9 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
3334
field = value
3435
}
3536

37+
// Done as a field so that we don't have to compute on each tab if animations are enabled
38+
private val animationsEnabled = DeviceUtils.hasAnimationsAnimatorDurationEnabled(context)
39+
3640
val binding = PlayerFastSeekSecondsViewBinding.inflate(LayoutInflater.from(context), this)
3741

3842
init {
@@ -44,12 +48,18 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
4448
binding.triangleContainer.rotation = if (isForward) 0f else 180f
4549
}
4650

47-
fun start() {
48-
stop()
49-
firstAnimator.start()
51+
fun startAnimation() {
52+
stopAnimation()
53+
54+
if (animationsEnabled) {
55+
firstAnimator.start()
56+
} else {
57+
// If no animations are enable show the arrow(s) without animation
58+
showWithoutAnimation()
59+
}
5060
}
5161

52-
fun stop() {
62+
fun stopAnimation() {
5363
firstAnimator.cancel()
5464
secondAnimator.cancel()
5565
thirdAnimator.cancel()
@@ -65,6 +75,12 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
6575
binding.icon3.alpha = 0f
6676
}
6777

78+
private fun showWithoutAnimation() {
79+
binding.icon1.alpha = 1f
80+
binding.icon2.alpha = 1f
81+
binding.icon3.alpha = 1f
82+
}
83+
6884
private val firstAnimator: ValueAnimator = CustomValueAnimator(
6985
{
7086
binding.icon1.alpha = 0f

0 commit comments

Comments
 (0)