diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index f7ef13d7a..431b4bb98 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -600,24 +600,24 @@ public final class Player implements } @Override - public Optional shouldFastForward( + public FastSeekDirection getFastSeekDirection( @NonNull final DisplayPortion portion ) { // Null indicates an invalid area or condition e.g. the middle portion // or video start or end was reached during double tap seeking if (invalidSeekConditions()) { playerGestureListener.endMultiDoubleTap(); - return Optional.empty(); + return FastSeekDirection.NONE; } if (portion == DisplayPortion.LEFT // Small puffer to eliminate infinite rewind seeking && simpleExoPlayer.getCurrentPosition() > 500L) { - return Optional.of(false); + return FastSeekDirection.BACKWARD; } else if (portion == DisplayPortion.RIGHT) { - return Optional.of(true); + return FastSeekDirection.FORWARD; } /* portion == DisplayPortion.MIDDLE */ - return Optional.empty(); + return FastSeekDirection.NONE; } @Override diff --git a/app/src/main/java/org/schabi/newpipe/views/player/PlayerFastSeekOverlay.kt b/app/src/main/java/org/schabi/newpipe/views/player/PlayerFastSeekOverlay.kt index 5a3eb9a4e..522977317 100644 --- a/app/src/main/java/org/schabi/newpipe/views/player/PlayerFastSeekOverlay.kt +++ b/app/src/main/java/org/schabi/newpipe/views/player/PlayerFastSeekOverlay.kt @@ -4,6 +4,7 @@ import android.content.Context import android.util.AttributeSet import android.util.Log import android.view.LayoutInflater +import androidx.annotation.NonNull import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.END import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID @@ -13,7 +14,6 @@ import org.schabi.newpipe.MainActivity import org.schabi.newpipe.R import org.schabi.newpipe.player.event.DisplayPortion import org.schabi.newpipe.player.event.DoubleTapListener -import java.util.Optional class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) : ConstraintLayout(context, attrs), DoubleTapListener { @@ -64,7 +64,7 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) : override fun onDoubleTapProgressDown(portion: DisplayPortion) { val shouldForward: Boolean = - performListener?.shouldFastForward(portion)?.orElse(null) ?: return + performListener?.getFastSeekDirection(portion)?.directionAsBoolean ?: return if (DEBUG) Log.d( @@ -125,12 +125,22 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) : interface PerformListener { fun onDoubleTap() fun onDoubleTapEnd() - fun shouldFastForward(portion: DisplayPortion): Optional + /** + * Determines if the playback should forward/rewind or do nothing. + */ + @NonNull + fun getFastSeekDirection(portion: DisplayPortion): FastSeekDirection fun seek(forward: Boolean) + + enum class FastSeekDirection(val directionAsBoolean: Boolean?) { + NONE(null), + FORWARD(true), + BACKWARD(false); + } } companion object { - private const val TAG = "PlayerSeekOverlay" + private const val TAG = "PlayerFastSeekOverlay" private val DEBUG = MainActivity.DEBUG } }