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 110eac0e5..a5cd694e7 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 @@ -6,7 +6,6 @@ import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.SeekBar import androidx.core.view.get import androidx.fragment.app.DialogFragment import io.legado.app.R @@ -57,8 +56,9 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + initView() initData() - initOnClick() + initViewEvent() } override fun onDestroy() { @@ -66,6 +66,15 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { ReadBookConfig.save() } + private fun initView() { + dsb_text_size.valueFormat = { + (it + 5).toString() + } + dsb_text_letter_spacing.valueFormat = { + ((it - 5) / 10f).toString() + } + } + private fun initData() { requireContext().getPrefInt(PreferKey.pageAnim).let { if (it >= 0 && it < rg_page_anim.childCount) { @@ -77,7 +86,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { upBg() } - private fun initOnClick() { + private fun initViewEvent() { chinese_converter.onChanged { postEvent(EventBus.UP_CONFIG, true) } @@ -107,67 +116,16 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { activity.showPaddingConfig() } } - seek_text_size.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - ReadBookConfig.getConfig().textSize = progress + 5 - tv_text_size.text = ReadBookConfig.getConfig().textSize.toString() - } - - override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit - override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(EventBus.UP_CONFIG, true) - } - }) - iv_text_size_add.onClick { - seek_text_size.progressAdd(1) - postEvent(EventBus.UP_CONFIG, true) - } - iv_text_size_remove.onClick { - seek_text_size.progressAdd(-1) - postEvent(EventBus.UP_CONFIG, true) - } - seek_text_letter_spacing.setOnSeekBarChangeListener(object : - SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - with(ReadBookConfig.getConfig()) { - letterSpacing = (seek_text_letter_spacing.progress - 5) / 10f - tv_text_letter_spacing.text = letterSpacing.toString() - } - } - - override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit - override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(EventBus.UP_CONFIG, true) - } - }) - iv_text_letter_spacing_add.onClick { - seek_text_letter_spacing.progressAdd(1) - postEvent(EventBus.UP_CONFIG, true) - } - iv_text_letter_spacing_remove.onClick { - seek_text_letter_spacing.progressAdd(-1) + dsb_text_size.onChanged = { + ReadBookConfig.getConfig().textSize = it + 5 postEvent(EventBus.UP_CONFIG, true) } - seek_line_size.setOnSeekBarChangeListener(object : - SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - with(ReadBookConfig.getConfig()) { - lineSpacingExtra = seek_line_size.progress - tv_line_size.text = lineSpacingExtra.toString() - } - } - - override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit - override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(EventBus.UP_CONFIG, true) - } - }) - iv_line_size_add.onClick { - seek_line_size.progressAdd(1) + dsb_text_letter_spacing.onChanged = { + ReadBookConfig.getConfig().letterSpacing = (it - 5) / 10f postEvent(EventBus.UP_CONFIG, true) } - iv_line_size_remove.onClick { - seek_line_size.progressAdd(-1) + dsb_line_size.onChanged = { + ReadBookConfig.getConfig().lineSpacingExtra = it postEvent(EventBus.UP_CONFIG, true) } rg_page_anim.onCheckedChange { _, checkedId -> @@ -217,12 +175,9 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { private fun upStyle() { ReadBookConfig.getConfig().let { tv_text_bold.isSelected = it.textBold - seek_text_size.progress = it.textSize - 5 - tv_text_size.text = it.textSize.toString() - seek_text_letter_spacing.progress = (it.letterSpacing * 10).toInt() + 5 - tv_text_letter_spacing.text = it.letterSpacing.toString() - seek_line_size.progress = it.lineSpacingExtra - tv_line_size.text = it.lineSpacingExtra.toString() + dsb_text_size.progress = it.textSize - 5 + dsb_text_letter_spacing.progress = (it.letterSpacing * 10).toInt() + 5 + dsb_line_size.progress = it.lineSpacingExtra } } 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 362a153d3..62e1bcdfb 100644 --- a/app/src/main/res/layout/dialog_read_book_style.xml +++ b/app/src/main/res/layout/dialog_read_book_style.xml @@ -1,7 +1,6 @@ - - - - - - - - - + app:max="45" + app:title="@string/text_size" + app:layout_constraintTop_toBottomOf="@+id/tv_text_bold" /> - - - - + app:max="10" + app:title="@string/text_letter_spacing" + app:layout_constraintTop_toBottomOf="@+id/dsb_text_size" /> - - - - - - - - - - - - - - - - - - - - - - - - + app:max="50" + app:title="@string/line_size" + app:layout_constraintTop_toBottomOf="@+id/dsb_text_letter_spacing" /> + app:layout_constraintTop_toBottomOf="@+id/dsb_line_size" />