1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 00:20:32 +00:00

Updated the gesture-switch-toggle

This commit is contained in:
ge78fug 2023-01-21 17:11:45 +01:00 committed by Stypox
parent c8d54ec6c7
commit 2ba649949f
3 changed files with 24 additions and 22 deletions

View File

@ -197,8 +197,9 @@ class MainPlayerGestureListener(
val isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context) val isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context)
val isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context) val isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context)
val brightnessSide = if (PreferenceManager.getDefaultSharedPreferences(player.context) val brightnessSide = if (PreferenceManager.getDefaultSharedPreferences(player.context)
.getBoolean(R.string.switch_gesture_sides_key.toString(), false)) DisplayPortion.RIGHT_HALF .getBoolean(R.string.switch_gesture_sides_key.toString(), false)
else DisplayPortion.LEFT_HALF ) DisplayPortion.RIGHT_HALF
else DisplayPortion.LEFT_HALF
if (isBrightnessGestureEnabled && isVolumeGestureEnabled) { if (isBrightnessGestureEnabled && isVolumeGestureEnabled) {
if (getDisplayHalfPortion(initialEvent) === brightnessSide) { if (getDisplayHalfPortion(initialEvent) === brightnessSide) {
onScrollBrightness(distanceY) onScrollBrightness(distanceY)

View File

@ -6,12 +6,10 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.SwitchPreferenceCompat;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -24,31 +22,15 @@ import java.util.List;
public class VideoAudioSettingsFragment extends BasePreferenceFragment { public class VideoAudioSettingsFragment extends BasePreferenceFragment {
private SharedPreferences.OnSharedPreferenceChangeListener listener; 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 @Override
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
addPreferencesFromResourceRegistry(); addPreferencesFromResourceRegistry();
updateSeekOptions(); updateSeekOptions();
updateGestureSwitch();
listener = (sharedPreferences, key) -> { 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 // 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, // and the app doesn't have display over other apps permission,
// show a snackbar to let the user give 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)) { } else if (getString(R.string.use_inexact_seek_key).equals(key)) {
updateSeekOptions(); 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() getPreferenceManager().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(listener); .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));
}
}
} }

View File

@ -107,6 +107,7 @@
<string name="brightness_gesture_control_summary">Use gestures to control player brightness</string> <string name="brightness_gesture_control_summary">Use gestures to control player brightness</string>
<string name="switch_gesture_sides_title">Switch gesture sides</string> <string name="switch_gesture_sides_title">Switch gesture sides</string>
<string name="switch_gesture_sides_summary">Switches the sides of the volume and brightness gesture controls</string> <string name="switch_gesture_sides_summary">Switches the sides of the volume and brightness gesture controls</string>
<string name="switch_gesture_sides_summary_disabled">Enable both brightness and volume gestures to use this feature</string>
<string name="show_search_suggestions_title">Search suggestions</string> <string name="show_search_suggestions_title">Search suggestions</string>
<string name="show_search_suggestions_summary">Choose the suggestions to show when searching</string> <string name="show_search_suggestions_summary">Choose the suggestions to show when searching</string>
<string name="local_search_suggestions">Local search suggestions</string> <string name="local_search_suggestions">Local search suggestions</string>