Skip to content

Commit 98f26a2

Browse files
committed
fix(YouTube - MaterialYou): Theme not applied to notification dots in YouTube 19.34.42+
1 parent 7991caa commit 98f26a2

File tree

5 files changed

+112
-41
lines changed

5 files changed

+112
-41
lines changed

patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/MaterialYouPatch.kt

Lines changed: 112 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import app.revanced.patches.youtube.utils.patch.PatchList.MATERIALYOU
66
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
77
import app.revanced.patches.youtube.utils.settings.ResourceUtils.updatePatchStatusTheme
88
import app.revanced.patches.youtube.utils.settings.settingsPatch
9-
import app.revanced.util.ResourceGroup
10-
import app.revanced.util.copyResources
119
import app.revanced.util.copyXmlNode
10+
import org.w3c.dom.Element
11+
import java.nio.file.Files
1212

1313
@Suppress("unused")
1414
val materialYouPatch = resourcePatch(
@@ -24,25 +24,118 @@ val materialYouPatch = resourcePatch(
2424
)
2525

2626
execute {
27-
arrayOf(
28-
ResourceGroup(
29-
"drawable-night-v31",
30-
"new_content_dot_background.xml"
31-
),
32-
ResourceGroup(
33-
"drawable-v31",
34-
"new_content_count_background.xml",
35-
"new_content_dot_background.xml"
36-
),
37-
ResourceGroup(
38-
"layout-v31",
39-
"new_content_count.xml"
40-
)
41-
).forEach {
42-
get("res/${it.resourceDirectoryName}").mkdirs()
43-
copyResources("youtube/materialyou", it)
27+
fun patchXmlFile(
28+
fromDir: String,
29+
toDir: String,
30+
xmlFileName: String,
31+
parentNode: String,
32+
targetNode: String? = null,
33+
attribute: String,
34+
newValue: String
35+
) {
36+
val resourceDirectory = get("res")
37+
val fromDirectory = resourceDirectory.resolve(fromDir)
38+
val toDirectory = resourceDirectory.resolve(toDir)
39+
40+
if (!toDirectory.isDirectory) Files.createDirectories(toDirectory.toPath())
41+
42+
val fromXmlFile = fromDirectory.resolve(xmlFileName)
43+
val toXmlFile = toDirectory.resolve(xmlFileName)
44+
45+
if (!fromXmlFile.exists()) {
46+
return
47+
}
48+
49+
if (!toXmlFile.exists()) {
50+
Files.copy(
51+
fromXmlFile.toPath(),
52+
toXmlFile.toPath()
53+
)
54+
}
55+
56+
document("res/$toDir/$xmlFileName").use { document ->
57+
val parentList = document.getElementsByTagName(parentNode).item(0) as Element
58+
59+
if (targetNode != null) {
60+
for (i in 0 until parentList.childNodes.length) {
61+
val node = parentList.childNodes.item(i) as? Element ?: continue
62+
63+
if (node.nodeName == targetNode && node.hasAttribute(attribute)) {
64+
node.getAttributeNode(attribute).textContent = newValue
65+
}
66+
}
67+
} else {
68+
if (parentList.hasAttribute(attribute)) {
69+
parentList.getAttributeNode(attribute).textContent = newValue
70+
}
71+
}
72+
}
4473
}
4574

75+
patchXmlFile(
76+
"drawable",
77+
"drawable-night-v31",
78+
"new_content_dot_background.xml",
79+
"shape",
80+
"solid",
81+
"android:color",
82+
"@android:color/system_accent1_100"
83+
)
84+
patchXmlFile(
85+
"drawable",
86+
"drawable-night-v31",
87+
"new_content_dot_background_cairo.xml",
88+
"shape",
89+
"solid",
90+
"android:color",
91+
"@android:color/system_accent1_100"
92+
)
93+
patchXmlFile(
94+
"drawable",
95+
"drawable-v31",
96+
"new_content_dot_background.xml",
97+
"shape",
98+
"solid",
99+
"android:color",
100+
"@android:color/system_accent1_200"
101+
)
102+
patchXmlFile(
103+
"drawable",
104+
"drawable-v31",
105+
"new_content_dot_background_cairo.xml",
106+
"shape",
107+
"solid",
108+
"android:color",
109+
"@android:color/system_accent1_200"
110+
)
111+
patchXmlFile(
112+
"drawable",
113+
"drawable-v31",
114+
"new_content_count_background.xml",
115+
"shape",
116+
"solid",
117+
"android:color",
118+
"@android:color/system_accent1_100"
119+
)
120+
patchXmlFile(
121+
"drawable",
122+
"drawable-v31",
123+
"new_content_count_background_cairo.xml",
124+
"shape",
125+
"solid",
126+
"android:color",
127+
"@android:color/system_accent1_100"
128+
)
129+
patchXmlFile(
130+
"layout",
131+
"layout-v31",
132+
"new_content_count.xml",
133+
"TextView",
134+
null,
135+
"android:textColor",
136+
"@android:color/system_neutral1_900"
137+
)
138+
46139
copyXmlNode("youtube/materialyou/host", "values-v31/colors.xml", "resources")
47140

48141
updatePatchStatusTheme("MaterialYou")

patches/src/main/resources/youtube/materialyou/drawable-night-v31/new_content_dot_background.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

patches/src/main/resources/youtube/materialyou/drawable-v31/new_content_count_background.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

patches/src/main/resources/youtube/materialyou/drawable-v31/new_content_dot_background.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

patches/src/main/resources/youtube/materialyou/layout-v31/new_content_count.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)