This commit is contained in:
Horis
2024-07-10 17:10:37 +08:00
parent 55fc1757b9
commit 46ea7d0f93
3 changed files with 10 additions and 8 deletions
@@ -78,9 +78,7 @@ abstract class BaseReadBookActivity :
FileDoc.fromUri(uri, true).find(book.originName)?.let { doc -> FileDoc.fromUri(uri, true).find(book.originName)?.let { doc ->
book.bookUrl = doc.uri.toString() book.bookUrl = doc.uri.toString()
book.save() book.save()
lifecycleScope.launch(IO) { viewModel.loadChapterList(book)
viewModel.loadChapterList(book)
}
} ?: ReadBook.upMsg("找不到文件") } ?: ReadBook.upMsg("找不到文件")
} }
} ?: ReadBook.upMsg("没有权限访问") } ?: ReadBook.upMsg("没有权限访问")
@@ -924,9 +924,7 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun loadChapterList(book: Book) { override fun loadChapterList(book: Book) {
ReadBook.upMsg(getString(R.string.toc_updateing)) ReadBook.upMsg(getString(R.string.toc_updateing))
lifecycleScope.launch(IO) { viewModel.loadChapterList(book)
viewModel.loadChapterList(book)
}
} }
/** /**
@@ -109,7 +109,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
if (book.isLocal && !checkLocalBookFileExist(book)) { if (book.isLocal && !checkLocalBookFileExist(book)) {
return return
} }
if ((ReadBook.chapterSize == 0 || book.isLocalModified()) && !loadChapterList(book)) { if ((ReadBook.chapterSize == 0 || book.isLocalModified()) && !loadChapterListAwait(book)) {
return return
} }
ReadBook.upMsg(null) ReadBook.upMsg(null)
@@ -163,7 +163,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
/** /**
* 加载目录 * 加载目录
*/ */
suspend fun loadChapterList(book: Book): Boolean { fun loadChapterList(book: Book) {
execute {
loadChapterListAwait(book)
}
}
private suspend fun loadChapterListAwait(book: Book): Boolean {
if (book.isLocal) { if (book.isLocal) {
kotlin.runCatching { kotlin.runCatching {
LocalBook.getChapterList(book).let { LocalBook.getChapterList(book).let {