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. 37
      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)
}
}
} }
} }
} }

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