|
|
@ -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,10 +80,14 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null |
|
|
|
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
ReadBook.webBook?.getBookInfo(book, this) |
|
|
|
if (book.isLocalBook()) { |
|
|
|
?.onSuccess { |
|
|
|
loadChapterList(book, changeDruChapterIndex) |
|
|
|
loadChapterList(book, changeDruChapterIndex) |
|
|
|
} else { |
|
|
|
} |
|
|
|
ReadBook.webBook?.getBookInfo(book, this) |
|
|
|
|
|
|
|
?.onSuccess { |
|
|
|
|
|
|
|
loadChapterList(book, changeDruChapterIndex) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -91,22 +96,30 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null |
|
|
|
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null |
|
|
|
) { |
|
|
|
) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
ReadBook.webBook?.getChapterList(book, this) |
|
|
|
if (book.isLocalBook()) { |
|
|
|
?.onSuccess(IO) { cList -> |
|
|
|
AnalyzeTxtFile.analyze(context, book).let { |
|
|
|
if (!cList.isNullOrEmpty()) { |
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
if (changeDruChapterIndex == null) { |
|
|
|
ReadBook.chapterSize = it.size |
|
|
|
App.db.bookChapterDao().insert(*cList.toTypedArray()) |
|
|
|
ReadBook.loadContent() |
|
|
|
ReadBook.chapterSize = cList.size |
|
|
|
} |
|
|
|
ReadBook.loadContent() |
|
|
|
} else { |
|
|
|
|
|
|
|
ReadBook.webBook?.getChapterList(book, this) |
|
|
|
|
|
|
|
?.onSuccess(IO) { cList -> |
|
|
|
|
|
|
|
if (!cList.isNullOrEmpty()) { |
|
|
|
|
|
|
|
if (changeDruChapterIndex == null) { |
|
|
|
|
|
|
|
App.db.bookChapterDao().insert(*cList.toTypedArray()) |
|
|
|
|
|
|
|
ReadBook.chapterSize = cList.size |
|
|
|
|
|
|
|
ReadBook.loadContent() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
changeDruChapterIndex(cList) |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
changeDruChapterIndex(cList) |
|
|
|
toast(R.string.error_load_toc) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
}?.onError { |
|
|
|
toast(R.string.error_load_toc) |
|
|
|
toast(R.string.error_load_toc) |
|
|
|
} |
|
|
|
} ?: autoChangeSource() |
|
|
|
}?.onError { |
|
|
|
} |
|
|
|
toast(R.string.error_load_toc) |
|
|
|
|
|
|
|
} ?: autoChangeSource() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|