Skip to content

Commit 119092f

Browse files
feat(Swipe controls): Add option to enable/disable fullscreen swipe to next video (ReVanced#4222)
1 parent d6e389c commit 119092f

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed

extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,9 @@ public class Settings extends BaseSettings {
294294
public static final BooleanSetting DEBUG_PROTOBUFFER = new BooleanSetting("revanced_debug_protobuffer", FALSE, parent(BaseSettings.DEBUG));
295295

296296
// Swipe controls
297-
public static final BooleanSetting SWIPE_BRIGHTNESS = new BooleanSetting("revanced_swipe_brightness", TRUE);
298-
public static final BooleanSetting SWIPE_VOLUME = new BooleanSetting("revanced_swipe_volume", TRUE);
297+
public static final BooleanSetting SWIPE_CHANGE_VIDEO = new BooleanSetting("revanced_swipe_change_video", FALSE, true);
298+
public static final BooleanSetting SWIPE_BRIGHTNESS = new BooleanSetting("revanced_swipe_brightness", FALSE);
299+
public static final BooleanSetting SWIPE_VOLUME = new BooleanSetting("revanced_swipe_volume", FALSE);
299300
public static final BooleanSetting SWIPE_PRESS_TO_ENGAGE = new BooleanSetting("revanced_swipe_press_to_engage", FALSE, true,
300301
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
301302
public static final BooleanSetting SWIPE_HAPTIC_FEEDBACK = new BooleanSetting("revanced_swipe_haptic_feedback", TRUE, true,

extensions/youtube/src/main/java/app/revanced/extension/youtube/swipecontrols/SwipeControlsHostActivity.kt

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.view.MotionEvent
88
import android.view.ViewGroup
99
import app.revanced.extension.shared.Logger.printDebug
1010
import app.revanced.extension.shared.Logger.printException
11+
import app.revanced.extension.youtube.settings.Settings
1112
import app.revanced.extension.youtube.shared.PlayerType
1213
import app.revanced.extension.youtube.swipecontrols.controller.AudioVolumeController
1314
import app.revanced.extension.youtube.swipecontrols.controller.ScreenBrightnessController
@@ -232,5 +233,12 @@ class SwipeControlsHostActivity : Activity() {
232233
@JvmStatic
233234
var currentHost: WeakReference<SwipeControlsHostActivity> = WeakReference(null)
234235
private set
236+
237+
/**
238+
* Injection point.
239+
*/
240+
@Suppress("unused")
241+
@JvmStatic
242+
fun allowSwipeChangeVideo(original: Boolean): Boolean = Settings.SWIPE_CHANGE_VIDEO.get()
235243
}
236244
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
package app.revanced.patches.youtube.interaction.swipecontrols
22

33
import app.revanced.patcher.fingerprint
4+
import app.revanced.util.literal
45
import com.android.tools.smali.dexlib2.AccessFlags
56

67
internal val swipeControlsHostActivityFingerprint = fingerprint {
78
accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR)
89
parameters()
910
custom { method, _ ->
10-
method.definingClass == "Lapp/revanced/extension/youtube/swipecontrols/SwipeControlsHostActivity;"
11+
method.definingClass == EXTENSION_CLASS_DESCRIPTOR
12+
}
13+
}
14+
15+
internal const val SWIPE_CHANGE_VIDEO_FEATURE_FLAG = 45631116L
16+
17+
internal val swipeChangeVideoFingerprint = fingerprint {
18+
accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR)
19+
parameters("L")
20+
literal {
21+
SWIPE_CHANGE_VIDEO_FEATURE_FLAG
1122
}
1223
}

patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/SwipeControlsPatch.kt

+21
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
1010
import app.revanced.patches.shared.misc.settings.preference.TextPreference
1111
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
1212
import app.revanced.patches.youtube.misc.playertype.playerTypeHookPatch
13+
import app.revanced.patches.youtube.misc.playservice.is_19_23_or_greater
14+
import app.revanced.patches.youtube.misc.playservice.is_19_25_or_greater
1315
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
1416
import app.revanced.patches.youtube.misc.settings.settingsPatch
1517
import app.revanced.patches.youtube.shared.mainActivityFingerprint
1618
import app.revanced.util.*
1719
import com.android.tools.smali.dexlib2.AccessFlags
1820
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
1921

22+
internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/swipecontrols/SwipeControlsHostActivity;"
23+
2024
private val swipeControlsResourcePatch = resourcePatch {
2125
dependsOn(
2226
settingsPatch,
@@ -26,6 +30,12 @@ private val swipeControlsResourcePatch = resourcePatch {
2630
execute {
2731
addResources("youtube", "interaction.swipecontrols.swipeControlsResourcePatch")
2832

33+
if (is_19_25_or_greater) {
34+
PreferenceScreen.SWIPE_CONTROLS.addPreferences(
35+
SwitchPreference("revanced_swipe_change_video")
36+
)
37+
}
38+
2939
PreferenceScreen.SWIPE_CONTROLS.addPreferences(
3040
SwitchPreference("revanced_swipe_brightness"),
3141
SwitchPreference("revanced_swipe_volume"),
@@ -101,5 +111,16 @@ val swipeControlsPatch = bytecodePatch(
101111
).toMutable()
102112
}
103113
}
114+
115+
// region patch to enable/disable swipe to change video.
116+
117+
if (is_19_23_or_greater) {
118+
swipeChangeVideoFingerprint.method.insertFeatureFlagBooleanOverride(
119+
SWIPE_CHANGE_VIDEO_FEATURE_FLAG,
120+
"$EXTENSION_CLASS_DESCRIPTOR->allowSwipeChangeVideo(Z)Z"
121+
)
122+
}
123+
124+
// endregion
104125
}
105126
}

patches/src/main/resources/addresources/values/strings.xml

+3
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ This feature is only available for older devices"</string>
449449
<string name="revanced_swipe_overlay_background_alpha_summary">The visibility of swipe overlay background</string>
450450
<string name="revanced_swipe_threshold_title">Swipe magnitude threshold</string>
451451
<string name="revanced_swipe_threshold_summary">The amount of threshold for swipe to occur</string>
452+
<string name="revanced_swipe_change_video_title">Enable swipe to change videos</string>
453+
<string name="revanced_swipe_change_video_summary_on">Swiping in fullscreen mode will change to the next/previous video</string>
454+
<string name="revanced_swipe_change_video_summary_off">Swiping in fullscreen mode will not change to the next/previous video</string>
452455
</patch>
453456
<patch id="layout.autocaptions.autoCaptionsPatch">
454457
<string name="revanced_auto_captions_title">Disable auto captions</string>

0 commit comments

Comments
 (0)