Skip to content

Commit

Permalink
feat(theme): arbitrary background color for light theme (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranshoe committed Sep 21, 2022
1 parent 6279557 commit 58e9478
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import org.w3c.dom.Element
@Version("0.0.1")
class ThemePatch : ResourcePatch() {
override fun execute(data: ResourceData): PatchResult {
val backgroundColor = backgroundColor!!
val darkThemeBackgroundColor = darkThemeBackgroundColor!!
val lightThemeBackgroundColor = lightThemeBackgroundColor!!

data.xmlEditor["res/values/colors.xml"].use { editor ->
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
Expand All @@ -33,7 +34,11 @@ class ThemePatch : ResourcePatch() {

node.textContent = when (node.getAttribute("name")) {
"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
}
}
Expand All @@ -43,13 +48,22 @@ class ThemePatch : ResourcePatch() {
}

companion object : OptionsContainer() {
var backgroundColor: String? by option(
var darkThemeBackgroundColor: String? by option(
PatchOption.StringOption(
key = "darkThemeBackgroundColor",
default = "@android:color/black",
title = "Background color for the dark theme",
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.",
)
)
}
}

0 comments on commit 58e9478

Please sign in to comment.