Skip to content

Commit c745409

Browse files
anddearufusin
authored andcommitted
feat(YouTube - Settings): Move SB and RYD to RVX Settings
1 parent 58961fa commit c745409

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

src/main/kotlin/app/revanced/patches/youtube/utils/settings/ResourceUtils.kt

+44-26
Original file line numberDiff line numberDiff line change
@@ -92,44 +92,62 @@ object ResourceUtils {
9292
}
9393

9494
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
9797

98-
this.xmlEditor[YOUTUBE_SETTINGS_PATH].use { editor ->
98+
this.xmlEditor[path].use { editor ->
9999
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")
107121
this.appendChild(
108122
ownerDocument.createElement("intent").also { intentNode ->
109-
intentNode.setAttribute(
110-
"android:targetPackage",
111-
targetPackage
112-
)
123+
intentNode.setAttribute("android:targetPackage", targetPackage)
113124
intentNode.setAttribute("android:data", key)
114125
intentNode.setAttribute("android:targetClass", targetClass)
115-
})
126+
}
127+
)
116128
}
117-
it.getAttributeNode("app:iconSpaceReserved").textContent = "true"
118-
return@loop
129+
node.setAttribute("app:iconSpaceReserved", "true")
119130
}
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"
129146
}
130147
}
131148
}
132149
}
133150
}
134151
}
152+
135153
}

0 commit comments

Comments
 (0)