Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
feat(YouTube - Swipe controls): Add Swipe sensitivity settings
Browse files Browse the repository at this point in the history
  • Loading branch information
anddea committed Oct 23, 2024
1 parent 0d93d8e commit 23958f4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ public class Settings extends BaseSettings {
public static final IntegerSetting SWIPE_OVERLAY_RECT_SIZE = new IntegerSetting("revanced_swipe_overlay_rect_size", 20, true, parentsAny(ENABLE_SWIPE_BRIGHTNESS, ENABLE_SWIPE_VOLUME));
public static final LongSetting SWIPE_OVERLAY_TIMEOUT = new LongSetting("revanced_swipe_overlay_timeout", 500L, true, parentsAny(ENABLE_SWIPE_BRIGHTNESS, ENABLE_SWIPE_VOLUME));

public static final IntegerSetting SWIPE_BRIGHTNESS_SENSITIVITY = new IntegerSetting("revanced_swipe_brightness_sensitivity", 100, true, parent(ENABLE_SWIPE_BRIGHTNESS));
public static final IntegerSetting SWIPE_VOLUME_SENSITIVITY = new IntegerSetting("revanced_swipe_volume_sensitivity", 100, true, parent(ENABLE_SWIPE_VOLUME));
/**
* @noinspection DeprecatedIsStillUsed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.graphics.Color
import app.revanced.integrations.youtube.settings.Settings
import app.revanced.integrations.youtube.shared.LockModeState
import app.revanced.integrations.youtube.shared.PlayerType
import app.revanced.integrations.youtube.utils.ExtendedUtils.validateValue

/**
* provider for configuration for volume and brightness swipe controls
Expand Down Expand Up @@ -76,6 +77,28 @@ class SwipeControlsConfigurationProvider(
val swipeMagnitudeThreshold: Int
get() = Settings.SWIPE_MAGNITUDE_THRESHOLD.get()

/**
* swipe distances for brightness
*/
val brightnessDistance: Float
get() = validateValue(
Settings.SWIPE_BRIGHTNESS_SENSITIVITY,
1,
1000,
"revanced_swipe_brightness_sensitivity_invalid_toast"
).toFloat() / 100 // 1f

/**
* swipe distances for volume
*/
val volumeDistance: Float
get() = validateValue(
Settings.SWIPE_VOLUME_SENSITIVITY,
1,
1000,
"revanced_swipe_volume_sensitivity_invalid_toast"
).toFloat() / 100 * 10 // 10f

// endregion

// region overlay adjustments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ abstract class BaseGestureController(
controller.audio,
controller.screen,
controller.overlay,
10,
1,
controller.config.volumeDistance,
controller.config.brightnessDistance,
) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class VolumeAndBrightnessScrollerImpl(
private val volumeController: AudioVolumeController?,
private val screenController: ScreenBrightnessController?,
private val overlayController: SwipeControlsOverlay,
volumeDistance: Int = 10,
brightnessDistance: Int = 1,
volumeDistance: Float = 10.0f,
brightnessDistance: Float = 1.0f,
) : VolumeAndBrightnessScroller {

// region volume
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlin.math.sign
* @param callback callback function for when unit distance is reached
*/
class ScrollDistanceHelper(
private val unitDistance: Int,
private val unitDistance: Double,
private val callback: (oldDistance: Double, newDistance: Double, direction: Int) -> Unit,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ fun Int.applyDimension(context: Context, unit: Int): Int {
context.resources.displayMetrics,
).roundToInt()
}

fun Float.applyDimension(context: Context, unit: Int): Double {
return TypedValue.applyDimension(
unit,
this,
context.resources.displayMetrics,
).toDouble()
}

0 comments on commit 23958f4

Please sign in to comment.