From 0728318303983b5850480b3ecf1237ea074e3de6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 13 Feb 2020 00:08:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/AppConfig.kt | 17 ++++++++++------- .../main/java/io/legado/app/lib/theme/ATH.kt | 2 +- .../io/legado/app/lib/theme/view/ATESeekBar.kt | 4 +--- .../io/legado/app/ui/widget/ChineseConverter.kt | 8 +++++--- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index a7d70efa8..1f4302fdc 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -1,5 +1,6 @@ package io.legado.app.help +import android.content.Context import io.legado.app.App import io.legado.app.R import io.legado.app.constant.PreferKey @@ -7,14 +8,16 @@ import io.legado.app.utils.* object AppConfig { - var isNightTheme: Boolean - get() { - return when (App.INSTANCE.getPrefString(PreferKey.themeMode, "0")) { - "1" -> false - "2" -> true - else -> App.INSTANCE.sysIsDarkMode() - } + fun isNightTheme(context: Context): Boolean { + return when (context.getPrefString(PreferKey.themeMode, "0")) { + "1" -> false + "2" -> true + else -> context.sysIsDarkMode() } + } + + var isNightTheme: Boolean + get() = isNightTheme(App.INSTANCE) set(value) { if (value) { App.INSTANCE.putPrefString(PreferKey.themeMode, "2") diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index e96cf3dc2..e20741987 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -130,7 +130,7 @@ object ATH { fun setTint( view: View, @ColorInt color: Int, - isDark: Boolean = AppConfig.isNightTheme + isDark: Boolean = AppConfig.isNightTheme(view.context) ) { TintHelper.setTintAuto(view, color, false, isDark) } diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt index 3b8f046aa..2d793ba82 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt @@ -12,8 +12,6 @@ import io.legado.app.lib.theme.accentColor class ATESeekBar(context: Context, attrs: AttributeSet) : AppCompatSeekBar(context, attrs) { init { - if (!isInEditMode) { - ATH.setTint(this, context.accentColor) - } + ATH.setTint(this, context.accentColor) } } diff --git a/app/src/main/java/io/legado/app/ui/widget/ChineseConverter.kt b/app/src/main/java/io/legado/app/ui/widget/ChineseConverter.kt index c88407b3a..e6df45f38 100644 --- a/app/src/main/java/io/legado/app/ui/widget/ChineseConverter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/ChineseConverter.kt @@ -6,7 +6,6 @@ import android.text.SpannableString import android.text.style.ForegroundColorSpan import android.util.AttributeSet import androidx.appcompat.widget.AppCompatTextView -import io.legado.app.App import io.legado.app.R import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert @@ -20,7 +19,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class ChineseConverter(context: Context, attrs: AttributeSet?) : AppCompatTextView(context, attrs) { private val spannableString = SpannableString("简/繁") - private val enabledSpan = ForegroundColorSpan(App.INSTANCE.accentColor) + private var enabledSpan: ForegroundColorSpan = ForegroundColorSpan(context.accentColor) private var onChanged: (() -> Unit)? = null init { @@ -39,7 +38,10 @@ class ChineseConverter(context: Context, attrs: AttributeSet?) : AppCompatTextVi .setDisabledColor(context.getCompatColor(R.color.md_grey_500)) .create() ) - upUi(AppConfig.chineseConverterType) + text = spannableString + if (!isInEditMode) { + upUi(AppConfig.chineseConverterType) + } onClick { selectType() }