From 2485f3e1eac13d59462fcf127d628cb20349c5e5 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Wed, 3 May 2023 19:43:29 +0900 Subject: [PATCH] add `custom-branding-music-name` patch --- .../patch/CustomBrandingMusicNamePatch.kt | 53 +++++++++++++++++++ .../shared/patch/options/PatchOptions.kt | 26 ++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/music/layout/branding/name/patch/CustomBrandingMusicNamePatch.kt diff --git a/src/main/kotlin/app/revanced/patches/music/layout/branding/name/patch/CustomBrandingMusicNamePatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/branding/name/patch/CustomBrandingMusicNamePatch.kt new file mode 100644 index 000000000..3610c45ba --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/branding/name/patch/CustomBrandingMusicNamePatch.kt @@ -0,0 +1,53 @@ +package app.revanced.patches.music.layout.branding.name.patch + +import app.revanced.extensions.startsWithAny +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility +import app.revanced.patches.shared.patch.options.PatchOptions +import org.w3c.dom.Element + +@Patch(false) +@Name("custom-branding-music-name") +@DependsOn([PatchOptions::class]) +@Description("Changes the Music launcher name to your choice (defaults to RVX Music, ReVanced Extended Music).") +@YouTubeMusicCompatibility +@Version("0.0.1") +class CustomBrandingMusicNamePatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + + // App name + val resourceFileNames = arrayOf("strings.xml") + val fullName = PatchOptions.MusicAppNameFull + val shortName = PatchOptions.MusicAppNameShort + + context.forEach { + if (!it.name.startsWithAny(*resourceFileNames)) return@forEach + + context.xmlEditor[it.absolutePath].use { editor -> + val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element + + for (i in 0 until resourcesNode.childNodes.length) { + val node = resourcesNode.childNodes.item(i) + if (node !is Element) continue + + val element = resourcesNode.childNodes.item(i) as Element + element.textContent = when (element.getAttribute("name")) { + "app_name" -> "$fullName" + "app_launcher_name" -> "$shortName" + else -> continue + } + } + } + } + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt b/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt index 357fe46bd..5da36d712 100644 --- a/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt +++ b/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt @@ -25,7 +25,7 @@ class PatchOptions : ResourcePatch { companion object : OptionsContainer() { /** - * Custom Branding Name + * Custom Branding Name (YouTube) */ internal var YouTubeAppName: String? by option( PatchOption.StringOption( @@ -48,6 +48,30 @@ class PatchOptions : ResourcePatch { ) ) + /** + * Custom Branding Full Name (YouTube Music) + */ + internal var MusicAppNameFull: String? by option( + PatchOption.StringOption( + key = "MusicAppNameFull", + default = "ReVanced Extended Music", + title = "Application Name of YouTube Music", + description = "The name of the YouTube Music it will show on your notification panel." + ) + ) + + /** + * Custom Branding Short Name (YouTube Music) + */ + internal var MusicAppNameShort: String? by option( + PatchOption.StringOption( + key = "MusicAppNameShort", + default = "RVX Music", + title = "Application Name of YouTube Music", + description = "The name of the YouTube Music it will show on your home screen." + ) + ) + /** * Custom Package Name (YouTube Music) */