feat(YouTube - Custom branding): Improve patch option description

This commit is contained in:
oSumAtrIX 2024-02-20 22:30:50 +01:00
parent 3b8bc08d4e
commit e27f56c8a3
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4

View file

@ -15,9 +15,9 @@ import java.nio.file.Files
name = "Custom branding", name = "Custom branding",
description = "Applies a custom app name and icon. Defaults to \"YouTube ReVanced\" and the ReVanced logo.", description = "Applies a custom app name and icon. Defaults to \"YouTube ReVanced\" and the ReVanced logo.",
compatiblePackages = [ compatiblePackages = [
CompatiblePackage("com.google.android.youtube") CompatiblePackage("com.google.android.youtube"),
], ],
use = false use = false,
) )
@Suppress("unused") @Suppress("unused")
object CustomBrandingPatch : ResourcePatch() { object CustomBrandingPatch : ResourcePatch() {
@ -28,7 +28,7 @@ object CustomBrandingPatch : ResourcePatch() {
"adaptiveproduct_youtube_background_color_108", "adaptiveproduct_youtube_background_color_108",
"adaptiveproduct_youtube_foreground_color_108", "adaptiveproduct_youtube_foreground_color_108",
"ic_launcher", "ic_launcher",
"ic_launcher_round" "ic_launcher_round",
).map { "$it.png" }.toTypedArray() ).map { "$it.png" }.toTypedArray()
private val mipmapDirectories = arrayOf( private val mipmapDirectories = arrayOf(
@ -36,7 +36,7 @@ object CustomBrandingPatch : ResourcePatch() {
"xxhdpi", "xxhdpi",
"xhdpi", "xhdpi",
"hdpi", "hdpi",
"mdpi" "mdpi",
).map { "mipmap-$it" } ).map { "mipmap-$it" }
private var appName by stringPatchOption( private var appName by stringPatchOption(
@ -49,7 +49,7 @@ object CustomBrandingPatch : ResourcePatch() {
"YouTube" to "YouTube", "YouTube" to "YouTube",
), ),
title = "App name", title = "App name",
description = "The name of the app." description = "The name of the app.",
) )
private var icon by stringPatchOption( private var icon by stringPatchOption(
@ -58,14 +58,16 @@ object CustomBrandingPatch : ResourcePatch() {
values = mapOf("ReVanced Logo" to REVANCED_ICON), values = mapOf("ReVanced Logo" to REVANCED_ICON),
title = "App icon", title = "App icon",
description = """ description = """
The path to a folder containing the following folders: The icon to apply to the app.
If a path to a folder is provided, the folder must contain the following folders:
${mipmapDirectories.joinToString("\n") { "- $it" }} ${mipmapDirectories.joinToString("\n") { "- $it" }}
Each of these folders has to have the following files: Each of these folders must contain the following files:
${iconResourceFileNames.joinToString("\n") { "- $it" }} ${iconResourceFileNames.joinToString("\n") { "- $it" }}
""".trimIndentMultiline() """.trimIndentMultiline(),
) )
override fun execute(context: ResourceContext) { override fun execute(context: ResourceContext) {
@ -73,7 +75,8 @@ object CustomBrandingPatch : ResourcePatch() {
// Change the app icon. // Change the app icon.
mipmapDirectories.map { directory -> mipmapDirectories.map { directory ->
ResourceGroup( ResourceGroup(
directory, *iconResourceFileNames directory,
*iconResourceFileNames,
) )
}.let { resourceGroups -> }.let { resourceGroups ->
if (icon != REVANCED_ICON) { if (icon != REVANCED_ICON) {
@ -87,11 +90,13 @@ object CustomBrandingPatch : ResourcePatch() {
group.resources.forEach { iconFileName -> group.resources.forEach { iconFileName ->
Files.write( Files.write(
toDirectory.resolve(iconFileName).toPath(), toDirectory.resolve(iconFileName).toPath(),
fromDirectory.resolve(iconFileName).readBytes() fromDirectory.resolve(iconFileName).readBytes(),
) )
} }
} }
} else resourceGroups.forEach { context.copyResources("custom-branding", it) } } else {
resourceGroups.forEach { context.copyResources("custom-branding", it) }
}
} }
} }
@ -102,8 +107,8 @@ object CustomBrandingPatch : ResourcePatch() {
manifest.readText() manifest.readText()
.replace( .replace(
"android:label=\"@string/application_name", "android:label=\"@string/application_name",
"android:label=\"$name" "android:label=\"$name",
) ),
) )
} }
} }