From 66b78f53af71ac64d7298dd4c46407fb713643d9 Mon Sep 17 00:00:00 2001 From: HapeLee <1321903405@qq.com> Date: Mon, 22 Sep 2025 01:18:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=BA=9B=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E7=9A=84=E7=95=8C=E9=9D=A2=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legato/kazusa/App.kt | 2 - .../io/legato/kazusa/base/BaseActivity.kt | 17 +- .../io/legato/kazusa/constant/PreferKey.kt | 1 + .../io/legato/kazusa/help/config/AppConfig.kt | 1 + .../kazusa/lib/prefs/ColorPreference.kt | 7 +- .../kazusa/lib/prefs/ThemeCardPreference.kt | 17 +- .../kazusa/lib/prefs/ThemeModePreference.kt | 6 +- .../kazusa/lib/theme/MaterialValueHelper.kt | 10 + .../io/legato/kazusa/lib/theme/ThemeStore.kt | 282 ++++++------------ .../kazusa/lib/theme/ThemeStoreInterface.kt | 52 +--- .../kazusa/lib/theme/ThemeStorePrefKeys.kt | 13 +- .../kazusa/ui/config/ThemeConfigFragment.kt | 54 +++- app/src/main/res/values-night/themes.xml | 29 ++ app/src/main/res/values/colors.xml | 6 +- app/src/main/res/values/themes.xml | 29 ++ app/src/main/res/xml/pref_config_theme.xml | 57 ++-- 16 files changed, 286 insertions(+), 297 deletions(-) diff --git a/app/src/main/java/io/legato/kazusa/App.kt b/app/src/main/java/io/legato/kazusa/App.kt index aea9835b4..06a32a32e 100644 --- a/app/src/main/java/io/legato/kazusa/App.kt +++ b/app/src/main/java/io/legato/kazusa/App.kt @@ -9,7 +9,6 @@ import android.content.pm.ApplicationInfo import android.content.res.Configuration import android.os.Build import com.github.liuyueyi.quick.transfer.constants.TransType -import com.google.android.material.color.DynamicColors import com.jeremyliao.liveeventbus.LiveEventBus import com.jeremyliao.liveeventbus.logger.DefaultLogger import com.script.rhino.ReadOnlyJavaObject @@ -66,7 +65,6 @@ class App : Application() { override fun onCreate() { super.onCreate() - DynamicColors.applyToActivitiesIfAvailable(this) FirebaseManager.init(this) CrashHandler(this) if (isDebuggable) { diff --git a/app/src/main/java/io/legato/kazusa/base/BaseActivity.kt b/app/src/main/java/io/legato/kazusa/base/BaseActivity.kt index 55dccfbd0..f0dd96c53 100644 --- a/app/src/main/java/io/legato/kazusa/base/BaseActivity.kt +++ b/app/src/main/java/io/legato/kazusa/base/BaseActivity.kt @@ -17,6 +17,7 @@ import androidx.core.view.WindowCompat import androidx.viewbinding.ViewBinding import com.google.android.material.appbar.AppBarLayout import com.google.android.material.color.DynamicColors +import com.google.android.material.color.DynamicColorsOptions import io.legato.kazusa.R import io.legato.kazusa.constant.AppLog import io.legato.kazusa.constant.EventBus @@ -31,6 +32,7 @@ import io.legato.kazusa.utils.hideSoftInput import io.legato.kazusa.utils.observeEvent import io.legato.kazusa.utils.toastOnUi import io.legato.kazusa.utils.windowSize +import io.legato.kazusa.lib.theme.primaryColor abstract class BaseActivity( @@ -128,7 +130,9 @@ abstract class BaseActivity( open fun initTheme() { when (getPrefString("app_theme", "0")) { - "0" -> DynamicColors.applyToActivitiesIfAvailable(application) + "0" -> { + DynamicColors.applyToActivitiesIfAvailable(application) + } "1" -> setTheme(R.style.Theme_Base_GR) "2" -> setTheme(R.style.Theme_Base_Lemon) "3" -> setTheme(R.style.Theme_Base_WH) @@ -139,8 +143,17 @@ abstract class BaseActivity( "8" -> setTheme(R.style.Theme_Base_Yuuka) "9" -> setTheme(R.style.Theme_Base_Phoebe) "10" -> setTheme(R.style.Theme_Base_Mujika) - "11" -> setTheme(R.style.AppTheme_Transparent) + "11" -> { + if (AppConfig.customMode == "accent") + setTheme(R.style.ThemeOverlay_WhiteBackground) + DynamicColors.applyToActivitiesIfAvailable(application, DynamicColorsOptions.Builder() + .setContentBasedSource(application.primaryColor) + .build()) + + } + "12" -> setTheme(R.style.AppTheme_Transparent) } + if (AppConfig.pureBlack) setTheme(R.style.ThemeOverlay_PureBlack) } diff --git a/app/src/main/java/io/legato/kazusa/constant/PreferKey.kt b/app/src/main/java/io/legato/kazusa/constant/PreferKey.kt index b670e3048..84c8f6f40 100644 --- a/app/src/main/java/io/legato/kazusa/constant/PreferKey.kt +++ b/app/src/main/java/io/legato/kazusa/constant/PreferKey.kt @@ -162,6 +162,7 @@ object PreferKey { const val firebaseEnable = "firebaseEnable" const val cPrimary = "colorPrimary" const val cAccent = "colorAccent" + const val customMode = "customMode" const val cBackground = "colorBackground" const val cBBackground = "colorBottomBackground" const val bgImage = "backgroundImage" diff --git a/app/src/main/java/io/legato/kazusa/help/config/AppConfig.kt b/app/src/main/java/io/legato/kazusa/help/config/AppConfig.kt index bd41be3e9..bfbcbff3f 100644 --- a/app/src/main/java/io/legato/kazusa/help/config/AppConfig.kt +++ b/app/src/main/java/io/legato/kazusa/help/config/AppConfig.kt @@ -27,6 +27,7 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { var useAntiAlias = appCtx.getPrefBoolean(PreferKey.antiAlias) var userAgent: String = getPrefUserAgent() var isEInkMode = appCtx.getPrefString(PreferKey.themeMode) == "3" + var customMode = appCtx.getPrefString(PreferKey.customMode) var clickActionTL = appCtx.getPrefInt(PreferKey.clickActionTL, 2) var clickActionTC = appCtx.getPrefInt(PreferKey.clickActionTC, 2) var clickActionTR = appCtx.getPrefInt(PreferKey.clickActionTR, 1) diff --git a/app/src/main/java/io/legato/kazusa/lib/prefs/ColorPreference.kt b/app/src/main/java/io/legato/kazusa/lib/prefs/ColorPreference.kt index 754126f00..d94297670 100644 --- a/app/src/main/java/io/legato/kazusa/lib/prefs/ColorPreference.kt +++ b/app/src/main/java/io/legato/kazusa/lib/prefs/ColorPreference.kt @@ -14,9 +14,13 @@ import androidx.preference.PreferenceViewHolder import com.jaredrummler.android.colorpicker.* import io.legato.kazusa.utils.ColorUtils import io.legato.kazusa.utils.applyTint +import io.legato.kazusa.utils.themeColor @Suppress("MemberVisibilityCanBePrivate", "unused") -class ColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs), +class ColorPreference @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null +) : Preference(context, attrs), ColorPickerDialogListener { var onSaveColor: ((color: Int) -> Boolean)? = null @@ -123,6 +127,7 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex ) if (v is ColorPanelView) { v.color = mColor + v.setBorderColor(context.themeColor(com.google.android.material.R.attr.colorPrimaryContainer)) } } diff --git a/app/src/main/java/io/legato/kazusa/lib/prefs/ThemeCardPreference.kt b/app/src/main/java/io/legato/kazusa/lib/prefs/ThemeCardPreference.kt index bf8d18c1b..10417008f 100644 --- a/app/src/main/java/io/legato/kazusa/lib/prefs/ThemeCardPreference.kt +++ b/app/src/main/java/io/legato/kazusa/lib/prefs/ThemeCardPreference.kt @@ -4,6 +4,8 @@ import android.annotation.SuppressLint import android.content.Context import android.content.res.ColorStateList import android.graphics.Color +import android.os.Handler +import android.os.Looper import android.util.AttributeSet import android.view.ContextThemeWrapper import android.view.LayoutInflater @@ -17,6 +19,7 @@ import com.google.android.material.card.MaterialCardView import io.legato.kazusa.R import io.legato.kazusa.constant.EventBus import io.legato.kazusa.utils.postEvent +import io.legato.kazusa.utils.restart @SuppressLint("ResourceType") class ThemeCardPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs) { @@ -73,11 +76,19 @@ class ThemeCardPreference(context: Context, attrs: AttributeSet) : Preference(co holder.card.setOnClickListener { if (value != currentValue) { + val oldValue = currentValue currentValue = value persistString(value) callChangeListener(value) notifyDataSetChanged() - postEvent(EventBus.RECREATE, "") + val isDynamicSwitch = (oldValue == "11" || value == "11") + Handler(Looper.getMainLooper()).postDelayed({ + if (isDynamicSwitch) { + context.restart() + } else { + postEvent(EventBus.RECREATE, "") + } + }, 300) } } } @@ -98,8 +109,8 @@ class ThemeCardPreference(context: Context, attrs: AttributeSet) : Preference(co "8" to R.style.Theme_Base_Yuuka, "9" to R.style.Theme_Base_Phoebe, "10" to R.style.Theme_Base_Mujika, - "11" to R.style.AppTheme_Transparent - ) + "11" to R.style.Theme_Base_WH, + "12" to R.style.AppTheme_Transparent) private fun getThemeColors(value: String): List { val themeResId = themeResIdMap[value] ?: return listOf(Color.GRAY, Color.GRAY, Color.GRAY, Color.GRAY) diff --git a/app/src/main/java/io/legato/kazusa/lib/prefs/ThemeModePreference.kt b/app/src/main/java/io/legato/kazusa/lib/prefs/ThemeModePreference.kt index 96892f295..9708573ed 100644 --- a/app/src/main/java/io/legato/kazusa/lib/prefs/ThemeModePreference.kt +++ b/app/src/main/java/io/legato/kazusa/lib/prefs/ThemeModePreference.kt @@ -1,6 +1,8 @@ package io.legato.kazusa.lib.prefs import android.content.Context +import android.os.Handler +import android.os.Looper import android.util.AttributeSet import androidx.preference.PreferenceViewHolder import com.google.android.material.button.MaterialButtonToggleGroup @@ -56,7 +58,9 @@ class ThemeModePreference(context: Context, attrs: AttributeSet) : Preference(co currentValue = newValue persistString(newValue) callChangeListener(newValue) - ThemeConfig.applyDayNight(context) + Handler(Looper.getMainLooper()).postDelayed({ + ThemeConfig.applyDayNight(context) + }, 300) } } } diff --git a/app/src/main/java/io/legato/kazusa/lib/theme/MaterialValueHelper.kt b/app/src/main/java/io/legato/kazusa/lib/theme/MaterialValueHelper.kt index 5aaf30afd..aa08d3a4b 100644 --- a/app/src/main/java/io/legato/kazusa/lib/theme/MaterialValueHelper.kt +++ b/app/src/main/java/io/legato/kazusa/lib/theme/MaterialValueHelper.kt @@ -2,6 +2,16 @@ package io.legato.kazusa.lib.theme +import android.content.Context + /** * @author Karim Abou Zeid (kabouzeid) */ +val Context.primaryColor: Int + get() = ThemeStore.primaryColor(this) + +val Context.secondaryColor: Int + get() = ThemeStore.secondaryColor(this) + +val Context.primaryContainerColor: Int + get() = ThemeStore.primaryContainerColor(this) \ No newline at end of file diff --git a/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStore.kt b/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStore.kt index 8e85b4661..ce8be8204 100644 --- a/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStore.kt +++ b/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStore.kt @@ -11,20 +11,63 @@ import androidx.core.content.ContextCompat import androidx.core.graphics.toColorInt import io.legato.kazusa.utils.ColorUtils import splitties.init.appCtx +import androidx.core.content.edit +import com.google.android.material.color.DynamicColors +import com.google.android.material.color.DynamicColorsOptions +import com.google.android.material.color.MaterialColors /** * @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid) */ + @Suppress("unused") class ThemeStore @SuppressLint("CommitPrefEdits") private constructor(private val mContext: Context) : ThemeStoreInterface { private val mEditor = prefs(mContext).edit() + override fun addColorScheme(@ColorInt color: Int): ThemeStore { + val options = DynamicColorsOptions.Builder() + .setContentBasedSource(color) + .build() + + val wrapped = DynamicColors.wrapContextIfAvailable( + mContext, + options).apply { + resources.configuration.uiMode = mContext.resources.configuration.uiMode + } + + val fallback = color + + val secondary = MaterialColors.getColor( + wrapped, + com.google.android.material.R.attr.colorSecondary, + fallback + ) + + val primaryContainer = MaterialColors.getColor( + wrapped, + com.google.android.material.R.attr.colorSecondaryContainer, + fallback + ) + + val primary = MaterialColors.getColor( + wrapped, + androidx.appcompat.R.attr.colorPrimary, + fallback + ) + + mEditor.putInt(ThemeStorePrefKeys.KEY_SECONDARY_COLOR, secondary) + mEditor.putInt(ThemeStorePrefKeys.KEY_PRIMARY_CONTAINER_COLOR, primaryContainer) + mEditor.putInt(ThemeStorePrefKeys.KEY_PRIMARY_COLOR, primary) + + return this + } + override fun primaryColor(@ColorInt color: Int): ThemeStore { - mEditor.putInt(ThemeStorePrefKeys.KEY_PRIMARY_COLOR, color) if (autoGeneratePrimaryDark(mContext)) primaryColorDark(ColorUtils.darkenColor(color)) + addColorScheme(color) return this } @@ -49,97 +92,6 @@ private constructor(private val mContext: Context) : ThemeStoreInterface { return primaryColorDark(ThemeUtils.resolveColor(mContext, colorAttr)) } - override fun accentColor(@ColorInt color: Int): ThemeStore { - mEditor.putInt(ThemeStorePrefKeys.KEY_ACCENT_COLOR, color) - return this - } - - override fun accentColorRes(@ColorRes colorRes: Int): ThemeStore { - return accentColor(ContextCompat.getColor(mContext, colorRes)) - } - - override fun accentColorAttr(@AttrRes colorAttr: Int): ThemeStore { - return accentColor(ThemeUtils.resolveColor(mContext, colorAttr)) - } - - override fun statusBarColor(@ColorInt color: Int): ThemeStore { - mEditor.putInt(ThemeStorePrefKeys.KEY_STATUS_BAR_COLOR, color) - return this - } - - override fun statusBarColorRes(@ColorRes colorRes: Int): ThemeStore { - return statusBarColor(ContextCompat.getColor(mContext, colorRes)) - } - - override fun statusBarColorAttr(@AttrRes colorAttr: Int): ThemeStore { - return statusBarColor(ThemeUtils.resolveColor(mContext, colorAttr)) - } - - override fun navigationBarColor(@ColorInt color: Int): ThemeStore { - mEditor.putInt(ThemeStorePrefKeys.KEY_NAVIGATION_BAR_COLOR, color) - return this - } - - override fun navigationBarColorRes(@ColorRes colorRes: Int): ThemeStore { - return navigationBarColor(ContextCompat.getColor(mContext, colorRes)) - } - - override fun navigationBarColorAttr(@AttrRes colorAttr: Int): ThemeStore { - return navigationBarColor(ThemeUtils.resolveColor(mContext, colorAttr)) - } - - override fun textColorPrimary(@ColorInt color: Int): ThemeStore { - mEditor.putInt(ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY, color) - return this - } - - override fun textColorPrimaryRes(@ColorRes colorRes: Int): ThemeStore { - return textColorPrimary(ContextCompat.getColor(mContext, colorRes)) - } - - override fun textColorPrimaryAttr(@AttrRes colorAttr: Int): ThemeStore { - return textColorPrimary(ThemeUtils.resolveColor(mContext, colorAttr)) - } - - override fun textColorPrimaryInverse(@ColorInt color: Int): ThemeStore { - mEditor.putInt(ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY_INVERSE, color) - return this - } - - override fun textColorPrimaryInverseRes(@ColorRes colorRes: Int): ThemeStore { - return textColorPrimaryInverse(ContextCompat.getColor(mContext, colorRes)) - } - - override fun textColorPrimaryInverseAttr(@AttrRes colorAttr: Int): ThemeStore { - return textColorPrimaryInverse(ThemeUtils.resolveColor(mContext, colorAttr)) - } - - override fun textColorSecondary(@ColorInt color: Int): ThemeStore { - mEditor.putInt(ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY, color) - return this - } - - override fun textColorSecondaryRes(@ColorRes colorRes: Int): ThemeStore { - return textColorSecondary(ContextCompat.getColor(mContext, colorRes)) - } - - override fun textColorSecondaryAttr(@AttrRes colorAttr: Int): ThemeStore { - return textColorSecondary(ThemeUtils.resolveColor(mContext, colorAttr)) - } - - override fun textColorSecondaryInverse(@ColorInt color: Int): ThemeStore { - mEditor.putInt(ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY_INVERSE, color) - return this - } - - override fun textColorSecondaryInverseRes(@ColorRes colorRes: Int): ThemeStore { - return textColorSecondaryInverse(ContextCompat.getColor(mContext, colorRes)) - } - - override fun textColorSecondaryInverseAttr(@AttrRes colorAttr: Int): ThemeStore { - return textColorSecondaryInverse(ThemeUtils.resolveColor(mContext, colorAttr)) - } - override fun backgroundColor(color: Int): ThemeStore { mEditor.putInt(ThemeStorePrefKeys.KEY_BACKGROUND_COLOR, color) return this @@ -161,17 +113,17 @@ private constructor(private val mContext: Context) : ThemeStoreInterface { mEditor.putLong(ThemeStorePrefKeys.VALUES_CHANGED, System.currentTimeMillis()) .putBoolean(ThemeStorePrefKeys.IS_CONFIGURED_KEY, true) .apply() - accentColor = accentColor() } companion object { - var accentColor = accentColor() - fun editTheme(context: Context): ThemeStore { return ThemeStore(context) } + fun isCustomThemeEnabled(context: Context): Boolean = true + // AppConfig.customTheme + // Static getters @CheckResult @@ -189,110 +141,70 @@ private constructor(private val mContext: Context) : ThemeStoreInterface { @CheckResult @ColorInt fun primaryColor(context: Context = appCtx): Int { - return prefs(context).getInt( - ThemeStorePrefKeys.KEY_PRIMARY_COLOR, - ThemeUtils.resolveColor( - context, - androidx.appcompat.R.attr.colorPrimary, - "#455A64".toColorInt() - ) - ) - } - - @CheckResult - @ColorInt - fun primaryColorDark(context: Context): Int { - return prefs(context).getInt( - ThemeStorePrefKeys.KEY_PRIMARY_COLOR_DARK, - ThemeUtils.resolveColor( - context, - androidx.appcompat.R.attr.colorPrimaryDark, - "#37474F".toColorInt() - ) - ) - } - - @CheckResult - @ColorInt - fun accentColor(context: Context = appCtx): Int { - return prefs(context).getInt( - ThemeStorePrefKeys.KEY_ACCENT_COLOR, - ThemeUtils.resolveColor( - context, - androidx.appcompat.R.attr.colorAccent, - "#263238".toColorInt() - ) - ) - } - - @CheckResult - @ColorInt - fun statusBarColor(context: Context, transparent: Boolean): Int { - return if (transparent) { + return if (isCustomThemeEnabled(context)) { prefs(context).getInt( - ThemeStorePrefKeys.KEY_STATUS_BAR_COLOR, + ThemeStorePrefKeys.KEY_PRIMARY_COLOR, + ThemeUtils.resolveColor( + context, + androidx.appcompat.R.attr.colorPrimary, + "#455A64".toColorInt() + ) + ) + } else { + ThemeUtils.resolveColor(context, androidx.appcompat.R.attr.colorPrimary) + } + } + + fun primaryContainerColor(context: Context = appCtx): Int { + return if (isCustomThemeEnabled(context)) { + prefs(context).getInt( + ThemeStorePrefKeys.KEY_PRIMARY_CONTAINER_COLOR, + "#FFFFFF".toColorInt() + ) + } else { + ThemeUtils.resolveColor(context, com.google.android.material.R.attr.colorPrimaryContainer) + } + } + + fun secondaryColor(context: Context = appCtx): Int { + return if (isCustomThemeEnabled(context)) { + prefs(context).getInt( + ThemeStorePrefKeys.KEY_SECONDARY_COLOR, primaryColor(context) ) } else { - prefs(context).getInt( - ThemeStorePrefKeys.KEY_STATUS_BAR_COLOR, - primaryColorDark(context) - ) + primaryColor(context) } } @CheckResult @ColorInt - fun navigationBarColor(context: Context): Int { - return prefs(context).getInt( - ThemeStorePrefKeys.KEY_NAVIGATION_BAR_COLOR, - bottomBackground(context) - ) - } - - @CheckResult - @ColorInt - fun textColorPrimary(context: Context): Int { - return prefs(context).getInt( - ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY, - ThemeUtils.resolveColor(context, android.R.attr.textColorPrimary) - ) - } - - @CheckResult - @ColorInt - fun textColorPrimaryInverse(context: Context): Int { - return prefs(context).getInt( - ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY_INVERSE, - ThemeUtils.resolveColor(context, android.R.attr.textColorPrimaryInverse) - ) - } - - @CheckResult - @ColorInt - fun textColorSecondary(context: Context): Int { - return prefs(context).getInt( - ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY, - ThemeUtils.resolveColor(context, android.R.attr.textColorSecondary) - ) - } - - @CheckResult - @ColorInt - fun textColorSecondaryInverse(context: Context): Int { - return prefs(context).getInt( - ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY_INVERSE, - ThemeUtils.resolveColor(context, android.R.attr.textColorSecondaryInverse) - ) + fun primaryColorDark(context: Context): Int { + return if (isCustomThemeEnabled(context)) { + prefs(context).getInt( + ThemeStorePrefKeys.KEY_PRIMARY_COLOR_DARK, + ThemeUtils.resolveColor( + context, + androidx.appcompat.R.attr.colorPrimaryDark, + "#37474F".toColorInt() + ) + ) + } else { + ThemeUtils.resolveColor(context, androidx.appcompat.R.attr.colorPrimaryDark) + } } @CheckResult @ColorInt fun backgroundColor(context: Context = appCtx): Int { - return prefs(context).getInt( - ThemeStorePrefKeys.KEY_BACKGROUND_COLOR, + return if (isCustomThemeEnabled(context)) { + prefs(context).getInt( + ThemeStorePrefKeys.KEY_BACKGROUND_COLOR, + ThemeUtils.resolveColor(context, android.R.attr.colorBackground) + ) + } else { ThemeUtils.resolveColor(context, android.R.attr.colorBackground) - ) + } } @CheckResult @@ -332,7 +244,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface { val prefs = prefs(context) val lastVersion = prefs.getInt(ThemeStorePrefKeys.IS_CONFIGURED_VERSION_KEY, -1) if (version > lastVersion) { - prefs.edit().putInt(ThemeStorePrefKeys.IS_CONFIGURED_VERSION_KEY, version).apply() + prefs.edit { putInt(ThemeStorePrefKeys.IS_CONFIGURED_VERSION_KEY, version) } return false } return true diff --git a/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStoreInterface.kt b/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStoreInterface.kt index d82a8eef5..2748b3a58 100644 --- a/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStoreInterface.kt +++ b/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStoreInterface.kt @@ -26,57 +26,7 @@ internal interface ThemeStoreInterface { fun primaryColorDarkAttr(@AttrRes colorAttr: Int): ThemeStore - // Accent colors - - fun accentColor(@ColorInt color: Int): ThemeStore - - fun accentColorRes(@ColorRes colorRes: Int): ThemeStore - - fun accentColorAttr(@AttrRes colorAttr: Int): ThemeStore - - // Status bar color - - fun statusBarColor(@ColorInt color: Int): ThemeStore - - fun statusBarColorRes(@ColorRes colorRes: Int): ThemeStore - - fun statusBarColorAttr(@AttrRes colorAttr: Int): ThemeStore - - // Navigation bar color - - fun navigationBarColor(@ColorInt color: Int): ThemeStore - - fun navigationBarColorRes(@ColorRes colorRes: Int): ThemeStore - - fun navigationBarColorAttr(@AttrRes colorAttr: Int): ThemeStore - - // Primary text color - - fun textColorPrimary(@ColorInt color: Int): ThemeStore - - fun textColorPrimaryRes(@ColorRes colorRes: Int): ThemeStore - - fun textColorPrimaryAttr(@AttrRes colorAttr: Int): ThemeStore - - fun textColorPrimaryInverse(@ColorInt color: Int): ThemeStore - - fun textColorPrimaryInverseRes(@ColorRes colorRes: Int): ThemeStore - - fun textColorPrimaryInverseAttr(@AttrRes colorAttr: Int): ThemeStore - - // Secondary text color - - fun textColorSecondary(@ColorInt color: Int): ThemeStore - - fun textColorSecondaryRes(@ColorRes colorRes: Int): ThemeStore - - fun textColorSecondaryAttr(@AttrRes colorAttr: Int): ThemeStore - - fun textColorSecondaryInverse(@ColorInt color: Int): ThemeStore - - fun textColorSecondaryInverseRes(@ColorRes colorRes: Int): ThemeStore - - fun textColorSecondaryInverseAttr(@AttrRes colorAttr: Int): ThemeStore + fun addColorScheme(@ColorInt color: Int): ThemeStore // Background diff --git a/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStorePrefKeys.kt b/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStorePrefKeys.kt index c6df1f653..9005243de 100644 --- a/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStorePrefKeys.kt +++ b/app/src/main/java/io/legato/kazusa/lib/theme/ThemeStorePrefKeys.kt @@ -9,21 +9,12 @@ object ThemeStorePrefKeys { const val IS_CONFIGURED_KEY = "is_configured" const val IS_CONFIGURED_VERSION_KEY = "is_configured_version" const val VALUES_CHANGED = "values_changed" - const val KEY_PRIMARY_COLOR = "primary_color" + const val KEY_PRIMARY_CONTAINER_COLOR = "KEY_PRIMARY_CONTAINER_COLOR" const val KEY_PRIMARY_COLOR_DARK = "primary_color_dark" - const val KEY_ACCENT_COLOR = "accent_color" - const val KEY_STATUS_BAR_COLOR = "status_bar_color" - const val KEY_NAVIGATION_BAR_COLOR = "navigation_bar_color" - - const val KEY_TEXT_COLOR_PRIMARY = "text_color_primary" - const val KEY_TEXT_COLOR_PRIMARY_INVERSE = "text_color_primary_inverse" - const val KEY_TEXT_COLOR_SECONDARY = "text_color_secondary" - const val KEY_TEXT_COLOR_SECONDARY_INVERSE = "text_color_secondary_inverse" - + const val KEY_SECONDARY_COLOR = "KEY_SECONDARY_COLOR" const val KEY_BACKGROUND_COLOR = "backgroundColor" const val KEY_BOTTOM_BACKGROUND = "bottomBackground" - const val KEY_APPLY_PRIMARYDARK_STATUSBAR = "apply_primarydark_statusbar" const val KEY_APPLY_PRIMARY_NAVBAR = "apply_primary_navbar" const val KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark" diff --git a/app/src/main/java/io/legato/kazusa/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legato/kazusa/ui/config/ThemeConfigFragment.kt index 3f21ea20b..4432c0bf1 100644 --- a/app/src/main/java/io/legato/kazusa/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legato/kazusa/ui/config/ThemeConfigFragment.kt @@ -2,13 +2,18 @@ package io.legato.kazusa.ui.config //import io.legado.app.lib.theme.primaryColor import android.annotation.SuppressLint +import android.app.Application import android.content.SharedPreferences import android.net.Uri import android.os.Bundle +import android.os.Handler +import android.os.Looper import android.view.View import android.widget.SeekBar import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import com.google.android.material.color.DynamicColors +import com.google.android.material.color.DynamicColorsOptions import io.legato.kazusa.R import io.legato.kazusa.base.AppContextWrapper import io.legato.kazusa.constant.EventBus @@ -21,8 +26,11 @@ import io.legato.kazusa.help.config.ThemeConfig import io.legato.kazusa.lib.dialogs.alert import io.legato.kazusa.lib.dialogs.selector import io.legato.kazusa.lib.prefs.ColorPreference +import io.legato.kazusa.lib.prefs.NameListPreference import io.legato.kazusa.lib.prefs.ThemeCardPreference import io.legato.kazusa.lib.prefs.ThemeModePreference +import io.legato.kazusa.lib.theme.ThemeStore +import io.legato.kazusa.lib.theme.primaryColor import io.legato.kazusa.ui.widget.number.NumberPickerDialog import io.legato.kazusa.ui.widget.seekbar.SeekBarChangeListener import io.legato.kazusa.utils.ColorUtils @@ -38,6 +46,7 @@ import io.legato.kazusa.utils.putPrefInt import io.legato.kazusa.utils.putPrefString import io.legato.kazusa.utils.readUri import io.legato.kazusa.utils.removePref +import io.legato.kazusa.utils.restart import io.legato.kazusa.utils.startActivity import io.legato.kazusa.utils.toastOnUi import splitties.init.appCtx @@ -101,11 +110,25 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), } } - findPreference(PreferKey.themePref)?.let { + val themePref = findPreference(PreferKey.themePref) + val colorPrimary = findPreference("colorPrimary") + + val currentTheme = getPrefString("app_theme") + colorPrimary?.isVisible = currentTheme == "11" + + val customMode = findPreference("customMode") + customMode?.isVisible = currentTheme == "11" + themePref?.let { it.setOnPreferenceChangeListener { _, _ -> true } } + + themePref?.setOnPreferenceChangeListener { _, newValue -> + colorPrimary?.isVisible = newValue == "11" + customMode?.isVisible = newValue == "11" + true + } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -136,19 +159,38 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), //recreateActivities() } + PreferKey.customMode -> { + Handler(Looper.getMainLooper()).postDelayed({ + requireContext().restart() + }, 300) + } + PreferKey.pureBlack -> { - recreateActivities() + Handler(Looper.getMainLooper()).postDelayed({ + recreateActivities() + }, 300) + } + + PreferKey.cPrimary -> { + val color = getPrefInt(key, ThemeStore.primaryColor(requireContext())) + ThemeStore.editTheme(requireContext()) + .primaryColor(color) + .apply() + DynamicColors.applyToActivitiesIfAvailable(requireContext().applicationContext as Application, DynamicColorsOptions.Builder() + .setContentBasedSource(requireContext().primaryColor) + .build()) + Handler(Looper.getMainLooper()).postDelayed({ + recreateActivities() + }, 300) } - PreferKey.cPrimary, - PreferKey.cAccent, PreferKey.cBackground, PreferKey.cBBackground -> { upTheme(false) } - PreferKey.cNPrimary, - PreferKey.cNAccent, + //PreferKey.cNPrimary, + PreferKey.cNBackground, PreferKey.cNBBackground -> { upTheme(true) diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 29a7e2623..95806fddd 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -12,6 +12,35 @@ @style/AppTheme.AlertDialog + + + + diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index 00e80780e..82a142fd6 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -33,7 +33,22 @@ + android:title="纯黑深色模式" /> + + + + + android:key="backgroundImage" + android:title="@string/background_image" /> + android:key="themeList" + android:summary="@string/theme_list_summary" + android:title="@string/theme_list" + app:allowDividerAbove="false" + app:allowDividerBelow="false" + app:iconSpaceReserved="false" /> - - - - - - - - \ No newline at end of file