feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 2589cb2e30
commit bb4d156438
  1. 87
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  2. 145
      app/src/main/res/layout/dialog_read_book_style.xml
  3. 2
      app/src/main/res/layout/dialog_read_padding.xml
  4. 2
      app/src/main/res/layout/view_detail_seek_bar.xml

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

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -82,155 +81,43 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/ll_text_size"
<io.legado.app.ui.widget.DetailSeekBar
android:id="@+id/dsb_text_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center"
app:layout_constraintTop_toBottomOf="@+id/tv_text_bold">
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="@string/text_size" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_text_size_remove"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_remove"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:tint="@color/tv_text_default" />
<io.legado.app.lib.theme.view.ATESeekBar
android:id="@+id/seek_text_size"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="4"
android:max="45" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_text_size_add"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_add"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:tint="@color/tv_text_default" />
app:max="45"
app:title="@string/text_size"
app:layout_constraintTop_toBottomOf="@+id/tv_text_bold" />
<TextView
android:id="@+id/tv_text_size"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="right"
tools:ignore="RtlHardcoded" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_text_letter_spacing"
<io.legado.app.ui.widget.DetailSeekBar
android:id="@+id/dsb_text_letter_spacing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center"
app:layout_constraintTop_toBottomOf="@+id/ll_text_size">
app:max="10"
app:title="@string/text_letter_spacing"
app:layout_constraintTop_toBottomOf="@+id/dsb_text_size" />
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="@string/text_letter_spacing" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_text_letter_spacing_remove"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_remove"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:tint="@color/tv_text_default" />
<io.legado.app.lib.theme.view.ATESeekBar
android:id="@+id/seek_text_letter_spacing"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="4"
android:max="10" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_text_letter_spacing_add"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_add"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:tint="@color/tv_text_default" />
<TextView
android:id="@+id/tv_text_letter_spacing"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="right"
tools:ignore="RtlHardcoded" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_line_size"
<io.legado.app.ui.widget.DetailSeekBar
android:id="@+id/dsb_line_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center"
app:layout_constraintTop_toBottomOf="@+id/ll_text_letter_spacing">
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="@string/line_size" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_line_size_remove"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_remove"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:tint="@color/tv_text_default" />
<io.legado.app.lib.theme.view.ATESeekBar
android:id="@+id/seek_line_size"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="4"
android:max="50" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_line_size_add"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_add"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:tint="@color/tv_text_default" />
<TextView
android:id="@+id/tv_line_size"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="right"
tools:ignore="RtlHardcoded" />
</LinearLayout>
app:max="50"
app:title="@string/line_size"
app:layout_constraintTop_toBottomOf="@+id/dsb_text_letter_spacing" />
<View
android:id="@+id/vw_bg_fg"
android:layout_width="match_parent"
android:layout_height="0.8dp"
android:background="@color/btn_bg_press"
app:layout_constraintTop_toBottomOf="@+id/ll_line_size" />
app:layout_constraintTop_toBottomOf="@+id/dsb_line_size" />
<TextView
android:id="@+id/tv_page_anim"

@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:padding="8dp"
android:padding="10dp"
android:orientation="vertical">
<io.legado.app.ui.widget.DetailSeekBar

@ -4,8 +4,6 @@
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center">
<TextView

Loading…
Cancel
Save