Skip to content

Commit 1c20eab

Browse files
committed
Code cleanup
1 parent f8c52c4 commit 1c20eab

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,24 +600,24 @@ public void onDoubleTapEnd() {
600600
}
601601

602602
@Override
603-
public Optional<Boolean> shouldFastForward(
603+
public FastSeekDirection getFastSeekDirection(
604604
@NonNull final DisplayPortion portion
605605
) {
606606
// Null indicates an invalid area or condition e.g. the middle portion
607607
// or video start or end was reached during double tap seeking
608608
if (invalidSeekConditions()) {
609609
playerGestureListener.endMultiDoubleTap();
610-
return Optional.empty();
610+
return FastSeekDirection.NONE;
611611
}
612612
if (portion == DisplayPortion.LEFT
613613
// Small puffer to eliminate infinite rewind seeking
614614
&& simpleExoPlayer.getCurrentPosition() > 500L) {
615-
return Optional.of(false);
615+
return FastSeekDirection.BACKWARD;
616616
} else if (portion == DisplayPortion.RIGHT) {
617-
return Optional.of(true);
617+
return FastSeekDirection.FORWARD;
618618
}
619619
/* portion == DisplayPortion.MIDDLE */
620-
return Optional.empty();
620+
return FastSeekDirection.NONE;
621621
}
622622

623623
@Override

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.util.AttributeSet
55
import android.util.Log
66
import android.view.LayoutInflater
7+
import androidx.annotation.NonNull
78
import androidx.constraintlayout.widget.ConstraintLayout
89
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.END
910
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID
@@ -13,7 +14,6 @@ import org.schabi.newpipe.MainActivity
1314
import org.schabi.newpipe.R
1415
import org.schabi.newpipe.player.event.DisplayPortion
1516
import org.schabi.newpipe.player.event.DoubleTapListener
16-
import java.util.Optional
1717

1818
class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
1919
ConstraintLayout(context, attrs), DoubleTapListener {
@@ -64,7 +64,7 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
6464

6565
override fun onDoubleTapProgressDown(portion: DisplayPortion) {
6666
val shouldForward: Boolean =
67-
performListener?.shouldFastForward(portion)?.orElse(null) ?: return
67+
performListener?.getFastSeekDirection(portion)?.directionAsBoolean ?: return
6868

6969
if (DEBUG)
7070
Log.d(
@@ -125,12 +125,22 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
125125
interface PerformListener {
126126
fun onDoubleTap()
127127
fun onDoubleTapEnd()
128-
fun shouldFastForward(portion: DisplayPortion): Optional<Boolean>
128+
/**
129+
* Determines if the playback should forward/rewind or do nothing.
130+
*/
131+
@NonNull
132+
fun getFastSeekDirection(portion: DisplayPortion): FastSeekDirection
129133
fun seek(forward: Boolean)
134+
135+
enum class FastSeekDirection(val directionAsBoolean: Boolean?) {
136+
NONE(null),
137+
FORWARD(true),
138+
BACKWARD(false);
139+
}
130140
}
131141

132142
companion object {
133-
private const val TAG = "PlayerSeekOverlay"
143+
private const val TAG = "PlayerFastSeekOverlay"
134144
private val DEBUG = MainActivity.DEBUG
135145
}
136146
}

0 commit comments

Comments
 (0)