feat: 优化代码

pull/98/head
kunfei 5 years ago
parent b9e1e89dd2
commit 2589cb2e30
  1. 96
      app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt
  2. 17
      app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt
  3. 200
      app/src/main/res/layout/dialog_read_padding.xml
  4. 4
      app/src/main/res/layout/view_detail_seek_bar.xml
  5. 1
      app/src/main/res/values/attrs.xml

@ -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)
}
})
}
}

@ -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()
}

@ -1,206 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:padding="8dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_padding_top"
<io.legado.app.ui.widget.DetailSeekBar
android:id="@+id/dsb_padding_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:layout_constraintTop_toBottomOf="@+id/tv_text_bold">
app:title="@string/padding_top"
app:max="100" />
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="@string/padding_top" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_padding_top_remove"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_remove"
android:tint="@color/tv_text_default" />
<io.legado.app.lib.theme.view.ATESeekBar
android:id="@+id/seek_padding_top"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="4"
android:max="100" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_padding_top_add"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_add"
android:tint="@color/tv_text_default" />
<TextView
android:id="@+id/tv_padding_top"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="right"
tools:ignore="RtlHardcoded" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_padding_bottom"
<io.legado.app.ui.widget.DetailSeekBar
android:id="@+id/dsb_padding_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:layout_constraintTop_toBottomOf="@+id/tv_text_bold">
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="@string/padding_bottom" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_padding_bottom_remove"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_remove"
android:tint="@color/tv_text_default" />
<io.legado.app.lib.theme.view.ATESeekBar
android:id="@+id/seek_padding_bottom"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="4"
android:max="100" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_padding_bottom_add"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_add"
android:tint="@color/tv_text_default" />
<TextView
android:id="@+id/tv_padding_bottom"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="right"
tools:ignore="RtlHardcoded" />
</LinearLayout>
app:title="@string/padding_bottom"
app:max="100" />
<LinearLayout
android:id="@+id/ll_padding_left"
<io.legado.app.ui.widget.DetailSeekBar
android:id="@+id/dsb_padding_left"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:layout_constraintTop_toBottomOf="@+id/tv_text_bold">
app:title="@string/padding_left"
app:max="100" />
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="@string/padding_left" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_padding_left_remove"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_remove"
android:tint="@color/tv_text_default" />
<io.legado.app.lib.theme.view.ATESeekBar
android:id="@+id/seek_padding_left"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="4"
android:max="100" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_padding_left_add"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_add"
android:tint="@color/tv_text_default" />
<TextView
android:id="@+id/tv_padding_left"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="right"
tools:ignore="RtlHardcoded" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_padding_right"
<io.legado.app.ui.widget.DetailSeekBar
android:id="@+id/dsb_padding_right"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:layout_constraintTop_toBottomOf="@+id/tv_text_bold">
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="@string/padding_right" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_padding_right_remove"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_remove"
android:tint="@color/tv_text_default" />
<io.legado.app.lib.theme.view.ATESeekBar
android:id="@+id/seek_padding_right"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="4"
android:max="100" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_padding_right_add"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_add"
android:tint="@color/tv_text_default" />
<TextView
android:id="@+id/tv_padding_right"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="right"
tools:ignore="RtlHardcoded" />
</LinearLayout>
app:title="@string/padding_right"
app:max="100" />
</LinearLayout>

@ -10,8 +10,9 @@
<TextView
android:id="@+id/tv_seek_title"
android:layout_width="40dp"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/text_letter_spacing" />
<androidx.appcompat.widget.AppCompatImageView
@ -43,6 +44,7 @@
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="right"
android:singleLine="true"
tools:ignore="RtlHardcoded" />
</LinearLayout>

@ -67,6 +67,7 @@
<declare-styleable name="DetailSeekBar">
<attr name="title" format="string" />
<attr name="max" format="integer" />
</declare-styleable>
<declare-styleable name="SmoothCheckBox">

Loading…
Cancel
Save