pull/1319/head
gedoor 3 years ago
parent 878635559f
commit e40d4b585a
  1. 29
      app/src/main/java/io/legado/app/model/ReadBook.kt
  2. 32
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -2,6 +2,7 @@ package io.legado.app.model
import androidx.lifecycle.MutableLiveData
import com.github.liuyueyi.quick.transfer.ChineseUtils
import io.legado.app.constant.AppLog
import io.legado.app.constant.BookType
import io.legado.app.data.appDb
import io.legado.app.data.entities.*
@ -245,20 +246,20 @@ object ReadBook : CoroutineScope by MainScope() {
resetPageOffset: Boolean = false,
success: (() -> Unit)? = null
) {
book?.let { book ->
if (addLoading(index)) {
Coroutine.async {
appDb.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
BookHelp.getContent(book, chapter)?.let {
contentLoadFinish(book, chapter, it, upContent, resetPageOffset) {
success?.invoke()
}
removeLoading(chapter.index)
} ?: download(this, chapter, resetPageOffset = resetPageOffset)
} ?: removeLoading(index)
}.onError {
removeLoading(index)
}
if (addLoading(index)) {
Coroutine.async {
val book = book!!
appDb.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
BookHelp.getContent(book, chapter)?.let {
contentLoadFinish(book, chapter, it, upContent, resetPageOffset) {
success?.invoke()
}
removeLoading(chapter.index)
} ?: download(this, chapter, resetPageOffset = resetPageOffset)
} ?: removeLoading(index)
}.onError {
removeLoading(index)
AppLog.addLog("加载正文出错\n${it.localizedMessage}")
}
}
}

@ -174,26 +174,26 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
WebBook.getBookInfoAwait(this, source, book)
}
val chapters = WebBook.getChapterListAwait(this, source, book)
ReadBook.book!!.let { oldBook ->
book.durChapterIndex = BookHelp.getDurChapter(
oldBook.durChapterIndex,
oldBook.totalChapterNum,
oldBook.durChapterTitle,
chapters
)
book.durChapterTitle = chapters[ReadBook.durChapterIndex].title
oldBook.changeTo(book)
}
val oldBook = ReadBook.book!!
book.durChapterIndex = BookHelp.getDurChapter(
oldBook.durChapterIndex,
oldBook.totalChapterNum,
oldBook.durChapterTitle,
chapters
)
book.durChapterTitle = chapters[book.durChapterIndex].title
oldBook.changeTo(book)
appDb.bookChapterDao.insert(*chapters.toTypedArray())
ReadBook.resetData(book)
ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true)
}.onError {
context.toastOnUi("换源失败\n${it.localizedMessage}")
ReadBook.upMsg(null)
}.onFinally {
postEvent(EventBus.SOURCE_CHANGED, book.bookUrl)
}
}.timeout(60000)
.onError {
context.toastOnUi("换源失败\n${it.localizedMessage}")
ReadBook.upMsg(null)
}.onFinally {
postEvent(EventBus.SOURCE_CHANGED, book.bookUrl)
}
}
private fun autoChangeSource(name: String, author: String) {

Loading…
Cancel
Save