pull/2622/head
kunfei 2 years ago
parent 0df1270831
commit 503e22dbad
  1. 10
      app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt
  2. 21
      app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt

@ -126,13 +126,17 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>(),
}
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
}
}
}
}

@ -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 {

Loading…
Cancel
Save