1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-24 20:15:16 +01: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 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)

View File

@ -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));
}
}
}

View File

@ -107,6 +107,7 @@
<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_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_summary">Choose the suggestions to show when searching</string>
<string name="local_search_suggestions">Local search suggestions</string>