diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java index 765f03f9a..dfaac87b9 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -294,8 +294,9 @@ public class Settings extends BaseSettings { public static final BooleanSetting DEBUG_PROTOBUFFER = new BooleanSetting("revanced_debug_protobuffer", FALSE, parent(BaseSettings.DEBUG)); // Swipe controls - public static final BooleanSetting SWIPE_BRIGHTNESS = new BooleanSetting("revanced_swipe_brightness", TRUE); - public static final BooleanSetting SWIPE_VOLUME = new BooleanSetting("revanced_swipe_volume", TRUE); + public static final BooleanSetting SWIPE_CHANGE_VIDEO = new BooleanSetting("revanced_swipe_change_video", FALSE, true); + public static final BooleanSetting SWIPE_BRIGHTNESS = new BooleanSetting("revanced_swipe_brightness", FALSE); + public static final BooleanSetting SWIPE_VOLUME = new BooleanSetting("revanced_swipe_volume", FALSE); public static final BooleanSetting SWIPE_PRESS_TO_ENGAGE = new BooleanSetting("revanced_swipe_press_to_engage", FALSE, true, parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME)); public static final BooleanSetting SWIPE_HAPTIC_FEEDBACK = new BooleanSetting("revanced_swipe_haptic_feedback", TRUE, true, diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/swipecontrols/SwipeControlsHostActivity.kt b/extensions/youtube/src/main/java/app/revanced/extension/youtube/swipecontrols/SwipeControlsHostActivity.kt index afb55d74b..c889c6d4c 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/swipecontrols/SwipeControlsHostActivity.kt +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/swipecontrols/SwipeControlsHostActivity.kt @@ -8,6 +8,7 @@ import android.view.MotionEvent import android.view.ViewGroup import app.revanced.extension.shared.Logger.printDebug import app.revanced.extension.shared.Logger.printException +import app.revanced.extension.youtube.settings.Settings import app.revanced.extension.youtube.shared.PlayerType import app.revanced.extension.youtube.swipecontrols.controller.AudioVolumeController import app.revanced.extension.youtube.swipecontrols.controller.ScreenBrightnessController @@ -232,5 +233,12 @@ class SwipeControlsHostActivity : Activity() { @JvmStatic var currentHost: WeakReference = WeakReference(null) private set + + /** + * Injection point. + */ + @Suppress("unused") + @JvmStatic + fun allowSwipeChangeVideo(original: Boolean): Boolean = Settings.SWIPE_CHANGE_VIDEO.get() } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/Fingerprints.kt index 0a31f1c30..e1161ea13 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/Fingerprints.kt @@ -1,12 +1,23 @@ package app.revanced.patches.youtube.interaction.swipecontrols import app.revanced.patcher.fingerprint +import app.revanced.util.literal import com.android.tools.smali.dexlib2.AccessFlags internal val swipeControlsHostActivityFingerprint = fingerprint { accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR) parameters() custom { method, _ -> - method.definingClass == "Lapp/revanced/extension/youtube/swipecontrols/SwipeControlsHostActivity;" + method.definingClass == EXTENSION_CLASS_DESCRIPTOR + } +} + +internal const val SWIPE_CHANGE_VIDEO_FEATURE_FLAG = 45631116L + +internal val swipeChangeVideoFingerprint = fingerprint { + accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR) + parameters("L") + literal { + SWIPE_CHANGE_VIDEO_FEATURE_FLAG } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/SwipeControlsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/SwipeControlsPatch.kt index 5d03b66be..ce9b537ed 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/SwipeControlsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/SwipeControlsPatch.kt @@ -10,6 +10,8 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.shared.misc.settings.preference.TextPreference import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.playertype.playerTypeHookPatch +import app.revanced.patches.youtube.misc.playservice.is_19_23_or_greater +import app.revanced.patches.youtube.misc.playservice.is_19_25_or_greater import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.patches.youtube.shared.mainActivityFingerprint @@ -17,6 +19,8 @@ import app.revanced.util.* import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.immutable.ImmutableMethod +internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/swipecontrols/SwipeControlsHostActivity;" + private val swipeControlsResourcePatch = resourcePatch { dependsOn( settingsPatch, @@ -26,6 +30,12 @@ private val swipeControlsResourcePatch = resourcePatch { execute { addResources("youtube", "interaction.swipecontrols.swipeControlsResourcePatch") + if (is_19_25_or_greater) { + PreferenceScreen.SWIPE_CONTROLS.addPreferences( + SwitchPreference("revanced_swipe_change_video") + ) + } + PreferenceScreen.SWIPE_CONTROLS.addPreferences( SwitchPreference("revanced_swipe_brightness"), SwitchPreference("revanced_swipe_volume"), @@ -101,5 +111,16 @@ val swipeControlsPatch = bytecodePatch( ).toMutable() } } + + // region patch to enable/disable swipe to change video. + + if (is_19_23_or_greater) { + swipeChangeVideoFingerprint.method.insertFeatureFlagBooleanOverride( + SWIPE_CHANGE_VIDEO_FEATURE_FLAG, + "$EXTENSION_CLASS_DESCRIPTOR->allowSwipeChangeVideo(Z)Z" + ) + } + + // endregion } } diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml index 83737d8c1..edd2222c2 100644 --- a/patches/src/main/resources/addresources/values/strings.xml +++ b/patches/src/main/resources/addresources/values/strings.xml @@ -449,6 +449,9 @@ This feature is only available for older devices" The visibility of swipe overlay background Swipe magnitude threshold The amount of threshold for swipe to occur + Enable swipe to change videos + Swiping in fullscreen mode will change to the next/previous video + Swiping in fullscreen mode will not change to the next/previous video Disable auto captions