diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 3d59ac6fe..0950afc3e 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -2013,7 +2013,10 @@ public final class VideoDetailFragment restoreDefaultBrightness(); } else { // Do not restore if user has disabled brightness gesture - if (!PlayerHelper.isBrightnessGestureEnabled(activity)) { + if (!PlayerHelper.getActionForRightGestureSide(activity) + .equals(getString(R.string.brightness_control_key)) + && !PlayerHelper.getActionForLeftGestureSide(activity) + .equals(getString(R.string.brightness_control_key))) { return; } // Restore already saved brightness level diff --git a/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt b/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt index a6dba0dd5..0d28f2f58 100644 --- a/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt +++ b/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt @@ -193,18 +193,20 @@ class MainPlayerGestureListener( isMoving = true // -- Brightness and Volume control -- - val isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context) - val isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context) - if (isBrightnessGestureEnabled && isVolumeGestureEnabled) { - if (getDisplayHalfPortion(initialEvent) === DisplayPortion.LEFT_HALF) { - onScrollBrightness(distanceY) - } else /* DisplayPortion.RIGHT_HALF */ { - onScrollVolume(distanceY) + if (getDisplayHalfPortion(initialEvent) == DisplayPortion.RIGHT_HALF) { + when (PlayerHelper.getActionForRightGestureSide(player.context)) { + player.context.getString(R.string.volume_control_key) -> + onScrollVolume(distanceY) + player.context.getString(R.string.brightness_control_key) -> + onScrollBrightness(distanceY) + } + } else { + when (PlayerHelper.getActionForLeftGestureSide(player.context)) { + player.context.getString(R.string.volume_control_key) -> + onScrollVolume(distanceY) + player.context.getString(R.string.brightness_control_key) -> + onScrollBrightness(distanceY) } - } else if (isBrightnessGestureEnabled) { - onScrollBrightness(distanceY) - } else if (isVolumeGestureEnabled) { - onScrollVolume(distanceY) } return true diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index 1bc6f41a1..a110a80d6 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -228,14 +228,16 @@ public final class PlayerHelper { .getBoolean(context.getString(R.string.resume_on_audio_focus_gain_key), false); } - public static boolean isVolumeGestureEnabled(@NonNull final Context context) { + public static String getActionForRightGestureSide(@NonNull final Context context) { return getPreferences(context) - .getBoolean(context.getString(R.string.volume_gesture_control_key), true); + .getString(context.getString(R.string.right_gesture_control_key), + context.getString(R.string.default_right_gesture_control_value)); } - public static boolean isBrightnessGestureEnabled(@NonNull final Context context) { + public static String getActionForLeftGestureSide(@NonNull final Context context) { return getPreferences(context) - .getBoolean(context.getString(R.string.brightness_gesture_control_key), true); + .getString(context.getString(R.string.left_gesture_control_key), + context.getString(R.string.default_left_gesture_control_value)); } public static boolean isStartMainPlayerFullscreenEnabled(@NonNull final Context context) { diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java b/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java index b1e2c04eb..1bfaec6c2 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java @@ -108,6 +108,25 @@ public final class SettingMigrations { } }; + public static final Migration MIGRATION_4_5 = new Migration(4, 5) { + @Override + protected void migrate(final Context context) { + final boolean brightness = sp.getBoolean("brightness_gesture_control", true); + final boolean volume = sp.getBoolean("volume_gesture_control", true); + + final SharedPreferences.Editor editor = sp.edit(); + + editor.putString(context.getString(R.string.right_gesture_control_key), + context.getString(volume + ? R.string.volume_control_key : R.string.none_control_key)); + editor.putString(context.getString(R.string.left_gesture_control_key), + context.getString(brightness + ? R.string.brightness_control_key : R.string.none_control_key)); + + editor.apply(); + } + }; + /** * List of all implemented migrations. *

@@ -119,12 +138,13 @@ public final class SettingMigrations { MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, + MIGRATION_4_5, }; /** * Version number for preferences. Must be incremented every time a migration is necessary. */ - public static final int VERSION = 4; + public static final int VERSION = 5; public static void initMigrations(final Context context, final boolean isFirstRun) { diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 6a1d5cd45..8f3e8e192 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -16,8 +16,6 @@ use_external_video_player use_external_audio_player - volume_gesture_control - brightness_gesture_control resume_on_audio_focus_gain popup_remember_size_pos_key use_inexact_seek_key @@ -192,6 +190,35 @@ @string/audio_webm_key + left_gesture_control + @string/brightness_control_key + brightness_control + volume_control + none_control + + @string/brightness + @string/volume + @string/none + + + @string/brightness_control_key + @string/volume_control_key + @string/none_control_key + + + right_gesture_control + @string/volume_control_key + + @string/volume + @string/brightness + @string/none + + + @string/volume_control_key + @string/brightness_control_key + @string/none_control_key + + last_resize_mode diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dd8b8a58d..43705056b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -101,10 +101,13 @@ Auto-enqueue next stream Continue ending (non-repeating) playback queue by appending a related stream Auto-enqueuing - Volume gesture control - Use gestures to control player volume - Brightness gesture control - Use gestures to control player brightness + Choose gesture for left half of player screen + Left gesture action + Choose gesture for right half of player screen + Right gesture action + Brightness + Volume + None Search suggestions Choose the suggestions to show when searching Local search suggestions diff --git a/app/src/main/res/xml/video_audio_settings.xml b/app/src/main/res/xml/video_audio_settings.xml index 117ee8703..e4485f154 100644 --- a/app/src/main/res/xml/video_audio_settings.xml +++ b/app/src/main/res/xml/video_audio_settings.xml @@ -174,19 +174,23 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> - -