Skip to content

Commit

Permalink
feat(Swipe controls): Add option to disable fullscreen swipe to next/…
Browse files Browse the repository at this point in the history
…previous video
  • Loading branch information
LisoUseInAIKyrios committed Dec 26, 2024
1 parent 4bc666c commit 1e022b8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public class Settings extends BaseSettings {
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
public static final IntegerSetting SWIPE_OVERLAY_BACKGROUND_ALPHA = new IntegerSetting("revanced_swipe_overlay_background_alpha", 127, true,
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
public static final BooleanSetting SWIPE_TO_CHANGE_VIDEO = new BooleanSetting("revanced_swipe_to_change_video", FALSE, true);

// Debugging
public static final IntegerSetting SWIPE_OVERLAY_TEXT_SIZE = new IntegerSetting("revanced_swipe_text_overlay_size", 22, true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -232,5 +233,12 @@ class SwipeControlsHostActivity : Activity() {
@JvmStatic
var currentHost: WeakReference<SwipeControlsHostActivity> = WeakReference(null)
private set

/**
* Injection point.
*/
@Suppress("unused")
@JvmStatic
fun allowSwipeToChangeVideo(original: Boolean): Boolean = Settings.SWIPE_TO_CHANGE_VIDEO.get()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 {
Expand All @@ -10,3 +11,13 @@ internal val swipeControlsHostActivityFingerprint = fingerprint {
method.definingClass == "Lapp/revanced/extension/youtube/swipecontrols/SwipeControlsHostActivity;"
}
}

internal const val SWIPE_TO_SWITCH_VIDEO_FEATURE_FLAG = 45631116L

internal val swipeToSwitchVideoFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR)
parameters("L")
literal {
SWIPE_TO_SWITCH_VIDEO_FEATURE_FLAG
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ 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.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.patches.youtube.shared.mainActivityFingerprint
import app.revanced.util.*
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod

private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/swipecontrols/SwipeControlsHostActivity;"

private val swipeControlsResourcePatch = resourcePatch {
dependsOn(
settingsPatch,
Expand All @@ -37,6 +40,7 @@ private val swipeControlsResourcePatch = resourcePatch {
TextPreference("revanced_swipe_text_overlay_size", inputType = InputType.NUMBER),
TextPreference("revanced_swipe_overlay_background_alpha", inputType = InputType.NUMBER),
TextPreference("revanced_swipe_threshold", inputType = InputType.NUMBER),
SwitchPreference("revanced_swipe_to_change_video"),
)

copyResources(
Expand Down Expand Up @@ -101,5 +105,16 @@ val swipeControlsPatch = bytecodePatch(
).toMutable()
}
}

// region patch for disable swipe to switch video

if (is_19_23_or_greater) {
swipeToSwitchVideoFingerprint.method.insertFeatureFlagBooleanOverride(
SWIPE_TO_SWITCH_VIDEO_FEATURE_FLAG,
"$EXTENSION_CLASS_DESCRIPTOR->allowSwipeToChangeVideo(Z)Z"
)
}

// endregion
}
}
3 changes: 3 additions & 0 deletions patches/src/main/resources/addresources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ This feature is only available for older devices"</string>
<string name="revanced_swipe_overlay_background_alpha_summary">The visibility of swipe overlay background</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_to_change_video_title">Fullscreen swipe to change videos</string>
<string name="revanced_swipe_to_change_video_summary_on">Swiping up / down in fullscreen mode will change to the next/previous video</string>
<string name="revanced_swipe_to_change_video_summary_off">Swiping up / down in fullscreen mode will not change to the next/previous video</string>
</patch>
<patch id="layout.autocaptions.autoCaptionsPatch">
<string name="revanced_auto_captions_title">Disable auto captions</string>
Expand Down

0 comments on commit 1e022b8

Please sign in to comment.