feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 9a481af33d
commit 3266c109c4
  1. 23
      app/src/main/java/io/legado/app/ui/book/read/config/ChineseConverter.kt
  2. 7
      app/src/main/java/io/legado/app/ui/widget/text/StrokeTextView.kt

@ -5,39 +5,20 @@ import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import io.legado.app.R
import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.Selector
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.dp
import io.legado.app.utils.getCompatColor
import io.legado.app.ui.widget.text.StrokeTextView
import org.jetbrains.anko.sdk27.listeners.onClick
class ChineseConverter(context: Context, attrs: AttributeSet?) : AppCompatTextView(context, attrs) {
class ChineseConverter(context: Context, attrs: AttributeSet?) : StrokeTextView(context, attrs) {
private val spannableString = SpannableString("简/繁")
private var enabledSpan: ForegroundColorSpan = ForegroundColorSpan(context.accentColor)
private var onChanged: (() -> Unit)? = null
init {
background = Selector.shapeBuild()
.setCornerRadius(1.dp)
.setStrokeWidth(1.dp)
.setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500))
.setDefaultStrokeColor(ThemeStore.textColorSecondary(context))
.setSelectedStrokeColor(ThemeStore.accentColor(context))
.setPressedBgColor(context.getCompatColor(R.color.transparent30))
.create()
setTextColor(
Selector.colorBuild()
.setDefaultColor(ThemeStore.textColorSecondary(context))
.setSelectedColor(ThemeStore.accentColor(context))
.setDisabledColor(context.getCompatColor(R.color.md_grey_500))
.create()
)
text = spannableString
if (!isInEditMode) {
upUi(AppConfig.chineseConverterType)

@ -9,7 +9,8 @@ import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.dp
import io.legado.app.utils.getCompatColor
class StrokeTextView(context: Context, attrs: AttributeSet) : AppCompatTextView(context, attrs) {
open class StrokeTextView(context: Context, attrs: AttributeSet?) :
AppCompatTextView(context, attrs) {
init {
if (isInEditMode) {
@ -21,7 +22,7 @@ class StrokeTextView(context: Context, attrs: AttributeSet) : AppCompatTextView(
.setSelectedStrokeColor(context.getCompatColor(R.color.colorAccent))
.setPressedBgColor(context.getCompatColor(R.color.transparent30))
.create()
setTextColor(
this.setTextColor(
Selector.colorBuild()
.setDefaultColor(context.getCompatColor(R.color.tv_text_secondary))
.setSelectedColor(context.getCompatColor(R.color.colorAccent))
@ -37,7 +38,7 @@ class StrokeTextView(context: Context, attrs: AttributeSet) : AppCompatTextView(
.setSelectedStrokeColor(ThemeStore.accentColor(context))
.setPressedBgColor(context.getCompatColor(R.color.transparent30))
.create()
setTextColor(
this.setTextColor(
Selector.colorBuild()
.setDefaultColor(ThemeStore.textColorSecondary(context))
.setSelectedColor(ThemeStore.accentColor(context))

Loading…
Cancel
Save