mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-07 18:14:36 +02:00
feat(YouTube Music): split Custom header for YouTube Music
patch from the Custom branding icon for YouTube Music
patch
This commit is contained in:
parent
1d592b8f3a
commit
1e85df5fc5
@ -5,6 +5,7 @@ import app.revanced.patcher.patch.PatchException
|
|||||||
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption
|
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption
|
||||||
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
|
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
|
||||||
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
|
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
|
||||||
|
import app.revanced.patches.music.utils.settings.ResourceUtils.setIconType
|
||||||
import app.revanced.util.ResourceGroup
|
import app.revanced.util.ResourceGroup
|
||||||
import app.revanced.util.Utils.trimIndentMultiline
|
import app.revanced.util.Utils.trimIndentMultiline
|
||||||
import app.revanced.util.copyResources
|
import app.revanced.util.copyResources
|
||||||
@ -56,12 +57,6 @@ object CustomBrandingIconPatch : BaseResourcePatch(
|
|||||||
|
|
||||||
private val mipmapDirectories = sizeArray.map { "mipmap-$it" }
|
private val mipmapDirectories = sizeArray.map { "mipmap-$it" }
|
||||||
|
|
||||||
private val headerIconResourceFileNames = arrayOf(
|
|
||||||
"action_bar_logo",
|
|
||||||
"logo_music",
|
|
||||||
"ytm_logo"
|
|
||||||
).map { "$it.png" }.toTypedArray()
|
|
||||||
|
|
||||||
private val launcherIconResourceFileNames = arrayOf(
|
private val launcherIconResourceFileNames = arrayOf(
|
||||||
"adaptiveproduct_youtube_music_background_color_108",
|
"adaptiveproduct_youtube_music_background_color_108",
|
||||||
"adaptiveproduct_youtube_music_foreground_color_108",
|
"adaptiveproduct_youtube_music_foreground_color_108",
|
||||||
@ -76,12 +71,6 @@ object CustomBrandingIconPatch : BaseResourcePatch(
|
|||||||
"record"
|
"record"
|
||||||
).map { "$it.png" }.toTypedArray()
|
).map { "$it.png" }.toTypedArray()
|
||||||
|
|
||||||
private val headerIconResourceGroups = drawableDirectories.map { directory ->
|
|
||||||
ResourceGroup(
|
|
||||||
directory, *headerIconResourceFileNames
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val launcherIconResourceGroups = mipmapDirectories.map { directory ->
|
private val launcherIconResourceGroups = mipmapDirectories.map { directory ->
|
||||||
ResourceGroup(
|
ResourceGroup(
|
||||||
directory, *launcherIconResourceFileNames
|
directory, *launcherIconResourceFileNames
|
||||||
@ -113,14 +102,6 @@ object CustomBrandingIconPatch : BaseResourcePatch(
|
|||||||
required = true
|
required = true
|
||||||
)
|
)
|
||||||
|
|
||||||
private val ChangeHeader by booleanPatchOption(
|
|
||||||
key = "ChangeHeader",
|
|
||||||
default = false,
|
|
||||||
title = "Change header",
|
|
||||||
description = "Apply the custom branding icon to the header.",
|
|
||||||
required = true
|
|
||||||
)
|
|
||||||
|
|
||||||
private val ChangeSplashIcon by booleanPatchOption(
|
private val ChangeSplashIcon by booleanPatchOption(
|
||||||
key = "ChangeSplashIcon",
|
key = "ChangeSplashIcon",
|
||||||
default = true,
|
default = true,
|
||||||
@ -179,15 +160,6 @@ object CustomBrandingIconPatch : BaseResourcePatch(
|
|||||||
context.copyResources("$appIconResourcePath/monochrome", resourceGroup)
|
context.copyResources("$appIconResourcePath/monochrome", resourceGroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change header.
|
|
||||||
if (ChangeHeader == true) {
|
|
||||||
headerIconResourceGroups.let { resourceGroups ->
|
|
||||||
resourceGroups.forEach {
|
|
||||||
context.copyResources("$appIconResourcePath/header", it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change splash icon.
|
// Change splash icon.
|
||||||
if (ChangeSplashIcon == true) {
|
if (ChangeSplashIcon == true) {
|
||||||
splashIconResourceGroups.let { resourceGroups ->
|
splashIconResourceGroups.let { resourceGroups ->
|
||||||
@ -196,6 +168,8 @@ object CustomBrandingIconPatch : BaseResourcePatch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIconType(appIcon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,139 @@
|
|||||||
|
package app.revanced.patches.music.layout.header
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.ResourceContext
|
||||||
|
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
|
||||||
|
import app.revanced.patches.music.utils.compatibility.Constants
|
||||||
|
import app.revanced.patches.music.utils.settings.ResourceUtils
|
||||||
|
import app.revanced.util.ResourceGroup
|
||||||
|
import app.revanced.util.Utils.trimIndentMultiline
|
||||||
|
import app.revanced.util.copyFile
|
||||||
|
import app.revanced.util.copyResources
|
||||||
|
import app.revanced.util.patch.BaseResourcePatch
|
||||||
|
import app.revanced.util.underBarOrThrow
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
object ChangeHeaderPatch : BaseResourcePatch(
|
||||||
|
name = "Custom header for YouTube Music",
|
||||||
|
description = "Applies a custom header in the top left corner within the app.",
|
||||||
|
compatiblePackages = Constants.COMPATIBLE_PACKAGE,
|
||||||
|
use = false,
|
||||||
|
) {
|
||||||
|
private const val DEFAULT_HEADER_KEY = "Custom branding icon"
|
||||||
|
private const val DEFAULT_HEADER_VALUE = "custom_branding_icon"
|
||||||
|
|
||||||
|
private val actionBarLogoResourceDirectoryNames = mapOf(
|
||||||
|
"xxxhdpi" to "320px x 96px",
|
||||||
|
"xxhdpi" to "240px x 72px",
|
||||||
|
"xhdpi" to "160px x 48px",
|
||||||
|
"hdpi" to "121px x 36px",
|
||||||
|
"mdpi" to "80px x 24px",
|
||||||
|
).map { (dpi, dim) ->
|
||||||
|
"drawable-$dpi" to dim
|
||||||
|
}.toMap()
|
||||||
|
|
||||||
|
private val logoMusicResourceDirectoryNames = mapOf(
|
||||||
|
"xxxhdpi" to "576px x 200px",
|
||||||
|
"xxhdpi" to "432px x 150px",
|
||||||
|
"xhdpi" to "288px x 100px",
|
||||||
|
"hdpi" to "217px x 76px",
|
||||||
|
"mdpi" to "144px x 50px",
|
||||||
|
).map { (dpi, dim) ->
|
||||||
|
"drawable-$dpi" to dim
|
||||||
|
}.toMap()
|
||||||
|
|
||||||
|
private val ytmMusicLogoResourceDirectoryNames = mapOf(
|
||||||
|
"xxxhdpi" to "412px x 144px",
|
||||||
|
"xxhdpi" to "309px x 108px",
|
||||||
|
"xhdpi" to "206px x 72px",
|
||||||
|
"hdpi" to "155px x 54px",
|
||||||
|
"mdpi" to "103px x 36px",
|
||||||
|
).map { (dpi, dim) ->
|
||||||
|
"drawable-$dpi" to dim
|
||||||
|
}.toMap()
|
||||||
|
|
||||||
|
private val headerIconResourceFileNames = arrayOf(
|
||||||
|
"action_bar_logo",
|
||||||
|
"logo_music",
|
||||||
|
"ytm_logo"
|
||||||
|
).map { "$it.png" }.toTypedArray()
|
||||||
|
|
||||||
|
private val headerIconResourceGroups =
|
||||||
|
actionBarLogoResourceDirectoryNames.keys.map { directory ->
|
||||||
|
ResourceGroup(
|
||||||
|
directory, *headerIconResourceFileNames
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val getDescription = {
|
||||||
|
var descriptionBody = """
|
||||||
|
The header to apply to the app.
|
||||||
|
|
||||||
|
Patch option '$DEFAULT_HEADER_KEY' applies only when:
|
||||||
|
|
||||||
|
1. Patch 'Custom branding icon for YouTube Music' is included.
|
||||||
|
2. Patch option for 'Custom branding icon for YouTube Music' is selected from the preset.
|
||||||
|
|
||||||
|
If a path to a folder is provided, the folder must contain one or more of the following folders, depending on the DPI of the device:
|
||||||
|
|
||||||
|
${actionBarLogoResourceDirectoryNames.keys.joinToString("\n") { "- $it" }}
|
||||||
|
|
||||||
|
Each of the folders must contain all of the following files:
|
||||||
|
|
||||||
|
${headerIconResourceFileNames.joinToString("\n") { "- $it" }}
|
||||||
|
"""
|
||||||
|
|
||||||
|
mapOf(
|
||||||
|
"action_bar_logo.png" to actionBarLogoResourceDirectoryNames,
|
||||||
|
"logo_music.png" to logoMusicResourceDirectoryNames,
|
||||||
|
"ytm_logo.png" to ytmMusicLogoResourceDirectoryNames
|
||||||
|
).forEach { (images, directoryNames) ->
|
||||||
|
descriptionBody += """
|
||||||
|
The image '$images' dimensions must be as follows:
|
||||||
|
|
||||||
|
${directoryNames.map { (dpi, dim) -> "- $dpi: $dim" }.joinToString("\n")}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
descriptionBody.trimIndentMultiline()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val CustomHeader = stringPatchOption(
|
||||||
|
key = "CustomHeader",
|
||||||
|
default = DEFAULT_HEADER_VALUE,
|
||||||
|
values = mapOf(
|
||||||
|
DEFAULT_HEADER_KEY to DEFAULT_HEADER_VALUE
|
||||||
|
),
|
||||||
|
title = "Custom header",
|
||||||
|
description = getDescription(),
|
||||||
|
required = true,
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun execute(context: ResourceContext) {
|
||||||
|
|
||||||
|
// Check patch options first.
|
||||||
|
val customHeader = CustomHeader
|
||||||
|
.underBarOrThrow()
|
||||||
|
|
||||||
|
val customBrandingIconType = ResourceUtils.getIconType()
|
||||||
|
val customBrandingIconIncluded = customBrandingIconType != "default"
|
||||||
|
|
||||||
|
val warnings = "WARNING: Invalid header path: $customHeader. Does not apply patches."
|
||||||
|
|
||||||
|
if (customHeader != DEFAULT_HEADER_VALUE) {
|
||||||
|
context.copyFile(
|
||||||
|
headerIconResourceGroups,
|
||||||
|
customHeader,
|
||||||
|
warnings
|
||||||
|
)
|
||||||
|
} else if (customBrandingIconIncluded) {
|
||||||
|
headerIconResourceGroups.let { resourceGroups ->
|
||||||
|
resourceGroups.forEach {
|
||||||
|
context.copyResources("music/branding/$customBrandingIconType/header", it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println(warnings)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -28,6 +28,13 @@ object ResourceUtils {
|
|||||||
|
|
||||||
var musicPackageName = "com.google.android.apps.youtube.music"
|
var musicPackageName = "com.google.android.apps.youtube.music"
|
||||||
|
|
||||||
|
private var iconType = "default"
|
||||||
|
fun getIconType() = iconType
|
||||||
|
|
||||||
|
fun setIconType(iconName: String) {
|
||||||
|
iconType = iconName
|
||||||
|
}
|
||||||
|
|
||||||
private fun isIncludedCategory(category: String): Boolean {
|
private fun isIncludedCategory(category: String): Boolean {
|
||||||
CategoryType.entries.forEach { preference ->
|
CategoryType.entries.forEach { preference ->
|
||||||
if (category == preference.value)
|
if (category == preference.value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user