mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 13:17:46 +02:00
feat(YouTube Music/Custom branding icon for YouTube Music): add patch option RestoreOldSplashIcon
https://github.com/inotia00/ReVanced_Extended/issues/2368
This commit is contained in:
@ -9,8 +9,10 @@ import app.revanced.patches.music.utils.settings.ResourceUtils.setIconType
|
||||
import app.revanced.util.ResourceGroup
|
||||
import app.revanced.util.Utils.trimIndentMultiline
|
||||
import app.revanced.util.copyResources
|
||||
import app.revanced.util.getResourceGroup
|
||||
import app.revanced.util.patch.BaseResourcePatch
|
||||
import app.revanced.util.underBarOrThrow
|
||||
import org.w3c.dom.Element
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
@ -71,17 +73,11 @@ object CustomBrandingIconPatch : BaseResourcePatch(
|
||||
"record"
|
||||
).map { "$it.png" }.toTypedArray()
|
||||
|
||||
private val launcherIconResourceGroups = mipmapDirectories.map { directory ->
|
||||
ResourceGroup(
|
||||
directory, *launcherIconResourceFileNames
|
||||
)
|
||||
}
|
||||
private val launcherIconResourceGroups =
|
||||
mipmapDirectories.getResourceGroup(launcherIconResourceFileNames)
|
||||
|
||||
private val splashIconResourceGroups = largeDrawableDirectories.map { directory ->
|
||||
ResourceGroup(
|
||||
directory, *splashIconResourceFileNames
|
||||
)
|
||||
}
|
||||
private val splashIconResourceGroups =
|
||||
largeDrawableDirectories.getResourceGroup(splashIconResourceFileNames)
|
||||
|
||||
private val AppIcon = stringPatchOption(
|
||||
key = "AppIcon",
|
||||
@ -110,6 +106,20 @@ object CustomBrandingIconPatch : BaseResourcePatch(
|
||||
required = true
|
||||
)
|
||||
|
||||
private val RestoreOldSplashIcon by booleanPatchOption(
|
||||
key = "RestoreOldSplashIcon",
|
||||
default = false,
|
||||
title = "Restore old splash icon",
|
||||
description = """
|
||||
Restore the old style splash icon.
|
||||
|
||||
If you enable both the old style splash icon and the Cairo splash animation,
|
||||
|
||||
Old style splash icon will appear first and then the Cairo splash animation will start.
|
||||
""".trimIndentMultiline(),
|
||||
required = true
|
||||
)
|
||||
|
||||
override fun execute(context: ResourceContext) {
|
||||
|
||||
// Check patch options first.
|
||||
@ -117,6 +127,7 @@ object CustomBrandingIconPatch : BaseResourcePatch(
|
||||
.underBarOrThrow()
|
||||
|
||||
val appIconResourcePath = "music/branding/$appIcon"
|
||||
val youtubeMusicIconResourcePath = "music/branding/youtube_music"
|
||||
|
||||
// Check if a custom path is used in the patch options.
|
||||
if (!availableIcon.containsValue(appIcon)) {
|
||||
@ -160,6 +171,39 @@ object CustomBrandingIconPatch : BaseResourcePatch(
|
||||
context.copyResources("$appIconResourcePath/monochrome", resourceGroup)
|
||||
}
|
||||
|
||||
// Change splash icon.
|
||||
if (RestoreOldSplashIcon == true) {
|
||||
var oldSplashIconNotExists: Boolean
|
||||
|
||||
context.xmlEditor["res/drawable/splash_screen.xml"].use { editor ->
|
||||
editor.file.apply {
|
||||
val node = getElementsByTagName("layer-list").item(0)
|
||||
oldSplashIconNotExists = (node as Element)
|
||||
.getElementsByTagName("item")
|
||||
.length == 1
|
||||
|
||||
if (oldSplashIconNotExists) {
|
||||
createElement("item").also { itemNode ->
|
||||
itemNode.appendChild(
|
||||
createElement("bitmap").also { bitmapNode ->
|
||||
bitmapNode.setAttribute("android:gravity", "center")
|
||||
bitmapNode.setAttribute("android:src", "@drawable/record")
|
||||
}
|
||||
)
|
||||
node.appendChild(itemNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (oldSplashIconNotExists) {
|
||||
splashIconResourceGroups.let { resourceGroups ->
|
||||
resourceGroups.forEach {
|
||||
context.copyResources("$youtubeMusicIconResourcePath/splash", it, createDirectoryIfNotExist = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Change splash icon.
|
||||
if (ChangeSplashIcon == true) {
|
||||
// Some resources have been removed in the latest YouTube Music.
|
||||
|
@ -11,6 +11,7 @@ import app.revanced.util.Utils.trimIndentMultiline
|
||||
import app.revanced.util.copyFile
|
||||
import app.revanced.util.copyResources
|
||||
import app.revanced.util.copyXmlNode
|
||||
import app.revanced.util.getResourceGroup
|
||||
import app.revanced.util.patch.BaseResourcePatch
|
||||
import app.revanced.util.underBarOrThrow
|
||||
|
||||
@ -73,12 +74,6 @@ object CustomBrandingIconPatch : BaseResourcePatch(
|
||||
"avd_anim"
|
||||
).map { "$it.xml" }.toTypedArray()
|
||||
|
||||
private fun List<String>.getResourceGroup(fileNames: Array<String>) = map { directory ->
|
||||
ResourceGroup(
|
||||
directory, *fileNames
|
||||
)
|
||||
}
|
||||
|
||||
private val launcherIconResourceGroups =
|
||||
mipmapDirectories.getResourceGroup(launcherIconResourceFileNames)
|
||||
|
||||
|
Reference in New Issue
Block a user