diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/MaterialYouPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/MaterialYouPatch.kt
index 21585d2a4..9688864a0 100644
--- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/MaterialYouPatch.kt
+++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/MaterialYouPatch.kt
@@ -6,9 +6,9 @@ import app.revanced.patches.youtube.utils.patch.PatchList.MATERIALYOU
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
import app.revanced.patches.youtube.utils.settings.ResourceUtils.updatePatchStatusTheme
import app.revanced.patches.youtube.utils.settings.settingsPatch
-import app.revanced.util.ResourceGroup
-import app.revanced.util.copyResources
import app.revanced.util.copyXmlNode
+import org.w3c.dom.Element
+import java.nio.file.Files
@Suppress("unused")
val materialYouPatch = resourcePatch(
@@ -24,25 +24,118 @@ val materialYouPatch = resourcePatch(
)
execute {
- arrayOf(
- ResourceGroup(
- "drawable-night-v31",
- "new_content_dot_background.xml"
- ),
- ResourceGroup(
- "drawable-v31",
- "new_content_count_background.xml",
- "new_content_dot_background.xml"
- ),
- ResourceGroup(
- "layout-v31",
- "new_content_count.xml"
- )
- ).forEach {
- get("res/${it.resourceDirectoryName}").mkdirs()
- copyResources("youtube/materialyou", it)
+ fun patchXmlFile(
+ fromDir: String,
+ toDir: String,
+ xmlFileName: String,
+ parentNode: String,
+ targetNode: String? = null,
+ attribute: String,
+ newValue: String
+ ) {
+ val resourceDirectory = get("res")
+ val fromDirectory = resourceDirectory.resolve(fromDir)
+ val toDirectory = resourceDirectory.resolve(toDir)
+
+ if (!toDirectory.isDirectory) Files.createDirectories(toDirectory.toPath())
+
+ val fromXmlFile = fromDirectory.resolve(xmlFileName)
+ val toXmlFile = toDirectory.resolve(xmlFileName)
+
+ if (!fromXmlFile.exists()) {
+ return
+ }
+
+ if (!toXmlFile.exists()) {
+ Files.copy(
+ fromXmlFile.toPath(),
+ toXmlFile.toPath()
+ )
+ }
+
+ document("res/$toDir/$xmlFileName").use { document ->
+ val parentList = document.getElementsByTagName(parentNode).item(0) as Element
+
+ if (targetNode != null) {
+ for (i in 0 until parentList.childNodes.length) {
+ val node = parentList.childNodes.item(i) as? Element ?: continue
+
+ if (node.nodeName == targetNode && node.hasAttribute(attribute)) {
+ node.getAttributeNode(attribute).textContent = newValue
+ }
+ }
+ } else {
+ if (parentList.hasAttribute(attribute)) {
+ parentList.getAttributeNode(attribute).textContent = newValue
+ }
+ }
+ }
}
+ patchXmlFile(
+ "drawable",
+ "drawable-night-v31",
+ "new_content_dot_background.xml",
+ "shape",
+ "solid",
+ "android:color",
+ "@android:color/system_accent1_100"
+ )
+ patchXmlFile(
+ "drawable",
+ "drawable-night-v31",
+ "new_content_dot_background_cairo.xml",
+ "shape",
+ "solid",
+ "android:color",
+ "@android:color/system_accent1_100"
+ )
+ patchXmlFile(
+ "drawable",
+ "drawable-v31",
+ "new_content_dot_background.xml",
+ "shape",
+ "solid",
+ "android:color",
+ "@android:color/system_accent1_200"
+ )
+ patchXmlFile(
+ "drawable",
+ "drawable-v31",
+ "new_content_dot_background_cairo.xml",
+ "shape",
+ "solid",
+ "android:color",
+ "@android:color/system_accent1_200"
+ )
+ patchXmlFile(
+ "drawable",
+ "drawable-v31",
+ "new_content_count_background.xml",
+ "shape",
+ "solid",
+ "android:color",
+ "@android:color/system_accent1_100"
+ )
+ patchXmlFile(
+ "drawable",
+ "drawable-v31",
+ "new_content_count_background_cairo.xml",
+ "shape",
+ "solid",
+ "android:color",
+ "@android:color/system_accent1_100"
+ )
+ patchXmlFile(
+ "layout",
+ "layout-v31",
+ "new_content_count.xml",
+ "TextView",
+ null,
+ "android:textColor",
+ "@android:color/system_neutral1_900"
+ )
+
copyXmlNode("youtube/materialyou/host", "values-v31/colors.xml", "resources")
updatePatchStatusTheme("MaterialYou")
diff --git a/patches/src/main/resources/youtube/materialyou/drawable-night-v31/new_content_dot_background.xml b/patches/src/main/resources/youtube/materialyou/drawable-night-v31/new_content_dot_background.xml
deleted file mode 100644
index 2f80732c2..000000000
--- a/patches/src/main/resources/youtube/materialyou/drawable-night-v31/new_content_dot_background.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/patches/src/main/resources/youtube/materialyou/drawable-v31/new_content_count_background.xml b/patches/src/main/resources/youtube/materialyou/drawable-v31/new_content_count_background.xml
deleted file mode 100644
index ece2cbf17..000000000
--- a/patches/src/main/resources/youtube/materialyou/drawable-v31/new_content_count_background.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/patches/src/main/resources/youtube/materialyou/drawable-v31/new_content_dot_background.xml b/patches/src/main/resources/youtube/materialyou/drawable-v31/new_content_dot_background.xml
deleted file mode 100644
index 71b83998d..000000000
--- a/patches/src/main/resources/youtube/materialyou/drawable-v31/new_content_dot_background.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/patches/src/main/resources/youtube/materialyou/layout-v31/new_content_count.xml b/patches/src/main/resources/youtube/materialyou/layout-v31/new_content_count.xml
deleted file mode 100644
index f7f7d9450..000000000
--- a/patches/src/main/resources/youtube/materialyou/layout-v31/new_content_count.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
\ No newline at end of file