diff --git a/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt b/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt index b8ab036b2..a68d3519c 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt @@ -126,13 +126,17 @@ class TocActivity : VMBaseActivity(), } override fun onTocRegexDialogResult(tocRegex: String) { - ReadBook.book?.let { book -> + viewModel.bookData.value?.let { book -> book.tocUrl = tocRegex waitDialog.show() - ReadBook.callBack?.loadChapterList(book) { - viewModel.initBook(book.bookUrl) + viewModel.upBookTocRule(book) { waitDialog.dismiss() } + ReadBook.book?.let { readBook -> + if (readBook == book) { + readBook.tocUrl = tocRegex + } + } } } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt b/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt index feb989943..0e7ef72dd 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt @@ -6,6 +6,8 @@ import androidx.lifecycle.MutableLiveData import io.legado.app.base.BaseViewModel import io.legado.app.data.appDb import io.legado.app.data.entities.Book +import io.legado.app.model.ReadBook +import io.legado.app.model.localBook.LocalBook class TocViewModel(application: Application) : BaseViewModel(application) { var bookUrl: String = "" @@ -23,6 +25,25 @@ class TocViewModel(application: Application) : BaseViewModel(application) { } } + fun upBookTocRule(book: Book, finally: () -> Unit) { + execute { + execute { + appDb.bookDao.update(book) + LocalBook.getChapterList(book).let { + book.latestChapterTime = System.currentTimeMillis() + appDb.bookChapterDao.delByBook(book.bookUrl) + appDb.bookChapterDao.insert(*it.toTypedArray()) + appDb.bookDao.update(book) + ReadBook.chapterSize = it.size + ReadBook.upMsg(null) + ReadBook.loadContent(resetPageOffset = true) + } + } + }.onFinally { + finally.invoke() + } + } + fun reverseToc(success: (book: Book) -> Unit) { execute { bookData.value?.apply {