Allow all dark themes to be amoled + dark theme reworking

AMOLED theme ded
Black 'n' Red ded (replaced with Chocolate Strawberries) (closes #763)
Hot pink ded (now use Midnight Dusk + Purl black)

Using those old themes will now revert back to default dark

Co-Authored-By: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com>
This commit is contained in:
Jays2Kings 2021-07-04 01:40:54 -04:00
parent 6224dc293f
commit 704a741f73
11 changed files with 95 additions and 50 deletions

View File

@ -10,6 +10,7 @@ object PreferenceKeys {
const val nightMode = "night_mode"
const val lightTheme = "light_theme"
const val darkTheme = "dark_theme"
const val themeDarkAmoled = "pref_theme_dark_amoled_key"
const val startingTab = "starting_tab"

View File

@ -112,6 +112,8 @@ class PreferencesHelper(val context: Context) {
fun nightMode() = flowPrefs.getInt(Keys.nightMode, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
fun themeDarkAmoled() = flowPrefs.getBoolean(Keys.themeDarkAmoled, false)
fun lightTheme() = flowPrefs.getEnum(Keys.lightTheme, Themes.PURE_WHITE)
fun darkTheme() = flowPrefs.getEnum(Keys.darkTheme, Themes.DARK)

View File

@ -7,6 +7,7 @@ import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.util.system.appDelegateNightMode
import eu.kanade.tachiyomi.util.system.getPrefTheme
@ -135,6 +136,25 @@ class SettingsGeneralController : SettingsController() {
isChecked = mode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}.launchIn(viewScope)
}
switchPreference {
key = Keys.themeDarkAmoled
titleRes = R.string.pure_black_dark_mode
defaultValue = false
preferences.nightMode().asImmediateFlowIn(viewScope) { mode ->
isVisible = mode != AppCompatDelegate.MODE_NIGHT_NO
}
onChange {
if (context.isInNightMode()) {
activity?.recreate()
} else {
themePreference?.fastAdapterDark?.notifyDataSetChanged()
}
true
}
}
}
preferenceCategory {

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.setting
import android.app.Activity
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
import androidx.appcompat.app.AppCompatDelegate
@ -22,6 +23,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.ThemeItemBinding
import eu.kanade.tachiyomi.databinding.ThemesPreferenceBinding
import eu.kanade.tachiyomi.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.Themes
import eu.kanade.tachiyomi.util.system.appDelegateNightMode
import eu.kanade.tachiyomi.util.system.dpToPx
@ -198,18 +200,32 @@ class ThemePreference @JvmOverloads constructor(context: Context, attrs: Attribu
binding.checkbox.alpha = if (themeMatchesApp) 1f else 0.5f
}
binding.themeToolbar.setBackgroundColor(item.colors.appBar)
binding.themeAppBarText.imageTintList = ColorStateList.valueOf(item.colors.appBarText)
binding.themeHeroImage.imageTintList = ColorStateList.valueOf(item.colors.primaryText)
binding.themePrimaryText.imageTintList = ColorStateList.valueOf(item.colors.primaryText)
binding.themeAccentedButton.imageTintList = ColorStateList.valueOf(item.colors.colorAccent)
binding.themeSecondaryText.imageTintList = ColorStateList.valueOf(item.colors.secondaryText)
binding.themeSecondaryText2.imageTintList = ColorStateList.valueOf(item.colors.secondaryText)
binding.themeAppBarText.imageTintList =
ColorStateList.valueOf(item.colors.appBarText)
binding.themeHeroImage.imageTintList =
ColorStateList.valueOf(item.colors.primaryText)
binding.themePrimaryText.imageTintList =
ColorStateList.valueOf(item.colors.primaryText)
binding.themeAccentedButton.imageTintList =
ColorStateList.valueOf(item.colors.colorAccent)
binding.themeSecondaryText.imageTintList =
ColorStateList.valueOf(item.colors.secondaryText)
binding.themeSecondaryText2.imageTintList =
ColorStateList.valueOf(item.colors.secondaryText)
binding.themeBottomBar.setBackgroundColor(item.colors.bottomBar)
binding.themeItem1.imageTintList = ColorStateList.valueOf(item.colors.inactiveTab)
binding.themeItem1.imageTintList =
ColorStateList.valueOf(item.colors.inactiveTab)
binding.themeItem2.imageTintList = ColorStateList.valueOf(item.colors.activeTab)
binding.themeItem3.imageTintList = ColorStateList.valueOf(item.colors.inactiveTab)
binding.themeItem3.imageTintList =
ColorStateList.valueOf(item.colors.inactiveTab)
binding.themeLayout.setBackgroundColor(item.colors.colorBackground)
if (item.theme.isDarkTheme && preferences.themeDarkAmoled().get()) {
binding.themeLayout.setBackgroundColor(Color.BLACK)
if (!ThemeUtil.isColoredTheme(item.theme)) {
binding.themeBottomBar.setBackgroundColor(Color.BLACK)
}
}
}
override fun unbindView(item: ThemeItem) {

View File

@ -16,6 +16,7 @@ import androidx.core.view.isVisible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.WebviewActivityBinding
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
import eu.kanade.tachiyomi.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.getPrefTheme
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.isInNightMode
@ -143,7 +144,14 @@ open class BaseWebViewActivity : BaseActivity<WebviewActivityBinding>() {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
val lightMode = !isInNightMode()
setTheme(getPrefTheme(preferences).styleRes)
val prefTheme = getPrefTheme(preferences)
setTheme(prefTheme.styleRes)
if (prefTheme.isDarkTheme && preferences.themeDarkAmoled().get()) {
setTheme(R.style.ThemeOverlay_Tachiyomi_Amoled)
if (ThemeUtil.isColoredTheme(prefTheme)) {
setTheme(R.style.ThemeOverlay_Tachiyomi_AllBlue)
}
}
window.statusBarColor = ColorUtils.setAlphaComponent(
getResourceColor(
R.attr

View File

@ -26,7 +26,6 @@ object ThemeUtil {
)
preferences.darkTheme().set(
when (theme) {
3 -> Themes.AMOLED
4 -> Themes.DARK_BLUE
else -> Themes.DARK
}
@ -60,6 +59,13 @@ fun Activity.setThemeAndNight(preferences: PreferencesHelper) {
AppCompatDelegate.setDefaultNightMode(preferences.nightMode().get())
val theme = getPrefTheme(preferences)
setTheme(theme.styleRes)
if (theme.isDarkTheme && preferences.themeDarkAmoled().get()) {
setTheme(R.style.ThemeOverlay_Tachiyomi_Amoled)
if (ThemeUtil.isColoredTheme(theme)) {
setTheme(R.style.ThemeOverlay_Tachiyomi_AllBlue)
}
}
}
fun Context.getPrefTheme(preferences: PreferencesHelper): Themes {

View File

@ -23,30 +23,20 @@ enum class Themes(@StyleRes val styleRes: Int, val nightMode: Int, @StringRes va
AppCompatDelegate.MODE_NIGHT_YES,
R.string.midnight_dusk
),
LIME(
R.style.Theme_Tachiyomi_FlatLime,
AppCompatDelegate.MODE_NIGHT_YES,
R.string.flat_lime
),
AMOLED(
R.style.Theme_Tachiyomi_Amoled,
AppCompatDelegate.MODE_NIGHT_YES,
R.string.amoled_black
),
STRAWBERRY_DAIQUIRI(
R.style.Theme_Tachiyomi_StrawberryDaiquiri,
AppCompatDelegate.MODE_NIGHT_NO,
R.string.strawberry_daiquiri
),
BLACK_N_RED(
R.style.Theme_Tachiyomi_BlackAndRed,
CHOCOLATE_STRAWBERRIES(
R.style.Theme_Tachiyomi_ChocolateStrawberries,
AppCompatDelegate.MODE_NIGHT_YES,
R.string.black_and_red
R.string.chocolate_strawberries
),
HOT_PINK(
R.style.Theme_Tachiyomi_HotPink,
LIME(
R.style.Theme_Tachiyomi_FlatLime,
AppCompatDelegate.MODE_NIGHT_YES,
R.string.hot_pink
R.string.flat_lime
),
YOTSUBA(
R.style.Theme_Tachiyomi_Yotsuba,
@ -64,6 +54,9 @@ enum class Themes(@StyleRes val styleRes: Int, val nightMode: Int, @StringRes va
R.string.dark_blue
);
val isDarkTheme: Boolean
get() = nightMode == AppCompatDelegate.MODE_NIGHT_YES
fun getColors(mode: Int = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM): Colors {
return when (nightMode) {
AppCompatDelegate.MODE_NIGHT_YES -> darkColors()
@ -138,7 +131,7 @@ enum class Themes(@StyleRes val styleRes: Int, val nightMode: Int, @StringRes va
@ColorInt
val darkBackground: Int = Color.parseColor(
when (styleRes) {
R.style.Theme_Tachiyomi_Amoled, R.style.Theme_Tachiyomi_BlackAndRed, R.style.Theme_Tachiyomi_HotPink -> "#000000"
R.style.Theme_Tachiyomi_ChocolateStrawberries -> "#1a1716"
R.style.Theme_Tachiyomi_MidnightDusk -> "#16151D"
R.style.Theme_Tachiyomi_FlatLime -> "#202125"
else -> "#1C1C1D"
@ -161,8 +154,7 @@ enum class Themes(@StyleRes val styleRes: Int, val nightMode: Int, @StringRes va
val darkAccent: Int = Color.parseColor(
when (styleRes) {
R.style.Theme_Tachiyomi_MidnightDusk -> "#F02475"
R.style.Theme_Tachiyomi_BlackAndRed -> "#AA2200"
R.style.Theme_Tachiyomi_HotPink -> "#FF3399"
R.style.Theme_Tachiyomi_ChocolateStrawberries -> "#AA2200"
R.style.Theme_Tachiyomi_FlatLime -> "#4AF88A"
else -> "#3399FF"
}
@ -212,7 +204,6 @@ enum class Themes(@StyleRes val styleRes: Int, val nightMode: Int, @StringRes va
val darkBottomBar: Int = Color.parseColor(
when (styleRes) {
R.style.Theme_Tachiyomi_AllBlue -> "#54759E"
R.style.Theme_Tachiyomi_Amoled, R.style.Theme_Tachiyomi_BlackAndRed, R.style.Theme_Tachiyomi_HotPink -> "#000000"
R.style.Theme_Tachiyomi_MidnightDusk -> "#201F27"
R.style.Theme_Tachiyomi_FlatLime -> "#282A2E"
else -> "#212121"

View File

@ -6,14 +6,11 @@
<item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>
</style>
<!--==============-->
<!-- Amoled Theme -->
<!--==============-->
<style name="Theme.Tachiyomi.Amoled">
<!--== AMOLED theme overlay ==-->
<style name="ThemeOverlay.Tachiyomi.Amoled" parent="">
<item name="colorSecondary">@color/colorAmoledPrimary</item>
<item name="colorPrimaryVariant">@color/colorAmoledPrimary</item>
<item name="colorOnPrimary">@color/colorAmoledPrimary</item>
<item name="colorPrimaryDark">@color/colorAmoledPrimary</item>
<item name="android:colorBackground">@color/colorAmoledPrimary</item>
<item name="readerBackground">@color/colorAmoledPrimary</item>
@ -21,16 +18,13 @@
<item name="md_background_color">@color/colorAmoledPrimary</item>
</style>
<style name="Theme.Tachiyomi.BlackAndRed" parent="Theme.Tachiyomi.Amoled">
<style name="Theme.Tachiyomi.ChocolateStrawberries">
<item name="colorPrimary">@color/primaryRed</item>
<item name="colorAccent">@color/holo_red</item>
<item name="colorAccentText">@color/md_red_500</item>
</style>
<style name="Theme.Tachiyomi.HotPink" parent="Theme.Tachiyomi.Amoled">
<item name="colorPrimary">@color/colorPrimaryPink</item>
<item name="colorAccent">@color/colorAccentPink</item>
<item name="colorAccentText">@color/colorAccentPink</item>
<item name="colorPrimaryVariant">@color/secondaryChocolateStrawberries</item>
<item name="android:colorBackground">@color/backgroundChocolateStrawberries</item>
<item name="colorSecondary">@color/backgroundChocolateStrawberries</item>
</style>
<style name="Theme.Tachiyomi.FlatLime">

View File

@ -77,10 +77,6 @@
<color name="textPrimaryDuskDawn">#DE240728</color>
<color name="appBarTextDuskDawn">#DE4c0d4b</color>
<!-- Hot Pink Theme -->
<color name="colorAccentPink">#FF3399</color>
<color name="colorPrimaryPink">#FF57B3</color>
<!-- Flat Lime Theme -->
<color name="primaryLime">#7CF7A5</color>
<color name="colorAccentLime">#4AF88A</color>
@ -97,6 +93,9 @@
<color name="colorAccentStrawberry">#ED4A65</color>
<color name="colorAccentStrawberryText">#b62e45</color>
<color name="backgroundChocolateStrawberries">#1a1716</color>
<color name="secondaryChocolateStrawberries">#211b19</color>
<!-- Yotsuba Theme -->
<color name="colorAccentYotsuba">#FC8C5C</color>
<color name="colorAccentYotsubaText">#d35b27</color>

View File

@ -618,7 +618,7 @@
<string name="spring_blossom">Spring Blossom</string>
<string name="strawberry_daiquiri">Strawberry Daiquiri</string>
<string name="yotsuba">Yotsuba</string>
<string name="black_and_red">Black \'n\' Red</string>
<string name="chocolate_strawberries">Chocolate Strawberries</string>
<string name="hot_pink">Hot Pink</string>
<string name="flat_lime">Flat Lime</string>
<string name="white_theme">Pure White</string>
@ -633,6 +633,7 @@
<string name="hide_bottom_nav">Auto-hide bottom navigation</string>
<string name="side_nav_icon_alignment">Side navigation icon alignment</string>
<string name="follow_system_theme">Follow system theme</string>
<string name="pure_black_dark_mode">Pure black dark mode</string>
<string name="hides_on_scroll">Hides when scrolling</string>
<string name="hide_app_block_screenshots">Hide app contents when switching apps and block screenshots</string>
<string name="security">Security</string>

View File

@ -69,9 +69,16 @@
<item name="android:windowLightStatusBar">false</item>
<item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>
</style>
<style name="Theme.Tachiyomi.Amoled"/>
<style name="Theme.Tachiyomi.BlackAndRed" parent="Theme.Tachiyomi.Amoled"/>
<style name="Theme.Tachiyomi.HotPink" parent="Theme.Tachiyomi.Amoled"/>
<style name="ThemeOverlay.Tachiyomi.AllBlue" parent="">
<item name="colorPrimaryVariant">@color/app_color_primary</item>
<item name="colorSecondary">@color/app_color_primary</item>
<item name="actionBarTintColor">@color/md_white_1000</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>
</style>
<style name="ThemeOverlay.Tachiyomi.Amoled" parent=""/>
<style name="Theme.Tachiyomi.ChocolateStrawberries"/>
<style name="Theme.Tachiyomi.FlatLime"/>
<style name="Theme.Tachiyomi.MidnightDusk">
<item name="colorPrimary">@color/primaryDuskDawn</item>