Code cleanup

This commit is contained in:
litetex 2022-01-06 14:39:12 +01:00
parent f8c52c4dac
commit 1c20eabb48
2 changed files with 19 additions and 9 deletions

View File

@ -600,24 +600,24 @@ public final class Player implements
} }
@Override @Override
public Optional<Boolean> shouldFastForward( public FastSeekDirection getFastSeekDirection(
@NonNull final DisplayPortion portion @NonNull final DisplayPortion portion
) { ) {
// Null indicates an invalid area or condition e.g. the middle portion // Null indicates an invalid area or condition e.g. the middle portion
// or video start or end was reached during double tap seeking // or video start or end was reached during double tap seeking
if (invalidSeekConditions()) { if (invalidSeekConditions()) {
playerGestureListener.endMultiDoubleTap(); playerGestureListener.endMultiDoubleTap();
return Optional.empty(); return FastSeekDirection.NONE;
} }
if (portion == DisplayPortion.LEFT if (portion == DisplayPortion.LEFT
// Small puffer to eliminate infinite rewind seeking // Small puffer to eliminate infinite rewind seeking
&& simpleExoPlayer.getCurrentPosition() > 500L) { && simpleExoPlayer.getCurrentPosition() > 500L) {
return Optional.of(false); return FastSeekDirection.BACKWARD;
} else if (portion == DisplayPortion.RIGHT) { } else if (portion == DisplayPortion.RIGHT) {
return Optional.of(true); return FastSeekDirection.FORWARD;
} }
/* portion == DisplayPortion.MIDDLE */ /* portion == DisplayPortion.MIDDLE */
return Optional.empty(); return FastSeekDirection.NONE;
} }
@Override @Override

View File

@ -4,6 +4,7 @@ import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import androidx.annotation.NonNull
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.END import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.END
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID 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.R
import org.schabi.newpipe.player.event.DisplayPortion import org.schabi.newpipe.player.event.DisplayPortion
import org.schabi.newpipe.player.event.DoubleTapListener import org.schabi.newpipe.player.event.DoubleTapListener
import java.util.Optional
class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) : class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
ConstraintLayout(context, attrs), DoubleTapListener { ConstraintLayout(context, attrs), DoubleTapListener {
@ -64,7 +64,7 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
override fun onDoubleTapProgressDown(portion: DisplayPortion) { override fun onDoubleTapProgressDown(portion: DisplayPortion) {
val shouldForward: Boolean = val shouldForward: Boolean =
performListener?.shouldFastForward(portion)?.orElse(null) ?: return performListener?.getFastSeekDirection(portion)?.directionAsBoolean ?: return
if (DEBUG) if (DEBUG)
Log.d( Log.d(
@ -125,12 +125,22 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
interface PerformListener { interface PerformListener {
fun onDoubleTap() fun onDoubleTap()
fun onDoubleTapEnd() 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) fun seek(forward: Boolean)
enum class FastSeekDirection(val directionAsBoolean: Boolean?) {
NONE(null),
FORWARD(true),
BACKWARD(false);
}
} }
companion object { companion object {
private const val TAG = "PlayerSeekOverlay" private const val TAG = "PlayerFastSeekOverlay"
private val DEBUG = MainActivity.DEBUG private val DEBUG = MainActivity.DEBUG
} }
} }