feat: 优化代码

pull/111/head
kunfei 5 years ago
parent 59cef5f5a7
commit 824f6e62d8
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 3
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  3. 14
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  4. 18
      app/src/main/java/io/legado/app/ui/widget/checkbox/SmoothCheckBox.kt

@ -36,4 +36,5 @@ object PreferKey {
const val textSelectAble = "selectText"
const val lastBackup = "lastBackup"
const val bodyIndent = "textIndent"
const val shareLayout = "shareLayout"
}

@ -107,7 +107,8 @@ object ReadBookConfig {
var textSize: Int = 15,//文字大小
var letterSpacing: Float = 1f,//字间距
var lineSpacingExtra: Int = 12,//行间距
var paragraphSpacing: Int = 12,
var paragraphSpacing: Int = 12,//段距
var titleCenter: Boolean = true,//标题居中
var paddingBottom: Int = 6,
var paddingLeft: Int = 16,
var paddingRight: Int = 16,

@ -76,6 +76,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
}
private fun initData() {
cb_share_layout.isChecked = getPrefBoolean(PreferKey.shareLayout)
requireContext().getPrefInt(PreferKey.pageAnim).let {
if (it >= 0 && it < rg_page_anim.childCount) {
rg_page_anim.check(rg_page_anim[it].id)
@ -90,6 +91,13 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
chinese_converter.onChanged {
postEvent(EventBus.UP_CONFIG, true)
}
tv_title_center.onClick {
ReadBookConfig.durConfig.apply {
titleCenter = !titleCenter
tv_text_bold.isSelected = titleCenter
}
postEvent(EventBus.UP_CONFIG, true)
}
tv_text_bold.onClick {
ReadBookConfig.durConfig.apply {
textBold = !textBold
@ -144,6 +152,11 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
}
}
}
cb_share_layout.onCheckedChangeListener = { checkBox, isChecked ->
if (checkBox.isPressed) {
putPrefBoolean(PreferKey.shareLayout, isChecked)
}
}
bg0.onClick { changeBg(0) }
bg0.onLongClick { showBgTextConfig(0) }
bg1.onClick { changeBg(1) }
@ -178,6 +191,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
private fun upStyle() {
ReadBookConfig.durConfig.let {
tv_title_center.isSelected = it.titleCenter
tv_text_bold.isSelected = it.textBold
dsb_text_size.progress = it.textSize - 5
dsb_text_letter_spacing.progress = (it.letterSpacing * 100).toInt() + 50

@ -40,7 +40,7 @@ class SmoothCheckBox @JvmOverloads constructor(
private var mFloorUnCheckedColor = 0
private var mChecked = false
private var mTickDrawing = false
private var mListener: OnCheckedChangeListener? = null
var onCheckedChangeListener: ((checkBox: SmoothCheckBox, isChecked: Boolean) -> Unit)? = null
init {
val ta = context.obtainStyledAttributes(attrs, R.styleable.SmoothCheckBox)
@ -89,9 +89,7 @@ class SmoothCheckBox @JvmOverloads constructor(
mChecked = checked
reset()
invalidate()
if (mListener != null) {
mListener!!.onCheckedChanged(this@SmoothCheckBox, mChecked)
}
onCheckedChangeListener?.invoke(this@SmoothCheckBox, mChecked)
}
override fun toggle() {
@ -114,9 +112,7 @@ class SmoothCheckBox @JvmOverloads constructor(
} else {
startUnCheckedAnimation()
}
if (mListener != null) {
mListener!!.onCheckedChanged(this@SmoothCheckBox, mChecked)
}
onCheckedChangeListener?.invoke(this@SmoothCheckBox, mChecked)
} else {
this.isChecked = checked
}
@ -308,14 +304,6 @@ class SmoothCheckBox @JvmOverloads constructor(
}, mAnimDuration.toLong())
}
fun setOnCheckedChangeListener(l: OnCheckedChangeListener?) {
mListener = l
}
interface OnCheckedChangeListener {
fun onCheckedChanged(checkBox: SmoothCheckBox?, isChecked: Boolean)
}
companion object {
private const val DEF_DRAW_SIZE = 25
private const val DEF_ANIM_DURATION = 300

Loading…
Cancel
Save