diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 7151fbe13..70abb4271 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -23,6 +23,7 @@ import io.legado.app.service.ReadAloudService import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.readbook.config.MoreConfigDialog +import io.legado.app.ui.readbook.config.PaddingConfigDialog import io.legado.app.ui.readbook.config.ReadAloudDialog import io.legado.app.ui.readbook.config.ReadStyleDialog import io.legado.app.ui.replacerule.ReplaceRuleActivity @@ -167,6 +168,10 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea }) } + fun showPaddingConfig() { + PaddingConfigDialog().show(supportFragmentManager, "paddingConfig") + } + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.read_book, menu) return super.onCompatCreateOptionsMenu(menu) diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt index e55e19ea0..6032b9884 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/PaddingConfigDialog.kt @@ -5,9 +5,14 @@ import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.SeekBar import androidx.fragment.app.DialogFragment import io.legado.app.R +import io.legado.app.constant.Bus +import io.legado.app.help.ReadBookConfig import io.legado.app.ui.readbook.Help +import io.legado.app.utils.postEvent +import kotlinx.android.synthetic.main.dialog_read_padding.* class PaddingConfigDialog : DialogFragment() { @@ -40,12 +45,74 @@ class PaddingConfigDialog : DialogFragment() { initView() } - private fun initData() { - + private fun initData() = with(ReadBookConfig.getConfig()) { + seek_padding_top.progress = paddingTop + seek_padding_bottom.progress = paddingBottom + seek_padding_left.progress = paddingLeft + seek_padding_right.progress = paddingRight + tv_padding_top.text = paddingTop.toString() + tv_padding_bottom.text = paddingBottom.toString() + tv_padding_left.text = paddingLeft.toString() + tv_padding_right.text = paddingRight.toString() } - private fun initView() { + private fun initView() = with(ReadBookConfig.getConfig()) { + seek_padding_top.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + paddingTop = progress + tv_padding_top.text = paddingTop.toString() + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) { + + } + + override fun onStopTrackingTouch(seekBar: SeekBar?) { + postEvent(Bus.UP_CONFIG, true) + } + }) + seek_padding_bottom.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + paddingBottom = progress + tv_padding_bottom.text = paddingBottom.toString() + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) { + + } + + override fun onStopTrackingTouch(seekBar: SeekBar?) { + postEvent(Bus.UP_CONFIG, true) + } + }) + seek_padding_left.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + paddingLeft = progress + tv_padding_left.text = paddingLeft.toString() + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) { + + } + + override fun onStopTrackingTouch(seekBar: SeekBar?) { + postEvent(Bus.UP_CONFIG, true) + } + }) + seek_padding_right.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + paddingRight = progress + tv_padding_right.text = paddingRight.toString() + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) { + + } + override fun onStopTrackingTouch(seekBar: SeekBar?) { + postEvent(Bus.UP_CONFIG, true) + } + }) } } diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt index 08e730014..bde80b8c3 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt @@ -87,6 +87,13 @@ class ReadStyleDialog : DialogFragment() { tv_text_bold.isSelected = textBold postEvent(Bus.UP_CONFIG, false) } + tv_padding.onClick { + val activity = activity + dismiss() + if (activity is ReadBookActivity) { + activity.showPaddingConfig() + } + } seek_text_size.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { textSize = progress + 5 diff --git a/app/src/main/res/layout/dialog_read_padding.xml b/app/src/main/res/layout/dialog_read_padding.xml index 7c2ce047e..498c1b91b 100644 --- a/app/src/main/res/layout/dialog_read_padding.xml +++ b/app/src/main/res/layout/dialog_read_padding.xml @@ -1,20 +1,21 @@ + android:max="100" /> + + android:max="100" /> + + android:max="100" /> + + android:max="100" /> + \ No newline at end of file