From 8c08a6d9e867e3646da7b717b90170ef2dc1c2a1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Mar 2020 23:02:42 +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 --- .../main/java/io/legado/app/help/ReadBookConfig.kt | 8 ++++---- .../app/ui/book/read/config/ReadStyleDialog.kt | 14 ++++++++------ .../app/ui/book/read/page/ChapterProvider.kt | 2 +- app/src/main/res/layout/dialog_read_book_style.xml | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) 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 dcef91c72..3ce2f514f 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -165,10 +165,10 @@ object ReadBookConfig { if (shareLayout) shareConfig.paragraphSpacing = value else durConfig.paragraphSpacing = value - var titleCenter: Boolean - get() = if (shareLayout) shareConfig.titleCenter else durConfig.titleCenter + var titleMode: Int + get() = if (shareLayout) shareConfig.titleMode else durConfig.titleMode set(value) = - if (shareLayout) shareConfig.titleCenter = value else durConfig.titleCenter = value + if (shareLayout) shareConfig.titleMode = value else durConfig.titleMode = value var paddingBottom: Int get() = if (shareLayout) shareConfig.paddingBottom else durConfig.paddingBottom @@ -253,7 +253,7 @@ object ReadBookConfig { var letterSpacing: Float = 0.5f,//字间距 var lineSpacingExtra: Int = 12,//行间距 var paragraphSpacing: Int = 12,//段距 - var titleCenter: Boolean = true,//标题居中 + var titleMode: Int = 0,//标题居中 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 b51d8c088..930ba61b5 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 @@ -32,6 +32,7 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { val callBack get() = activity as? ReadBookActivity + lateinit var titleModes: Array override fun onStart() { super.onStart() @@ -61,6 +62,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + titleModes = requireContext().resources.getStringArray(R.array.title_mode) initView() initData() initViewEvent() @@ -97,12 +99,12 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { chinese_converter.onChanged { postEvent(EventBus.UP_CONFIG, true) } - tv_title_center.onClick { - ReadBookConfig.apply { - titleCenter = !titleCenter - tv_title_center.isSelected = titleCenter + tv_title_mode.onClick { + requireContext().selector("标题模式", titleModes.toList()) { _, index -> + ReadBookConfig.titleMode = index + tv_title_mode.text = titleModes[index] + postEvent(EventBus.UP_CONFIG, true) } - postEvent(EventBus.UP_CONFIG, true) } tv_text_bold.onClick { ReadBookConfig.apply { @@ -187,7 +189,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { private fun upStyle() { ReadBookConfig.let { - tv_title_center.isSelected = it.titleCenter + tv_title_mode.text = titleModes.getOrElse(it.titleMode) { titleModes[0] } 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/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 20afe26cf..0c7ab0e7f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -153,7 +153,7 @@ object ChapterProvider { addCharsToLineFirst(textLine, words, textPaint, desiredWidth) } else if (lineIndex == layout.lineCount - 1) { //最后一行 - val x = if (isTitle && ReadBookConfig.titleCenter) + val x = if (isTitle && ReadBookConfig.titleMode == 1) (visibleWidth - layout.getLineWidth(lineIndex)) / 2 else 0f addCharsToLineLast(textLine, words, stringBuilder, textPaint, x) diff --git a/app/src/main/res/layout/dialog_read_book_style.xml b/app/src/main/res/layout/dialog_read_book_style.xml index 42b79b97d..0722b9e51 100644 --- a/app/src/main/res/layout/dialog_read_book_style.xml +++ b/app/src/main/res/layout/dialog_read_book_style.xml @@ -10,7 +10,7 @@ android:padding="10dp">