|
|
@ -13,6 +13,7 @@ import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.help.ContentProcessor |
|
|
|
import io.legado.app.help.ContentProcessor |
|
|
|
|
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
import io.legado.app.help.storage.AppWebDav |
|
|
|
import io.legado.app.help.storage.AppWebDav |
|
|
|
import io.legado.app.model.NoStackTraceException |
|
|
|
import io.legado.app.model.NoStackTraceException |
|
|
|
import io.legado.app.model.ReadAloud |
|
|
|
import io.legado.app.model.ReadAloud |
|
|
@ -25,10 +26,12 @@ import io.legado.app.utils.msg |
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
import io.legado.app.utils.toastOnUi |
|
|
|
import io.legado.app.utils.toastOnUi |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
|
|
|
import kotlinx.coroutines.ensureActive |
|
|
|
|
|
|
|
|
|
|
|
class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
var isInitFinish = false |
|
|
|
var isInitFinish = false |
|
|
|
var searchContentQuery = "" |
|
|
|
var searchContentQuery = "" |
|
|
|
|
|
|
|
var changeSourceCoroutine: Coroutine<*>? = null |
|
|
|
|
|
|
|
|
|
|
|
fun initData(intent: Intent) { |
|
|
|
fun initData(intent: Intent) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
@ -165,12 +168,15 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun changeTo(source: BookSource, book: Book) { |
|
|
|
fun changeTo(source: BookSource, book: Book) { |
|
|
|
execute { |
|
|
|
changeSourceCoroutine?.cancel() |
|
|
|
|
|
|
|
changeSourceCoroutine = execute { |
|
|
|
ReadBook.upMsg(context.getString(R.string.loading)) |
|
|
|
ReadBook.upMsg(context.getString(R.string.loading)) |
|
|
|
if (book.tocUrl.isEmpty()) { |
|
|
|
if (book.tocUrl.isEmpty()) { |
|
|
|
WebBook.getBookInfoAwait(this, source, book) |
|
|
|
WebBook.getBookInfoAwait(this, source, book) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ensureActive() |
|
|
|
val chapters = WebBook.getChapterListAwait(this, source, book) |
|
|
|
val chapters = WebBook.getChapterListAwait(this, source, book) |
|
|
|
|
|
|
|
ensureActive() |
|
|
|
val oldBook = ReadBook.book!! |
|
|
|
val oldBook = ReadBook.book!! |
|
|
|
book.durChapterIndex = BookHelp.getDurChapter( |
|
|
|
book.durChapterIndex = BookHelp.getDurChapter( |
|
|
|
oldBook.durChapterIndex, |
|
|
|
oldBook.durChapterIndex, |
|
|
|