|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
package io.legado.app.ui.book.read.config |
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
|
import android.content.DialogInterface |
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.util.DisplayMetrics |
|
|
|
@ -13,6 +14,7 @@ import io.legado.app.R |
|
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
|
import io.legado.app.help.ReadBookConfig |
|
|
|
|
import io.legado.app.lib.dialogs.alert |
|
|
|
|
import io.legado.app.lib.dialogs.selector |
|
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
|
import io.legado.app.lib.theme.bottomBackground |
|
|
|
@ -20,12 +22,10 @@ import io.legado.app.lib.theme.primaryColor |
|
|
|
|
import io.legado.app.ui.book.read.Help |
|
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
|
import io.legado.app.ui.widget.font.FontSelectDialog |
|
|
|
|
import io.legado.app.utils.getIndexById |
|
|
|
|
import io.legado.app.utils.getPrefString |
|
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
|
import io.legado.app.utils.putPrefString |
|
|
|
|
import io.legado.app.utils.* |
|
|
|
|
import kotlinx.android.synthetic.main.activity_book_read.* |
|
|
|
|
import kotlinx.android.synthetic.main.dialog_read_book_style.* |
|
|
|
|
import kotlinx.android.synthetic.main.dialog_title_config.view.* |
|
|
|
|
import org.jetbrains.anko.sdk27.listeners.onCheckedChange |
|
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
|
import org.jetbrains.anko.sdk27.listeners.onLongClick |
|
|
|
@ -33,7 +33,6 @@ 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() |
|
|
|
@ -63,7 +62,6 @@ 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() |
|
|
|
@ -76,6 +74,14 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
|
|
|
|
|
|
private fun initView() { |
|
|
|
|
root_view.setBackgroundColor(requireContext().bottomBackground) |
|
|
|
|
dsb_text_size.valueFormat = { |
|
|
|
|
(it + 5).toString() |
|
|
|
|
} |
|
|
|
|
dsb_text_letter_spacing.valueFormat = { |
|
|
|
|
((it - 50) / 100f).toString() |
|
|
|
|
} |
|
|
|
|
dsb_line_size.valueFormat = { ((it - 10) / 10f).toString() } |
|
|
|
|
dsb_paragraph_spacing.valueFormat = { (it / 10f).toString() } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initData() { |
|
|
|
@ -95,11 +101,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
} |
|
|
|
|
tv_title_mode.onClick { |
|
|
|
|
requireContext().selector("标题模式", titleModes.toList()) { _, index -> |
|
|
|
|
ReadBookConfig.titleMode = index |
|
|
|
|
tv_title_mode.text = titleModes[index] |
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
} |
|
|
|
|
showTitleConfig() |
|
|
|
|
} |
|
|
|
|
tv_text_bold.onClick { |
|
|
|
|
ReadBookConfig.apply { |
|
|
|
@ -124,16 +126,10 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
|
dismiss() |
|
|
|
|
callBack?.showPaddingConfig() |
|
|
|
|
} |
|
|
|
|
tv_type.onClick { |
|
|
|
|
dismiss() |
|
|
|
|
callBack?.showTypeConfig() |
|
|
|
|
} |
|
|
|
|
rg_page_anim.onCheckedChange { _, checkedId -> |
|
|
|
|
rg_page_anim.getIndexById(checkedId).let { |
|
|
|
|
ReadBookConfig.pageAnim = it |
|
|
|
|
ReadBookConfig.pageAnim = rg_page_anim.getIndexById(checkedId) |
|
|
|
|
callBack?.page_view?.upPageAnim() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
cb_share_layout.onCheckedChangeListener = { checkBox, isChecked -> |
|
|
|
|
if (checkBox.isPressed) { |
|
|
|
|
ReadBookConfig.shareLayout = isChecked |
|
|
|
@ -141,19 +137,20 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
iv_default1.onClick { |
|
|
|
|
ReadBookConfig.lineSpacingExtra = 16 |
|
|
|
|
ReadBookConfig.paragraphSpacing = 6 |
|
|
|
|
dsb_text_size.onChanged = { |
|
|
|
|
ReadBookConfig.textSize = it + 5 |
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
} |
|
|
|
|
iv_default2.onClick { |
|
|
|
|
ReadBookConfig.lineSpacingExtra = 13 |
|
|
|
|
ReadBookConfig.paragraphSpacing = 3 |
|
|
|
|
dsb_text_letter_spacing.onChanged = { |
|
|
|
|
ReadBookConfig.letterSpacing = (it - 50) / 100f |
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
} |
|
|
|
|
iv_default3.onClick { |
|
|
|
|
ReadBookConfig.lineSpacingExtra = 10 |
|
|
|
|
ReadBookConfig.paragraphSpacing = 0 |
|
|
|
|
dsb_line_size.onChanged = { |
|
|
|
|
ReadBookConfig.lineSpacingExtra = it |
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
} |
|
|
|
|
dsb_paragraph_spacing.onChanged = { |
|
|
|
|
ReadBookConfig.paragraphSpacing = it |
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
} |
|
|
|
|
bg0.onClick { changeBg(0) } |
|
|
|
@ -168,6 +165,36 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
|
bg4.onLongClick { showBgTextConfig(4) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams") |
|
|
|
|
private fun showTitleConfig() = ReadBookConfig.apply { |
|
|
|
|
requireContext().alert(R.string.title) { |
|
|
|
|
val rootView = LayoutInflater.from(requireContext()) |
|
|
|
|
.inflate(R.layout.dialog_title_config, null).apply { |
|
|
|
|
rg_title_mode.checkByIndex(titleMode) |
|
|
|
|
dsb_title_size.progress = titleSize |
|
|
|
|
dsb_title_top.progress = titleTopSpacing |
|
|
|
|
dsb_title_bottom.progress = titleBottomSpacing |
|
|
|
|
rg_title_mode.onCheckedChange { _, checkedId -> |
|
|
|
|
titleMode = rg_title_mode.getIndexById(checkedId) |
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
} |
|
|
|
|
dsb_title_size.onChanged = { |
|
|
|
|
titleSize = it |
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
} |
|
|
|
|
dsb_title_top.onChanged = { |
|
|
|
|
titleTopSpacing = it |
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
} |
|
|
|
|
dsb_title_bottom.onChanged = { |
|
|
|
|
titleBottomSpacing = it |
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
customView = rootView |
|
|
|
|
}.show() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun changeBg(index: Int) { |
|
|
|
|
if (ReadBookConfig.styleSelect != index) { |
|
|
|
|
ReadBookConfig.styleSelect = index |
|
|
|
@ -187,17 +214,20 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
|
|
|
|
|
|
private fun upStyle() { |
|
|
|
|
ReadBookConfig.let { |
|
|
|
|
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 |
|
|
|
|
dsb_line_size.progress = it.lineSpacingExtra |
|
|
|
|
dsb_paragraph_spacing.progress = it.paragraphSpacing |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun setBg() { |
|
|
|
|
bg0.setTextColor(ReadBookConfig.getConfig(0).textColor()) |
|
|
|
|
bg1.setTextColor(ReadBookConfig.getConfig(1).textColor()) |
|
|
|
|
bg2.setTextColor(ReadBookConfig.getConfig(2).textColor()) |
|
|
|
|
bg3.setTextColor(ReadBookConfig.getConfig(3).textColor()) |
|
|
|
|
bg4.setTextColor(ReadBookConfig.getConfig(4).textColor()) |
|
|
|
|
private fun setBg() = ReadBookConfig.apply { |
|
|
|
|
bg0.setTextColor(getConfig(0).textColor()) |
|
|
|
|
bg1.setTextColor(getConfig(1).textColor()) |
|
|
|
|
bg2.setTextColor(getConfig(2).textColor()) |
|
|
|
|
bg3.setTextColor(getConfig(3).textColor()) |
|
|
|
|
bg4.setTextColor(getConfig(4).textColor()) |
|
|
|
|
for (i in 0..4) { |
|
|
|
|
val iv = when (i) { |
|
|
|
|
1 -> bg1 |
|
|
|
@ -206,22 +236,22 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
|
4 -> bg4 |
|
|
|
|
else -> bg0 |
|
|
|
|
} |
|
|
|
|
iv.setImageDrawable(ReadBookConfig.getConfig(i).bgDrawable(100, 150)) |
|
|
|
|
iv.setImageDrawable(getConfig(i).bgDrawable(100, 150)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun upBg() { |
|
|
|
|
bg0.borderColor = requireContext().primaryColor |
|
|
|
|
bg1.borderColor = requireContext().primaryColor |
|
|
|
|
bg2.borderColor = requireContext().primaryColor |
|
|
|
|
bg3.borderColor = requireContext().primaryColor |
|
|
|
|
bg4.borderColor = requireContext().primaryColor |
|
|
|
|
private fun upBg() = requireContext().apply { |
|
|
|
|
bg0.borderColor = primaryColor |
|
|
|
|
bg1.borderColor = primaryColor |
|
|
|
|
bg2.borderColor = primaryColor |
|
|
|
|
bg3.borderColor = primaryColor |
|
|
|
|
bg4.borderColor = primaryColor |
|
|
|
|
when (ReadBookConfig.styleSelect) { |
|
|
|
|
1 -> bg1.borderColor = requireContext().accentColor |
|
|
|
|
2 -> bg2.borderColor = requireContext().accentColor |
|
|
|
|
3 -> bg3.borderColor = requireContext().accentColor |
|
|
|
|
4 -> bg4.borderColor = requireContext().accentColor |
|
|
|
|
else -> bg0.borderColor = requireContext().accentColor |
|
|
|
|
1 -> bg1.borderColor = accentColor |
|
|
|
|
2 -> bg2.borderColor = accentColor |
|
|
|
|
3 -> bg3.borderColor = accentColor |
|
|
|
|
4 -> bg4.borderColor = accentColor |
|
|
|
|
else -> bg0.borderColor = accentColor |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|