Skip to content

feat(YouTube - Swipe controls): Add option to change volume swipe sensitivity #4557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ abstract class BaseGestureController(
controller.overlay,
10,
1,
controller.config.volumeSwipeSensitivity,
) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -49,6 +50,7 @@ class VolumeAndBrightnessScrollerImpl(
private val overlayController: SwipeControlsOverlay,
volumeDistance: Int = 10,
brightnessDistance: Int = 1,
private val volumeSwipeSensitivity: Int,
) : VolumeAndBrightnessScroller {

// region volume
Expand All @@ -60,7 +62,7 @@ class VolumeAndBrightnessScrollerImpl(
),
) { _, _, direction ->
volumeController?.run {
volume += direction
volume += direction * volumeSwipeSensitivity
overlayController.onVolumeChanged(volume, maxVolume)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions patches/src/main/resources/addresources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,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>
Expand Down