|
|
@ -10,6 +10,7 @@ import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.help.IntentDataHelp |
|
|
|
import io.legado.app.help.IntentDataHelp |
|
|
|
import io.legado.app.model.WebBook |
|
|
|
import io.legado.app.model.WebBook |
|
|
|
|
|
|
|
import io.legado.app.model.localBook.AnalyzeTxtFile |
|
|
|
import io.legado.app.service.BaseReadAloudService |
|
|
|
import io.legado.app.service.BaseReadAloudService |
|
|
|
import io.legado.app.service.help.ReadAloud |
|
|
|
import io.legado.app.service.help.ReadAloud |
|
|
|
import io.legado.app.service.help.ReadBook |
|
|
|
import io.legado.app.service.help.ReadBook |
|
|
@ -79,18 +80,29 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null |
|
|
|
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
|
|
|
|
if (book.isLocalBook()) { |
|
|
|
|
|
|
|
loadChapterList(book, changeDruChapterIndex) |
|
|
|
|
|
|
|
} else { |
|
|
|
ReadBook.webBook?.getBookInfo(book, this) |
|
|
|
ReadBook.webBook?.getBookInfo(book, this) |
|
|
|
?.onSuccess { |
|
|
|
?.onSuccess { |
|
|
|
loadChapterList(book, changeDruChapterIndex) |
|
|
|
loadChapterList(book, changeDruChapterIndex) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun loadChapterList( |
|
|
|
private fun loadChapterList( |
|
|
|
book: Book, |
|
|
|
book: Book, |
|
|
|
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null |
|
|
|
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
|
|
|
|
if (book.isLocalBook()) { |
|
|
|
|
|
|
|
AnalyzeTxtFile.analyze(context, book).let { |
|
|
|
|
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
|
|
|
|
ReadBook.chapterSize = it.size |
|
|
|
|
|
|
|
ReadBook.loadContent() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
ReadBook.webBook?.getChapterList(book, this) |
|
|
|
ReadBook.webBook?.getChapterList(book, this) |
|
|
|
?.onSuccess(IO) { cList -> |
|
|
|
?.onSuccess(IO) { cList -> |
|
|
|
if (!cList.isNullOrEmpty()) { |
|
|
|
if (!cList.isNullOrEmpty()) { |
|
|
@ -109,6 +121,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
} ?: autoChangeSource() |
|
|
|
} ?: autoChangeSource() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun changeTo(book1: Book) { |
|
|
|
fun changeTo(book1: Book) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|