feat(theme): arbitrary background color for light theme (#565)

This commit is contained in:
Pranshu Goyal 2022-09-22 02:31:23 +05:30 committed by GitHub
parent 10e028626f
commit da40e7e0cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,7 +23,8 @@ import org.w3c.dom.Element
@Version("0.0.1") @Version("0.0.1")
class ThemePatch : ResourcePatch() { class ThemePatch : ResourcePatch() {
override fun execute(data: ResourceData): PatchResult { override fun execute(data: ResourceData): PatchResult {
val backgroundColor = backgroundColor!! val darkThemeBackgroundColor = darkThemeBackgroundColor!!
val lightThemeBackgroundColor = lightThemeBackgroundColor!!
data.xmlEditor["res/values/colors.xml"].use { editor -> data.xmlEditor["res/values/colors.xml"].use { editor ->
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
@ -33,7 +34,11 @@ class ThemePatch : ResourcePatch() {
node.textContent = when (node.getAttribute("name")) { node.textContent = when (node.getAttribute("name")) {
"yt_black1", "yt_black1_opacity95", "yt_black2", "yt_black3", "yt_black4", "yt_black1", "yt_black1_opacity95", "yt_black2", "yt_black3", "yt_black4",
"yt_status_bar_background_dark" -> backgroundColor "yt_status_bar_background_dark" -> darkThemeBackgroundColor
"yt_white1", "yt_white1_opacity95", "yt_white2", "yt_white3",
"yt_white4" -> lightThemeBackgroundColor
else -> continue else -> continue
} }
} }
@ -43,7 +48,7 @@ class ThemePatch : ResourcePatch() {
} }
companion object : OptionsContainer() { companion object : OptionsContainer() {
var backgroundColor: String? by option( var darkThemeBackgroundColor: String? by option(
PatchOption.StringOption( PatchOption.StringOption(
key = "darkThemeBackgroundColor", key = "darkThemeBackgroundColor",
default = "@android:color/black", default = "@android:color/black",
@ -51,5 +56,14 @@ class ThemePatch : ResourcePatch() {
description = "The background color of the dark theme. Can be a hex color or a resource reference.", description = "The background color of the dark theme. Can be a hex color or a resource reference.",
) )
) )
var lightThemeBackgroundColor: String? by option(
PatchOption.StringOption(
key = "lightThemeBackgroundColor",
default = "@android:color/white",
title = "Background color for the light theme",
description = "The background color of the light theme. Can be a hex color or a resource reference.",
)
)
} }
} }