feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 36bd755b0b
commit 0728318303
  1. 17
      app/src/main/java/io/legado/app/help/AppConfig.kt
  2. 2
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  3. 4
      app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt
  4. 8
      app/src/main/java/io/legado/app/ui/widget/ChineseConverter.kt

@ -1,5 +1,6 @@
package io.legado.app.help package io.legado.app.help
import android.content.Context
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
@ -7,14 +8,16 @@ import io.legado.app.utils.*
object AppConfig { object AppConfig {
var isNightTheme: Boolean fun isNightTheme(context: Context): Boolean {
get() { return when (context.getPrefString(PreferKey.themeMode, "0")) {
return when (App.INSTANCE.getPrefString(PreferKey.themeMode, "0")) { "1" -> false
"1" -> false "2" -> true
"2" -> true else -> context.sysIsDarkMode()
else -> App.INSTANCE.sysIsDarkMode()
}
} }
}
var isNightTheme: Boolean
get() = isNightTheme(App.INSTANCE)
set(value) { set(value) {
if (value) { if (value) {
App.INSTANCE.putPrefString(PreferKey.themeMode, "2") App.INSTANCE.putPrefString(PreferKey.themeMode, "2")

@ -130,7 +130,7 @@ object ATH {
fun setTint( fun setTint(
view: View, view: View,
@ColorInt color: Int, @ColorInt color: Int,
isDark: Boolean = AppConfig.isNightTheme isDark: Boolean = AppConfig.isNightTheme(view.context)
) { ) {
TintHelper.setTintAuto(view, color, false, isDark) 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) { class ATESeekBar(context: Context, attrs: AttributeSet) : AppCompatSeekBar(context, attrs) {
init { init {
if (!isInEditMode) { ATH.setTint(this, context.accentColor)
ATH.setTint(this, context.accentColor)
}
} }
} }

@ -6,7 +6,6 @@ import android.text.SpannableString
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert 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) { class ChineseConverter(context: Context, attrs: AttributeSet?) : AppCompatTextView(context, attrs) {
private val spannableString = SpannableString("简/繁") private val spannableString = SpannableString("简/繁")
private val enabledSpan = ForegroundColorSpan(App.INSTANCE.accentColor) private var enabledSpan: ForegroundColorSpan = ForegroundColorSpan(context.accentColor)
private var onChanged: (() -> Unit)? = null private var onChanged: (() -> Unit)? = null
init { init {
@ -39,7 +38,10 @@ class ChineseConverter(context: Context, attrs: AttributeSet?) : AppCompatTextVi
.setDisabledColor(context.getCompatColor(R.color.md_grey_500)) .setDisabledColor(context.getCompatColor(R.color.md_grey_500))
.create() .create()
) )
upUi(AppConfig.chineseConverterType) text = spannableString
if (!isInEditMode) {
upUi(AppConfig.chineseConverterType)
}
onClick { onClick {
selectType() selectType()
} }

Loading…
Cancel
Save