From 09a8eb71142a642b328e87e4963a3e6ab19908ba Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Mon, 31 Mar 2025 21:05:06 +0900 Subject: [PATCH] fix(YouTube - Custom branding icon): Splash animation background color is always white https://github.com/inotia00/ReVanced_Extended/issues/2892 --- .../branding/icon/CustomBrandingIconPatch.kt | 21 +++--- .../fix/splash/DarkModeSplashScreenPatch.kt | 73 +++++++++++++------ .../utils/playservice/VersionCheckPatch.kt | 5 +- 3 files changed, 65 insertions(+), 34 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt index 1ccc3e575..e954f02b8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt @@ -217,8 +217,16 @@ val customBrandingIconPatch = resourcePatch( } } - val styleList = if (is_19_32_or_greater) - listOf( + val styleList = mutableListOf( + Triple( + "values-v31", + "Base.Theme.YouTube.Launcher", + "@style/Theme.AppCompat.DayNight.NoActionBar" + ), + ) + + if (is_19_32_or_greater) { + styleList += listOf( Triple( "values-night-v31", "Theme.YouTube.Home", @@ -230,14 +238,7 @@ val customBrandingIconPatch = resourcePatch( "@style/Base.V27.Theme.YouTube.Home" ), ) - else - listOf( - Triple( - "values-v31", - "Base.Theme.YouTube.Launcher", - "@style/Theme.AppCompat.DayNight.NoActionBar" - ), - ) + } styleList.forEach { (directory, nodeAttributeName, nodeAttributeParent) -> document("res/$directory/styles.xml").use { document -> diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt index 2e3276993..f67961e91 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt @@ -1,8 +1,11 @@ package app.revanced.patches.youtube.utils.fix.splash import app.revanced.patcher.patch.resourcePatch +import app.revanced.patches.youtube.utils.compatibility.Constants.YOUTUBE_PACKAGE_NAME import app.revanced.patches.youtube.utils.playservice.is_19_32_or_greater import app.revanced.patches.youtube.utils.playservice.versionCheckPatch +import app.revanced.patches.youtube.utils.settings.ResourceUtils.youtubePackageName +import app.revanced.util.findElementByAttributeValueOrThrow import org.w3c.dom.Element /** @@ -25,31 +28,55 @@ val darkModeSplashScreenPatch = resourcePatch( } arrayOf( - "values-night" to "@style/Base.V23.Theme.YouTube.Home", - "values-night-v27" to "@style/Base.V27.Theme.YouTube.Home", - ).forEach { (directory, parent) -> + "values-night", + "values-night-v27", + ).forEach { directory -> document("res/$directory/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", parent) - - val colorSplashBackgroundColor = "@color/yt_black1" - arrayOf( - "android:navigationBarColor" to colorSplashBackgroundColor, - "android:windowBackground" to colorSplashBackgroundColor, - "android:colorBackground" to colorSplashBackgroundColor, - "colorPrimaryDark" to colorSplashBackgroundColor, - "android:windowLightStatusBar" to "false", - ).forEach { (name, value) -> - val styleItem = document.createElement("item") - styleItem.setAttribute("name", name) - styleItem.textContent = value - style.appendChild(styleItem) - } - 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 colorSplashBackgroundColor = "@color/yt_black1" + arrayOf( + "android:navigationBarColor" to colorSplashBackgroundColor, + "android:windowBackground" to colorSplashBackgroundColor, + "android:colorBackground" to colorSplashBackgroundColor, + "colorPrimaryDark" to colorSplashBackgroundColor, + "android:windowLightStatusBar" to "false", + ).forEach { (name, value) -> + val styleItem = document.createElement("item") + styleItem.setAttribute("name", name) + styleItem.textContent = value + style.appendChild(styleItem) + } + + resourcesNode.removeChild(node) + resourcesNode.appendChild(style) + } + } + } + } + } + + finalize { + // GmsCore support included + if (youtubePackageName != YOUTUBE_PACKAGE_NAME) { + document("AndroidManifest.xml").use { document -> + val mainActivityElement = document.childNodes.findElementByAttributeValueOrThrow( + "android:name", + "com.google.android.apps.youtube.app.watchwhile.MainActivity", + ) + + mainActivityElement.setAttribute("android:launchMode", "singleTask") } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/playservice/VersionCheckPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/playservice/VersionCheckPatch.kt index 19bf4774f..11e9b7239 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/playservice/VersionCheckPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/playservice/VersionCheckPatch.kt @@ -55,6 +55,8 @@ var is_19_36_or_greater = false private set var is_19_41_or_greater = false private set +var is_19_42_or_greater = false + private set var is_19_43_or_greater = false private set var is_19_44_or_greater = false @@ -116,7 +118,8 @@ val versionCheckPatch = resourcePatch( is_19_32_or_greater = 243305000 <= playStoreServicesVersion is_19_34_or_greater = 243499000 <= playStoreServicesVersion is_19_36_or_greater = 243705000 <= playStoreServicesVersion - is_19_41_or_greater = 244305000 <= playStoreServicesVersion + is_19_41_or_greater = 244205000 <= playStoreServicesVersion + is_19_42_or_greater = 244305000 <= playStoreServicesVersion is_19_43_or_greater = 244405000 <= playStoreServicesVersion is_19_44_or_greater = 244505000 <= playStoreServicesVersion is_19_46_or_greater = 244705000 <= playStoreServicesVersion