Themes cleanup (#4894)

This commit is contained in:
Ivan Iskandar 2021-04-18 22:29:56 +07:00 committed by GitHub
parent 17f7dea21b
commit ad57fde1c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 75 deletions

View file

@ -1,65 +1,39 @@
package eu.kanade.tachiyomi.ui.base.activity
import android.content.res.Configuration
import android.os.Build
import android.content.res.Configuration.UI_MODE_NIGHT_MASK
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DarkThemeVariant
import eu.kanade.tachiyomi.data.preference.PreferenceValues.LightThemeVariant
import eu.kanade.tachiyomi.data.preference.PreferenceValues.ThemeMode
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import uy.kohesive.injekt.injectLazy
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
abstract class BaseThemedActivity : AppCompatActivity() {
val preferences: PreferencesHelper by injectLazy()
private val isDarkMode: Boolean by lazy {
val themeMode = preferences.themeMode().get()
(themeMode == Values.ThemeMode.dark) ||
(
themeMode == Values.ThemeMode.system &&
(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES)
)
}
private val lightTheme: Int by lazy {
when (preferences.themeLight().get()) {
Values.LightThemeVariant.blue -> R.style.Theme_Tachiyomi_LightBlue
else -> {
when {
// Light status + navigation bar
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 -> {
R.style.Theme_Tachiyomi_Light_Api27
}
// Light status bar + fallback gray navigation bar
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
R.style.Theme_Tachiyomi_Light_Api23
}
// Fallback gray status + navigation bar
else -> {
R.style.Theme_Tachiyomi_Light
}
}
}
}
}
private val darkTheme: Int by lazy {
when (preferences.themeDark().get()) {
Values.DarkThemeVariant.blue -> R.style.Theme_Tachiyomi_DarkBlue
Values.DarkThemeVariant.amoled -> R.style.Theme_Tachiyomi_Amoled
else -> R.style.Theme_Tachiyomi_Dark
}
}
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(
when {
isDarkMode -> darkTheme
else -> lightTheme
val isDarkMode = when (preferences.themeMode().get()) {
ThemeMode.light -> false
ThemeMode.dark -> true
ThemeMode.system -> resources.configuration.uiMode and UI_MODE_NIGHT_MASK == UI_MODE_NIGHT_YES
}
val themeId = if (isDarkMode) {
when (preferences.themeDark().get()) {
DarkThemeVariant.default -> R.style.Theme_Tachiyomi_Dark
DarkThemeVariant.blue -> R.style.Theme_Tachiyomi_Dark_Blue
DarkThemeVariant.amoled -> R.style.Theme_Tachiyomi_Dark_Amoled
}
)
} else {
when (preferences.themeLight().get()) {
LightThemeVariant.default -> R.style.Theme_Tachiyomi_Light
LightThemeVariant.blue -> R.style.Theme_Tachiyomi_Light_Blue
}
}
setTheme(themeId)
super.onCreate(savedInstanceState)
}
}

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Tachiyomi.Light.Api23">
<item name="android:statusBarColor">@color/md_white_1000</item>
<style name="Base.V23.Theme.Tachiyomi.Light" parent="Base.Theme.Tachiyomi.Light">
<item name="android:statusBarColor">?attr/colorPrimary</item>
<item name="android:windowLightStatusBar">true</item>
</style>
<style name="Theme.Tachiyomi.Light" parent="Base.V23.Theme.Tachiyomi.Light" />
</resources>

View file

@ -1,12 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Tachiyomi.Light.Api27">
<item name="android:statusBarColor">@color/md_white_1000</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:navigationBarColor">@color/md_white_1000</item>
<style name="Base.V27.Theme.Tachiyomi.Light" parent="Base.V23.Theme.Tachiyomi.Light">
<item name="android:navigationBarColor">?attr/colorPrimary</item>
<item name="android:windowLightNavigationBar">true</item>
</style>
<style name="Theme.Tachiyomi.Light" parent="Base.V27.Theme.Tachiyomi.Light" />
</resources>

View file

@ -47,8 +47,9 @@
<item name="android:textDirection">locale</item>
<!-- Themes -->
<item name="android:statusBarColor">?attr/colorPrimary</item>
<item name="android:navigationBarColor">?attr/colorPrimary</item>
<item name="android:statusBarColor">@color/md_black_1000</item>
<item name="android:navigationBarColor">@color/md_black_1000</item>
<item name="android:navigationBarDividerColor" tools:targetApi="o_mr1">@null</item>
<item name="android:enforceNavigationBarContrast" tools:targetApi="Q">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="elevationOverlayEnabled">false</item>
@ -84,28 +85,24 @@
<!-- Custom Attributes-->
<item name="colorLibrarySelection">?attr/colorAccent</item>
<item name="colorLibrarySelectionActive">@color/selectorColorLight</item>
<item name="colorFilterActive">@color/filterColorDark</item>
<item name="colorFilterActive">@color/filterColorLight</item>
</style>
<!--===========-->
<!-- Main Theme-->
<!--===========-->
<style name="Theme.Tachiyomi.Light" parent="Theme.Base">
<item name="android:statusBarColor">@color/md_black_1000</item>
<item name="android:navigationBarColor">@color/md_black_1000_54</item>
<style name="Base.Theme.Tachiyomi.Light" parent="Theme.Base" />
<style name="Theme.Tachiyomi.Light" parent="Base.Theme.Tachiyomi.Light" />
<item name="colorFilterActive">@color/filterColorLight</item>
</style>
<style name="Theme.Tachiyomi.LightBlue" parent="Theme.Base">
<style name="Theme.Tachiyomi.Light.Blue">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorOnPrimary">@color/textColorPrimaryDark</item>
<item name="colorAccentOnPrimary">@color/textColorPrimaryDark</item>
<item name="colorPrimaryVariant">@color/colorPrimaryDark</item>
<item name="colorFilterActive">@color/filterColorDark</item>
<item name="actionBarTheme">@style/Theme.Toolbar.Light</item>
<item name="android:navigationBarColor">@color/colorPrimary_70</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
</style>
<!--=============-->
@ -145,6 +142,7 @@
<!-- Themes -->
<item name="android:statusBarColor">?attr/colorPrimary</item>
<item name="android:navigationBarColor">?attr/colorPrimary</item>
<item name="android:navigationBarDividerColor" tools:targetApi="o_mr1">@null</item>
<item name="android:enforceNavigationBarContrast" tools:targetApi="Q">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="elevationOverlayEnabled">false</item>
@ -184,16 +182,15 @@
<item name="colorFilterActive">@color/filterColorDark</item>
</style>
<style name="Theme.Tachiyomi.Dark" parent="Theme.Base.Dark">
</style>
<style name="Theme.Tachiyomi.Dark" parent="Theme.Base.Dark" />
<style name="Theme.Tachiyomi.DarkBlue" parent="Theme.Base.Dark">
<style name="Theme.Tachiyomi.Dark.Blue">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorAccentOnPrimary">@color/textColorPrimaryDark</item>
<item name="colorPrimaryVariant">@color/colorPrimary</item>
</style>
<style name="Theme.Tachiyomi.Amoled" parent="Theme.Base.Dark">
<style name="Theme.Tachiyomi.Dark.Amoled">
<item name="colorPrimary">@color/colorAmoledPrimary</item>
<item name="colorPrimaryVariant">@color/colorAmoledPrimary</item>
<item name="colorSurface">@color/colorAmoledPrimary</item>
@ -255,7 +252,7 @@
<!--===============-->
<!-- Launch Screen -->
<!--===============-->
<style name="Theme.Splash" parent="Theme.Tachiyomi.LightBlue">
<style name="Theme.Splash" parent="Theme.Tachiyomi.Light.Blue">
<item name="colorBackgroundSplash">@color/colorPrimary</item>
<item name="android:windowBackground">@drawable/splash_background</item>