diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 4548c102b..41bfa3c77 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.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) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 39e07a458..43cf51183 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -345,22 +345,26 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } override fun upView() { - ReadBook.curTextChapter?.let { - tv_chapter_name.text = it.title - tv_chapter_name.visible() - if (!ReadBook.isLocalBook) { - tv_chapter_url.text = it.url - tv_chapter_url.visible() + launch { + ReadBook.curTextChapter?.let { + tv_chapter_name.text = it.title + tv_chapter_name.visible() + if (!ReadBook.isLocalBook) { + tv_chapter_url.text = it.url + tv_chapter_url.visible() + } + seek_read_page.max = it.pageSize().minus(1) + seek_read_page.progress = ReadBook.durPageIndex + tv_pre.isEnabled = ReadBook.durChapterIndex != 0 + tv_next.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1 } - seek_read_page.max = it.pageSize().minus(1) - seek_read_page.progress = ReadBook.durPageIndex - tv_pre.isEnabled = ReadBook.durChapterIndex != 0 - tv_next.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1 } } override fun upPageProgress() { - seek_read_page.progress = ReadBook.durPageIndex + launch { + seek_read_page.progress = ReadBook.durPageIndex + } } override fun showMenuBar() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index decd54ee8..ae501c0a7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -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 } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index d2c405de5..9fadd4f06 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -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()