Aaron Veil 09ed1b965d
feat: merge patch RVX/anddea (#55)
* feat(YouTube): Add `Custom Shorts action buttons` patch (Replaces `Shorts outline icon` patch)

* feat(YouTube): Add `Visual preferences icons` patch

* feat(Custom branding icon): Add more icons

* feat(Custom branding icon): Add patch options `ChangeHeader`, `ChangeSplashIcon`, `RestoreOldSplashAnimation`

* feat(Translations): Add patch options to remove languages and provide own translation / strings.xml

* feat(YouTube/Settings): Add search bar in settings

* feat(YouTube/Shorts components): Add `Hide disabled comments button` and `Hide live chat header` settings

* refactor(YouTube/Settings): Fix typos in strings

* feat(YouTube/Settings): clarify patch option descriptions

Co-authored-by: KobeW50 <84587632+KobeW50@users.noreply.github.com>

* feat(YouTube): clarify patch option

Co-authored-by: KobeW50 <84587632+KobeW50@users.noreply.github.com>

---------

Co-authored-by: inotia00 <108592928+inotia00@users.noreply.github.com>
Co-authored-by: KobeW50 <84587632+KobeW50@users.noreply.github.com>
2024-06-09 00:04:23 +09:00

45 lines
1.4 KiB
Kotlin

package app.revanced.patches.shared.elements
import app.revanced.patcher.data.ResourceContext
@Suppress("DEPRECATION", "unused")
object StringsElementsUtils {
internal fun ResourceContext.removeStringsElements(
replacements: Array<String>
) {
var languageList = emptyArray<String>()
val resourceDirectory = this["res"]
val dir = resourceDirectory.listFiles()
for (file in dir!!) {
val path = file.name
if (path.startsWith("values")) {
val targetXml = resourceDirectory.resolve(path).resolve("strings.xml")
if (targetXml.exists()) languageList += path
}
}
removeStringsElements(languageList, replacements)
}
internal fun ResourceContext.removeStringsElements(
paths: Array<String>,
replacements: Array<String>
) {
paths.forEach { path ->
val targetXmlPath = this["res"].resolve(path).resolve("strings.xml")
if (targetXmlPath.exists()) {
val targetXml = this["res/$path/strings.xml"]
replacements.forEach replacementsLoop@{ replacement ->
targetXml.writeText(
targetXml.readText()
.replaceFirst(""" {4}<string name="$replacement".+""".toRegex(), "")
)
}
}
}
}
}