feat(YouTube Music): add Hide double tap overlay filter patch

This commit is contained in:
inotia00 2024-01-03 20:39:27 +09:00
parent f61cf4b1c2
commit 3b1bad3bab
3 changed files with 60 additions and 29 deletions

View File

@ -0,0 +1,17 @@
package app.revanced.patches.music.layout.doubletapbackground
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.shared.patch.doubletapbackground.AbstractDoubleTapOverlayBackgroundPatch
@Patch(
name = "Hide double tap overlay filter",
description = "Hides the double tap dark filter layer.",
compatiblePackages = [CompatiblePackage("com.google.android.apps.youtube.music")],
use = false
)
@Suppress("unused")
object DoubleTapOverlayBackgroundPatch : AbstractDoubleTapOverlayBackgroundPatch(
arrayOf("quick_seek_overlay.xml", "music_controls_overlay.xml"),
arrayOf("tap_bloom_view", "dark_background", "player_control_screen")
)

View File

@ -0,0 +1,37 @@
package app.revanced.patches.shared.patch.doubletapbackground
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.util.doRecursively
import org.w3c.dom.Element
import kotlin.io.path.exists
abstract class AbstractDoubleTapOverlayBackgroundPatch(
private val files: Array<String>,
private val targetId: Array<String>,
) : ResourcePatch() {
override fun execute(context: ResourceContext) {
val resDirectory = context["res"]
files.forEach { file ->
val targetXmlPath = resDirectory.resolve("layout").resolve(file).toPath()
if (targetXmlPath.exists()) {
targetId.forEach { identifier ->
context.xmlEditor["res/layout/$file"].use { editor ->
editor.file.doRecursively {
arrayOf("height", "width").forEach replacement@{ replacement ->
if (it !is Element) return@replacement
if (it.attributes.getNamedItem("android:id")?.nodeValue?.endsWith(identifier) == true) {
it.getAttributeNode("android:layout_$replacement")?.let { attribute -> attribute.textContent = "0.0dip" }
}
}
}
}
}
}
}
}
}

View File

@ -1,9 +1,9 @@
package app.revanced.patches.youtube.layout.doubletapbackground
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.shared.patch.doubletapbackground.AbstractDoubleTapOverlayBackgroundPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch
@Patch(
@ -39,37 +39,14 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch
use = false
)
@Suppress("unused")
object DoubleTapOverlayBackgroundPatch : ResourcePatch() {
object DoubleTapOverlayBackgroundPatch : AbstractDoubleTapOverlayBackgroundPatch(
arrayOf("quick_seek_overlay.xml"),
arrayOf("tap_bloom_view", "dark_background")
) {
override fun execute(context: ResourceContext) {
context.xmlEditor[RESOURCE_FILE_PATH].use {
it.file.getElementsByTagName("merge").item(0).childNodes.apply {
val attributes = arrayOf("height", "width")
for (i in 1 until length) {
val view = item(i)
if (
view.hasAttributes() &&
view.attributes.getNamedItem("android:id").nodeValue.endsWith("tap_bloom_view")
) {
attributes.forEach { attribute ->
view.attributes.getNamedItem("android:layout_$attribute").nodeValue =
"0.0dip"
}
}
if (
view.hasAttributes() &&
view.attributes.getNamedItem("android:id").nodeValue.endsWith("dark_background")
) {
view.attributes.getNamedItem("android:src").nodeValue =
"@color/full_transparent"
break
}
}
}
}
super.execute(context)
SettingsPatch.updatePatchStatus("Hide double tap overlay filter")
}
private const val RESOURCE_FILE_PATH = "res/layout/quick_seek_overlay.xml"
}