feat(YouTube/Theme): add set of dark themes to chose from

This commit is contained in:
inotia00 2023-10-28 09:55:33 +09:00
parent d535ab3df7
commit 98e386ec51
5 changed files with 77 additions and 53 deletions

View File

@ -71,7 +71,7 @@ object MaterialYouPatch : ResourcePatch() {
/**
* Add settings
*/
context.updatePatchStatusTheme("materialyou")
context.updatePatchStatusTheme("MaterialYou")
isMonetPatchIncluded = true

View File

@ -44,21 +44,52 @@ 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)
internal var DarkThemeBackgroundColor by stringPatchOption(
key = "DarkThemeBackgroundColor",
default = AMOLED_BLACK_COLOR,
values = mapOf(
"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"
}
private fun ResourceContext.setTheme(valuesPath: String) {
val darkThemeColor = darkThemeBackgroundColor
override fun execute(context: ResourceContext) {
val darkThemeColor = DarkThemeBackgroundColor
?: throw PatchException("Invalid color.")
this.xmlEditor["res/$valuesPath/colors.xml"].use { editor ->
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) {
@ -74,20 +105,12 @@ object ThemePatch : ResourcePatch() {
}
}
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"
),
title = "Dark theme background color",
description = "Can be a hex color (#AARRGGBB) or a color resource reference.",
)
val currentTheme = if (isMonetPatchIncluded)
"MaterialYou + " + getThemeString(darkThemeColor)
else
getThemeString(darkThemeColor)
context.updatePatchStatusTheme(currentTheme)
}
}

View File

@ -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(

View File

@ -64,11 +64,11 @@
<string name="revanced_hide_subscriptions_button_title">@string/revanced_hide_shorts_player_subscriptions_button_title</string>
<string name="revanced_header_default">Stock</string>
<string name="revanced_icons_default">Stock</string>
<string name="revanced_icons_mmt">MMT</string>
<string name="revanced_icons_revancify_blue">Revancify Blue</string>
<string name="revanced_icons_revancify_red">Revancify Red</string>
<string name="revanced_labels_default">Stock</string>
<string name="revanced_icon_default">Stock</string>
<string name="revanced_icon_mmt">MMT</string>
<string name="revanced_icon_revancify_blue">Revancify Blue</string>
<string name="revanced_icon_revancify_red">Revancify Red</string>
<string name="revanced_label_default">Stock</string>
<string name="revanced_patches_excluded">Excluded</string>
<string name="revanced_patches_included">Included</string>
@ -83,10 +83,7 @@
<string name="revanced_sponsorblock_settings_title">SponsorBlock</string>
<string name="revanced_themes_amoled">Amoled</string>
<string name="revanced_themes_default">Stock</string>
<string name="revanced_themes_materialyou">MaterialYou</string>
<string name="revanced_themes_mix">MaterialYou + Amoled</string>
<string name="revanced_theme_default">Stock</string>
<string name="sb_about">@string/pref_about_category</string>
<string name="sb_about_api">sponsor.ajay.app</string>

View File

@ -439,12 +439,12 @@
<Preference android:title="Header" android:summary="@string/revanced_header_default" android:selectable="false"/>
<Preference android:title="Hide double tap overlay filter" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Hide tooltip content" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Icons" android:summary="@string/revanced_icons_default" android:selectable="false"/>
<Preference android:title="Labels" android:summary="@string/revanced_labels_default" android:selectable="false"/>
<Preference android:title="Icon" android:summary="@string/revanced_icon_default" android:selectable="false"/>
<Preference android:title="Label" android:summary="@string/revanced_label_default" android:selectable="false"/>
<Preference android:title="MicroG support" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Return YouTube Dislike" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="SponsorBlock" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Themes" android:summary="@string/revanced_themes_default" android:selectable="false"/>
<Preference android:title="Theme" android:summary="@string/revanced_themes_default" android:selectable="false"/>
<Preference android:title="Translations" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
</PreferenceScreen>
</PreferenceScreen>