Skip to content

Commit

Permalink
fix(YouTube - Theme): only set splash screen color if background colo…
Browse files Browse the repository at this point in the history
…rs are set
  • Loading branch information
oSumAtrIX committed Jul 21, 2023
1 parent a808eca commit f058db4
Showing 1 changed file with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")

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
// 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

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()
}

Expand Down

0 comments on commit f058db4

Please sign in to comment.