feat: 优化代码

pull/106/head
kunfei 5 years ago
parent db33516ac5
commit b2b68378f8
  1. 12
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  4. 25
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt

@ -13,8 +13,10 @@ import io.legado.app.model.WebBook
import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.read.page.ChapterProvider
import io.legado.app.ui.book.read.page.entities.TextChapter
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
object ReadBook {
@ -264,18 +266,18 @@ object ReadBook {
book!!.useReplaceRule
)
when (chapter.index) {
durChapterIndex -> withContext(Main) {
durChapterIndex -> {
curTextChapter = ChapterProvider.getTextChapter(chapter, c, chapterSize)
callBack?.upContent()
callBack?.upView()
curPageChanged()
callBack?.contentLoadFinish()
}
durChapterIndex - 1 -> withContext(Main) {
durChapterIndex - 1 -> {
prevTextChapter = ChapterProvider.getTextChapter(chapter, c, chapterSize)
callBack?.upContent(-1)
}
durChapterIndex + 1 -> withContext(Main) {
durChapterIndex + 1 -> {
nextTextChapter = ChapterProvider.getTextChapter(chapter, c, chapterSize)
callBack?.upContent(1)
}

@ -345,6 +345,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
}
override fun upView() {
launch {
ReadBook.curTextChapter?.let {
tv_chapter_name.text = it.title
tv_chapter_name.visible()
@ -358,10 +359,13 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
tv_next.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1
}
}
}
override fun upPageProgress() {
launch {
seek_read_page.progress = ReadBook.durPageIndex
}
}
override fun showMenuBar() {
read_menu.runMenuIn()

@ -91,7 +91,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
postEvent(EventBus.UP_CONFIG, true)
}
tv_text_bold.onClick {
with(ReadBookConfig.durConfig) {
ReadBookConfig.durConfig.apply {
textBold = !textBold
tv_text_bold.isSelected = textBold
}

@ -1,9 +1,13 @@
package io.legado.app.ui.book.read.page
import android.graphics.Point
import android.graphics.Typeface
import android.text.Layout
import android.text.StaticLayout
import android.text.TextPaint
import android.text.TextUtils
import io.legado.app.App
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp
import io.legado.app.help.ReadBookConfig
@ -12,6 +16,8 @@ import io.legado.app.ui.book.read.page.entities.TextChar
import io.legado.app.ui.book.read.page.entities.TextLine
import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.utils.dp
import io.legado.app.utils.getPrefString
import io.legado.app.utils.removePref
object ChapterProvider {
@ -31,10 +37,29 @@ object ChapterProvider {
}
fun upStyle(config: ReadBookConfig.Config) {
val typeface: Typeface = try {
val fontPath = App.INSTANCE.getPrefString(PreferKey.readBookFont)
if (!TextUtils.isEmpty(fontPath)) {
Typeface.createFromFile(fontPath)
} else {
Typeface.SANS_SERIF
}
} catch (e: Exception) {
App.INSTANCE.removePref(PreferKey.readBookFont)
Typeface.SANS_SERIF
}
//标题
titlePaint.isAntiAlias = true
titlePaint.color = config.textColor()
titlePaint.letterSpacing = config.letterSpacing
titlePaint.typeface = Typeface.create(typeface, Typeface.BOLD)
//正文
contentPaint.isAntiAlias = true
contentPaint.color = config.textColor()
contentPaint.letterSpacing = config.letterSpacing
val bold = if (config.textBold) Typeface.BOLD else Typeface.NORMAL
contentPaint.typeface = Typeface.create(typeface, bold)
//间距
lineSpacingExtra = config.lineSpacingExtra
paragraphSpacing = config.paragraphSpacing
titlePaint.textSize = (config.textSize + 2).dp.toFloat()

Loading…
Cancel
Save