From 3c74cb3439bd64f7ac92add78e0492e04afaa334 Mon Sep 17 00:00:00 2001 From: ge78fug Date: Fri, 20 Jan 2023 16:35:47 +0100 Subject: [PATCH 01/14] Created a setting to switch the sides of volume and brightness --- .../gesture/MainPlayerGestureListener.kt | 13 +++++++++--- .../settings/VideoAudioSettingsFragment.java | 20 +++++++++++++++++++ app/src/main/res/values/settings_keys.xml | 1 + app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/video_audio_settings.xml | 8 ++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) 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..75a27896d 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 @@ -9,6 +9,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.content.res.AppCompatResources import androidx.core.math.MathUtils import androidx.core.view.isVisible +import androidx.preference.PreferenceManager import org.schabi.newpipe.MainActivity import org.schabi.newpipe.R import org.schabi.newpipe.ktx.AnimationType @@ -193,10 +194,16 @@ class MainPlayerGestureListener( isMoving = true // -- Brightness and Volume control -- - val isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context) - val isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context) + var isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context) + var isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context) + var displaySide = DisplayPortion.LEFT_HALF + val sidesSwitched = PreferenceManager.getDefaultSharedPreferences(player.context) + .getBoolean(R.string.switch_gesture_sides_key.toString(), false) + if (sidesSwitched) { + displaySide = DisplayPortion.RIGHT_HALF + } if (isBrightnessGestureEnabled && isVolumeGestureEnabled) { - if (getDisplayHalfPortion(initialEvent) === DisplayPortion.LEFT_HALF) { + if (getDisplayHalfPortion(initialEvent) === displaySide) { onScrollBrightness(distanceY) } else /* DisplayPortion.RIGHT_HALF */ { onScrollVolume(distanceY) diff --git a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java index aae9cfca5..4936f979b 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java @@ -6,8 +6,11 @@ import android.os.Build; import android.os.Bundle; import android.provider.Settings; import android.text.format.DateUtils; +import android.view.View; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.preference.ListPreference; import com.google.android.material.snackbar.Snackbar; @@ -21,6 +24,17 @@ import java.util.List; public class VideoAudioSettingsFragment extends BasePreferenceFragment { private SharedPreferences.OnSharedPreferenceChangeListener listener; + @Override + public void onViewCreated(@NonNull final View rootView, + @Nullable final Bundle savedInstanceState) { + super.onViewCreated(rootView, savedInstanceState); + findPreference(getString(R.string.switch_gesture_sides_key)) + .setEnabled(getPreferenceManager().getSharedPreferences() + .getBoolean(getString(R.string.volume_gesture_control_key), true) + && getPreferenceManager().getSharedPreferences() + .getBoolean(getString(R.string.brightness_gesture_control_key), true)); + } + @Override public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { addPreferencesFromResourceRegistry(); @@ -29,6 +43,12 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment { listener = (sharedPreferences, key) -> { + findPreference(getString(R.string.switch_gesture_sides_key)) + .setEnabled(sharedPreferences.getBoolean( + getString(R.string.volume_gesture_control_key), true) + && sharedPreferences.getBoolean( + getString(R.string.brightness_gesture_control_key), true)); + // on M and above, if user chooses to minimise to popup player on exit // and the app doesn't have display over other apps permission, // show a snackbar to let the user give permission diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 6a1d5cd45..dae8cc113 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -18,6 +18,7 @@ volume_gesture_control brightness_gesture_control + switch_gesture_sides resume_on_audio_focus_gain popup_remember_size_pos_key use_inexact_seek_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dd8b8a58d..67acdcf0c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -105,6 +105,8 @@ Use gestures to control player volume Brightness gesture control Use gestures to control player brightness + Switch gesture sides + Switches the sides of the volume and brightness gesture controls 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..da932bb38 100644 --- a/app/src/main/res/xml/video_audio_settings.xml +++ b/app/src/main/res/xml/video_audio_settings.xml @@ -190,6 +190,14 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> + + Date: Fri, 20 Jan 2023 22:48:10 +0100 Subject: [PATCH 02/14] Update app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt Co-authored-by: Stypox --- .../newpipe/player/gesture/MainPlayerGestureListener.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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 75a27896d..d6dc37e95 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 @@ -196,12 +196,9 @@ class MainPlayerGestureListener( // -- Brightness and Volume control -- var isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context) var isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context) - var displaySide = DisplayPortion.LEFT_HALF - val sidesSwitched = PreferenceManager.getDefaultSharedPreferences(player.context) - .getBoolean(R.string.switch_gesture_sides_key.toString(), false) - if (sidesSwitched) { - displaySide = DisplayPortion.RIGHT_HALF - } + val brightnessSide = if (PreferenceManager.getDefaultSharedPreferences(player.context) + .getBoolean(R.string.switch_gesture_sides_key.toString(), false)) DisplayPortion.RIGHT_HALF + else DisplayPortion.LEFT_HALF if (isBrightnessGestureEnabled && isVolumeGestureEnabled) { if (getDisplayHalfPortion(initialEvent) === displaySide) { onScrollBrightness(distanceY) From c8d54ec6c77d172bf51dc5d6988aee953375bc6e Mon Sep 17 00:00:00 2001 From: ge78fug Date: Fri, 20 Jan 2023 23:10:55 +0100 Subject: [PATCH 03/14] Changed to val --- .../newpipe/player/gesture/MainPlayerGestureListener.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 d6dc37e95..3c40f714e 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 @@ -194,13 +194,13 @@ class MainPlayerGestureListener( isMoving = true // -- Brightness and Volume control -- - var isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context) - var isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context) + val isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context) + val isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context) val brightnessSide = if (PreferenceManager.getDefaultSharedPreferences(player.context) .getBoolean(R.string.switch_gesture_sides_key.toString(), false)) DisplayPortion.RIGHT_HALF else DisplayPortion.LEFT_HALF if (isBrightnessGestureEnabled && isVolumeGestureEnabled) { - if (getDisplayHalfPortion(initialEvent) === displaySide) { + if (getDisplayHalfPortion(initialEvent) === brightnessSide) { onScrollBrightness(distanceY) } else /* DisplayPortion.RIGHT_HALF */ { onScrollVolume(distanceY) From 2ba649949fbb6968706dfa5e3058ad7a4fbfcf7e Mon Sep 17 00:00:00 2001 From: ge78fug Date: Sat, 21 Jan 2023 17:11:45 +0100 Subject: [PATCH 04/14] Updated the gesture-switch-toggle --- .../gesture/MainPlayerGestureListener.kt | 5 ++- .../settings/VideoAudioSettingsFragment.java | 40 +++++++++---------- app/src/main/res/values/strings.xml | 1 + 3 files changed, 24 insertions(+), 22 deletions(-) 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 3c40f714e..960edbce2 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 @@ -197,8 +197,9 @@ class MainPlayerGestureListener( val isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context) val isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context) val brightnessSide = if (PreferenceManager.getDefaultSharedPreferences(player.context) - .getBoolean(R.string.switch_gesture_sides_key.toString(), false)) DisplayPortion.RIGHT_HALF - else DisplayPortion.LEFT_HALF + .getBoolean(R.string.switch_gesture_sides_key.toString(), false) + ) DisplayPortion.RIGHT_HALF + else DisplayPortion.LEFT_HALF if (isBrightnessGestureEnabled && isVolumeGestureEnabled) { if (getDisplayHalfPortion(initialEvent) === brightnessSide) { onScrollBrightness(distanceY) diff --git a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java index 4936f979b..e1a8dd90b 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java @@ -6,12 +6,10 @@ import android.os.Build; import android.os.Bundle; import android.provider.Settings; import android.text.format.DateUtils; -import android.view.View; import android.widget.Toast; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.preference.ListPreference; +import androidx.preference.SwitchPreferenceCompat; import com.google.android.material.snackbar.Snackbar; @@ -24,31 +22,15 @@ import java.util.List; public class VideoAudioSettingsFragment extends BasePreferenceFragment { private SharedPreferences.OnSharedPreferenceChangeListener listener; - @Override - public void onViewCreated(@NonNull final View rootView, - @Nullable final Bundle savedInstanceState) { - super.onViewCreated(rootView, savedInstanceState); - findPreference(getString(R.string.switch_gesture_sides_key)) - .setEnabled(getPreferenceManager().getSharedPreferences() - .getBoolean(getString(R.string.volume_gesture_control_key), true) - && getPreferenceManager().getSharedPreferences() - .getBoolean(getString(R.string.brightness_gesture_control_key), true)); - } - @Override public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { addPreferencesFromResourceRegistry(); updateSeekOptions(); + updateGestureSwitch(); listener = (sharedPreferences, key) -> { - findPreference(getString(R.string.switch_gesture_sides_key)) - .setEnabled(sharedPreferences.getBoolean( - getString(R.string.volume_gesture_control_key), true) - && sharedPreferences.getBoolean( - getString(R.string.brightness_gesture_control_key), true)); - // on M and above, if user chooses to minimise to popup player on exit // and the app doesn't have display over other apps permission, // show a snackbar to let the user give permission @@ -68,6 +50,9 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment { } } else if (getString(R.string.use_inexact_seek_key).equals(key)) { updateSeekOptions(); + } else if (getString(R.string.volume_gesture_control_key).equals(key) + || getString(R.string.brightness_gesture_control_key).equals(key)) { + updateGestureSwitch(); } }; } @@ -137,4 +122,19 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment { getPreferenceManager().getSharedPreferences() .unregisterOnSharedPreferenceChangeListener(listener); } + + private void updateGestureSwitch() { + final SwitchPreferenceCompat gestureSwitch = (SwitchPreferenceCompat) + findPreference(getString(R.string.switch_gesture_sides_key)); + if (getPreferenceManager().getSharedPreferences() + .getBoolean(getString(R.string.volume_gesture_control_key), true) + && getPreferenceManager().getSharedPreferences() + .getBoolean(getString(R.string.brightness_gesture_control_key), true)) { + gestureSwitch.setEnabled(true); + gestureSwitch.setSummary(getString(R.string.switch_gesture_sides_summary)); + } else { + gestureSwitch.setEnabled(false); + gestureSwitch.setSummary(getString(R.string.switch_gesture_sides_summary_disabled)); + } + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 67acdcf0c..e1c5bc0bb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -107,6 +107,7 @@ Use gestures to control player brightness Switch gesture sides Switches the sides of the volume and brightness gesture controls + Enable both brightness and volume gestures to use this feature Search suggestions Choose the suggestions to show when searching Local search suggestions From 759a9080a8af28b52f56eda187faca5bb69c15fd Mon Sep 17 00:00:00 2001 From: ge78fug Date: Mon, 23 Jan 2023 21:25:05 +0100 Subject: [PATCH 05/14] Fixed a bug --- .../newpipe/player/gesture/MainPlayerGestureListener.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 960edbce2..74542af70 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 @@ -197,11 +197,12 @@ class MainPlayerGestureListener( val isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context) val isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context) val brightnessSide = if (PreferenceManager.getDefaultSharedPreferences(player.context) - .getBoolean(R.string.switch_gesture_sides_key.toString(), false) - ) DisplayPortion.RIGHT_HALF + .getBoolean( + player.context.getString(R.string.switch_gesture_sides_key), false)) + DisplayPortion.RIGHT_HALF else DisplayPortion.LEFT_HALF if (isBrightnessGestureEnabled && isVolumeGestureEnabled) { - if (getDisplayHalfPortion(initialEvent) === brightnessSide) { + if (getDisplayHalfPortion(initialEvent) == brightnessSide) { onScrollBrightness(distanceY) } else /* DisplayPortion.RIGHT_HALF */ { onScrollVolume(distanceY) From 2ded8c7cc18b7414d244e0e559acd3a1e9d7259f Mon Sep 17 00:00:00 2001 From: ge78fug Date: Sun, 29 Jan 2023 19:23:39 +0100 Subject: [PATCH 06/14] Made two list options --- .../fragments/detail/VideoDetailFragment.java | 5 ++- .../gesture/MainPlayerGestureListener.kt | 33 +++++++++-------- .../newpipe/player/helper/PlayerHelper.java | 10 +++--- .../settings/VideoAudioSettingsFragment.java | 20 ----------- app/src/main/res/values/settings_keys.xml | 35 +++++++++++++++++-- app/src/main/res/values/strings.xml | 14 ++++---- app/src/main/res/xml/video_audio_settings.xml | 32 ++++++++--------- 7 files changed, 79 insertions(+), 70 deletions(-) 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..885034e5a 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.getRightSideGesture(activity) + .equals(getString(R.string.right_brightness_control_key)) + && PlayerHelper.getLeftSideGesture(activity) + .equals(getString(R.string.left_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 74542af70..82cf2244c 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 @@ -9,7 +9,6 @@ import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.content.res.AppCompatResources import androidx.core.math.MathUtils import androidx.core.view.isVisible -import androidx.preference.PreferenceManager import org.schabi.newpipe.MainActivity import org.schabi.newpipe.R import org.schabi.newpipe.ktx.AnimationType @@ -194,23 +193,23 @@ class MainPlayerGestureListener( isMoving = true // -- Brightness and Volume control -- - val isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context) - val isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context) - val brightnessSide = if (PreferenceManager.getDefaultSharedPreferences(player.context) - .getBoolean( - player.context.getString(R.string.switch_gesture_sides_key), false)) - DisplayPortion.RIGHT_HALF - else DisplayPortion.LEFT_HALF - if (isBrightnessGestureEnabled && isVolumeGestureEnabled) { - if (getDisplayHalfPortion(initialEvent) == brightnessSide) { - onScrollBrightness(distanceY) - } else /* DisplayPortion.RIGHT_HALF */ { - onScrollVolume(distanceY) + val rightSide = PlayerHelper.getRightSideGesture(player.context) + val leftSide = PlayerHelper.getLeftSideGesture(player.context) + + if (getDisplayHalfPortion(initialEvent) == DisplayPortion.RIGHT_HALF) { + when (rightSide) { + player.context.getString(R.string.right_volume_control_key) -> + onScrollVolume(distanceY) + player.context.getString(R.string.right_brightness_control_key) -> + onScrollBrightness(distanceY) + } + } else { + when (leftSide) { + player.context.getString(R.string.left_volume_control_key) -> + onScrollVolume(distanceY) + player.context.getString(R.string.left_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..74bcf047c 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 getRightSideGesture(@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 getLeftSideGesture(@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/VideoAudioSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java index e1a8dd90b..aae9cfca5 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java @@ -9,7 +9,6 @@ import android.text.format.DateUtils; import android.widget.Toast; import androidx.preference.ListPreference; -import androidx.preference.SwitchPreferenceCompat; import com.google.android.material.snackbar.Snackbar; @@ -27,7 +26,6 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment { addPreferencesFromResourceRegistry(); updateSeekOptions(); - updateGestureSwitch(); listener = (sharedPreferences, key) -> { @@ -50,9 +48,6 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment { } } else if (getString(R.string.use_inexact_seek_key).equals(key)) { updateSeekOptions(); - } else if (getString(R.string.volume_gesture_control_key).equals(key) - || getString(R.string.brightness_gesture_control_key).equals(key)) { - updateGestureSwitch(); } }; } @@ -122,19 +117,4 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment { getPreferenceManager().getSharedPreferences() .unregisterOnSharedPreferenceChangeListener(listener); } - - private void updateGestureSwitch() { - final SwitchPreferenceCompat gestureSwitch = (SwitchPreferenceCompat) - findPreference(getString(R.string.switch_gesture_sides_key)); - if (getPreferenceManager().getSharedPreferences() - .getBoolean(getString(R.string.volume_gesture_control_key), true) - && getPreferenceManager().getSharedPreferences() - .getBoolean(getString(R.string.brightness_gesture_control_key), true)) { - gestureSwitch.setEnabled(true); - gestureSwitch.setSummary(getString(R.string.switch_gesture_sides_summary)); - } else { - gestureSwitch.setEnabled(false); - gestureSwitch.setSummary(getString(R.string.switch_gesture_sides_summary_disabled)); - } - } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index dae8cc113..ad6b1777b 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -16,9 +16,6 @@ use_external_video_player use_external_audio_player - volume_gesture_control - brightness_gesture_control - switch_gesture_sides resume_on_audio_focus_gain popup_remember_size_pos_key use_inexact_seek_key @@ -193,6 +190,38 @@ @string/audio_webm_key + left_gesture_control + @string/left_brightness_control_key + left_brightness_control + left_volume_control + left_none_control + + @string/brightness + @string/volume + @string/none + + + @string/left_brightness_control_key + @string/left_volume_control_key + @string/left_none_control_key + + + right_gesture_control + @string/right_volume_control_key + right_brightness_control + right_volume_control + right_none_control + + @string/volume + @string/brightness + @string/none + + + @string/right_volume_control_key + @string/right_brightness_control_key + @string/right_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 e1c5bc0bb..6890e4dd0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -101,13 +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 - Switch gesture sides - Switches the sides of the volume and brightness gesture controls - Enable both brightness and volume gestures to use this feature + Change the left gesture control + Left gesture control + Change the right gesture control + Right gesture control + 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 da932bb38..e4485f154 100644 --- a/app/src/main/res/xml/video_audio_settings.xml +++ b/app/src/main/res/xml/video_audio_settings.xml @@ -174,27 +174,23 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> - - - - From 72ca52a29b403961c43ac3e53491b3c1641af159 Mon Sep 17 00:00:00 2001 From: Marius Wagner Date: Tue, 7 Feb 2023 17:10:18 +0000 Subject: [PATCH 07/14] Made the requested changes --- .../fragments/detail/VideoDetailFragment.java | 8 +++--- .../gesture/MainPlayerGestureListener.kt | 8 +++--- app/src/main/res/values/settings_keys.xml | 25 ++++++++----------- 3 files changed, 19 insertions(+), 22 deletions(-) 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 885034e5a..e63e549a2 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,10 +2013,10 @@ public final class VideoDetailFragment restoreDefaultBrightness(); } else { // Do not restore if user has disabled brightness gesture - if (!(PlayerHelper.getRightSideGesture(activity) - .equals(getString(R.string.right_brightness_control_key)) - && PlayerHelper.getLeftSideGesture(activity) - .equals(getString(R.string.left_brightness_control_key)))) { + if (PlayerHelper.getRightSideGesture(activity) + .equals(getString(R.string.brightness_control_key)) + || PlayerHelper.getLeftSideGesture(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 82cf2244c..ce78fcfe2 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 @@ -198,16 +198,16 @@ class MainPlayerGestureListener( if (getDisplayHalfPortion(initialEvent) == DisplayPortion.RIGHT_HALF) { when (rightSide) { - player.context.getString(R.string.right_volume_control_key) -> + player.context.getString(R.string.volume_control_key) -> onScrollVolume(distanceY) - player.context.getString(R.string.right_brightness_control_key) -> + player.context.getString(R.string.brightness_control_key) -> onScrollBrightness(distanceY) } } else { when (leftSide) { - player.context.getString(R.string.left_volume_control_key) -> + player.context.getString(R.string.volume_control_key) -> onScrollVolume(distanceY) - player.context.getString(R.string.left_brightness_control_key) -> + player.context.getString(R.string.brightness_control_key) -> onScrollBrightness(distanceY) } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index ad6b1777b..8f3e8e192 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -191,35 +191,32 @@ left_gesture_control - @string/left_brightness_control_key - left_brightness_control - left_volume_control - left_none_control + @string/brightness_control_key + brightness_control + volume_control + none_control @string/brightness @string/volume @string/none - @string/left_brightness_control_key - @string/left_volume_control_key - @string/left_none_control_key + @string/brightness_control_key + @string/volume_control_key + @string/none_control_key right_gesture_control - @string/right_volume_control_key - right_brightness_control - right_volume_control - right_none_control + @string/volume_control_key @string/volume @string/brightness @string/none - @string/right_volume_control_key - @string/right_brightness_control_key - @string/right_none_control_key + @string/volume_control_key + @string/brightness_control_key + @string/none_control_key last_resize_mode From 32cec6c9a74efd65b58ebf504c646bb61a222961 Mon Sep 17 00:00:00 2001 From: ge78fug Date: Tue, 7 Feb 2023 19:08:47 +0100 Subject: [PATCH 08/14] Changed the naming --- .../newpipe/fragments/detail/VideoDetailFragment.java | 4 ++-- .../newpipe/player/gesture/MainPlayerGestureListener.kt | 7 ++----- .../org/schabi/newpipe/player/helper/PlayerHelper.java | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) 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 e63e549a2..7654e7689 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,9 +2013,9 @@ public final class VideoDetailFragment restoreDefaultBrightness(); } else { // Do not restore if user has disabled brightness gesture - if (PlayerHelper.getRightSideGesture(activity) + if (PlayerHelper.getActionForRightGestureSide(activity) .equals(getString(R.string.brightness_control_key)) - || PlayerHelper.getLeftSideGesture(activity) + || PlayerHelper.getActionForLeftGestureSide(activity) .equals(getString(R.string.brightness_control_key))) { return; } 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 ce78fcfe2..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,15 @@ class MainPlayerGestureListener( isMoving = true // -- Brightness and Volume control -- - val rightSide = PlayerHelper.getRightSideGesture(player.context) - val leftSide = PlayerHelper.getLeftSideGesture(player.context) - if (getDisplayHalfPortion(initialEvent) == DisplayPortion.RIGHT_HALF) { - when (rightSide) { + 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 (leftSide) { + when (PlayerHelper.getActionForLeftGestureSide(player.context)) { player.context.getString(R.string.volume_control_key) -> onScrollVolume(distanceY) player.context.getString(R.string.brightness_control_key) -> 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 74bcf047c..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,13 +228,13 @@ public final class PlayerHelper { .getBoolean(context.getString(R.string.resume_on_audio_focus_gain_key), false); } - public static String getRightSideGesture(@NonNull final Context context) { + public static String getActionForRightGestureSide(@NonNull final Context context) { return getPreferences(context) .getString(context.getString(R.string.right_gesture_control_key), context.getString(R.string.default_right_gesture_control_value)); } - public static String getLeftSideGesture(@NonNull final Context context) { + public static String getActionForLeftGestureSide(@NonNull final Context context) { return getPreferences(context) .getString(context.getString(R.string.left_gesture_control_key), context.getString(R.string.default_left_gesture_control_value)); From 65d8589e7a40c1d2d5fdbf66a4096e4de7030c15 Mon Sep 17 00:00:00 2001 From: ge78fug Date: Fri, 10 Feb 2023 08:41:54 +0100 Subject: [PATCH 09/14] Changed the naming --- app/src/main/res/values/strings.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6890e4dd0..43705056b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -101,10 +101,10 @@ Auto-enqueue next stream Continue ending (non-repeating) playback queue by appending a related stream Auto-enqueuing - Change the left gesture control - Left gesture control - Change the right gesture control - Right gesture control + 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 From 7689d1d15cb26ef31193aef4cf0b02f59db13374 Mon Sep 17 00:00:00 2001 From: ge78fug Date: Wed, 1 Mar 2023 23:22:30 +0100 Subject: [PATCH 10/14] Added the migration --- .../newpipe/settings/SettingMigrations.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) 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..21c0e1be4 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,39 @@ public final class SettingMigrations { } }; + public static final Migration MIGRATION_4_5 = new Migration(4, 5) { + @Override + protected void migrate(final Context context) { + boolean brightnessGestureSwitch = sp.getBoolean( + context.getString(R.string.left_gesture_control_key), false); + boolean volumeGestureSwitch = sp.getBoolean( + context.getString(R.string.right_gesture_control_key), false); + + SharedPreferences.Editor editor = sp.edit(); + + if (volumeGestureSwitch) { + if (!brightnessGestureSwitch) { + editor.putString(context.getString(R.string.left_gesture_control_key), + context.getString(R.string.brightness)); + } + editor.putString(context.getString(R.string.right_gesture_control_key), + context.getString(R.string.volume)); + } else if (brightnessGestureSwitch) { + editor.putString(context.getString(R.string.right_gesture_control_key), + context.getString(R.string.brightness)); + editor.putString(context.getString(R.string.left_gesture_control_key), + context.getString(R.string.volume)); + } else { + editor.putString(context.getString(R.string.left_gesture_control_key), + context.getString(R.string.none)); + editor.putString(context.getString(R.string.right_gesture_control_key), + context.getString(R.string.none)); + } + + editor.apply(); + } + }; + /** * List of all implemented migrations. *

@@ -119,12 +152,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) { From 3c72992c395fc1053c821ed8069bfedf40449ad3 Mon Sep 17 00:00:00 2001 From: Marius Wagner Date: Sun, 26 Feb 2023 17:00:06 +0100 Subject: [PATCH 11/14] Update app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java Co-authored-by: Stypox --- .../schabi/newpipe/fragments/detail/VideoDetailFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 7654e7689..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,9 +2013,9 @@ public final class VideoDetailFragment restoreDefaultBrightness(); } else { // Do not restore if user has disabled brightness gesture - if (PlayerHelper.getActionForRightGestureSide(activity) + if (!PlayerHelper.getActionForRightGestureSide(activity) .equals(getString(R.string.brightness_control_key)) - || PlayerHelper.getActionForLeftGestureSide(activity) + && !PlayerHelper.getActionForLeftGestureSide(activity) .equals(getString(R.string.brightness_control_key))) { return; } From d2735607b84a5fbe442302ec9464161faed5daa1 Mon Sep 17 00:00:00 2001 From: ge78fug Date: Mon, 3 Apr 2023 23:11:40 +0200 Subject: [PATCH 12/14] Changed the default of the switches --- .../java/org/schabi/newpipe/settings/SettingMigrations.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 21c0e1be4..e2bb18b2d 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java @@ -112,9 +112,9 @@ public final class SettingMigrations { @Override protected void migrate(final Context context) { boolean brightnessGestureSwitch = sp.getBoolean( - context.getString(R.string.left_gesture_control_key), false); + context.getString(R.string.left_gesture_control_key), true); boolean volumeGestureSwitch = sp.getBoolean( - context.getString(R.string.right_gesture_control_key), false); + context.getString(R.string.right_gesture_control_key), true); SharedPreferences.Editor editor = sp.edit(); From 704e9bd7b6e4d58d10b0cce349cd3f8a13e46b85 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 4 Apr 2023 10:02:01 +0200 Subject: [PATCH 13/14] Fix checkstyle --- .../java/org/schabi/newpipe/settings/SettingMigrations.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 e2bb18b2d..818d587d5 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java @@ -111,12 +111,12 @@ public final class SettingMigrations { public static final Migration MIGRATION_4_5 = new Migration(4, 5) { @Override protected void migrate(final Context context) { - boolean brightnessGestureSwitch = sp.getBoolean( + final boolean brightnessGestureSwitch = sp.getBoolean( context.getString(R.string.left_gesture_control_key), true); - boolean volumeGestureSwitch = sp.getBoolean( + final boolean volumeGestureSwitch = sp.getBoolean( context.getString(R.string.right_gesture_control_key), true); - SharedPreferences.Editor editor = sp.edit(); + final SharedPreferences.Editor editor = sp.edit(); if (volumeGestureSwitch) { if (!brightnessGestureSwitch) { From 4bb45c001de54d9734f7e3e1c7fbed75744b9c3e Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 4 Apr 2023 10:27:43 +0200 Subject: [PATCH 14/14] Fix settings migration --- .../newpipe/settings/SettingMigrations.java | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) 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 818d587d5..1bfaec6c2 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java @@ -111,31 +111,17 @@ public final class SettingMigrations { public static final Migration MIGRATION_4_5 = new Migration(4, 5) { @Override protected void migrate(final Context context) { - final boolean brightnessGestureSwitch = sp.getBoolean( - context.getString(R.string.left_gesture_control_key), true); - final boolean volumeGestureSwitch = sp.getBoolean( - context.getString(R.string.right_gesture_control_key), true); + final boolean brightness = sp.getBoolean("brightness_gesture_control", true); + final boolean volume = sp.getBoolean("volume_gesture_control", true); final SharedPreferences.Editor editor = sp.edit(); - if (volumeGestureSwitch) { - if (!brightnessGestureSwitch) { - editor.putString(context.getString(R.string.left_gesture_control_key), - context.getString(R.string.brightness)); - } - editor.putString(context.getString(R.string.right_gesture_control_key), - context.getString(R.string.volume)); - } else if (brightnessGestureSwitch) { - editor.putString(context.getString(R.string.right_gesture_control_key), - context.getString(R.string.brightness)); - editor.putString(context.getString(R.string.left_gesture_control_key), - context.getString(R.string.volume)); - } else { - editor.putString(context.getString(R.string.left_gesture_control_key), - context.getString(R.string.none)); - editor.putString(context.getString(R.string.right_gesture_control_key), - context.getString(R.string.none)); - } + 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(); }