feat(YouTube): Add some compile time patches (#51)

* feat(YouTube - Shorts): Add `Force disable Shorts dim` in the new RVX code

* feat(YouTube - Shorts): Add `Hide double tap to like animations` in the new RVX code

* feat(YouTube - Shorts): Add `Hide animated button background` in the new RVX code

* feat(YouTube - Player): Rename `ForcePlayerButtonBackgroundPatch`

* chore: Better patch naming

* chore: Use deprecated method to maintain compatibility
This commit is contained in:
Francesco Marastoni
2024-05-21 16:00:30 +02:00
committed by GitHub
parent 84dd65f8a7
commit 60c05cb193
8 changed files with 118 additions and 4 deletions

View File

@ -0,0 +1,33 @@
package app.revanced.patches.youtube.layout.animated
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.copyResources
import app.revanced.util.ResourceGroup
@Suppress("unused")
object ForceAnimatedButtonBackgroundPatch : ResourcePatch(
name = "Force hide animated button background",
description = "Hides the background of the pause and play animated buttons in the Shorts player at compile time.",
dependencies = setOf(SettingsPatch::class),
compatiblePackages = COMPATIBLE_PACKAGE,
use = false
) {
override fun execute(context: ResourceContext) {
/**
* Copy json
*/
context.copyResources(
"youtube/animated",
ResourceGroup(
"raw",
"pause_tap_feedback.json",
"play_tap_feedback.json"
)
)
SettingsPatch.updatePatchStatus("Hide animated button background")
}
}

View File

@ -0,0 +1,33 @@
package app.revanced.patches.youtube.layout.animated
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.ResourceGroup
import app.revanced.util.copyResources
@Suppress("unused")
object ForceAnimatedLikePatch : ResourcePatch(
name = "Force hide double tap to like animations",
description = "Hide the like animations when double tap the screen in the Shorts player at compile time.",
dependencies = setOf(SettingsPatch::class),
compatiblePackages = COMPATIBLE_PACKAGE,
use = false
) {
override fun execute(context: ResourceContext) {
/**
* Copy json
*/
context.copyResources(
"youtube/animated",
ResourceGroup(
"raw",
"like_tap_feedback.json"
)
)
SettingsPatch.updatePatchStatus("Hide double tap to like animations")
}
}

View File

@ -7,10 +7,10 @@ import app.revanced.util.doRecursively
import app.revanced.util.patch.BaseResourcePatch
import org.w3c.dom.Element
@Suppress("DEPRECATION", "unused")
object PlayerButtonBackgroundPatch : BaseResourcePatch(
name = "Hide player button background",
description = "Hides the dark background surrounding the video player controls.",
@Suppress("Deprecation", "unused")
object ForcePlayerButtonBackgroundPatch : BaseResourcePatch(
name = "Force hide player buttons background",
description = "Hide the dark background surrounding the video player controls at compile time.",
dependencies = setOf(SettingsPatch::class),
compatiblePackages = COMPATIBLE_PACKAGE,
use = false

View File

@ -0,0 +1,43 @@
package app.revanced.patches.youtube.shorts.dimming
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("Deprecation", "unused")
object ForceDisableShortsDimPatch : ResourcePatch(
name = "Force disable Shorts dim",
description = "Hide the dimming effect on the top and bottom of Shorts video at compile time.",
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.xmlEditor[layoutFile].use { editor ->
editor.file.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")
}
}