|
@@ -14,7 +14,6 @@ import io.legado.app.data.appDb
|
|
|
import io.legado.app.data.entities.Book
|
|
import io.legado.app.data.entities.Book
|
|
|
import io.legado.app.data.entities.BookChapter
|
|
import io.legado.app.data.entities.BookChapter
|
|
|
import io.legado.app.data.entities.BookProgress
|
|
import io.legado.app.data.entities.BookProgress
|
|
|
-import io.legado.app.data.entities.BookSource
|
|
|
|
|
import io.legado.app.exception.NoStackTraceException
|
|
import io.legado.app.exception.NoStackTraceException
|
|
|
import io.legado.app.help.AppWebDav
|
|
import io.legado.app.help.AppWebDav
|
|
|
import io.legado.app.help.BookHelp
|
|
import io.legado.app.help.BookHelp
|
|
@@ -93,7 +92,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|
|
if (ReadBook.durChapterIndex > ReadBook.chapterSize - 1) {
|
|
if (ReadBook.durChapterIndex > ReadBook.chapterSize - 1) {
|
|
|
ReadBook.durChapterIndex = ReadBook.chapterSize - 1
|
|
ReadBook.durChapterIndex = ReadBook.chapterSize - 1
|
|
|
}
|
|
}
|
|
|
- ReadBook.loadContent(resetPageOffset = isSameBook)
|
|
|
|
|
|
|
+ ReadBook.loadContent(resetPageOffset = false)
|
|
|
}
|
|
}
|
|
|
if (!isSameBook || !BaseReadAloudService.isRun) {
|
|
if (!isSameBook || !BaseReadAloudService.isRun) {
|
|
|
syncBookProgress(book)
|
|
syncBookProgress(book)
|
|
@@ -210,20 +209,11 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|
|
/**
|
|
/**
|
|
|
* 换源
|
|
* 换源
|
|
|
*/
|
|
*/
|
|
|
- fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
|
|
|
|
|
|
|
+ fun changeTo(book: Book, toc: List<BookChapter>) {
|
|
|
changeSourceCoroutine?.cancel()
|
|
changeSourceCoroutine?.cancel()
|
|
|
changeSourceCoroutine = execute {
|
|
changeSourceCoroutine = execute {
|
|
|
ReadBook.upMsg(context.getString(R.string.loading))
|
|
ReadBook.upMsg(context.getString(R.string.loading))
|
|
|
ReadBook.book?.changeTo(book, toc)
|
|
ReadBook.book?.changeTo(book, toc)
|
|
|
- val nextChapter = toc.getOrElse(book.durChapterIndex) {
|
|
|
|
|
- toc.first()
|
|
|
|
|
- }
|
|
|
|
|
- WebBook.getContentAwait(
|
|
|
|
|
- bookSource = source,
|
|
|
|
|
- book = book,
|
|
|
|
|
- bookChapter = toc[book.durChapterIndex],
|
|
|
|
|
- nextChapterUrl = nextChapter.url
|
|
|
|
|
- )
|
|
|
|
|
appDb.bookDao.insert(book)
|
|
appDb.bookDao.insert(book)
|
|
|
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
|
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
|
|
ReadBook.resetData(book)
|
|
ReadBook.resetData(book)
|
|
@@ -250,11 +240,25 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|
|
WebBook.getBookInfoAwait(source, book)
|
|
WebBook.getBookInfoAwait(source, book)
|
|
|
}
|
|
}
|
|
|
val toc = WebBook.getChapterListAwait(source, book).getOrThrow()
|
|
val toc = WebBook.getChapterListAwait(source, book).getOrThrow()
|
|
|
- changeTo(source, book, toc)
|
|
|
|
|
- return@execute
|
|
|
|
|
|
|
+ val chapter = toc.getOrElse(book.durChapterIndex) {
|
|
|
|
|
+ toc.last()
|
|
|
|
|
+ }
|
|
|
|
|
+ val nextChapter = toc.getOrElse(chapter.index) {
|
|
|
|
|
+ toc.first()
|
|
|
|
|
+ }
|
|
|
|
|
+ kotlin.runCatching {
|
|
|
|
|
+ WebBook.getContentAwait(
|
|
|
|
|
+ bookSource = source,
|
|
|
|
|
+ book = book,
|
|
|
|
|
+ bookChapter = chapter,
|
|
|
|
|
+ nextChapterUrl = nextChapter.url
|
|
|
|
|
+ )
|
|
|
|
|
+ changeTo(book, toc)
|
|
|
|
|
+ return@execute
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- throw NoStackTraceException("没有搜索到 ${name}(${author})")
|
|
|
|
|
|
|
+ throw NoStackTraceException("没有合适书源")
|
|
|
}.onStart {
|
|
}.onStart {
|
|
|
ReadBook.upMsg(context.getString(R.string.source_auto_changing))
|
|
ReadBook.upMsg(context.getString(R.string.source_auto_changing))
|
|
|
}.onError {
|
|
}.onError {
|