@@ -92,44 +92,62 @@ object ResourceUtils {
92
92
}
93
93
94
94
fun ResourceContext.addReVancedPreference (key : String ) {
95
- val targetClass =
96
- " com.google.android.apps.youtube.app.settings.videoquality.VideoQualitySettingsActivity "
95
+ val targetClass = " com.google.android.apps.youtube.app.settings.videoquality.VideoQualitySettingsActivity "
96
+ val path = if (key == " extended_settings " ) YOUTUBE_SETTINGS_PATH else TARGET_PREFERENCE_PATH
97
97
98
- this .xmlEditor[YOUTUBE_SETTINGS_PATH ].use { editor ->
98
+ this .xmlEditor[path ].use { editor ->
99
99
with (editor.file) {
100
- doRecursively loop@{
101
- if (it !is Element ) return @loop
102
- it.getAttributeNode(" android:key" )?.let { attribute ->
103
- if (attribute.textContent == " @string/about_key" && it.getAttributeNode(" app:iconSpaceReserved" ).textContent == " false" ) {
104
- it.insertNode(" Preference" , it) {
105
- setAttribute(" android:key" , " revanced_" + key + " _key" )
106
- setAttribute(" android:title" , " @string/revanced_" + key + " _title" )
100
+ val processedKeys = mutableSetOf<String >() // To track processed keys
101
+
102
+ doRecursively loop@{ node ->
103
+ if (node !is Element ) return @loop // Skip if not an element
104
+
105
+ val attributeNode = node.getAttributeNode(" android:key" ) ? : return @loop // Skip if no key attribute
106
+
107
+ val currentKey = attributeNode.textContent
108
+
109
+ // Check if the current key has already been processed
110
+ if (processedKeys.contains(currentKey)) {
111
+ return @loop // Skip if already processed
112
+ } else {
113
+ processedKeys.add(currentKey) // Add the current key to processedKeys
114
+ }
115
+
116
+ when {
117
+ key == " extended_settings" && currentKey == " @string/about_key" && node.getAttribute(" app:iconSpaceReserved" ) == " false" -> {
118
+ node.insertNode(" Preference" , node) {
119
+ setAttribute(" android:key" , " revanced_${key} _key" )
120
+ setAttribute(" android:title" , " @string/revanced_${key} _title" )
107
121
this .appendChild(
108
122
ownerDocument.createElement(" intent" ).also { intentNode ->
109
- intentNode.setAttribute(
110
- " android:targetPackage" ,
111
- targetPackage
112
- )
123
+ intentNode.setAttribute(" android:targetPackage" , targetPackage)
113
124
intentNode.setAttribute(" android:data" , key)
114
125
intentNode.setAttribute(" android:targetClass" , targetClass)
115
- })
126
+ }
127
+ )
116
128
}
117
- it.getAttributeNode(" app:iconSpaceReserved" ).textContent = " true"
118
- return @loop
129
+ node.setAttribute(" app:iconSpaceReserved" , " true" )
119
130
}
120
- }
121
- }
122
-
123
- doRecursively loop@{
124
- if (it !is Element ) return @loop
125
-
126
- it.getAttributeNode(" app:iconSpaceReserved" )?.let { attribute ->
127
- if (attribute.textContent == " true" ) {
128
- attribute.textContent = " false"
131
+ key != " extended_settings" && currentKey == " misc" -> {
132
+ node.insertNode(" PreferenceScreen" , node) {
133
+ setAttribute(" android:key" , " revanced_${key} _key" )
134
+ setAttribute(" android:title" , " @string/revanced_${key} _title" )
135
+ this .appendChild(
136
+ ownerDocument.createElement(" intent" ).also { intentNode ->
137
+ intentNode.setAttribute(" android:targetPackage" , targetPackage)
138
+ intentNode.setAttribute(" android:data" , key)
139
+ intentNode.setAttribute(" android:targetClass" , targetClass)
140
+ }
141
+ )
142
+ }
143
+ }
144
+ currentKey == " true" -> {
145
+ attributeNode.textContent = " false"
129
146
}
130
147
}
131
148
}
132
149
}
133
150
}
134
151
}
152
+
135
153
}
0 commit comments