mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-04-29 14:14:28 +02:00
feat(YouTube - Swipe controls): Add option to change volume swipe sensitivity (step size) (#4557)
Co-authored-by: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
This commit is contained in:
parent
aba6a6b5c5
commit
8957325d78
@ -319,6 +319,7 @@ public class Settings extends BaseSettings {
|
||||
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
|
||||
public static final IntegerSetting SWIPE_MAGNITUDE_THRESHOLD = new IntegerSetting("revanced_swipe_threshold", 30, true,
|
||||
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
|
||||
public static final IntegerSetting SWIPE_VOLUME_SENSITIVITY = new IntegerSetting("revanced_swipe_volume_sensitivity", 1, true, parent(SWIPE_VOLUME));
|
||||
public static final BooleanSetting SWIPE_SHOW_CIRCULAR_OVERLAY = new BooleanSetting("revanced_swipe_show_circular_overlay", FALSE, true,
|
||||
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
|
||||
public static final BooleanSetting SWIPE_OVERLAY_MINIMAL_STYLE = new BooleanSetting("revanced_swipe_overlay_minimal_style", FALSE, true,
|
||||
|
@ -1,6 +1,5 @@
|
||||
package app.revanced.extension.youtube.swipecontrols
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import app.revanced.extension.shared.StringRef.str
|
||||
import app.revanced.extension.shared.Utils
|
||||
@ -9,12 +8,8 @@ import app.revanced.extension.youtube.shared.PlayerType
|
||||
|
||||
/**
|
||||
* provider for configuration for volume and brightness swipe controls
|
||||
*
|
||||
* @param context the context to create in
|
||||
*/
|
||||
class SwipeControlsConfigurationProvider(
|
||||
private val context: Context,
|
||||
) {
|
||||
class SwipeControlsConfigurationProvider {
|
||||
//region swipe enable
|
||||
/**
|
||||
* should swipe controls be enabled? (global setting)
|
||||
@ -60,6 +55,23 @@ class SwipeControlsConfigurationProvider(
|
||||
*/
|
||||
val swipeMagnitudeThreshold: Int
|
||||
get() = Settings.SWIPE_MAGNITUDE_THRESHOLD.get()
|
||||
|
||||
/**
|
||||
* How much volume will change by single swipe.
|
||||
* If it is set to 0, it will reset to the default value because 0 would disable swiping.
|
||||
* */
|
||||
val volumeSwipeSensitivity: Int
|
||||
get() {
|
||||
val sensitivity = Settings.SWIPE_VOLUME_SENSITIVITY.get()
|
||||
|
||||
if (sensitivity < 1) {
|
||||
Settings.SWIPE_VOLUME_SENSITIVITY.resetToDefault()
|
||||
|
||||
return Settings.SWIPE_VOLUME_SENSITIVITY.get()
|
||||
}
|
||||
|
||||
return sensitivity
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region overlay adjustments
|
||||
|
@ -127,7 +127,7 @@ class SwipeControlsHostActivity : Activity() {
|
||||
private fun initialize() {
|
||||
// create controllers
|
||||
printDebug { "initializing swipe controls controllers" }
|
||||
config = SwipeControlsConfigurationProvider(this)
|
||||
config = SwipeControlsConfigurationProvider()
|
||||
keys = VolumeKeysController(this)
|
||||
audio = createAudioController()
|
||||
screen = createScreenController()
|
||||
|
@ -41,7 +41,7 @@ class VolumeKeysController(
|
||||
private fun handleVolumeKeyEvent(event: KeyEvent, volumeUp: Boolean): Boolean {
|
||||
if (event.action == KeyEvent.ACTION_DOWN) {
|
||||
controller.audio?.apply {
|
||||
volume += if (volumeUp) 1 else -1
|
||||
volume += controller.config.volumeSwipeSensitivity * if (volumeUp) 1 else -1
|
||||
controller.overlay.onVolumeChanged(volume, maxVolume)
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ abstract class BaseGestureController(
|
||||
controller.overlay,
|
||||
10,
|
||||
1,
|
||||
controller.config.volumeSwipeSensitivity,
|
||||
) {
|
||||
|
||||
/**
|
||||
|
@ -41,6 +41,7 @@ interface VolumeAndBrightnessScroller {
|
||||
* @param overlayController overlay controller instance
|
||||
* @param volumeDistance unit distance for volume scrolling, in dp
|
||||
* @param brightnessDistance unit distance for brightness scrolling, in dp
|
||||
* @param volumeSwipeSensitivity how much volume will change by single swipe
|
||||
*/
|
||||
class VolumeAndBrightnessScrollerImpl(
|
||||
context: Context,
|
||||
@ -49,6 +50,7 @@ class VolumeAndBrightnessScrollerImpl(
|
||||
private val overlayController: SwipeControlsOverlay,
|
||||
volumeDistance: Int = 10,
|
||||
brightnessDistance: Int = 1,
|
||||
private val volumeSwipeSensitivity: Int,
|
||||
) : VolumeAndBrightnessScroller {
|
||||
|
||||
// region volume
|
||||
@ -60,7 +62,7 @@ class VolumeAndBrightnessScrollerImpl(
|
||||
),
|
||||
) { _, _, direction ->
|
||||
volumeController?.run {
|
||||
volume += direction
|
||||
volume += direction * volumeSwipeSensitivity
|
||||
overlayController.onVolumeChanged(volume, maxVolume)
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class SwipeControlsOverlayLayout(
|
||||
private val config: SwipeControlsConfigurationProvider,
|
||||
) : RelativeLayout(context), SwipeControlsOverlay {
|
||||
|
||||
constructor(context: Context) : this(context, SwipeControlsConfigurationProvider(context))
|
||||
constructor(context: Context) : this(context, SwipeControlsConfigurationProvider())
|
||||
|
||||
// Drawable icons for brightness and volume
|
||||
private val autoBrightnessIcon: Drawable = getDrawable("revanced_ic_sc_brightness_auto")
|
||||
|
@ -47,6 +47,7 @@ private val swipeControlsResourcePatch = resourcePatch {
|
||||
TextPreference("revanced_swipe_overlay_background_opacity", inputType = InputType.NUMBER),
|
||||
TextPreference("revanced_swipe_overlay_timeout", inputType = InputType.NUMBER),
|
||||
TextPreference("revanced_swipe_threshold", inputType = InputType.NUMBER),
|
||||
TextPreference("revanced_swipe_volume_sensitivity", inputType = InputType.NUMBER),
|
||||
)
|
||||
|
||||
copyResources(
|
||||
|
@ -527,6 +527,8 @@ Adjust volume by swiping vertically on the right side of the screen"</string>
|
||||
<string name="revanced_swipe_overlay_background_opacity_invalid_toast">Swipe opacity must be between 0-100</string>
|
||||
<string name="revanced_swipe_threshold_title">Swipe magnitude threshold</string>
|
||||
<string name="revanced_swipe_threshold_summary">The amount of threshold for swipe to occur</string>
|
||||
<string name="revanced_swipe_volume_sensitivity_title">Volume swipe sensitivity</string>
|
||||
<string name="revanced_swipe_volume_sensitivity_summary">How much the volume changes per swipe</string>
|
||||
<string name="revanced_swipe_show_circular_overlay_title">Show circular overlay</string>
|
||||
<string name="revanced_swipe_show_circular_overlay_summary_on">Circular overlay is shown</string>
|
||||
<string name="revanced_swipe_show_circular_overlay_summary_off">Horizontal overlay is shown</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user