From d233d96faf838b22f4c458ad445af048362e7421 Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Wed, 26 Apr 2023 03:08:28 +0500 Subject: [PATCH] feat(youtube): `hide-player-overlay` patch (#1965) --- .../HidePlayerOverlayPatchCompatibility.kt | 8 ++++ .../overlay/patch/HidePlayerOverlayPatch.kt | 46 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/annotations/HidePlayerOverlayPatchCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/annotations/HidePlayerOverlayPatchCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/annotations/HidePlayerOverlayPatchCompatibility.kt new file mode 100644 index 00000000..9ca55f52 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/annotations/HidePlayerOverlayPatchCompatibility.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.youtube.layout.hide.player.overlay.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("com.google.android.youtube")]) +@Target(AnnotationTarget.CLASS) +internal annotation class HidePlayerOverlayPatchCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt new file mode 100644 index 00000000..ee486dc0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt @@ -0,0 +1,46 @@ +package app.revanced.patches.youtube.layout.hide.player.overlay.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.youtube.layout.hide.player.overlay.annotations.HidePlayerOverlayPatchCompatibility + +@Patch +@Name("hide-player-overlay") +@Description("Hides the dark player overlay when player controls are visible.") +@HidePlayerOverlayPatchCompatibility +@Version("0.0.1") +class HidePlayerOverlayPatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + val attributes = arrayOf("height", "width") + + context.xmlEditor[RESOURCE_FILE_PATH].use { editor -> + editor.file.getElementsByTagName("FrameLayout").item(0).childNodes.apply { + for (i in 1 until length) { + val view = item(i) + if ( + view.attributes.getNamedItem("android:id") + ?.nodeValue + ?.endsWith("scrim_overlay") == true + ) { + attributes.forEach { + view.attributes.getNamedItem("android:layout_$it").nodeValue = "0.0dip" + } + break + } + } + } + } + + return PatchResultSuccess() + } + + private companion object { + const val RESOURCE_FILE_PATH = "res/layout/youtube_controls_overlay.xml" + } +}