From f058db4ba4300400ac92b4a9790708eb8bde7092 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 22 Jul 2023 00:08:25 +0200 Subject: [PATCH] fix(YouTube - Theme): only set splash screen color if background colors are set --- .../theme/resource/ThemeResourcePatch.kt | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt index 9bafb4178..ecdbbb192 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt @@ -66,27 +66,31 @@ class ThemeResourcePatch : ResourcePatch { addColorResource(context, "res/values-night/colors.xml", SPLASH_BACKGROUND_COLOR, it) } - // Edit splash screen files and change the background color. - val splashScreenResourceFiles = listOf( - "res/drawable/quantum_launchscreen_youtube.xml", - "res/drawable-sw600dp/quantum_launchscreen_youtube.xml") + // Edit splash screen files and change the background color, + // if the background colors are set. + if (darkThemeBackgroundColor != null && lightThemeBackgroundColor != null) { + val splashScreenResourceFiles = listOf( + "res/drawable/quantum_launchscreen_youtube.xml", + "res/drawable-sw600dp/quantum_launchscreen_youtube.xml") - splashScreenResourceFiles.forEach editSplashScreen@ { resourceFile -> - context.xmlEditor[resourceFile].use { - val layerList = it.file.getElementsByTagName("layer-list").item(0) as Element + splashScreenResourceFiles.forEach editSplashScreen@ { resourceFile -> + context.xmlEditor[resourceFile].use { + val layerList = it.file.getElementsByTagName("layer-list").item(0) as Element - val childNodes = layerList.childNodes - for (i in 0 until childNodes.length) { - val node = childNodes.item(i) - if (node is Element && node.hasAttribute("android:drawable")) { - node.setAttribute("android:drawable", "@color/$SPLASH_BACKGROUND_COLOR") - return@editSplashScreen + val childNodes = layerList.childNodes + for (i in 0 until childNodes.length) { + val node = childNodes.item(i) + if (node is Element && node.hasAttribute("android:drawable")) { + node.setAttribute("android:drawable", "@color/$SPLASH_BACKGROUND_COLOR") + return@editSplashScreen + } } + return PatchResultError("Failed to modify launch screen") } - return PatchResultError("Failed to modify launch screen") } } + return PatchResultSuccess() }