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

Made two list options

This commit is contained in:
ge78fug 2023-01-29 19:23:39 +01:00 committed by Stypox
parent 759a9080a8
commit 2ded8c7cc1
7 changed files with 79 additions and 70 deletions

View File

@ -2013,7 +2013,10 @@ public final class VideoDetailFragment
restoreDefaultBrightness(); restoreDefaultBrightness();
} else { } else {
// Do not restore if user has disabled brightness gesture // 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; return;
} }
// Restore already saved brightness level // Restore already saved brightness level

View File

@ -9,7 +9,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.content.res.AppCompatResources
import androidx.core.math.MathUtils import androidx.core.math.MathUtils
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.preference.PreferenceManager
import org.schabi.newpipe.MainActivity import org.schabi.newpipe.MainActivity
import org.schabi.newpipe.R import org.schabi.newpipe.R
import org.schabi.newpipe.ktx.AnimationType import org.schabi.newpipe.ktx.AnimationType
@ -194,23 +193,23 @@ class MainPlayerGestureListener(
isMoving = true isMoving = true
// -- Brightness and Volume control -- // -- Brightness and Volume control --
val isBrightnessGestureEnabled = PlayerHelper.isBrightnessGestureEnabled(player.context) val rightSide = PlayerHelper.getRightSideGesture(player.context)
val isVolumeGestureEnabled = PlayerHelper.isVolumeGestureEnabled(player.context) val leftSide = PlayerHelper.getLeftSideGesture(player.context)
val brightnessSide = if (PreferenceManager.getDefaultSharedPreferences(player.context)
.getBoolean( if (getDisplayHalfPortion(initialEvent) == DisplayPortion.RIGHT_HALF) {
player.context.getString(R.string.switch_gesture_sides_key), false)) when (rightSide) {
DisplayPortion.RIGHT_HALF player.context.getString(R.string.right_volume_control_key) ->
else DisplayPortion.LEFT_HALF
if (isBrightnessGestureEnabled && isVolumeGestureEnabled) {
if (getDisplayHalfPortion(initialEvent) == brightnessSide) {
onScrollBrightness(distanceY)
} else /* DisplayPortion.RIGHT_HALF */ {
onScrollVolume(distanceY) onScrollVolume(distanceY)
player.context.getString(R.string.right_brightness_control_key) ->
onScrollBrightness(distanceY)
} }
} else if (isBrightnessGestureEnabled) { } else {
onScrollBrightness(distanceY) when (leftSide) {
} else if (isVolumeGestureEnabled) { player.context.getString(R.string.left_volume_control_key) ->
onScrollVolume(distanceY) onScrollVolume(distanceY)
player.context.getString(R.string.left_brightness_control_key) ->
onScrollBrightness(distanceY)
}
} }
return true return true

View File

@ -228,14 +228,16 @@ public final class PlayerHelper {
.getBoolean(context.getString(R.string.resume_on_audio_focus_gain_key), false); .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) 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) 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) { public static boolean isStartMainPlayerFullscreenEnabled(@NonNull final Context context) {

View File

@ -9,7 +9,6 @@ import android.text.format.DateUtils;
import android.widget.Toast; import android.widget.Toast;
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;
@ -27,7 +26,6 @@ public class VideoAudioSettingsFragment extends BasePreferenceFragment {
addPreferencesFromResourceRegistry(); addPreferencesFromResourceRegistry();
updateSeekOptions(); updateSeekOptions();
updateGestureSwitch();
listener = (sharedPreferences, key) -> { listener = (sharedPreferences, key) -> {
@ -50,9 +48,6 @@ 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();
} }
}; };
} }
@ -122,19 +117,4 @@ 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

@ -16,9 +16,6 @@
<string name="use_external_video_player_key">use_external_video_player</string> <string name="use_external_video_player_key">use_external_video_player</string>
<string name="use_external_audio_player_key">use_external_audio_player</string> <string name="use_external_audio_player_key">use_external_audio_player</string>
<string name="volume_gesture_control_key">volume_gesture_control</string>
<string name="brightness_gesture_control_key">brightness_gesture_control</string>
<string name="switch_gesture_sides_key">switch_gesture_sides</string>
<string name="resume_on_audio_focus_gain_key">resume_on_audio_focus_gain</string> <string name="resume_on_audio_focus_gain_key">resume_on_audio_focus_gain</string>
<string name="popup_remember_size_pos_key">popup_remember_size_pos_key</string> <string name="popup_remember_size_pos_key">popup_remember_size_pos_key</string>
<string name="use_inexact_seek_key">use_inexact_seek_key</string> <string name="use_inexact_seek_key">use_inexact_seek_key</string>
@ -193,6 +190,38 @@
<item>@string/audio_webm_key</item> <item>@string/audio_webm_key</item>
</string-array> </string-array>
<string name="left_gesture_control_key">left_gesture_control</string>
<string name="default_left_gesture_control_value">@string/left_brightness_control_key</string>
<string name="left_brightness_control_key">left_brightness_control</string>
<string name="left_volume_control_key">left_volume_control</string>
<string name="left_none_control_key">left_none_control</string>
<string-array name="left_gesture_control_description">
<item>@string/brightness</item>
<item>@string/volume</item>
<item>@string/none</item>
</string-array>
<string-array name="left_gesture_control_values">
<item>@string/left_brightness_control_key</item>
<item>@string/left_volume_control_key</item>
<item>@string/left_none_control_key</item>
</string-array>
<string name="right_gesture_control_key">right_gesture_control</string>
<string name="default_right_gesture_control_value">@string/right_volume_control_key</string>
<string name="right_brightness_control_key">right_brightness_control</string>
<string name="right_volume_control_key">right_volume_control</string>
<string name="right_none_control_key">right_none_control</string>
<string-array name="right_gesture_control_description">
<item>@string/volume</item>
<item>@string/brightness</item>
<item>@string/none</item>
</string-array>
<string-array name="right_gesture_control_values">
<item>@string/right_volume_control_key</item>
<item>@string/right_brightness_control_key</item>
<item>@string/right_none_control_key</item>
</string-array>
<string name="last_resize_mode">last_resize_mode</string> <string name="last_resize_mode">last_resize_mode</string>
<!-- DEBUG ONLY --> <!-- DEBUG ONLY -->

View File

@ -101,13 +101,13 @@
<string name="auto_queue_title">Auto-enqueue next stream</string> <string name="auto_queue_title">Auto-enqueue next stream</string>
<string name="auto_queue_summary">Continue ending (non-repeating) playback queue by appending a related stream</string> <string name="auto_queue_summary">Continue ending (non-repeating) playback queue by appending a related stream</string>
<string name="auto_queue_toggle">Auto-enqueuing</string> <string name="auto_queue_toggle">Auto-enqueuing</string>
<string name="volume_gesture_control_title">Volume gesture control</string> <string name="left_gesture_control_summary">Change the left gesture control</string>
<string name="volume_gesture_control_summary">Use gestures to control player volume</string> <string name="left_gesture_control_title">Left gesture control</string>
<string name="brightness_gesture_control_title">Brightness gesture control</string> <string name="right_gesture_control_summary">Change the right gesture control</string>
<string name="brightness_gesture_control_summary">Use gestures to control player brightness</string> <string name="right_gesture_control_title">Right gesture control</string>
<string name="switch_gesture_sides_title">Switch gesture sides</string> <string name="brightness">Brightness</string>
<string name="switch_gesture_sides_summary">Switches the sides of the volume and brightness gesture controls</string> <string name="volume">Volume</string>
<string name="switch_gesture_sides_summary_disabled">Enable both brightness and volume gestures to use this feature</string> <string name="none">None</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>

View File

@ -174,27 +174,23 @@
app:singleLineTitle="false" app:singleLineTitle="false"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat <ListPreference
android:defaultValue="true" android:defaultValue="@string/default_left_gesture_control_value"
android:key="@string/volume_gesture_control_key" android:entries="@array/left_gesture_control_description"
android:summary="@string/volume_gesture_control_summary" android:entryValues="@array/left_gesture_control_values"
android:title="@string/volume_gesture_control_title" android:key="@string/left_gesture_control_key"
android:summary="@string/left_gesture_control_summary"
android:title="@string/left_gesture_control_title"
app:singleLineTitle="false" app:singleLineTitle="false"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreferenceCompat <ListPreference
android:defaultValue="true" android:defaultValue="@string/default_right_gesture_control_value"
android:key="@string/brightness_gesture_control_key" android:entries="@array/right_gesture_control_description"
android:summary="@string/brightness_gesture_control_summary" android:entryValues="@array/right_gesture_control_values"
android:title="@string/brightness_gesture_control_title" android:key="@string/right_gesture_control_key"
app:singleLineTitle="false" android:summary="@string/right_gesture_control_summary"
app:iconSpaceReserved="false" /> android:title="@string/right_gesture_control_title"
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/switch_gesture_sides_key"
android:summary="@string/switch_gesture_sides_summary"
android:title="@string/switch_gesture_sides_title"
app:singleLineTitle="false" app:singleLineTitle="false"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />