mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
refactor(YouTube/Overlay buttons): rename class, method, and resource files to be more appropriaten
This commit is contained in:
@ -91,7 +91,7 @@ object OverlayButtonsPatch : BaseResourcePatch(
|
||||
"TimeOrderedPlaylist;",
|
||||
"Whitelists;"
|
||||
).forEach { className ->
|
||||
PlayerControlsPatch.hookOverlayButtons("$OVERLAY_BUTTONS_PATH/$className")
|
||||
PlayerControlsPatch.hookBottomControlButton("$OVERLAY_BUTTONS_PATH/$className")
|
||||
}
|
||||
|
||||
// Copy necessary resources for the overlay buttons.
|
||||
@ -101,7 +101,7 @@ object OverlayButtonsPatch : BaseResourcePatch(
|
||||
"drawable",
|
||||
"playlist_repeat_button.xml",
|
||||
"playlist_shuffle_button.xml",
|
||||
"revanced_repeat_icon.xml"
|
||||
"revanced_repeat_button.xml"
|
||||
)
|
||||
)
|
||||
|
||||
@ -122,12 +122,12 @@ object OverlayButtonsPatch : BaseResourcePatch(
|
||||
"quantum_ic_fullscreen_exit_white_24.png",
|
||||
"quantum_ic_fullscreen_grey600_24.png",
|
||||
"quantum_ic_fullscreen_white_24.png",
|
||||
"revanced_time_ordered_playlist_icon.png",
|
||||
"revanced_copy_icon.png",
|
||||
"revanced_copy_icon_with_time.png",
|
||||
"revanced_download_icon.png",
|
||||
"revanced_speed_icon.png",
|
||||
"revanced_whitelist_icon.png",
|
||||
"revanced_time_ordered_playlist_button.png",
|
||||
"revanced_copy_button.png",
|
||||
"revanced_copy_timestamp_button.png",
|
||||
"revanced_download_button.png",
|
||||
"revanced_speed_button.png",
|
||||
"revanced_whitelist_button.png",
|
||||
"yt_fill_arrow_repeat_white_24.png",
|
||||
"yt_outline_arrow_repeat_1_white_24.png",
|
||||
"yt_outline_arrow_shuffle_1_white_24.png",
|
||||
|
@ -43,8 +43,8 @@ object PlayerControlsPatch : BytecodePatch(
|
||||
|
||||
private lateinit var changeVisibilityMethod: MutableMethod
|
||||
private lateinit var changeVisibilityNegatedImmediatelyMethod: MutableMethod
|
||||
private lateinit var initializeOverlayButtonsMethod: MutableMethod
|
||||
private lateinit var initializeSponsorBlockButtonsMethod: MutableMethod
|
||||
private lateinit var initializeBottomControlButtonMethod: MutableMethod
|
||||
private lateinit var initializeTopControlButtonMethod: MutableMethod
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
@ -101,8 +101,8 @@ object PlayerControlsPatch : BytecodePatch(
|
||||
// region patch initialize of overlay button or SponsorBlock button
|
||||
|
||||
mapOf(
|
||||
BottomControlsInflateFingerprint to "initializeOverlayButtons",
|
||||
ControlsLayoutInflateFingerprint to "initializeSponsorBlockButtons"
|
||||
BottomControlsInflateFingerprint to "initializeBottomControlButton",
|
||||
ControlsLayoutInflateFingerprint to "initializeTopControlButton"
|
||||
).forEach { (fingerprint, methodName) ->
|
||||
fingerprint.resultOrThrow().let {
|
||||
it.mutableMethod.apply {
|
||||
@ -135,14 +135,14 @@ object PlayerControlsPatch : BytecodePatch(
|
||||
method.name == "changeVisibilityNegatedImmediately"
|
||||
}
|
||||
|
||||
initializeOverlayButtonsMethod =
|
||||
initializeBottomControlButtonMethod =
|
||||
playerControlsMutableClass.methods.single { method ->
|
||||
method.name == "initializeOverlayButtons"
|
||||
method.name == "initializeBottomControlButton"
|
||||
}
|
||||
|
||||
initializeSponsorBlockButtonsMethod =
|
||||
initializeTopControlButtonMethod =
|
||||
playerControlsMutableClass.methods.single { method ->
|
||||
method.name == "initializeSponsorBlockButtons"
|
||||
method.name == "initializeTopControlButton"
|
||||
}
|
||||
|
||||
// endregion
|
||||
@ -167,14 +167,14 @@ object PlayerControlsPatch : BytecodePatch(
|
||||
"invoke-static {}, $classDescriptor->changeVisibilityNegatedImmediate()V"
|
||||
)
|
||||
|
||||
internal fun hookOverlayButtons(classDescriptor: String) {
|
||||
initializeOverlayButtonsMethod.initializeHook(classDescriptor)
|
||||
internal fun hookBottomControlButton(classDescriptor: String) {
|
||||
initializeBottomControlButtonMethod.initializeHook(classDescriptor)
|
||||
changeVisibilityHook(classDescriptor)
|
||||
changeVisibilityNegatedImmediateHook(classDescriptor)
|
||||
}
|
||||
|
||||
internal fun hookSponsorBlockButtons(classDescriptor: String) {
|
||||
initializeSponsorBlockButtonsMethod.initializeHook(classDescriptor)
|
||||
internal fun hookTopControlButton(classDescriptor: String) {
|
||||
initializeTopControlButtonMethod.initializeHook(classDescriptor)
|
||||
changeVisibilityHook(classDescriptor)
|
||||
changeVisibilityNegatedImmediateHook(classDescriptor)
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
|
||||
|
||||
// Voting & Shield button
|
||||
arrayOf("CreateSegmentButtonController;", "VotingButtonController;").forEach { className ->
|
||||
PlayerControlsPatch.hookSponsorBlockButtons("$INTEGRATIONS_SPONSOR_BLOCK_UI_PATH/$className")
|
||||
PlayerControlsPatch.hookTopControlButton("$INTEGRATIONS_SPONSOR_BLOCK_UI_PATH/$className")
|
||||
}
|
||||
|
||||
// Append timestamp
|
||||
|
@ -92,47 +92,42 @@ object SponsorBlockPatch : BaseResourcePatch(
|
||||
* merge xml nodes from the host to their real xml files
|
||||
*/
|
||||
// copy nodes from host resources to their real xml files
|
||||
val hostingResourceStream =
|
||||
inputStreamFromBundledResource(
|
||||
"youtube/sponsorblock",
|
||||
"shared/host/layout/youtube_controls_layout.xml",
|
||||
)!!
|
||||
|
||||
var modifiedControlsLayout = false
|
||||
val editor = context.xmlEditor["res/layout/youtube_controls_layout.xml"]
|
||||
|
||||
// voting button id from the voting button view from the youtube_controls_layout.xml host file
|
||||
val votingButtonId = "@+id/revanced_sb_voting_button"
|
||||
inputStreamFromBundledResource(
|
||||
"youtube/sponsorblock",
|
||||
"shared/host/layout/youtube_controls_layout.xml",
|
||||
)?.let { hostingResourceStream ->
|
||||
val editor = context.xmlEditor["res/layout/youtube_controls_layout.xml"]
|
||||
|
||||
"RelativeLayout".copyXmlNode(
|
||||
context.xmlEditor[hostingResourceStream],
|
||||
editor
|
||||
).also {
|
||||
val document = editor.file
|
||||
val children = document.getElementsByTagName("RelativeLayout").item(0).childNodes
|
||||
// voting button id from the voting button view from the youtube_controls_layout.xml host file
|
||||
val votingButtonId = "@+id/revanced_sb_voting_button"
|
||||
|
||||
// Replace the startOf with the voting button view so that the button does not overlap
|
||||
for (i in 1 until children.length) {
|
||||
val view = children.item(i)
|
||||
"RelativeLayout".copyXmlNode(
|
||||
context.xmlEditor[hostingResourceStream],
|
||||
editor
|
||||
).also {
|
||||
val document = editor.file
|
||||
val children = document.getElementsByTagName("RelativeLayout").item(0).childNodes
|
||||
|
||||
// Replace the attribute for a specific node only
|
||||
if (!(
|
||||
view.hasAttributes() &&
|
||||
view.attributes.getNamedItem(
|
||||
"android:id",
|
||||
).nodeValue.endsWith("player_video_heading")
|
||||
)
|
||||
) {
|
||||
continue
|
||||
// Replace the startOf with the voting button view so that the button does not overlap
|
||||
for (i in 1 until children.length) {
|
||||
val view = children.item(i)
|
||||
|
||||
val playerVideoHeading = view.hasAttributes() &&
|
||||
view.attributes.getNamedItem("android:id").nodeValue.endsWith("player_video_heading")
|
||||
|
||||
// Replace the attribute for a specific node only
|
||||
if (!playerVideoHeading) continue
|
||||
|
||||
view.attributes.getNamedItem("android:layout_toStartOf").nodeValue =
|
||||
votingButtonId
|
||||
|
||||
modifiedControlsLayout = true
|
||||
break
|
||||
}
|
||||
|
||||
view.attributes.getNamedItem("android:layout_toStartOf").nodeValue =
|
||||
votingButtonId
|
||||
|
||||
modifiedControlsLayout = true
|
||||
break
|
||||
}
|
||||
}.close()
|
||||
}.close()
|
||||
}
|
||||
|
||||
if (!modifiedControlsLayout) throw PatchException("Could not modify controls layout")
|
||||
|
||||
|
Reference in New Issue
Block a user