pull/32/head
kunfei 5 years ago
parent b5246cd3a9
commit a34dfb9a33
  1. 23
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 42
      app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt
  3. 4
      app/src/main/res/layout/dialog_read_book_style.xml

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

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

@ -97,7 +97,7 @@
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="4"
android:max="50" />
android:max="45" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_text_size_remove"
@ -138,7 +138,7 @@
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_weight="4"
android:max="50" />
android:max="10" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_text_letter_spacing_remove"

Loading…
Cancel
Save