feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 36bd755b0b
commit 0728318303
  1. 11
      app/src/main/java/io/legado/app/help/AppConfig.kt
  2. 2
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  3. 2
      app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt
  4. 6
      app/src/main/java/io/legado/app/ui/widget/ChineseConverter.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")) {
fun isNightTheme(context: Context): Boolean {
return when (context.getPrefString(PreferKey.themeMode, "0")) {
"1" -> false
"2" -> true
else -> App.INSTANCE.sysIsDarkMode()
else -> context.sysIsDarkMode()
}
}
var isNightTheme: Boolean
get() = isNightTheme(App.INSTANCE)
set(value) {
if (value) {
App.INSTANCE.putPrefString(PreferKey.themeMode, "2")

@ -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)
}

@ -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)
}
}
}

@ -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()
)
text = spannableString
if (!isInEditMode) {
upUi(AppConfig.chineseConverterType)
}
onClick {
selectType()
}

Loading…
Cancel
Save