From bb4d15643834565b1c7573c5b3f51eec4fb1179f Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 12 Feb 2020 23:33:30 +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 --- .../ui/book/read/config/ReadStyleDialog.kt | 87 +++-------- .../res/layout/dialog_read_book_style.xml | 145 ++---------------- .../main/res/layout/dialog_read_padding.xml | 2 +- .../main/res/layout/view_detail_seek_bar.xml | 2 - 4 files changed, 38 insertions(+), 198 deletions(-) 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" />