feat(youtube): support version 18.19.35
This commit is contained in:
+10
-1
@@ -8,8 +8,8 @@ import app.revanced.patcher.patch.*
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patches.youtube.layout.seekbar.bytecode.patch.SeekbarColorBytecodePatch
|
||||
import app.revanced.patches.youtube.layout.theme.resource.ThemeResourcePatch
|
||||
import app.revanced.patches.youtube.layout.theme.annotations.ThemeCompatibility
|
||||
import app.revanced.patches.youtube.layout.theme.resource.ThemeResourcePatch
|
||||
|
||||
@Patch
|
||||
@Name("theme")
|
||||
@@ -45,5 +45,14 @@ class ThemeBytecodePatch : BytecodePatch() {
|
||||
description = "The background color of the light theme. Can be a hex color or a resource reference.",
|
||||
)
|
||||
)
|
||||
|
||||
var splashScreenBackgroundColor: String? by option(
|
||||
PatchOption.StringOption(
|
||||
key = "splashScreenBackgroundColor",
|
||||
default = "@android:color/black",
|
||||
title = "Background color for the splash screen",
|
||||
description = "The background color of the splash screen. Can be a hex color or a resource reference.",
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+60
-14
@@ -1,7 +1,9 @@
|
||||
package app.revanced.patches.youtube.layout.theme.resource
|
||||
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.patch.*
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.ResourcePatch
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
|
||||
import app.revanced.patches.shared.settings.preference.impl.InputType
|
||||
@@ -9,9 +11,8 @@ import app.revanced.patches.shared.settings.preference.impl.StringResource
|
||||
import app.revanced.patches.shared.settings.preference.impl.TextPreference
|
||||
import app.revanced.patches.youtube.layout.theme.bytecode.patch.ThemeBytecodePatch.Companion.darkThemeBackgroundColor
|
||||
import app.revanced.patches.youtube.layout.theme.bytecode.patch.ThemeBytecodePatch.Companion.lightThemeBackgroundColor
|
||||
import app.revanced.patches.youtube.layout.theme.bytecode.patch.ThemeBytecodePatch.Companion.splashScreenBackgroundColor
|
||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||
import app.revanced.util.resources.ResourceUtils
|
||||
import app.revanced.util.resources.ResourceUtils.copyResources
|
||||
import org.w3c.dom.Element
|
||||
|
||||
@DependsOn([SettingsPatch::class, ResourceMappingPatch::class])
|
||||
@@ -29,35 +30,80 @@ class ThemeResourcePatch : ResourcePatch {
|
||||
),
|
||||
)
|
||||
|
||||
val darkThemeBackgroundColor = darkThemeBackgroundColor!!
|
||||
val lightThemeBackgroundColor = lightThemeBackgroundColor!!
|
||||
|
||||
// Edit theme colors via resources.
|
||||
context.xmlEditor["res/values/colors.xml"].use { editor ->
|
||||
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
|
||||
|
||||
for (i in 0 until resourcesNode.childNodes.length) {
|
||||
val node = resourcesNode.childNodes.item(i) as? Element ?: continue
|
||||
val children = resourcesNode.childNodes
|
||||
for (i in 0 until children.length) {
|
||||
val node = children.item(i) as? Element ?: continue
|
||||
|
||||
node.textContent = when (node.getAttribute("name")) {
|
||||
"yt_black0", "yt_black1", "yt_black1_opacity95", "yt_black1_opacity98", "yt_black2", "yt_black3",
|
||||
"yt_black4", "yt_status_bar_background_dark", "material_grey_850" -> darkThemeBackgroundColor
|
||||
?: continue
|
||||
|
||||
"yt_white1", "yt_white1_opacity95", "yt_white1_opacity98",
|
||||
"yt_white2", "yt_white3", "yt_white4",
|
||||
-> lightThemeBackgroundColor
|
||||
-> lightThemeBackgroundColor ?: continue
|
||||
|
||||
else -> continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the resource file to change the splash screen color.
|
||||
context.copyResources(
|
||||
"theme", ResourceUtils.ResourceGroup("values-night-v31", "styles.xml")
|
||||
)
|
||||
splashScreenBackgroundColor ?: return PatchResultSuccess()
|
||||
|
||||
// Edit splash screen background color for Android 11 and below.
|
||||
context.xmlEditor["res/values/styles.xml"].use {
|
||||
val resourcesNode = it.file.getElementsByTagName("resources").item(0) as Element
|
||||
|
||||
val children = resourcesNode.childNodes
|
||||
for (i in 0 until children.length) {
|
||||
val node = children.item(i) as? Element ?: continue
|
||||
|
||||
if (node.tagName != "style") continue
|
||||
|
||||
val name = node.getAttribute("name")
|
||||
if (name != LAUNCHER_STYLE_NAME) continue
|
||||
|
||||
it.file.createElement("item").apply {
|
||||
setAttribute("name", "android:windowSplashScreenBackground")
|
||||
textContent = splashScreenBackgroundColor
|
||||
}.also(node::appendChild)
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Edit splash screen background color for Android 12+.
|
||||
|
||||
// Add the splash screen background color to the colors.xml file.
|
||||
context.xmlEditor["res/values/colors.xml"].use {
|
||||
val resourcesNode = it.file.getElementsByTagName("resources").item(0) as Element
|
||||
|
||||
it.file.createElement("color").apply {
|
||||
setAttribute("name", COLOR_NAME)
|
||||
setAttribute("category", "color")
|
||||
textContent = splashScreenBackgroundColor
|
||||
}.also(resourcesNode::appendChild)
|
||||
}
|
||||
|
||||
// Point to the splash screen background color.
|
||||
context.xmlEditor["res/drawable/quantum_launchscreen_youtube.xml"].use {
|
||||
val node = it.file.getElementsByTagName("layer-list").item(0) as Element
|
||||
|
||||
val backgroundColorItem = node.childNodes.item(1) as Element
|
||||
backgroundColorItem.apply {
|
||||
setAttribute("android:drawable", "@color/$COLOR_NAME")
|
||||
}
|
||||
}
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
}
|
||||
private companion object {
|
||||
private const val LAUNCHER_STYLE_NAME = "Base.Theme.YouTube.Launcher"
|
||||
private const val COLOR_NAME = "splash_background_color"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user