forked from ReVanced/revanced-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube - Change header): Change to ReVanced borderless logo hea…
…der by default (ReVanced#2512) Co-authored-by: LisoUseInAIKyrios <[email protected]>
- Loading branch information
1 parent
a2c4876
commit 75f785d
Showing
45 changed files
with
153 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/ChangeHeaderPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package app.revanced.patches.youtube.layout.branding.header | ||
|
||
import app.revanced.patcher.data.ResourceContext | ||
import app.revanced.patcher.patch.PatchException | ||
import app.revanced.patcher.patch.ResourcePatch | ||
import app.revanced.patcher.patch.annotation.CompatiblePackage | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption | ||
import app.revanced.util.ResourceGroup | ||
import app.revanced.util.copyResources | ||
import java.io.File | ||
|
||
@Patch( | ||
name = "Change header", | ||
description = "Change the in app header. Defaults to the ReVanced header.", | ||
compatiblePackages = [ | ||
CompatiblePackage("com.google.android.youtube") | ||
], | ||
use = false | ||
) | ||
@Suppress("unused") | ||
object ChangeHeaderPatch : ResourcePatch() { | ||
private const val HEADER_NAME = "yt_wordmark_header" | ||
private const val PREMIUM_HEADER_NAME = "yt_premium_wordmark_header" | ||
private const val REVANCED_HEADER_NAME = "ReVanced" | ||
private const val REVANCED_BORDERLESS_HEADER_NAME = "ReVanced (borderless logo)" | ||
|
||
private val targetResourceDirectoryNames = arrayOf( | ||
"xxxhdpi", | ||
"xxhdpi", | ||
"xhdpi", | ||
"mdpi", | ||
"hdpi", | ||
).map { dpi -> | ||
"drawable-$dpi" | ||
} | ||
|
||
private val variants = arrayOf("light", "dark") | ||
|
||
private val header by stringPatchOption( | ||
key = "header", | ||
default = REVANCED_BORDERLESS_HEADER_NAME, | ||
values = mapOf( | ||
"YouTube" to HEADER_NAME, | ||
"YouTube Premium" to PREMIUM_HEADER_NAME, | ||
"ReVanced" to REVANCED_HEADER_NAME, | ||
"ReVanced (borderless logo)" to REVANCED_BORDERLESS_HEADER_NAME, | ||
), | ||
title = "Header", | ||
description = """ | ||
The header to use in top bar or the path to a custom header. | ||
The path to a folder containing one or more of the following folders matching the DPI of your device: | ||
${targetResourceDirectoryNames.joinToString("\n") { "- $it" }} | ||
These folders must contain the following files: | ||
${variants.joinToString("\n") { variant -> "- ${HEADER_NAME}_$variant.png" }} | ||
""".trimIndent(), | ||
required = true, | ||
) | ||
|
||
override fun execute(context: ResourceContext) { | ||
// The directories to copy the header to. | ||
val targetResourceDirectories = targetResourceDirectoryNames.mapNotNull { | ||
context["res"].resolve(it).takeIf(File::exists) | ||
} | ||
// The files to replace in the target directories. | ||
val targetResourceFiles = targetResourceDirectoryNames.map { directoryName -> | ||
ResourceGroup( | ||
directoryName, | ||
*variants.map { variant -> "${HEADER_NAME}_$variant.png" }.toTypedArray() | ||
) | ||
} | ||
|
||
/** | ||
* A function that overwrites both header variants from [from] to [to] in the target resource directories. | ||
*/ | ||
val overwriteFromTo: (String, String) -> Unit = { from: String, to: String -> | ||
targetResourceDirectories.forEach { directory -> | ||
variants.forEach { variant -> | ||
val fromPath = directory.resolve("${from}_$variant.png") | ||
val toPath = directory.resolve("${to}_$variant.png") | ||
|
||
fromPath.copyTo(toPath, true) | ||
} | ||
} | ||
} | ||
|
||
// Functions to overwrite the header to the different variants. | ||
val toPremium = { overwriteFromTo(PREMIUM_HEADER_NAME, HEADER_NAME) } | ||
val toHeader = { overwriteFromTo(HEADER_NAME, PREMIUM_HEADER_NAME) } | ||
val toReVanced = { | ||
// Copy the ReVanced header to the resource directories. | ||
targetResourceFiles.forEach { context.copyResources("change-header/revanced", it) } | ||
|
||
// Overwrite the premium with the custom header as well. | ||
toHeader() | ||
} | ||
val toReVancedBorderless = { | ||
// Copy the ReVanced borderless header to the resource directories. | ||
targetResourceFiles.forEach { context.copyResources("change-header/revanced-borderless", it) } | ||
|
||
// Overwrite the premium with the custom header as well. | ||
toHeader() | ||
} | ||
val toCustom = { | ||
var copiedReplacementImages = false | ||
// For all the resource groups in the custom header folder, copy them to the resource directories. | ||
File(header!!).listFiles { file -> file.isDirectory }?.forEach { folder -> | ||
val targetDirectory = context["res"].resolve(folder.name) | ||
// Skip if the target directory (DPI) doesn't exist. | ||
if (!targetDirectory.exists()) return@forEach | ||
|
||
folder.listFiles { file -> file.isFile }?.forEach { | ||
val targetResourceFile = targetDirectory.resolve(it.name) | ||
|
||
it.copyTo(targetResourceFile, true) | ||
copiedReplacementImages = true | ||
} | ||
} | ||
|
||
if (!copiedReplacementImages) throw PatchException("Could not find any custom images resources in directory: $header") | ||
|
||
// Overwrite the premium with the custom header as well. | ||
toHeader() | ||
} | ||
|
||
when (header) { | ||
HEADER_NAME -> toHeader | ||
PREMIUM_HEADER_NAME -> toPremium | ||
REVANCED_HEADER_NAME -> toReVanced | ||
REVANCED_BORDERLESS_HEADER_NAME -> toReVancedBorderless | ||
else -> toCustom | ||
}() | ||
} | ||
} |
57 changes: 2 additions & 55 deletions
57
src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/PremiumHeadingPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,9 @@ | ||
package app.revanced.patches.youtube.layout.branding.header | ||
|
||
import app.revanced.patcher.data.ResourceContext | ||
import app.revanced.patcher.patch.PatchException | ||
import app.revanced.patcher.patch.ResourcePatch | ||
import app.revanced.patcher.patch.annotation.CompatiblePackage | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption | ||
import kotlin.io.path.copyTo | ||
|
||
@Patch( | ||
name = "Premium heading", | ||
description = "Adds or removes the YouTube Premium logo at the top of feeds.", | ||
compatiblePackages = [ | ||
CompatiblePackage("com.google.android.youtube") | ||
] | ||
) | ||
@Suppress("unused") | ||
@Deprecated("Use PremiumHeadingPatch instead.") | ||
object PremiumHeadingPatch : ResourcePatch() { | ||
private const val DEFAULT_HEADING_RES = "yt_wordmark_header" | ||
private const val PREMIUM_HEADING_RES = "yt_premium_wordmark_header" | ||
|
||
private val usePremiumHeading by booleanPatchOption( | ||
key = "usePremiumHeading", | ||
default = true, | ||
title = "Use premium heading", | ||
description = "Whether to use the YouTube Premium logo.", | ||
required = true, | ||
) | ||
|
||
override fun execute(context: ResourceContext) { | ||
val resDirectory = context["res"] | ||
|
||
val (original, replacement) = if (usePremiumHeading!!) | ||
PREMIUM_HEADING_RES to DEFAULT_HEADING_RES | ||
else | ||
DEFAULT_HEADING_RES to PREMIUM_HEADING_RES | ||
|
||
val variants = arrayOf("light", "dark") | ||
|
||
arrayOf( | ||
"xxxhdpi", | ||
"xxhdpi", | ||
"xhdpi", | ||
"hdpi", | ||
"mdpi" | ||
).mapNotNull { dpi -> | ||
resDirectory.resolve("drawable-$dpi").takeIf { it.exists() }?.toPath() | ||
}.also { | ||
if (it.isEmpty()) | ||
throw PatchException("The drawable folder can not be found. Therefore, the patch can not be applied.") | ||
}.forEach { path -> | ||
|
||
variants.forEach { mode -> | ||
val fromPath = path.resolve("${original}_$mode.png") | ||
val toPath = path.resolve("${replacement}_$mode.png") | ||
|
||
fromPath.copyTo(toPath, true) | ||
} | ||
} | ||
} | ||
override fun execute(context: ResourceContext) = ChangeHeaderPatch.execute(context) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+2.3 KB
...ces/change-header/revanced-borderless/drawable-hdpi/yt_wordmark_header_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.27 KB
...es/change-header/revanced-borderless/drawable-hdpi/yt_wordmark_header_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.53 KB
...ces/change-header/revanced-borderless/drawable-mdpi/yt_wordmark_header_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.5 KB
...es/change-header/revanced-borderless/drawable-mdpi/yt_wordmark_header_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.06 KB
...es/change-header/revanced-borderless/drawable-xhdpi/yt_wordmark_header_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.05 KB
...s/change-header/revanced-borderless/drawable-xhdpi/yt_wordmark_header_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.88 KB
...s/change-header/revanced-borderless/drawable-xxhdpi/yt_wordmark_header_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.84 KB
.../change-header/revanced-borderless/drawable-xxhdpi/yt_wordmark_header_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.49 KB
.../change-header/revanced-borderless/drawable-xxxhdpi/yt_wordmark_header_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.45 KB
...change-header/revanced-borderless/drawable-xxxhdpi/yt_wordmark_header_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.36 KB
...main/resources/change-header/revanced/drawable-hdpi/yt_wordmark_header_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.4 KB
...ain/resources/change-header/revanced/drawable-hdpi/yt_wordmark_header_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.06 KB
...main/resources/change-header/revanced/drawable-mdpi/yt_wordmark_header_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.04 KB
...ain/resources/change-header/revanced/drawable-mdpi/yt_wordmark_header_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.69 KB
...ain/resources/change-header/revanced/drawable-xhdpi/yt_wordmark_header_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.67 KB
...in/resources/change-header/revanced/drawable-xhdpi/yt_wordmark_header_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.15 KB
...in/resources/change-header/revanced/drawable-xxhdpi/yt_wordmark_header_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.14 KB
...n/resources/change-header/revanced/drawable-xxhdpi/yt_wordmark_header_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.5 KB
...n/resources/change-header/revanced/drawable-xxxhdpi/yt_wordmark_header_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.46 KB
.../resources/change-header/revanced/drawable-xxxhdpi/yt_wordmark_header_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes