From 2ba649949fbb6968706dfa5e3058ad7a4fbfcf7e Mon Sep 17 00:00:00 2001 From: ge78fug Date: Sat, 21 Jan 2023 17:11:45 +0100 Subject: [PATCH] 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