refactor custom-branding-icon patch

This commit is contained in:
inotia00 2023-01-30 10:53:34 +09:00
parent 5cee503357
commit a7c8fc2926
153 changed files with 164 additions and 168 deletions

View File

@ -6,104 +6,19 @@ import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.*
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.shared.annotation.YouTubeMusicCompatibility
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import app.revanced.shared.util.resources.IconHelper
@Patch
@Name("custom-branding-music-red")
@Description("Changes the YouTube Music launcher icon to your choice (defaults to ReVanced Red).")
@Name("custom-branding-music-afn-red")
@Description("Changes the YouTube Music launcher icon (Afn / Red).")
@YouTubeMusicCompatibility
@Version("0.0.1")
class CustomBrandingMusicPatch_Red : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
val classLoader = this.javaClass.classLoader
val resDirectory = context["res"]
if (!resDirectory.isDirectory) return PatchResultError("The res folder can not be found.")
// App Icon
val AppiconNames = arrayOf(
"adaptiveproduct_youtube_music_background_color_108",
"adaptiveproduct_youtube_music_foreground_color_108",
"ic_launcher_release"
)
mapOf(
"xxxhdpi" to 192,
"xxhdpi" to 144,
"xhdpi" to 96,
"hdpi" to 72,
"mdpi" to 48
).forEach { (iconDirectory, size) ->
AppiconNames.forEach iconLoop@{ iconName ->
Files.copy(
classLoader.getResourceAsStream("music/branding/red/launchericon/$size/$iconName.png")!!,
resDirectory.resolve("mipmap-$iconDirectory").resolve("$iconName.png").toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
}
// Other Resource
val drawables1 = "drawable-hdpi" to arrayOf(
"action_bar_logo",
"action_bar_logo_release",
"record"
)
val drawables2 = "drawable-large-hdpi" to arrayOf(
"record"
)
val drawables3 = "drawable-large-mdpi" to arrayOf(
"record"
)
val drawables4 = "drawable-large-xhdpi" to arrayOf(
"record"
)
val drawables5 = "drawable-mdpi" to arrayOf(
"action_bar_logo",
"record"
)
val drawables6 = "drawable-xhdpi" to arrayOf(
"action_bar_logo",
"record"
)
val drawables7 = "drawable-xlarge-hdpi" to arrayOf(
"record"
)
val drawables8 = "drawable-xlarge-mdpi" to arrayOf(
"record"
)
val drawables9 = "drawable-xxhdpi" to arrayOf(
"action_bar_logo",
"record"
)
val drawables10 = "drawable-xxxhdpi" to arrayOf(
"action_bar_logo"
)
val pngResources = arrayOf(drawables1, drawables2, drawables3, drawables4, drawables5, drawables6, drawables7, drawables8, drawables9, drawables10)
pngResources.forEach { (path, resourceNames) ->
resourceNames.forEach { name ->
val relativePath = "$path/$name.png"
Files.copy(
classLoader.getResourceAsStream("music/branding/red/resource/$relativePath")!!,
context["res"].resolve(relativePath).toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
}
IconHelper.customIconMusic(context, "red")
IconHelper.customIconMusicAdditional(context, "red")
return PatchResultSuccess()
}

View File

@ -6,10 +6,8 @@ import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.*
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.shared.annotation.YouTubeMusicCompatibility
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import app.revanced.shared.util.resources.IconHelper
@Patch(false)
@Name("custom-branding-music-revancify")
@ -18,45 +16,8 @@ import java.nio.file.StandardCopyOption
@Version("0.0.1")
class CustomBrandingMusicPatch_Revancify : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
val classLoader = this.javaClass.classLoader
val resDirectory = context["res"]
if (!resDirectory.isDirectory) return PatchResultError("The res folder can not be found.")
// App Icon
val AppiconNames = arrayOf(
"adaptiveproduct_youtube_music_background_color_108",
"adaptiveproduct_youtube_music_foreground_color_108",
"ic_launcher_release"
)
mapOf(
"xxxhdpi" to 192,
"xxhdpi" to 144,
"xhdpi" to 96,
"hdpi" to 72,
"mdpi" to 48
).forEach { (iconDirectory, size) ->
AppiconNames.forEach iconLoop@{ iconName ->
Files.copy(
classLoader.getResourceAsStream("music/branding/revancify/launchericon/$size/$iconName.png")!!,
resDirectory.resolve("mipmap-$iconDirectory").resolve("$iconName.png").toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
}
// MonoChrome Icon
arrayOf("drawable" to arrayOf("ic_app_icons_themed_youtube_music")).forEach { (path, resourceNames) ->
resourceNames.forEach { name ->
val relativePath = "$path/$name.xml"
Files.copy(
classLoader.getResourceAsStream("music/branding/revancify/monochromeicon/$relativePath")!!,
context["res"].resolve(relativePath).toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
}
IconHelper.customIconMusic(context, "revancify")
return PatchResultSuccess()
}

View File

@ -11,45 +11,44 @@ internal object IconHelper {
context: ResourceContext,
iconName: String
) {
val classLoader = this.javaClass.classLoader
val resDirectory = context["res"]
val Appnames = arrayOf(
val launchIcon = arrayOf(
"adaptiveproduct_youtube_background_color_108",
"adaptiveproduct_youtube_foreground_color_108",
"ic_launcher",
"ic_launcher_round"
)
val Splashnames = arrayOf(
val splashIcon = arrayOf(
"product_logo_youtube_color_24",
"product_logo_youtube_color_36",
"product_logo_youtube_color_144",
"product_logo_youtube_color_192"
)
mapOf(
"xxxhdpi" to 192,
"xxhdpi" to 144,
"xhdpi" to 96,
"hdpi" to 72,
"mdpi" to 48
).forEach { (iconDirectory, size) ->
Appnames.forEach iconLoop@{ name ->
Files.copy(
classLoader.getResourceAsStream("youtube/branding/$iconName/launchericon/$size/$name.png")!!,
resDirectory.resolve("mipmap-$iconDirectory").resolve("$name.png").toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
Splashnames.forEach iconLoop@{ name ->
Files.copy(
classLoader.getResourceAsStream("youtube/branding/$iconName/splashicon/$size/$name.png")!!,
resDirectory.resolve("drawable-$iconDirectory").resolve("$name.png").toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
}
copyResources(
context,
"youtube",
iconName,
"launchericon",
"mipmap",
launchIcon
)
copyResources(
context,
"youtube",
iconName,
"splashicon",
"drawable",
splashIcon
)
monochromeIcon(
context,
"youtube",
"adaptive_monochrome_ic_youtube_launcher",
iconName
)
context.xmlEditor["res/values-v31/styles.xml"].use { editor ->
with(editor.file) {
@ -64,19 +63,140 @@ internal object IconHelper {
}
}
}
}
try {
arrayOf("drawable" to arrayOf("adaptive_monochrome_ic_youtube_launcher")).forEach { (path, resourceNames) ->
resourceNames.forEach { name ->
val relativePath = "$path/$name.xml"
fun customIconMusic(
context: ResourceContext,
iconName: String
) {
val launchIcon = arrayOf(
"adaptiveproduct_youtube_music_background_color_108",
"adaptiveproduct_youtube_music_foreground_color_108",
"ic_launcher_release"
)
Files.copy(
classLoader.getResourceAsStream("youtube/branding/$iconName/monochromeicon/$relativePath")!!,
context["res"].resolve(relativePath).toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
copyResources(
context,
"music",
iconName,
"launchericon",
"mipmap",
launchIcon
)
monochromeIcon(
context,
"music",
"ic_app_icons_themed_youtube_music",
iconName
)
}
fun customIconMusicAdditional(
context: ResourceContext,
iconName: String
) {
val record = arrayOf(
"hdpi",
"large-hdpi",
"large-mdpi",
"large-xhdpi",
"mdpi",
"xhdpi",
"xlarge-hdpi",
"xlarge-mdpi",
"xxhdpi"
)
val actionbarLogo = arrayOf(
"hdpi",
"mdpi",
"xhdpi",
"xxhdpi",
"xxxhdpi"
)
val actionbarLogoRelease = arrayOf(
"hdpi"
)
copyMusicResources(
context,
iconName,
record,
"record"
)
copyMusicResources(
context,
iconName,
actionbarLogo,
"action_bar_logo"
)
copyMusicResources(
context,
iconName,
actionbarLogoRelease,
"action_bar_logo_release"
)
}
private fun copyResources(
context: ResourceContext,
appName: String,
iconName: String,
iconPath: String,
directory: String,
iconArray: Array<String>
){
arrayOf(
"xxxhdpi",
"xxhdpi",
"xhdpi",
"hdpi",
"mdpi"
).forEach { size ->
iconArray.forEach iconLoop@{ name ->
Files.copy(
this.javaClass.classLoader.getResourceAsStream("$appName/branding/$iconName/$iconPath/$size/$name.png")!!,
context["res"].resolve("$directory-$size").resolve("$name.png").toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
}
}
private fun monochromeIcon(
context: ResourceContext,
appName: String,
monochromeIconName: String,
iconName: String
){
try {
val relativePath = "drawable/$monochromeIconName.xml"
Files.copy(
this.javaClass.classLoader.getResourceAsStream("$appName/branding/$iconName/monochromeicon/$relativePath")!!,
context["res"].resolve(relativePath).toPath(),
StandardCopyOption.REPLACE_EXISTING
)
} catch (_: Exception) {}
}
private fun copyMusicResources(
context: ResourceContext,
iconName: String,
iconArray: Array<String>,
resourceNames: String
){
iconArray.forEach { path ->
val relativePath = "drawable-$path/$resourceNames.png"
Files.copy(
this.javaClass.classLoader.getResourceAsStream("music/branding/$iconName/resource/$relativePath")!!,
context["res"].resolve(relativePath).toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
}
}

Some files were not shown because too many files have changed in this diff Show More