feat: 优化代码

pull/132/head
kunfei 5 years ago
parent ffcb73718e
commit 8c08a6d9e8
  1. 8
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 14
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  4. 4
      app/src/main/res/layout/dialog_read_book_style.xml

@ -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,

@ -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<String>
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,13 +99,13 @@ 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)
}
}
tv_text_bold.onClick {
ReadBookConfig.apply {
textBold = !textBold
@ -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

@ -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)

@ -10,7 +10,7 @@
android:padding="10dp">
<io.legado.app.ui.widget.text.StrokeTextView
android:id="@+id/tv_title_center"
android:id="@+id/tv_title_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="6dp"
@ -34,7 +34,7 @@
android:text="@string/text_bold"
android:gravity="center"
android:textSize="14sp"
app:layout_constraintLeft_toRightOf="@+id/tv_title_center"
app:layout_constraintLeft_toRightOf="@+id/tv_title_mode"
app:layout_constraintRight_toLeftOf="@+id/tv_text_font"
app:layout_constraintTop_toTopOf="parent" />

Loading…
Cancel
Save