pull/49/head
kunfei 5 years ago
parent 0b8bcfb3d6
commit c002d01137
  1. 25
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 41
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -12,6 +12,7 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.read.ReadBookViewModel import io.legado.app.ui.book.read.ReadBookViewModel
import io.legado.app.ui.widget.page.ChapterProvider
import io.legado.app.ui.widget.page.TextChapter import io.legado.app.ui.widget.page.TextChapter
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
@ -204,6 +205,9 @@ object ReadBook {
} }
} }
/**
* 内容加载完成
*/
private fun contentLoadFinish(chapter: BookChapter, content: String) { private fun contentLoadFinish(chapter: BookChapter, content: String) {
Coroutine.async { Coroutine.async {
if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) {
@ -214,7 +218,26 @@ object ReadBook {
content, content,
book!!.useReplaceRule book!!.useReplaceRule
) )
callBack?.contentLoadFinish(chapter, c) when (chapter.index) {
durChapterIndex -> launch {
curTextChapter = ChapterProvider
.getTextChapter(chapter, c, chapterSize)
callBack?.upContent()
callBack?.curChapterChanged()
curPageChanged()
callBack?.contentLoadFinish()
}
durChapterIndex - 1 -> launch {
prevTextChapter = ChapterProvider
.getTextChapter(chapter, c, chapterSize)
callBack?.upContent(-1)
}
durChapterIndex + 1 -> launch {
nextTextChapter = ChapterProvider
.getTextChapter(chapter, c, chapterSize)
callBack?.upContent(1)
}
}
} }
} }
} }

@ -254,43 +254,24 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
} }
/** /**
* 加载章节内容, index章节序号 * 内容加载完成
*/ */
override fun loadContent(index: Int) { override fun contentLoadFinish() {
ReadBook.loadContent(index) if (intent.getBooleanExtra("readAloud", false)) {
intent.removeExtra("readAloud")
ReadBook.readAloud()
}
} }
/** /**
* 内容加载完成 * 加载章节内容, index章节序号
*/ */
override fun contentLoadFinish(bookChapter: BookChapter, content: String) { override fun loadContent(index: Int) {
when (bookChapter.index) { ReadBook.loadContent(index)
ReadBook.durChapterIndex -> launch {
ReadBook.curTextChapter = ChapterProvider
.getTextChapter(bookChapter, content, ReadBook.chapterSize)
page_view.upContent()
curChapterChanged()
ReadBook.curPageChanged()
if (intent.getBooleanExtra("readAloud", false)) {
intent.removeExtra("readAloud")
ReadBook.readAloud()
}
}
ReadBook.durChapterIndex - 1 -> launch {
ReadBook.prevTextChapter = ChapterProvider
.getTextChapter(bookChapter, content, ReadBook.chapterSize)
page_view.upContent(-1)
}
ReadBook.durChapterIndex + 1 -> launch {
ReadBook.nextTextChapter = ChapterProvider
.getTextChapter(bookChapter, content, ReadBook.chapterSize)
page_view.upContent(1)
}
}
} }
override fun upContent() { override fun upContent(position: Int) {
page_view.upContent() page_view.upContent(position)
} }
override fun curChapterChanged() { override fun curChapterChanged() {

@ -202,9 +202,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
interface CallBack { interface CallBack {
fun loadContent() fun loadContent()
fun contentLoadFinish(bookChapter: BookChapter, content: String) fun upContent(position: Int = 0)
fun upContent()
fun curChapterChanged() fun curChapterChanged()
fun upPageProgress() fun upPageProgress()
fun contentLoadFinish()
} }
} }
Loading…
Cancel
Save