增加纯黑暗色模式,清理代码
This commit is contained in:
@@ -21,6 +21,7 @@ import io.legato.kazusa.R
|
||||
import io.legato.kazusa.constant.AppLog
|
||||
import io.legato.kazusa.constant.EventBus
|
||||
import io.legato.kazusa.constant.Theme
|
||||
import io.legato.kazusa.help.config.AppConfig
|
||||
import io.legato.kazusa.help.config.ThemeConfig
|
||||
import io.legato.kazusa.utils.applyOpenTint
|
||||
import io.legato.kazusa.utils.applyTint
|
||||
@@ -28,8 +29,6 @@ import io.legato.kazusa.utils.disableAutoFill
|
||||
import io.legato.kazusa.utils.getPrefString
|
||||
import io.legato.kazusa.utils.hideSoftInput
|
||||
import io.legato.kazusa.utils.observeEvent
|
||||
import io.legato.kazusa.utils.setNavigationBarColorAuto
|
||||
import io.legato.kazusa.utils.themeColor
|
||||
import io.legato.kazusa.utils.toastOnUi
|
||||
import io.legato.kazusa.utils.windowSize
|
||||
|
||||
@@ -74,7 +73,7 @@ abstract class BaseActivity<VB : ViewBinding>(
|
||||
super.onCreate(savedInstanceState)
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
enableEdgeToEdge()
|
||||
window.setNavigationBarColorAuto(themeColor(com.google.android.material.R.attr.colorSurface))
|
||||
//window.setNavigationBarColorAuto(themeColor(com.google.android.material.R.attr.colorSurface))
|
||||
//setupSystemBar()
|
||||
setContentView(binding.root)
|
||||
upBackgroundImage()
|
||||
@@ -129,18 +128,21 @@ abstract class BaseActivity<VB : ViewBinding>(
|
||||
|
||||
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)
|
||||
"4" -> setTheme(R.style.Theme_Base_Koharu)
|
||||
"5" -> setTheme(R.style.Theme_Base_Yuuka)
|
||||
"6" -> setTheme(R.style.Theme_Base_Phoebe)
|
||||
"7" -> setTheme(R.style.AppTheme_Transparent)
|
||||
"4" -> setTheme(R.style.Theme_Base_Sora)
|
||||
"5" -> setTheme(R.style.Theme_Base_August)
|
||||
"6" -> setTheme(R.style.Theme_Base_Carlotta)
|
||||
"7" -> setTheme(R.style.Theme_Base_Koharu)
|
||||
"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)
|
||||
}
|
||||
if (AppConfig.pureBlack)
|
||||
setTheme(R.style.ThemeOverlay_PureBlack)
|
||||
}
|
||||
|
||||
open fun upBackgroundImage() {
|
||||
|
||||
@@ -78,9 +78,6 @@ object PreferKey {
|
||||
const val textFullJustify = "textFullJustify"
|
||||
const val textBottomJustify = "textBottomJustify"
|
||||
const val autoReadSpeed = "autoReadSpeed"
|
||||
//const val barElevation = "barElevation"
|
||||
//const val transparentStatusBar = "transparentStatusBar"
|
||||
//const val immNavigationBar = "immNavigationBar"
|
||||
const val defaultCover = "defaultCover"
|
||||
const val defaultCoverDark = "defaultCoverDark"
|
||||
const val replaceEnableDefault = "replaceEnableDefault"
|
||||
@@ -126,13 +123,6 @@ object PreferKey {
|
||||
const val tocCountWords = "tocCountWords"
|
||||
const val enableReadRecord = "enableReadRecord"
|
||||
const val localBookImportSort = "localBookImportSort"
|
||||
const val customWelcome = "customWelcome"
|
||||
const val welcomeImage = "welcomeImagePath"
|
||||
const val welcomeImageDark = "welcomeImagePathDark"
|
||||
const val welcomeShowText = "welcomeShowText"
|
||||
const val welcomeShowTextDark = "welcomeShowTextDark"
|
||||
const val welcomeShowIcon = "welcomeShowIcon"
|
||||
const val welcomeShowIconDark = "welcomeShowIconDark"
|
||||
const val pageTouchSlop = "pageTouchSlop"
|
||||
const val showAddToShelfAlert = "showAddToShelfAlert"
|
||||
const val ignoreAudioFocus = "ignoreAudioFocus"
|
||||
@@ -211,6 +201,6 @@ object PreferKey {
|
||||
const val sharedElementEnterTransitionEnable = "sharedElementEnterTransitionEnable"
|
||||
const val bookshelfLayoutGridLandscape = "bookshelfLayoutGridLandscape"
|
||||
const val bookshelfLayoutGridPortrait = "bookshelfLayoutGridPortrait"
|
||||
|
||||
const val tabletInterface = "tabletInterface"
|
||||
const val pureBlack = "pure_black"
|
||||
}
|
||||
|
||||
@@ -149,12 +149,6 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
var isFirstLaunch: Boolean
|
||||
get() = appCtx.getPrefBoolean(PreferKey.isFirstLaunch, true)
|
||||
set(value) {
|
||||
appCtx.putPrefBoolean(PreferKey.isFirstLaunch, value)
|
||||
}
|
||||
|
||||
var showUnread: Boolean
|
||||
get() = appCtx.getPrefBoolean(PreferKey.showUnread, true)
|
||||
set(value) {
|
||||
@@ -615,7 +609,7 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
}
|
||||
|
||||
var bookshelfSortOrder: Int
|
||||
get() = appCtx.getPrefInt(PreferKey.bookshelfSortOrder, 0)
|
||||
get() = appCtx.getPrefInt(PreferKey.bookshelfSortOrder, 1)
|
||||
set(value) {
|
||||
appCtx.putPrefInt(PreferKey.bookshelfSortOrder, value)
|
||||
}
|
||||
@@ -814,5 +808,10 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
appCtx.putPrefString(PreferKey.tabletInterface, value)
|
||||
}
|
||||
|
||||
var pureBlack
|
||||
get() = appCtx.getPrefBoolean(PreferKey.pureBlack, false)
|
||||
set(value) {
|
||||
appCtx.getPrefBoolean(PreferKey.pureBlack, value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,10 +91,14 @@ class ThemeCardPreference(context: Context, attrs: AttributeSet) : Preference(co
|
||||
"1" to R.style.Theme_Base_GR,
|
||||
"2" to R.style.Theme_Base_Lemon,
|
||||
"3" to R.style.Theme_Base_WH,
|
||||
"4" to R.style.Theme_Base_Koharu,
|
||||
"5" to R.style.Theme_Base_Yuuka,
|
||||
"6" to R.style.Theme_Base_Phoebe,
|
||||
"7" to R.style.AppTheme_Transparent
|
||||
"4" to R.style.Theme_Base_Sora,
|
||||
"5" to R.style.Theme_Base_August,
|
||||
"6" to R.style.Theme_Base_Carlotta,
|
||||
"7" to R.style.Theme_Base_Koharu,
|
||||
"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
|
||||
)
|
||||
|
||||
private fun getThemeColors(value: String): List<Int> {
|
||||
|
||||
@@ -3,15 +3,14 @@ package io.legato.kazusa.lib.theme
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Color
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.CheckResult
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.toColorInt
|
||||
import io.legato.kazusa.utils.ColorUtils
|
||||
import splitties.init.appCtx
|
||||
import androidx.core.graphics.toColorInt
|
||||
|
||||
/**
|
||||
* @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid)
|
||||
@@ -208,7 +207,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
|
||||
ThemeUtils.resolveColor(
|
||||
context,
|
||||
androidx.appcompat.R.attr.colorPrimaryDark,
|
||||
Color.parseColor("#37474F")
|
||||
"#37474F".toColorInt()
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -221,7 +220,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
|
||||
ThemeUtils.resolveColor(
|
||||
context,
|
||||
androidx.appcompat.R.attr.colorAccent,
|
||||
Color.parseColor("#263238")
|
||||
"#263238".toColorInt()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ package io.legato.kazusa.lib.theme
|
||||
* @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
object ThemeStorePrefKeys {
|
||||
const val KEY_DYNAMIC_COLORS_ENABLED = ""
|
||||
|
||||
const val CONFIG_PREFS_KEY_DEFAULT = "app_themes"
|
||||
const val IS_CONFIGURED_KEY = "is_configured"
|
||||
@@ -29,9 +28,4 @@ object ThemeStorePrefKeys {
|
||||
const val KEY_APPLY_PRIMARY_NAVBAR = "apply_primary_navbar"
|
||||
const val KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark"
|
||||
|
||||
const val KEY_COLOR_PRIMARY = "key_color_primary"
|
||||
const val KEY_COLOR_ON_PRIMARY = "key_color_on_primary"
|
||||
const val KEY_COLOR_PRIMARY_CONTAINER = "key_color_primary_container"
|
||||
const val KEY_COLOR_ON_PRIMARY_CONTAINER = "key_color_on_primary_container"
|
||||
const val KEY_COLOR_SECONDARY = "key_color_secondary"
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.graphics.RenderEffect
|
||||
import android.graphics.Shader
|
||||
@@ -533,7 +534,13 @@ class BookInfoActivity :
|
||||
val surfaceTransition = ValueAnimator.ofArgb(surfaceFinalColor, colorSurface).apply {
|
||||
duration = 400L
|
||||
addUpdateListener { animation ->
|
||||
val color = animation.animatedValue as Int
|
||||
val nightModeFlags =
|
||||
resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
val isDarkMode = nightModeFlags == Configuration.UI_MODE_NIGHT_YES
|
||||
var color = animation.animatedValue as Int
|
||||
if (AppConfig.pureBlack && isDarkMode) {
|
||||
color = Color.BLACK
|
||||
}
|
||||
binding.cdInfo?.setCardBackgroundColor(color)
|
||||
binding.llInfo.setBackgroundColor(color)
|
||||
(binding.llCover.background as? GradientDrawable)?.colors =
|
||||
|
||||
@@ -5,9 +5,7 @@ import androidx.activity.viewModels
|
||||
import androidx.fragment.app.Fragment
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.base.VMBaseActivity
|
||||
import io.legato.kazusa.constant.EventBus
|
||||
import io.legato.kazusa.databinding.ActivityConfigBinding
|
||||
import io.legato.kazusa.utils.observeEvent
|
||||
import io.legato.kazusa.utils.viewbindingdelegate.viewBinding
|
||||
|
||||
class ConfigActivity : VMBaseActivity<ActivityConfigBinding, ConfigViewModel>() {
|
||||
@@ -23,7 +21,6 @@ class ConfigActivity : VMBaseActivity<ActivityConfigBinding, ConfigViewModel>()
|
||||
ConfigTag.THEME_CONFIG -> replaceFragment<ThemeConfigFragment>(configTag)
|
||||
ConfigTag.BACKUP_CONFIG -> replaceFragment<BackupConfigFragment>(configTag)
|
||||
ConfigTag.COVER_CONFIG -> replaceFragment<CoverConfigFragment>(configTag)
|
||||
ConfigTag.WELCOME_CONFIG -> replaceFragment<WelcomeConfigFragment>(configTag)
|
||||
else -> finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,10 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
|
||||
//recreateActivities()
|
||||
}
|
||||
|
||||
PreferKey.pureBlack -> {
|
||||
recreateActivities()
|
||||
}
|
||||
|
||||
PreferKey.cPrimary,
|
||||
PreferKey.cAccent,
|
||||
PreferKey.cBackground,
|
||||
@@ -193,10 +197,6 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
|
||||
"coverConfig" -> startActivity<ConfigActivity> {
|
||||
putExtra("configTag", ConfigTag.COVER_CONFIG)
|
||||
}
|
||||
|
||||
"welcomeStyle" -> startActivity<ConfigActivity> {
|
||||
putExtra("configTag", ConfigTag.WELCOME_CONFIG)
|
||||
}
|
||||
}
|
||||
return super.onPreferenceTreeClick(preference)
|
||||
}
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
package io.legato.kazusa.ui.config
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.preference.Preference
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.constant.PreferKey
|
||||
import io.legato.kazusa.lib.dialogs.selector
|
||||
import io.legato.kazusa.lib.prefs.fragment.PreferenceFragment
|
||||
//import io.legado.app.lib.theme.primaryColor
|
||||
import io.legato.kazusa.model.BookCover
|
||||
import io.legato.kazusa.utils.*
|
||||
import splitties.init.appCtx
|
||||
import java.io.FileOutputStream
|
||||
|
||||
class WelcomeConfigFragment : PreferenceFragment(),
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private val requestWelcomeImage = 221
|
||||
private val requestWelcomeImageDark = 222
|
||||
private val selectImage = registerForActivityResult(SelectImageContract()) {
|
||||
it.uri?.let { uri ->
|
||||
when (it.requestCode) {
|
||||
requestWelcomeImage -> setCoverFromUri(PreferKey.welcomeImage, uri)
|
||||
requestWelcomeImageDark -> setCoverFromUri(PreferKey.welcomeImageDark, uri)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.pref_config_welcome)
|
||||
upPreferenceSummary(PreferKey.welcomeImage, getPrefString(PreferKey.welcomeImage))
|
||||
upPreferenceSummary(PreferKey.welcomeImageDark, getPrefString(PreferKey.welcomeImageDark))
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
activity?.setTitle(R.string.welcome_style)
|
||||
//listView.setEdgeEffectColor(primaryColor)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
sharedPreferences ?: return
|
||||
when (key) {
|
||||
PreferKey.welcomeImage,
|
||||
PreferKey.welcomeImageDark -> {
|
||||
upPreferenceSummary(key, getPrefString(key))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("PrivateResource")
|
||||
override fun onPreferenceTreeClick(preference: Preference): Boolean {
|
||||
when (preference.key) {
|
||||
PreferKey.welcomeImage ->
|
||||
if (getPrefString(preference.key).isNullOrEmpty()) {
|
||||
selectImage.launch(requestWelcomeImage)
|
||||
} else {
|
||||
context?.selector(
|
||||
items = arrayListOf(
|
||||
getString(R.string.delete),
|
||||
getString(R.string.select_image)
|
||||
)
|
||||
) { _, i ->
|
||||
if (i == 0) {
|
||||
removePref(preference.key)
|
||||
BookCover.upDefaultCover()
|
||||
} else {
|
||||
selectImage.launch(requestWelcomeImage)
|
||||
}
|
||||
}
|
||||
}
|
||||
PreferKey.welcomeImageDark ->
|
||||
if (getPrefString(preference.key).isNullOrEmpty()) {
|
||||
selectImage.launch(requestWelcomeImageDark)
|
||||
} else {
|
||||
context?.selector(
|
||||
items = arrayListOf(
|
||||
getString(R.string.delete),
|
||||
getString(R.string.select_image)
|
||||
)
|
||||
) { _, i ->
|
||||
if (i == 0) {
|
||||
removePref(preference.key)
|
||||
BookCover.upDefaultCover()
|
||||
} else {
|
||||
selectImage.launch(requestWelcomeImageDark)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onPreferenceTreeClick(preference)
|
||||
}
|
||||
|
||||
private fun upPreferenceSummary(preferenceKey: String, value: String?) {
|
||||
val preference = findPreference<Preference>(preferenceKey) ?: return
|
||||
when (preferenceKey) {
|
||||
PreferKey.welcomeImage,
|
||||
PreferKey.welcomeImageDark -> preference.summary = if (value.isNullOrBlank()) {
|
||||
getString(R.string.select_image)
|
||||
} else {
|
||||
value
|
||||
}
|
||||
else -> preference.summary = value
|
||||
}
|
||||
}
|
||||
|
||||
private fun setCoverFromUri(preferenceKey: String, uri: Uri) {
|
||||
readUri(uri) { fileDoc, inputStream ->
|
||||
kotlin.runCatching {
|
||||
var file = requireContext().externalFiles
|
||||
val suffix = fileDoc.name.substringAfterLast(".")
|
||||
val fileName = uri.inputStream(requireContext()).getOrThrow().use {
|
||||
MD5Utils.md5Encode(it) + ".$suffix"
|
||||
}
|
||||
file = FileUtils.createFileIfNotExist(file, "covers", fileName)
|
||||
FileOutputStream(file).use {
|
||||
inputStream.copyTo(it)
|
||||
}
|
||||
putPrefString(preferenceKey, file.absolutePath)
|
||||
}.onFailure {
|
||||
appCtx.toastOnUi(it.localizedMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -107,7 +107,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
if (AppConfig.isFirstLaunch) {
|
||||
if (LocalConfig.isFirstOpenApp) {
|
||||
startActivity<WelcomeActivity>()
|
||||
finish()
|
||||
return
|
||||
|
||||
@@ -99,7 +99,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
private var enableRefresh = true
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
setSupportToolbar(binding.titleBar.toolbar)
|
||||
setSupportToolbar(binding.topBar)
|
||||
initRecyclerView()
|
||||
initBookGroupData()
|
||||
initAllBooksData()
|
||||
@@ -182,7 +182,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
private fun initBooksData() {
|
||||
if (groupId == BookGroup.Companion.IdRoot) {
|
||||
if (isAdded) {
|
||||
binding.titleBar.title = getString(R.string.bookshelf)
|
||||
binding.topBar.title = getString(R.string.bookshelf)
|
||||
binding.refreshLayout.isEnabled = true
|
||||
enableRefresh = true
|
||||
}
|
||||
@@ -190,7 +190,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
bookGroups.firstOrNull {
|
||||
groupId == it.groupId
|
||||
}?.let {
|
||||
binding.titleBar.title = it.groupName
|
||||
binding.topBar.title = it.groupName
|
||||
binding.refreshLayout.isEnabled = it.enableRefresh
|
||||
enableRefresh = it.enableRefresh
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import io.legato.kazusa.base.BaseActivity
|
||||
import io.legato.kazusa.databinding.ActivityWelcomeBinding
|
||||
import io.legato.kazusa.help.config.AppConfig
|
||||
import io.legato.kazusa.help.config.LocalConfig
|
||||
import io.legato.kazusa.ui.main.MainActivity
|
||||
import io.legato.kazusa.utils.startActivity
|
||||
@@ -96,7 +95,6 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
||||
}
|
||||
|
||||
private fun finishSetup() {
|
||||
AppConfig.isFirstLaunch = false
|
||||
startActivity<MainActivity>()
|
||||
finish()
|
||||
}
|
||||
|
||||
@@ -67,7 +67,6 @@ fun Context.longToastOnUiLegacy(message: CharSequence) {
|
||||
/**
|
||||
* JS 专用弹窗,短时间显示
|
||||
*/
|
||||
|
||||
fun Context.toastForJs(message: CharSequence?, duration: Int = Toast.LENGTH_SHORT) {
|
||||
runOnUI {
|
||||
kotlin.runCatching {
|
||||
|
||||
Reference in New Issue
Block a user