Skip to content

Commit

Permalink
fix(YouTube - SponsorBlock): Fade out SB buttons without overlapping …
Browse files Browse the repository at this point in the history
…other buttons (ReVanced#3719)
  • Loading branch information
LisoUseInAIKyrios authored Sep 29, 2024
1 parent 5e5a55f commit bf96108
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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("live_chat_overlay_button")
) {
// 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")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</RelativeLayout>

0 comments on commit bf96108

Please sign in to comment.