|
|
@ -1,5 +1,6 @@ |
|
|
|
package io.legado.app.ui.book.read.config |
|
|
|
package io.legado.app.ui.book.read.config |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
import android.content.DialogInterface |
|
|
|
import android.content.DialogInterface |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.util.DisplayMetrics |
|
|
|
import android.util.DisplayMetrics |
|
|
@ -13,6 +14,7 @@ import io.legado.app.R |
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.help.ReadBookConfig |
|
|
|
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.dialogs.selector |
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
import io.legado.app.lib.theme.bottomBackground |
|
|
|
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.Help |
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
import io.legado.app.ui.widget.font.FontSelectDialog |
|
|
|
import io.legado.app.ui.widget.font.FontSelectDialog |
|
|
|
import io.legado.app.utils.getIndexById |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.getPrefString |
|
|
|
|
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
|
|
|
|
import io.legado.app.utils.putPrefString |
|
|
|
|
|
|
|
import kotlinx.android.synthetic.main.activity_book_read.* |
|
|
|
import kotlinx.android.synthetic.main.activity_book_read.* |
|
|
|
import kotlinx.android.synthetic.main.dialog_read_book_style.* |
|
|
|
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.onCheckedChange |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onLongClick |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onLongClick |
|
|
@ -33,7 +33,6 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick |
|
|
|
class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
|
|
|
|
|
|
|
|
val callBack get() = activity as? ReadBookActivity |
|
|
|
val callBack get() = activity as? ReadBookActivity |
|
|
|
lateinit var titleModes: Array<String> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onStart() { |
|
|
|
override fun onStart() { |
|
|
|
super.onStart() |
|
|
|
super.onStart() |
|
|
@ -63,7 +62,6 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
titleModes = requireContext().resources.getStringArray(R.array.title_mode) |
|
|
|
|
|
|
|
initView() |
|
|
|
initView() |
|
|
|
initData() |
|
|
|
initData() |
|
|
|
initViewEvent() |
|
|
|
initViewEvent() |
|
|
@ -76,6 +74,14 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
|
|
|
|
|
|
|
|
private fun initView() { |
|
|
|
private fun initView() { |
|
|
|
root_view.setBackgroundColor(requireContext().bottomBackground) |
|
|
|
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() { |
|
|
|
private fun initData() { |
|
|
@ -95,11 +101,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
} |
|
|
|
} |
|
|
|
tv_title_mode.onClick { |
|
|
|
tv_title_mode.onClick { |
|
|
|
requireContext().selector("标题模式", titleModes.toList()) { _, index -> |
|
|
|
showTitleConfig() |
|
|
|
ReadBookConfig.titleMode = index |
|
|
|
|
|
|
|
tv_title_mode.text = titleModes[index] |
|
|
|
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
tv_text_bold.onClick { |
|
|
|
tv_text_bold.onClick { |
|
|
|
ReadBookConfig.apply { |
|
|
|
ReadBookConfig.apply { |
|
|
@ -124,15 +126,9 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
dismiss() |
|
|
|
dismiss() |
|
|
|
callBack?.showPaddingConfig() |
|
|
|
callBack?.showPaddingConfig() |
|
|
|
} |
|
|
|
} |
|
|
|
tv_type.onClick { |
|
|
|
|
|
|
|
dismiss() |
|
|
|
|
|
|
|
callBack?.showTypeConfig() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
rg_page_anim.onCheckedChange { _, checkedId -> |
|
|
|
rg_page_anim.onCheckedChange { _, checkedId -> |
|
|
|
rg_page_anim.getIndexById(checkedId).let { |
|
|
|
ReadBookConfig.pageAnim = rg_page_anim.getIndexById(checkedId) |
|
|
|
ReadBookConfig.pageAnim = it |
|
|
|
callBack?.page_view?.upPageAnim() |
|
|
|
callBack?.page_view?.upPageAnim() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
cb_share_layout.onCheckedChangeListener = { checkBox, isChecked -> |
|
|
|
cb_share_layout.onCheckedChangeListener = { checkBox, isChecked -> |
|
|
|
if (checkBox.isPressed) { |
|
|
|
if (checkBox.isPressed) { |
|
|
@ -141,19 +137,20 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
iv_default1.onClick { |
|
|
|
dsb_text_size.onChanged = { |
|
|
|
ReadBookConfig.lineSpacingExtra = 16 |
|
|
|
ReadBookConfig.textSize = it + 5 |
|
|
|
ReadBookConfig.paragraphSpacing = 6 |
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dsb_text_letter_spacing.onChanged = { |
|
|
|
|
|
|
|
ReadBookConfig.letterSpacing = (it - 50) / 100f |
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
} |
|
|
|
} |
|
|
|
iv_default2.onClick { |
|
|
|
dsb_line_size.onChanged = { |
|
|
|
ReadBookConfig.lineSpacingExtra = 13 |
|
|
|
ReadBookConfig.lineSpacingExtra = it |
|
|
|
ReadBookConfig.paragraphSpacing = 3 |
|
|
|
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
} |
|
|
|
} |
|
|
|
iv_default3.onClick { |
|
|
|
dsb_paragraph_spacing.onChanged = { |
|
|
|
ReadBookConfig.lineSpacingExtra = 10 |
|
|
|
ReadBookConfig.paragraphSpacing = it |
|
|
|
ReadBookConfig.paragraphSpacing = 0 |
|
|
|
|
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
postEvent(EventBus.UP_CONFIG, true) |
|
|
|
} |
|
|
|
} |
|
|
|
bg0.onClick { changeBg(0) } |
|
|
|
bg0.onClick { changeBg(0) } |
|
|
@ -168,6 +165,33 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
bg4.onLongClick { showBgTextConfig(4) } |
|
|
|
bg4.onLongClick { showBgTextConfig(4) } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams") |
|
|
|
|
|
|
|
private fun showTitleConfig() { |
|
|
|
|
|
|
|
requireContext().alert(R.string.title) { |
|
|
|
|
|
|
|
val rootView = LayoutInflater.from(requireContext()) |
|
|
|
|
|
|
|
.inflate(R.layout.dialog_title_config, null).apply { |
|
|
|
|
|
|
|
ReadBookConfig.apply { |
|
|
|
|
|
|
|
rg_title_mode.checkByIndex(titleMode) |
|
|
|
|
|
|
|
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_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) { |
|
|
|
private fun changeBg(index: Int) { |
|
|
|
if (ReadBookConfig.styleSelect != index) { |
|
|
|
if (ReadBookConfig.styleSelect != index) { |
|
|
|
ReadBookConfig.styleSelect = index |
|
|
|
ReadBookConfig.styleSelect = index |
|
|
@ -187,8 +211,11 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { |
|
|
|
|
|
|
|
|
|
|
|
private fun upStyle() { |
|
|
|
private fun upStyle() { |
|
|
|
ReadBookConfig.let { |
|
|
|
ReadBookConfig.let { |
|
|
|
tv_title_mode.text = titleModes.getOrElse(it.titleMode) { titleModes[0] } |
|
|
|
|
|
|
|
tv_text_bold.isSelected = it.textBold |
|
|
|
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 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|