diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/materialyou/MaterialYouPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/materialyou/MaterialYouPatch.kt index 37d4914fb..e0317a0e7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/materialyou/MaterialYouPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/materialyou/MaterialYouPatch.kt @@ -71,7 +71,7 @@ object MaterialYouPatch : ResourcePatch() { /** * Add settings */ - context.updatePatchStatusTheme("materialyou") + context.updatePatchStatusTheme("MaterialYou") isMonetPatchIncluded = true diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt index 6b2fd991f..6448e9469 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt @@ -44,50 +44,73 @@ import org.w3c.dom.Element @Suppress("unused") object ThemePatch : ResourcePatch() { private const val AMOLED_BLACK_COLOR = "@android:color/black" - override fun execute(context: ResourceContext) { + private const val CATPPUCCIN_COLOR = "#FF181825" + private const val DARK_PINK_COLOR = "#FF290025" + private const val DARK_BLUE_COLOR = "#FF001029" + private const val DARK_GREEN_COLOR = "#FF002905" + private const val DARK_YELLOW_COLOR = "#FF282900" + private const val DARK_ORANGE_COLOR = "#FF291800" + private const val DARK_RED_COLOR = "#FF290000" - arrayOf("values", "values-v31").forEach { context.setTheme(it) } - val currentTheme = if (isMonetPatchIncluded) "mix" else "amoled" - - context.updatePatchStatusTheme(currentTheme) - - } - - private fun ResourceContext.setTheme(valuesPath: String) { - val darkThemeColor = darkThemeBackgroundColor - ?: throw PatchException("Invalid color.") - - this.xmlEditor["res/$valuesPath/colors.xml"].use { editor -> - val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element - - for (i in 0 until resourcesNode.childNodes.length) { - val node = resourcesNode.childNodes.item(i) as? Element ?: continue - - node.textContent = when (node.getAttribute("name")) { - "yt_black0", "yt_black1", "yt_black1_opacity95", "yt_black1_opacity98", "yt_black2", "yt_black3", - "yt_black4", "yt_status_bar_background_dark", "material_grey_850" -> darkThemeColor - - else -> continue - } - } - } - } - - internal var darkThemeBackgroundColor by stringPatchOption( + internal var DarkThemeBackgroundColor by stringPatchOption( key = "DarkThemeBackgroundColor", default = AMOLED_BLACK_COLOR, values = mapOf( - "Amoled black" to AMOLED_BLACK_COLOR, - "Catppuccin (Mocha)" to "#FF181825", - "Dark pink" to "#FF290025", - "Dark blue" to "#FF001029", - "Dark green" to "#FF002905", - "Dark yellow" to "#FF282900", - "Dark orange" to "#FF291800", - "Dark red" to "#FF290000" + "Amoled Black" to AMOLED_BLACK_COLOR, + "Catppuccin (Mocha)" to CATPPUCCIN_COLOR, + "Dark Pink" to DARK_PINK_COLOR, + "Dark Blue" to DARK_BLUE_COLOR, + "Dark Green" to DARK_GREEN_COLOR, + "Dark Yellow" to DARK_YELLOW_COLOR, + "Dark Orange" to DARK_ORANGE_COLOR, + "Dark Red" to DARK_RED_COLOR ), title = "Dark theme background color", description = "Can be a hex color (#AARRGGBB) or a color resource reference.", ) + + private fun getThemeString(darkThemeColor: String) = + when (darkThemeColor) { + AMOLED_BLACK_COLOR -> "Amoled Black" + CATPPUCCIN_COLOR -> "Catppuccin (Mocha)" + DARK_PINK_COLOR -> "Dark Pink" + DARK_BLUE_COLOR -> "Dark Blue" + DARK_GREEN_COLOR -> "Dark Green" + DARK_YELLOW_COLOR -> "Dark Yellow" + DARK_ORANGE_COLOR -> "Dark Orange" + DARK_RED_COLOR -> "Dark Red" + else -> "Custom" + } + + override fun execute(context: ResourceContext) { + + val darkThemeColor = DarkThemeBackgroundColor + ?: throw PatchException("Invalid color.") + + arrayOf("values", "values-v31").forEach { path -> + context.xmlEditor["res/$path/colors.xml"].use { editor -> + val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element + + for (i in 0 until resourcesNode.childNodes.length) { + val node = resourcesNode.childNodes.item(i) as? Element ?: continue + + node.textContent = when (node.getAttribute("name")) { + "yt_black0", "yt_black1", "yt_black1_opacity95", "yt_black1_opacity98", "yt_black2", "yt_black3", + "yt_black4", "yt_status_bar_background_dark", "material_grey_850" -> darkThemeColor + + else -> continue + } + } + } + } + + val currentTheme = if (isMonetPatchIncluded) + "MaterialYou + " + getThemeString(darkThemeColor) + else + getThemeString(darkThemeColor) + + context.updatePatchStatusTheme(currentTheme) + + } } diff --git a/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt b/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt index 0305047fd..8de3c99e9 100644 --- a/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt +++ b/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt @@ -66,16 +66,20 @@ internal object ResourceHelper { updatePatchStatusSettings(patchTitle, "@string/revanced_patches_included") } + internal fun ResourceContext.updatePatchStatusHeader(headerName: String) { + updatePatchStatusSettings("Header", headerName) + } + internal fun ResourceContext.updatePatchStatusLabel(appName: String) { - updatePatchStatusSettings("Labels", appName) + updatePatchStatusSettings("Label", appName) } internal fun ResourceContext.updatePatchStatusIcon(iconName: String) { - updatePatchStatusSettings("Icons", "@string/revanced_icons_$iconName") + updatePatchStatusSettings("Icon", "@string/revanced_icon_$iconName") } internal fun ResourceContext.updatePatchStatusTheme(themeName: String) { - updatePatchStatusSettings("Themes", "@string/revanced_themes_$themeName") + updatePatchStatusSettings("Theme", themeName) } private fun ResourceContext.updatePatchStatusSettings( diff --git a/src/main/resources/youtube/settings/values-v21/strings.xml b/src/main/resources/youtube/settings/values-v21/strings.xml index ef36120eb..fbb69cd24 100644 --- a/src/main/resources/youtube/settings/values-v21/strings.xml +++ b/src/main/resources/youtube/settings/values-v21/strings.xml @@ -64,11 +64,11 @@ @string/revanced_hide_shorts_player_subscriptions_button_title Stock - Stock - MMT - Revancify Blue - Revancify Red - Stock + Stock + MMT + Revancify Blue + Revancify Red + Stock Excluded Included @@ -83,10 +83,7 @@ SponsorBlock - Amoled - Stock - MaterialYou - MaterialYou + Amoled + Stock @string/pref_about_category sponsor.ajay.app diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 7922e5b75..a1ad1f50e 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -439,12 +439,12 @@ - - + + - +