diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt
index 7d852791c..3708a7a1e 100644
--- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt
+++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt
@@ -5,6 +5,9 @@ import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import io.legado.app.App
import io.legado.app.utils.*
+import kotlinx.coroutines.Dispatchers.IO
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.launch
import java.io.BufferedWriter
import java.io.File
import java.io.FileWriter
@@ -60,16 +63,18 @@ object ReadBookConfig {
}
fun save() {
- val json = GSON.toJson(configList)
- val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + fileName)
- //获取流并存储
- try {
- BufferedWriter(FileWriter(configFile)).use { writer ->
- writer.write(json)
- writer.flush()
+ GlobalScope.launch(IO) {
+ val json = GSON.toJson(configList)
+ val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + fileName)
+ //获取流并存储
+ try {
+ BufferedWriter(FileWriter(configFile)).use { writer ->
+ writer.write(json)
+ writer.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
}
- } catch (e: IOException) {
- e.printStackTrace()
}
}
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 08603ddf6..a04803537 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
@@ -6,6 +6,7 @@ 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
@@ -56,18 +57,57 @@ class ReadStyleDialog : DialogFragment() {
}
}
+ override fun onDestroy() {
+ super.onDestroy()
+ ReadBookConfig.save()
+ }
+
private fun initData() {
requireContext().getPrefInt("pageAnim").let {
if (it >= 0 && it < rg_page_anim.childCount) {
rg_page_anim.check(rg_page_anim[it].id)
}
}
+ ReadBookConfig.getConfig().let {
+ tv_text_bold.isSelected = it.textBold
+ seek_text_size.progress = it.textSize - 5
+ seek_text_letter_spacing.progress = (it.letterSpacing * 10).toInt() + 5
+ seek_line_size.progress = it.lineSpacingExtra.toInt()
+ }
setBg()
upBg()
}
- private fun initOnClick() {
+ private fun initOnClick() = with(ReadBookConfig.getConfig()) {
+ tv_text_bold.onClick {
+ textBold = !textBold
+ tv_text_bold.isSelected = textBold
+ postEvent(Bus.UP_CONFIG, true)
+ }
+ seek_text_size.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
+ override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
+ textSize = progress + 5
+ postEvent(Bus.UP_CONFIG, true)
+ }
+
+ override fun onStartTrackingTouch(seekBar: SeekBar?) {}
+
+ override fun onStopTrackingTouch(seekBar: SeekBar?) {
+
+ }
+
+ })
+ iv_text_size_add.onClick {
+ textSize++
+ if (textSize > 50) textSize = 50
+ postEvent(Bus.UP_CONFIG, true)
+ }
+ iv_line_size_remove.onClick {
+ textSize--
+ if (textSize < 5) textSize = 5
+ postEvent(Bus.UP_CONFIG, true)
+ }
rg_page_anim.onCheckedChange { _, checkedId ->
for (i in 0 until rg_page_anim.childCount) {
if (checkedId == rg_page_anim[i].id) {
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 948b5cc1f..2c84c4adf 100644
--- a/app/src/main/res/layout/dialog_read_book_style.xml
+++ b/app/src/main/res/layout/dialog_read_book_style.xml
@@ -97,7 +97,7 @@
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="4"
- android:max="50" />
+ android:max="45" />
+ android:max="10" />