This commit is contained in:
Horis 2024-08-27 14:41:44 +08:00
parent d867068b05
commit 7e2a89a95a
2 changed files with 26 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.LogUtils
import splitties.init.appCtx
/**
@ -50,6 +51,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
}
override fun accentColor(@ColorInt color: Int): ThemeStore {
LogUtils.d("ThemeStore", "set accentColor $color")
mEditor.putInt(ThemeStorePrefKeys.KEY_ACCENT_COLOR, color)
return this
}
@ -161,6 +163,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
mEditor.putLong(ThemeStorePrefKeys.VALUES_CHANGED, System.currentTimeMillis())
.putBoolean(ThemeStorePrefKeys.IS_CONFIGURED_KEY, true)
.apply()
LogUtils.d("ThemeStore", "sharedPreference apply")
}
companion object : SharedPreferences.OnSharedPreferenceChangeListener {
@ -176,7 +179,10 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
key: String?
) {
when (key) {
ThemeStorePrefKeys.KEY_ACCENT_COLOR -> accentColor = accentColor()
ThemeStorePrefKeys.KEY_ACCENT_COLOR -> {
accentColor = accentColor()
LogUtils.d("ThemeStore", "onSharedPreferenceChanged accentColor $accentColor")
}
}
}

View File

@ -2,6 +2,7 @@ package io.legado.app.ui.config
import android.annotation.SuppressLint
import android.content.SharedPreferences
import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.os.Bundle
@ -26,11 +27,15 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.prefs.ColorPreference
import io.legado.app.lib.prefs.fragment.PreferenceFragment
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.ThemeUtils
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.number.NumberPickerDialog
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.FileUtils
import io.legado.app.utils.LogUtils
import io.legado.app.utils.MD5Utils
import io.legado.app.utils.SelectImageContract
import io.legado.app.utils.applyTint
@ -100,6 +105,20 @@ class ThemeConfigFragment : PreferenceFragment(),
}
}
}
val defaultValue = ThemeUtils.resolveColor(
requireContext(),
androidx.appcompat.R.attr.colorAccent,
Color.parseColor("#263238")
)
LogUtils.d("ThemeStore", "-------------")
LogUtils.d("ThemeStore", "accentColor from context $context defaultValue $defaultValue")
LogUtils.d("ThemeStore", "accentColor from context $context value $accentColor")
val v = ThemeStore.accentColor()
LogUtils.d("ThemeStore", "accentColor from appCtx $appCtx value $v")
LogUtils.d("ThemeStore", "context.packageName ${context?.packageName}")
LogUtils.d("ThemeStore", "appCtx.packageName ${appCtx.packageName}")
LogUtils.d("ThemeStore", "context.packageName == appCtx.packageName ${context?.packageName == appCtx.packageName}")
LogUtils.d("ThemeStore", "-------------")
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {