From 824f6e62d8c85d90268c39f1b31404b43249b4e4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 21 Feb 2020 21:37:19 +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 --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../java/io/legado/app/help/ReadBookConfig.kt | 3 ++- .../app/ui/book/read/config/ReadStyleDialog.kt | 14 ++++++++++++++ .../app/ui/widget/checkbox/SmoothCheckBox.kt | 18 +++--------------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 320bc87ee..ce49d6023 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -36,4 +36,5 @@ object PreferKey { const val textSelectAble = "selectText" const val lastBackup = "lastBackup" const val bodyIndent = "textIndent" + const val shareLayout = "shareLayout" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 5dc2d4817..75777d51b 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -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, diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index ecfdb4525..fac24cdfe 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/widget/checkbox/SmoothCheckBox.kt b/app/src/main/java/io/legado/app/ui/widget/checkbox/SmoothCheckBox.kt index 09a095fad..b18e59332 100644 --- a/app/src/main/java/io/legado/app/ui/widget/checkbox/SmoothCheckBox.kt +++ b/app/src/main/java/io/legado/app/ui/widget/checkbox/SmoothCheckBox.kt @@ -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