From 9c821189dc69747a9e1c518f288f94fafacd7b0d Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sun, 29 Sep 2024 17:05:55 -0400 Subject: [PATCH 1/2] fix(YouTube - SponsorBlock): Fade out SB buttons without overlapping other buttons --- .../youtube/misc/playercontrols/PlayerControlsResourcePatch.kt | 2 +- .../sponsorblock/host/layout/youtube_controls_layout.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsResourcePatch.kt index f78bc92592..be3a2f824a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsResourcePatch.kt @@ -79,7 +79,7 @@ object PlayerControlsResourcePatch : ResourcePatch(), Closeable { // FIXME: This uses hard coded values that only works with SponsorBlock. // If other top buttons are added by other patches, this code must be changed. if (view.hasAttributes() && view.attributes.getNamedItem("android:id") - .nodeValue.endsWith("live_chat_overlay_button") + .nodeValue.endsWith("player_video_heading") ) { // voting button id from the voting button view from the youtube_controls_layout.xml host file val votingButtonId = "@+id/revanced_sb_voting_button" diff --git a/src/main/resources/sponsorblock/host/layout/youtube_controls_layout.xml b/src/main/resources/sponsorblock/host/layout/youtube_controls_layout.xml index aec11d7c52..8db9fa6649 100644 --- a/src/main/resources/sponsorblock/host/layout/youtube_controls_layout.xml +++ b/src/main/resources/sponsorblock/host/layout/youtube_controls_layout.xml @@ -22,7 +22,7 @@ android:layout_alignParentTop="true" android:layout_marginTop="2dp" android:layout_marginEnd="4dp" - android:layout_toStartOf="@+id/player_additional_view_container" + android:layout_toStartOf="@id/music_app_deeplink_button" android:padding="@dimen/controls_overlay_action_button_padding" android:src="@drawable/revanced_sb_logo" /> From 29b8af2ffb67a41304cedaa790a1cd165b524fab Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sun, 29 Sep 2024 17:07:49 -0400 Subject: [PATCH 2/2] refactor --- .../PlayerControlsResourcePatch.kt | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsResourcePatch.kt index be3a2f824a..9ff131f71a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsResourcePatch.kt @@ -1,7 +1,6 @@ package app.revanced.patches.youtube.misc.playercontrols import app.revanced.patcher.data.ResourceContext -import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.ResourcePatch import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.DomFileEditor @@ -69,29 +68,17 @@ object PlayerControlsResourcePatch : ResourcePatch(), Closeable { resourceContext.xmlEditor[hostingResourceStream], editor, ).use { - val document = editor.file - val children = document.getElementsByTagName("RelativeLayout").item(0).childNodes - - // Replace the startOf with the voting button view so that the button does not overlap - for (index in 1 until children.length) { - val view = children.item(index) - - // FIXME: This uses hard coded values that only works with SponsorBlock. - // If other top buttons are added by other patches, this code must be changed. - if (view.hasAttributes() && view.attributes.getNamedItem("android:id") - .nodeValue.endsWith("player_video_heading") - ) { - // voting button id from the voting button view from the youtube_controls_layout.xml host file - val votingButtonId = "@+id/revanced_sb_voting_button" - view.attributes.getNamedItem("android:layout_toStartOf").nodeValue = - votingButtonId - - return - } - } + val element = editor.file.childNodes.findElementByAttributeValueOrThrow( + "android:id", + "@id/player_video_heading" + ) + + // FIXME: This uses hard coded values that only works with SponsorBlock. + // If other top buttons are added by other patches, this code must be changed. + // voting button id from the voting button view from the youtube_controls_layout.xml host file + val votingButtonId = "@+id/revanced_sb_voting_button" + element.attributes.getNamedItem("android:layout_toStartOf").nodeValue = votingButtonId } - - throw PatchException("Could not find expected xml to modify") } /**