feat: custom-branding patch

This commit is contained in:
oSumAtrIX 2022-06-14 23:49:51 +02:00
parent 6046f077ab
commit 0d65ea8cdb
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
18 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package app.revanced.patches.youtube.layout.icon.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package
@Compatibility(
[Package(
"com.google.android.youtube", arrayOf()
)]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class CustomBrandingCompatibility

View File

@ -0,0 +1,56 @@
package app.revanced.patches.youtube.layout.icon.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.implementation.ResourceData
import app.revanced.patcher.patch.annotations.Dependencies
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.implementation.ResourcePatch
import app.revanced.patcher.patch.implementation.misc.PatchResult
import app.revanced.patcher.patch.implementation.misc.PatchResultError
import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess
import app.revanced.patches.youtube.layout.icon.annotations.CustomBrandingCompatibility
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
import java.nio.file.Files
@Patch
@Dependencies(
dependencies = [FixLocaleConfigErrorPatch::class]
)
@Name("custom-branding")
@Description("Change the branding of YouTube.")
@CustomBrandingCompatibility
@Version("0.0.1")
class CustomBrandingPatch : ResourcePatch() {
override fun execute(data: ResourceData): PatchResult {
val resDirectory = data.get("res")
if (!resDirectory.isDirectory) return PatchResultError("The res folder can not be found.")
val iconNames = arrayOf(
"adaptiveproduct_youtube_background_color_108",
"adaptiveproduct_youtube_foreground_color_108",
"ic_launcher",
"ic_launcher_round"
)
mapOf(
"mipmap-xxxhdpi" to 192,
"mipmap-xxhdpi" to 144,
"mipmap-xhdpi" to 96,
"mipmap-hdpi" to 72,
"mipmap-mdpi" to 48
).forEach { (iconDirectory, size) ->
iconNames.forEach iconLoop@{ iconName ->
val iconFile = this.javaClass.classLoader.getResourceAsStream("$size/$iconName.png")
?: return PatchResultError("The icon $iconName can not be found.")
Files.write(
resDirectory.resolve(iconDirectory).resolve("$iconName.png").toPath(), iconFile.readAllBytes()
)
}
}
return PatchResultSuccess()
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB