Skip to content

Commit

Permalink
feat(YouTube - Custom branding): Improve patch option description
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Feb 20, 2024
1 parent 3b8bc08 commit e27f56c
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import java.nio.file.Files
name = "Custom branding",
description = "Applies a custom app name and icon. Defaults to \"YouTube ReVanced\" and the ReVanced logo.",
compatiblePackages = [
CompatiblePackage("com.google.android.youtube")
CompatiblePackage("com.google.android.youtube"),
],
use = false
use = false,
)
@Suppress("unused")
object CustomBrandingPatch : ResourcePatch() {
Expand All @@ -28,15 +28,15 @@ object CustomBrandingPatch : ResourcePatch() {
"adaptiveproduct_youtube_background_color_108",
"adaptiveproduct_youtube_foreground_color_108",
"ic_launcher",
"ic_launcher_round"
"ic_launcher_round",
).map { "$it.png" }.toTypedArray()

private val mipmapDirectories = arrayOf(
"xxxhdpi",
"xxhdpi",
"xhdpi",
"hdpi",
"mdpi"
"mdpi",
).map { "mipmap-$it" }

private var appName by stringPatchOption(
Expand All @@ -49,7 +49,7 @@ object CustomBrandingPatch : ResourcePatch() {
"YouTube" to "YouTube",
),
title = "App name",
description = "The name of the app."
description = "The name of the app.",
)

private var icon by stringPatchOption(
Expand All @@ -58,22 +58,25 @@ object CustomBrandingPatch : ResourcePatch() {
values = mapOf("ReVanced Logo" to REVANCED_ICON),
title = "App icon",
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" }}
Each of these folders has to have the following files:
Each of these folders must contain the following files:
${iconResourceFileNames.joinToString("\n") { "- $it" }}
""".trimIndentMultiline()
""".trimIndentMultiline(),
)

override fun execute(context: ResourceContext) {
icon?.let { icon ->
// Change the app icon.
mipmapDirectories.map { directory ->
ResourceGroup(
directory, *iconResourceFileNames
directory,
*iconResourceFileNames,
)
}.let { resourceGroups ->
if (icon != REVANCED_ICON) {
Expand All @@ -87,11 +90,13 @@ object CustomBrandingPatch : ResourcePatch() {
group.resources.forEach { iconFileName ->
Files.write(
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) }
}
}
}

Expand All @@ -102,8 +107,8 @@ object CustomBrandingPatch : ResourcePatch() {
manifest.readText()
.replace(
"android:label=\"@string/application_name",
"android:label=\"$name"
)
"android:label=\"$name",
),
)
}
}
Expand Down

0 comments on commit e27f56c

Please sign in to comment.