From eeeb673f8792e9bed8120bb31fe82954baae5ae9 Mon Sep 17 00:00:00 2001 From: Francesco146 Date: Fri, 17 May 2024 23:17:17 +0200 Subject: [PATCH] feat(YouTube - Shorts): Add `Force disable Shorts dim` in the new RVX code --- api/revanced-patches.api | 6 +++ .../shortsdim/ForceDisableShortsDimPatch.kt | 43 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/shortsdim/ForceDisableShortsDimPatch.kt diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 9aa78995d..7b4f177f9 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -1231,6 +1231,12 @@ public final class app/revanced/patches/youtube/shorts/repeat/ShortsRepeatPatch public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } +public final class app/revanced/patches/youtube/shorts/shortsdim/ForceDisableShortsDimPatch : app/revanced/patcher/patch/ResourcePatch { + public static final field INSTANCE Lapp/revanced/patches/youtube/shorts/shortsdim/ForceDisableShortsDimPatch; + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V + public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V +} + public final class app/revanced/patches/youtube/shorts/shortsoverlay/ShortsOverlayButtonsPatch : app/revanced/util/patch/BaseResourcePatch { public static final field INSTANCE Lapp/revanced/patches/youtube/shorts/shortsoverlay/ShortsOverlayButtonsPatch; public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/shortsdim/ForceDisableShortsDimPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortsdim/ForceDisableShortsDimPatch.kt new file mode 100644 index 000000000..6d9908825 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/shortsdim/ForceDisableShortsDimPatch.kt @@ -0,0 +1,43 @@ +package app.revanced.patches.youtube.shorts.shortsdim + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE +import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.doRecursively +import org.w3c.dom.Element + +@Suppress("unused") +object ForceDisableShortsDimPatch : ResourcePatch( + name = "Force disable Shorts dim", + description = "Forcefully disables the dimming effect on the top and bottom of Shorts video.", + dependencies = setOf(SettingsPatch::class), + compatiblePackages = COMPATIBLE_PACKAGE, + use = false +) { + override fun execute(context: ResourceContext) { + val hide = "0.0dip" + + fun hideLayoutAttributes(layoutFile: String, targetId: String) { + context.document[layoutFile].use { editor -> + editor.doRecursively { node -> + if (node !is Element) return@doRecursively + + when (node.getAttributeNode("android:id")?.textContent) { + targetId -> { + node.apply { + setAttribute("android:layout_height", hide) + setAttribute("android:layout_width", hide) + } + } + } + } + } + } + + hideLayoutAttributes("res/layout/reel_player_overlay_scrims.xml", "@id/reel_player_overlay_v2_scrims_vertical") + hideLayoutAttributes("res/layout/reel_watch_fragment.xml", "@id/reel_scrim_shorts_while_top") + + SettingsPatch.updatePatchStatus("Force disable Shorts dim") + } +}