From 0240efe33e5444625ca2b760c861c9046d3dc836 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sun, 22 Dec 2024 15:27:02 +0400 Subject: [PATCH] fix(YouTube - Theme): Use dark theme color for status and navigation bar --- .../youtube/layout/theme/ThemePatch.kt | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt index 2aa027802..92d3a3fd8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt @@ -163,22 +163,31 @@ val themePatch = bytecodePatch( } // Fix the splash screen dark mode background color. - // In earlier versions of the app this is white and makes no sense for dark mode. - // This is only required for 19.32 and greater, but is applied to all targets. - // Only dark mode needs this fix as light mode correctly uses the custom color. + // In 19.32+ the dark mode splash screen is white and fades to black. + // Maybe it's a bug in YT, or maybe it intentionally. Who knows. document("res/values-night/styles.xml").use { document -> - // Create a night mode specific override for the splash screen background. - val style = document.createElement("style") - style.setAttribute("name", "Theme.YouTube.Home") - style.setAttribute("parent", "@style/Base.V23.Theme.YouTube.Home") - - val windowItem = document.createElement("item") - windowItem.setAttribute("name", "android:windowBackground") - windowItem.textContent = "@color/$splashBackgroundColor" - style.appendChild(windowItem) - val resourcesNode = document.getElementsByTagName("resources").item(0) as Element - resourcesNode.appendChild(style) + val childNodes = resourcesNode.childNodes + + for (i in 0 until childNodes.length) { + val node = childNodes.item(i) as? Element ?: continue + val nodeAttributeName = node.getAttribute("name") + if (nodeAttributeName.startsWith("Theme.YouTube.Launcher")) { + val nodeAttributeParent = node.getAttribute("parent") + + val style = document.createElement("style") + style.setAttribute("name", "Theme.YouTube.Home") + style.setAttribute("parent", nodeAttributeParent) + + val windowItem = document.createElement("item") + windowItem.setAttribute("name", "android:windowBackground") + windowItem.textContent = "@color/$splashBackgroundColor" + style.appendChild(windowItem) + + resourcesNode.removeChild(node) + resourcesNode.appendChild(style) + } + } } } }