mirror of
https://github.com/revanced/revanced-patches
synced 2024-11-10 16:19:23 +01:00
feat(theme): arbitrary background color for dark theme
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
29b8f9ee53
commit
08b48b2bb4
@ -4,7 +4,10 @@ import app.revanced.patcher.annotation.Description
|
|||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.data.impl.ResourceData
|
import app.revanced.patcher.data.impl.ResourceData
|
||||||
import app.revanced.patcher.patch.*
|
import app.revanced.patcher.patch.OptionsContainer
|
||||||
|
import app.revanced.patcher.patch.PatchOption
|
||||||
|
import app.revanced.patcher.patch.PatchResult
|
||||||
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patcher.patch.annotations.Patch
|
import app.revanced.patcher.patch.annotations.Patch
|
||||||
import app.revanced.patcher.patch.impl.ResourcePatch
|
import app.revanced.patcher.patch.impl.ResourcePatch
|
||||||
@ -20,14 +23,19 @@ 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 theme = Themes.of(theme!!) ?: return PatchResultError("Theme '$theme' not found.")
|
val backgroundColor = backgroundColor!!
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
for (i in 0 until resourcesNode.childNodes.length) {
|
for (i in 0 until resourcesNode.childNodes.length) {
|
||||||
val node = resourcesNode.childNodes.item(i) as? Element ?: continue
|
val node = resourcesNode.childNodes.item(i) as? Element ?: continue
|
||||||
node.textContent = theme.apply(node.getAttribute("name")) ?: continue
|
|
||||||
|
node.textContent = when (node.getAttribute("name")) {
|
||||||
|
"yt_black1", "yt_black1_opacity95", "yt_black2", "yt_black3", "yt_black4",
|
||||||
|
"yt_status_bar_background_dark" -> backgroundColor
|
||||||
|
else -> continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,33 +43,13 @@ class ThemePatch : ResourcePatch() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object : OptionsContainer() {
|
companion object : OptionsContainer() {
|
||||||
var theme: String? by option(
|
var backgroundColor: String? by option(
|
||||||
PatchOption.StringListOption(
|
PatchOption.StringOption(
|
||||||
key = "theme",
|
key = "darkThemeBackgroundColor",
|
||||||
default = Themes.Amoled.name,
|
default = "@android:color/black",
|
||||||
options = Themes.names,
|
title = "Background color for the dark theme",
|
||||||
title = "Theme",
|
description = "The background color of the dark theme. Can be a hex color or a resource reference.",
|
||||||
description = "Select a theme.",
|
|
||||||
required = true
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Themes(val apply: (String) -> String?) {
|
|
||||||
Amoled({ attr ->
|
|
||||||
when (attr) {
|
|
||||||
"yt_black1", "yt_black1_opacity95", "yt_black2", "yt_black3", "yt_black4",
|
|
||||||
"yt_status_bar_background_dark" -> "@android:color/black"
|
|
||||||
|
|
||||||
"yt_selected_nav_label_dark" -> "#ffdf0000"
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val names = values().map { it.name }
|
|
||||||
|
|
||||||
fun of(name: String) = values().firstOrNull { it.name == name }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user