From 2ded8c7cc18b7414d244e0e559acd3a1e9d7259f Mon Sep 17 00:00:00 2001 From: ge78fug Date: Sun, 29 Jan 2023 19:23:39 +0100 Subject: [PATCH] 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" /> - - - -