From 2589cb2e30ccd708124047f92613b6125f82889d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 12 Feb 2020 23:00:51 +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 --- .../book/read/config/PaddingConfigDialog.kt | 96 ++------- .../io/legado/app/ui/widget/DetailSeekBar.kt | 17 +- .../main/res/layout/dialog_read_padding.xml | 200 ++---------------- .../main/res/layout/view_detail_seek_bar.xml | 4 +- app/src/main/res/values/attrs.xml | 1 + 5 files changed, 45 insertions(+), 273 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt index c1a9e5e8f..0d16229b0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt @@ -5,16 +5,13 @@ 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.EventBus import io.legado.app.help.ReadBookConfig import io.legado.app.ui.book.read.Help import io.legado.app.utils.postEvent -import io.legado.app.utils.progressAdd import kotlinx.android.synthetic.main.dialog_read_padding.* -import org.jetbrains.anko.sdk27.listeners.onClick class PaddingConfigDialog : DialogFragment() { @@ -48,98 +45,29 @@ class PaddingConfigDialog : DialogFragment() { } 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() + dsb_padding_top.progress = paddingTop + dsb_padding_bottom.progress = paddingBottom + dsb_padding_left.progress = paddingLeft + dsb_padding_right.progress = paddingRight } private fun initView() = with(ReadBookConfig.getConfig()) { - iv_padding_top_add.onClick { - seek_padding_top.progressAdd(1) + dsb_padding_top.onChanged = { + paddingTop = it postEvent(EventBus.UP_CONFIG, true) } - iv_padding_top_remove.onClick { - seek_padding_top.progressAdd(-1) + dsb_padding_bottom.onChanged = { + paddingBottom = it postEvent(EventBus.UP_CONFIG, true) } - iv_padding_bottom_add.onClick { - seek_padding_bottom.progressAdd(1) + dsb_padding_left.onChanged = { + paddingLeft = it postEvent(EventBus.UP_CONFIG, true) } - iv_padding_bottom_remove.onClick { - seek_padding_bottom.progressAdd(-1) + dsb_padding_right.onChanged = { + paddingRight = it postEvent(EventBus.UP_CONFIG, true) } - iv_padding_left_add.onClick { - seek_padding_left.progressAdd(1) - postEvent(EventBus.UP_CONFIG, true) - } - iv_padding_left_remove.onClick { - seek_padding_left.progressAdd(-1) - postEvent(EventBus.UP_CONFIG, true) - } - iv_padding_right_add.onClick { - seek_padding_right.progressAdd(1) - postEvent(EventBus.UP_CONFIG, true) - } - iv_padding_right_remove.onClick { - seek_padding_right.progressAdd(-1) - postEvent(EventBus.UP_CONFIG, true) - } - - 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?) = Unit - - override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(EventBus.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?) = Unit - - override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(EventBus.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?) = Unit - - override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(EventBus.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?) = Unit - - override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(EventBus.UP_CONFIG, true) - } - }) } } diff --git a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt index 53ca79375..9d956def5 100644 --- a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt @@ -14,10 +14,18 @@ import org.jetbrains.anko.sdk27.listeners.onClick class DetailSeekBar(context: Context, attrs: AttributeSet?) : LinearLayoutCompat(context, attrs), SeekBar.OnSeekBarChangeListener { - private var valueFormat: String? = null - private var onChanged: ((progress: Int) -> Unit)? = null - val progress: Int + var valueFormat: ((progress: Int) -> String)? = null + var onChanged: ((progress: Int) -> Unit)? = null + var progress: Int get() = seek_bar.progress + set(value) { + seek_bar.progress = value + } + var max: Int + get() = seek_bar.max + set(value) { + seek_bar.max = value + } init { gravity = Gravity.CENTER_VERTICAL @@ -25,6 +33,7 @@ class DetailSeekBar(context: Context, attrs: AttributeSet?) : LinearLayoutCompat val typedArray = context.obtainStyledAttributes(attrs, R.styleable.DetailSeekBar) tv_seek_title.text = typedArray.getText(R.styleable.DetailSeekBar_title) + seek_bar.max = typedArray.getInteger(R.styleable.DetailSeekBar_max, 0) typedArray.recycle() iv_seek_add.onClick { @@ -40,7 +49,7 @@ class DetailSeekBar(context: Context, attrs: AttributeSet?) : LinearLayoutCompat private fun upValue(progress: Int = seek_bar.progress) { valueFormat?.let { - tv_seek_value.text = String.format(it, progress) + tv_seek_value.text = it.invoke(progress) } ?: let { tv_seek_value.text = progress.toString() } diff --git a/app/src/main/res/layout/dialog_read_padding.xml b/app/src/main/res/layout/dialog_read_padding.xml index 22bb10e50..7b878a442 100644 --- a/app/src/main/res/layout/dialog_read_padding.xml +++ b/app/src/main/res/layout/dialog_read_padding.xml @@ -1,206 +1,38 @@ - + app:title="@string/padding_top" + app:max="100" /> - - - - - - - - - - - - - - - - - - - - - - - - - + app:title="@string/padding_bottom" + app:max="100" /> - + app:title="@string/padding_left" + app:max="100" /> - - - - - - - - - - - - - - - - - - - - - - - - - + app:title="@string/padding_right" + app:max="100" /> \ No newline at end of file diff --git a/app/src/main/res/layout/view_detail_seek_bar.xml b/app/src/main/res/layout/view_detail_seek_bar.xml index 1af90c9e0..3bfed2f06 100644 --- a/app/src/main/res/layout/view_detail_seek_bar.xml +++ b/app/src/main/res/layout/view_detail_seek_bar.xml @@ -10,8 +10,9 @@ \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index e3ca97f5a..485e8ef20 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -67,6 +67,7 @@ +