Skip to content

Commit 46b345c

Browse files
committed
fix(YouTube - Theme): Remove redundant code and seekbar color
1 parent 8441374 commit 46b345c

File tree

1 file changed

+8
-82
lines changed
  • src/main/kotlin/app/revanced/patches/youtube/layout/theme

1 file changed

+8
-82
lines changed

src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt

+8-82
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ object ThemePatch : ResourcePatch() {
8282
private const val ADVANCED_DARK_COLOR = "#FF252A3A"
8383
private const val ADVANCED_LIGHT_COLOR = "#FFF2F8FF"
8484

85-
private const val SEEKBAR_COLOR = "#FFFF0000"
8685
private val DarkThemeBackgroundColor by stringPatchOption(
8786
key = "DarkThemeBackgroundColor",
8887
default = AMOLED_BLACK_COLOR,
8988
values = mapOf(
89+
"Advanced Dark Color" to ADVANCED_DARK_COLOR,
9090
"Black" to AMOLED_BLACK_COLOR,
9191
"Catppuccin (Mocha)" to CATPPUCCIN_MOCHA_COLOR,
9292
"Dark Pink" to DARK_PINK_COLOR,
@@ -101,21 +101,11 @@ object ThemePatch : ResourcePatch() {
101101
required = true
102102
)
103103

104-
private val AdvancedDarkThemeBackgroundColor by stringPatchOption(
105-
key = "AdvancedDarkThemeBackgroundColor",
106-
default = ADVANCED_DARK_COLOR,
107-
values = mapOf(
108-
"Advanced Dark Color" to ADVANCED_DARK_COLOR
109-
),
110-
title = "Advanced dark theme color",
111-
description = "Can be a hex color (#AARRGGBB) or a color resource reference.",
112-
required = true
113-
)
114-
115104
private val LightThemeBackgroundColor by stringPatchOption(
116105
key = "LightThemeBackgroundColor",
117106
default = WHITE_COLOR,
118107
values = mapOf(
108+
"Advanced Light Color" to ADVANCED_LIGHT_COLOR,
119109
"White" to WHITE_COLOR,
120110
"Catppuccin (Latte)" to CATPPUCCIN_LATTE_COLOR,
121111
"Light Pink" to LIGHT_PINK_COLOR,
@@ -129,28 +119,6 @@ object ThemePatch : ResourcePatch() {
129119
description = "Can be a hex color (#AARRGGBB) or a color resource reference.",
130120
)
131121

132-
private val AdvancedLightThemeBackgroundColor by stringPatchOption(
133-
key = "AdvancedLightThemeBackgroundColor",
134-
default = ADVANCED_LIGHT_COLOR,
135-
values = mapOf(
136-
"Advanced Light Color" to ADVANCED_LIGHT_COLOR
137-
),
138-
title = "Advanced light theme color",
139-
description = "Can be a hex color (#AARRGGBB) or a color resource reference.",
140-
required = true
141-
)
142-
143-
private val SeekbarBackgroundColor by stringPatchOption(
144-
key = "SeekbarBackgroundColor",
145-
default = SEEKBAR_COLOR,
146-
values = mapOf(
147-
"Seekbar Color" to SEEKBAR_COLOR
148-
),
149-
title = "Seekbar color",
150-
description = "Can be a hex color (#AARRGGBB) or a color resource reference.",
151-
required = true
152-
)
153-
154122
private fun getThemeString(
155123
darkThemeColor: String,
156124
lightThemeColor: String
@@ -163,6 +131,7 @@ object ThemePatch : ResourcePatch() {
163131

164132
private fun getDarkThemeString(darkThemeColor: String) =
165133
when (darkThemeColor) {
134+
ADVANCED_DARK_COLOR -> "Advanced Dark Color"
166135
AMOLED_BLACK_COLOR -> "Black"
167136
CATPPUCCIN_MOCHA_COLOR -> "Catppuccin (Mocha)"
168137
DARK_PINK_COLOR -> "Dark Pink"
@@ -174,14 +143,9 @@ object ThemePatch : ResourcePatch() {
174143
else -> "Custom"
175144
}
176145

177-
private fun getAdvancedDarkThemeColorString(advancedDarkThemeColor: String) =
178-
when (advancedDarkThemeColor) {
179-
ADVANCED_DARK_COLOR -> "Advanced Dark Color"
180-
else -> "Custom"
181-
}
182-
183146
private fun getLightThemeString(lightThemeColor: String) =
184147
when (lightThemeColor) {
148+
ADVANCED_LIGHT_COLOR -> "Advanced Light Color"
185149
CATPPUCCIN_LATTE_COLOR -> "Catppuccin (Latte)"
186150
LIGHT_PINK_COLOR -> "Light Pink"
187151
LIGHT_BLUE_COLOR -> "Light Blue"
@@ -192,35 +156,14 @@ object ThemePatch : ResourcePatch() {
192156
else -> "Custom"
193157
}
194158

195-
private fun getAdvancedLightThemeColorString(advancedLightThemeColor: String) =
196-
when (advancedLightThemeColor) {
197-
ADVANCED_LIGHT_COLOR -> "Advanced Light Color"
198-
else -> "Custom"
199-
}
200-
201-
private fun getSeekbarString(seekbarColor: String) =
202-
when (seekbarColor) {
203-
SEEKBAR_COLOR -> "Seekbar Color"
204-
else -> "Custom"
205-
}
206-
207159
override fun execute(context: ResourceContext) {
208160

209161
val darkThemeColor = DarkThemeBackgroundColor
210162
?: throw PatchException("Invalid dark color.")
211163

212-
val advancedDarkThemeColor = AdvancedDarkThemeBackgroundColor
213-
?: throw PatchException("Invalid advanced dark color.")
214-
215164
val lightThemeColor = LightThemeBackgroundColor
216165
?: throw PatchException("Invalid light color.")
217166

218-
val advancedLightThemeColor = AdvancedLightThemeBackgroundColor
219-
?: throw PatchException("Invalid advanced light color.")
220-
221-
val seekbarColor = SeekbarBackgroundColor
222-
?: throw PatchException("Invalid seekbar color.")
223-
224167
arrayOf("values", "values-v31").forEach { path ->
225168
context.xmlEditor["res/$path/colors.xml"].use { editor ->
226169
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
@@ -230,8 +173,7 @@ object ThemePatch : ResourcePatch() {
230173

231174
node.textContent = when (node.getAttribute("name")) {
232175
"yt_black0", "yt_black1", "yt_black1_opacity95", "yt_black1_opacity98", "yt_black2", "yt_black3",
233-
"yt_black4", "yt_status_bar_background_dark", "material_grey_850", "material_grey_900" -> darkThemeColor
234-
"yt_navy_blue" -> advancedDarkThemeColor
176+
"yt_black4", "yt_navy_blue", "yt_status_bar_background_dark", "material_grey_850", "material_grey_900" -> darkThemeColor
235177

236178
else -> continue
237179
}
@@ -247,30 +189,14 @@ object ThemePatch : ResourcePatch() {
247189
val node = children.item(i) as? Element ?: continue
248190

249191
node.textContent = when (node.getAttribute("name")) {
250-
"yt_white1", "yt_white1_opacity95", "yt_white1_opacity98",
192+
"yt_pale_blue", "yt_white1", "yt_white1_opacity95", "yt_white1_opacity98",
251193
"yt_white2", "yt_white3", "yt_white4",
252194
-> lightThemeColor
253-
"yt_pale_blue" -> advancedLightThemeColor
254195

255-
else -> continue
256-
}
257-
}
258-
}
259-
260-
context.xmlEditor["res/values/colors.xml"].use { editor ->
261-
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
262-
263-
val children = resourcesNode.childNodes
264-
for (i in 0 until children.length) {
265-
val node = children.item(i) as? Element ?: continue
266-
267-
node.textContent = when (node.getAttribute("name")) {
268-
"inline_time_bar_colorized_bar_played_color_dark" -> seekbarColor
269-
270-
else -> continue
271-
}
196+
else -> continue
272197
}
273198
}
199+
}
274200

275201
val currentTheme = if (isMonetPatchIncluded)
276202
"MaterialYou " + getThemeString(darkThemeColor, lightThemeColor)

0 commit comments

Comments
 (0)