Add Dynamic theme for Android 12 (#5569)

* Add Dynamic theme for Android 12

* Also theme text colors
This commit is contained in:
Ivan Iskandar 2021-07-19 00:01:58 +07:00 committed by GitHub
parent 8bfc5f0450
commit b2d58e04d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 79 additions and 3 deletions

View file

@ -23,6 +23,7 @@ object PreferenceValues {
enum class AppTheme(val titleResId: Int?) {
DEFAULT(R.string.theme_default),
MONET(R.string.theme_monet),
BLUE(R.string.theme_blue),
GREEN_APPLE(R.string.theme_greenapple),
MIDNIGHT_DUSK(R.string.theme_midnightdusk),

View file

@ -40,6 +40,9 @@ abstract class BaseThemedActivity : AppCompatActivity() {
fun AppCompatActivity.applyThemePreferences(preferences: PreferencesHelper) {
val resIds = mutableListOf<Int>()
when (preferences.appTheme().get()) {
PreferenceValues.AppTheme.MONET -> {
resIds += R.style.Theme_Tachiyomi_Monet
}
PreferenceValues.AppTheme.BLUE -> {
resIds += R.style.Theme_Tachiyomi_Blue
resIds += R.style.ThemeOverlay_Tachiyomi_ColoredBars

View file

@ -122,7 +122,14 @@ class SettingsGeneralController : SettingsController() {
key = Keys.appTheme
titleRes = R.string.pref_app_theme
val appThemes = Values.AppTheme.values().filter { it.titleResId != null }
val appThemes = Values.AppTheme.values().filter {
val monetFilter = if (it == Values.AppTheme.MONET) {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
} else {
true
}
it.titleResId != null && monetFilter
}
entriesRes = appThemes.map { it.titleResId!! }.toTypedArray()
entryValues = appThemes.map { it.name }.toTypedArray()
defaultValue = appThemes[0].name

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/system_neutral1_500" android:state_enabled="false" />
<item android:color="@android:color/system_neutral1_50" />
</selector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="?android:attr/disabledAlpha" android:color="@android:color/system_neutral2_200" android:state_enabled="false" />
<item android:color="@android:color/system_neutral2_200" />
</selector>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/accent_monet" android:alpha="0.12" />
</selector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/system_neutral1_400" android:state_enabled="false" />
<item android:color="@android:color/system_neutral1_900" />
</selector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="?android:attr/disabledAlpha" android:color="@android:color/system_neutral2_700" android:state_enabled="false" />
<item android:color="@android:color/system_neutral2_700" />
</selector>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<color name="splash">@color/background_default</color>
<!-- Default Theme -->
@ -9,6 +9,15 @@
<color name="background_default">#202125</color>
<color name="ripple_colored_default">#1F3399FF</color>
<!-- Monet Theme -->
<color name="accent_monet" tools:targetApi="31">@android:color/system_accent1_100</color>
<color name="on_accent_monet" tools:targetApi="31">@android:color/system_accent1_900</color>
<color name="divider_monet" tools:targetApi="31">@android:color/system_neutral1_700</color>
<color name="tertiary_monet" tools:targetApi="31">@android:color/system_accent3_100</color>
<color name="on_tertiary_monet" tools:targetApi="31">@android:color/system_accent3_900</color>
<color name="surface_monet" tools:targetApi="31">@android:color/system_neutral1_900</color>
<color name="on_surface_monet" tools:targetApi="31">@android:color/system_neutral1_50</color>
<!-- Green Apple Theme -->
<color name="accent_greenapple">#48E484</color>
<color name="color_on_primary_greenapple">@color/md_black_1000</color>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Tachiyomi.Monet">
<item name="colorPrimary">@color/accent_monet</item>
<item name="colorOnPrimary">@color/on_accent_monet</item>
<item name="colorTertiary">@color/tertiary_monet</item>
<item name="colorOnTertiary">@color/on_tertiary_monet</item>
<item name="colorSurface">@color/surface_monet</item>
<item name="colorOnSurface">@color/on_surface_monet</item>
<item name="android:colorBackground">@color/background_monet</item>
<item name="colorOnBackground">@color/on_background_monet</item>
<item name="colorControlHighlight">@color/ripple_colored_monet</item>
<item name="android:divider">@color/divider_monet</item>
<item name="android:textColorPrimary">@color/text_primary_monet</item>
<item name="android:textColorSecondary">@color/text_secondary_monet</item>
</style>
</resources>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<color name="splash">@color/accent_blue</color>
<!-- Default Theme -->
@ -9,6 +9,17 @@
<color name="background_default">@color/md_grey_50</color>
<color name="ripple_colored_default">@color/md_blue_A400_12</color>
<!-- Monet Theme -->
<color name="accent_monet" tools:targetApi="31">@android:color/system_accent1_600</color>
<color name="on_accent_monet" tools:targetApi="31">@android:color/system_accent1_10</color>
<color name="divider_monet" tools:targetApi="31">@android:color/system_neutral1_200</color>
<color name="tertiary_monet" tools:targetApi="31">@android:color/system_accent3_600</color>
<color name="on_tertiary_monet" tools:targetApi="31">@android:color/system_accent3_10</color>
<color name="surface_monet" tools:targetApi="31">@android:color/system_neutral1_50</color>
<color name="on_surface_monet" tools:targetApi="31">@android:color/system_neutral1_900</color>
<color name="background_monet" tools:targetApi="31">@color/surface_monet</color>
<color name="on_background_monet" tools:targetApi="31">@color/on_surface_monet</color>
<!-- Blue Theme -->
<color name="accent_blue">#54759E</color>
<color name="ripple_colored_blue">#1F54759E</color>

View file

@ -148,6 +148,7 @@
<string name="theme_dark">On</string>
<string name="pref_app_theme">App theme</string>
<string name="theme_default">Default</string>
<string name="theme_monet">Dynamic</string>
<string name="theme_blue">Blue</string>
<string name="theme_greenapple">Green Apple</string>
<string name="theme_midnightdusk">Midnight Dusk</string>

View file

@ -74,6 +74,9 @@
<!--== Default Theme ==-->
<style name="Theme.Tachiyomi" parent="Base.Theme.Tachiyomi" />
<!-- Monet theme only support S+ -->
<style name="Theme.Tachiyomi.Monet" />
<!--== Blue Theme ==-->
<style name="Theme.Tachiyomi.Blue">
<!-- Theme Colors -->