@@ -6,9 +6,9 @@ import app.revanced.patches.youtube.utils.patch.PatchList.MATERIALYOU
6
6
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
7
7
import app.revanced.patches.youtube.utils.settings.ResourceUtils.updatePatchStatusTheme
8
8
import app.revanced.patches.youtube.utils.settings.settingsPatch
9
- import app.revanced.util.ResourceGroup
10
- import app.revanced.util.copyResources
11
9
import app.revanced.util.copyXmlNode
10
+ import org.w3c.dom.Element
11
+ import java.nio.file.Files
12
12
13
13
@Suppress(" unused" )
14
14
val materialYouPatch = resourcePatch(
@@ -24,25 +24,118 @@ val materialYouPatch = resourcePatch(
24
24
)
25
25
26
26
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
+ }
44
73
}
45
74
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
+
46
139
copyXmlNode(" youtube/materialyou/host" , " values-v31/colors.xml" , " resources" )
47
140
48
141
updatePatchStatusTheme(" MaterialYou" )
0 commit comments