Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
litetex committed Jan 21, 2022
1 parent f8c52c4 commit 1c20eab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 5 additions & 5 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -600,24 +600,24 @@ public void onDoubleTapEnd() {
}

@Override
public Optional<Boolean> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -125,12 +125,22 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
interface PerformListener {
fun onDoubleTap()
fun onDoubleTapEnd()
fun shouldFastForward(portion: DisplayPortion): Optional<Boolean>
/**
* 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
}
}

0 comments on commit 1c20eab

Please sign in to comment.