diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index eb899f0f21..7c105bae85 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -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" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 5086c4a3bf..d432625259 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index 80ec95f73d..502674abce 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -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 { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/ThemePreference.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/ThemePreference.kt index 552b29cc5d..1edaaf7800 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/ThemePreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/ThemePreference.kt @@ -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) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/BaseWebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/BaseWebViewActivity.kt index 9aa1a50b3c..91a0de23a7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/BaseWebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/BaseWebViewActivity.kt @@ -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() { 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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt index e4257c18f3..c502a86384 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt @@ -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 { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/Themes.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/Themes.kt index e052453454..534716160c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/Themes.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/Themes.kt @@ -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" diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index b2691556b9..b3d22b4087 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -6,14 +6,11 @@ false - - - - - - - - +