Player gestures: Fix respecting brightness-volume-gesture settings

This commit is contained in:
vkay94 2020-11-20 21:08:02 +01:00
parent 66d15ea635
commit b5321152fd

View file

@ -36,15 +36,10 @@ public class PlayerGestureListener
private static final String TAG = ".PlayerGestureListener"; private static final String TAG = ".PlayerGestureListener";
private static final boolean DEBUG = BasePlayer.DEBUG; private static final boolean DEBUG = BasePlayer.DEBUG;
private final boolean isVolumeGestureEnabled;
private final boolean isBrightnessGestureEnabled;
private final int maxVolume; private final int maxVolume;
public PlayerGestureListener(final VideoPlayerImpl playerImpl, final MainPlayer service) { public PlayerGestureListener(final VideoPlayerImpl playerImpl, final MainPlayer service) {
super(playerImpl, service); super(playerImpl, service);
isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(service);
isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(service);
maxVolume = playerImpl.getAudioReactor().getMaxVolume(); maxVolume = playerImpl.getAudioReactor().getMaxVolume();
} }
@ -110,12 +105,22 @@ public class PlayerGestureListener
+ portion + "]"); + portion + "]");
} }
if (playerType == MainPlayer.PlayerType.VIDEO) { if (playerType == MainPlayer.PlayerType.VIDEO) {
final boolean isBrightnessGestureEnabled =
PlayerHelper.isBrightnessGestureEnabled(service);
final boolean isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(service);
if (isBrightnessGestureEnabled && isVolumeGestureEnabled) {
if (portion == DisplayPortion.LEFT_HALF) { if (portion == DisplayPortion.LEFT_HALF) {
onScrollMainBrightness(distanceX, distanceY); onScrollMainBrightness(distanceX, distanceY);
} else /* DisplayPortion.RIGHT_HALF */ { } else /* DisplayPortion.RIGHT_HALF */ {
onScrollMainVolume(distanceX, distanceY); onScrollMainVolume(distanceX, distanceY);
} }
} else if (isBrightnessGestureEnabled) {
onScrollMainBrightness(distanceX, distanceY);
} else if (isVolumeGestureEnabled) {
onScrollMainVolume(distanceX, distanceY);
}
} else /* MainPlayer.PlayerType.POPUP */ { } else /* MainPlayer.PlayerType.POPUP */ {
final View closingOverlayView = playerImpl.getClosingOverlayView(); final View closingOverlayView = playerImpl.getClosingOverlayView();
@ -132,7 +137,6 @@ public class PlayerGestureListener
} }
private void onScrollMainVolume(final float distanceX, final float distanceY) { private void onScrollMainVolume(final float distanceX, final float distanceY) {
if (isVolumeGestureEnabled) {
playerImpl.getVolumeProgressBar().incrementProgressBy((int) distanceY); playerImpl.getVolumeProgressBar().incrementProgressBy((int) distanceY);
final float currentProgressPercent = (float) playerImpl final float currentProgressPercent = (float) playerImpl
.getVolumeProgressBar().getProgress() / playerImpl.getMaxGestureLength(); .getVolumeProgressBar().getProgress() / playerImpl.getMaxGestureLength();
@ -158,10 +162,8 @@ public class PlayerGestureListener
playerImpl.getBrightnessRelativeLayout().setVisibility(View.GONE); playerImpl.getBrightnessRelativeLayout().setVisibility(View.GONE);
} }
} }
}
private void onScrollMainBrightness(final float distanceX, final float distanceY) { private void onScrollMainBrightness(final float distanceX, final float distanceY) {
if (isBrightnessGestureEnabled) {
final Activity parent = playerImpl.getParentActivity(); final Activity parent = playerImpl.getParentActivity();
if (parent == null) { if (parent == null) {
return; return;
@ -202,7 +204,6 @@ public class PlayerGestureListener
playerImpl.getVolumeRelativeLayout().setVisibility(View.GONE); playerImpl.getVolumeRelativeLayout().setVisibility(View.GONE);
} }
} }
}
@Override @Override
public void onScrollEnd(@NotNull final MainPlayer.PlayerType playerType, public void onScrollEnd(@NotNull final MainPlayer.PlayerType playerType,