|
|
@ -33,6 +33,8 @@ import io.legado.app.utils.postEvent |
|
|
|
import io.legado.app.utils.toStringArray |
|
|
|
import io.legado.app.utils.toStringArray |
|
|
|
import io.legado.app.utils.toastOnUi |
|
|
|
import io.legado.app.utils.toastOnUi |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 阅读界面数据处理 |
|
|
|
* 阅读界面数据处理 |
|
|
@ -145,20 +147,24 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ReadBook.bookSource?.let { |
|
|
|
ReadBook.bookSource?.let { |
|
|
|
val preUpdateJs = it.ruleToc?.preUpdateJs |
|
|
|
viewModelScope.launch { |
|
|
|
if (!preUpdateJs.isNullOrBlank()) { |
|
|
|
withContext(IO) { |
|
|
|
AnalyzeRule(book, it).evalJS(preUpdateJs) |
|
|
|
val preUpdateJs = it.ruleToc?.preUpdateJs |
|
|
|
} |
|
|
|
if (!preUpdateJs.isNullOrBlank()) { |
|
|
|
WebBook.getChapterList(viewModelScope, it, book) |
|
|
|
AnalyzeRule(book, it).evalJS(preUpdateJs) |
|
|
|
.onSuccess(IO) { cList -> |
|
|
|
} |
|
|
|
appDb.bookChapterDao.insert(*cList.toTypedArray()) |
|
|
|
|
|
|
|
appDb.bookDao.update(book) |
|
|
|
|
|
|
|
ReadBook.chapterSize = cList.size |
|
|
|
|
|
|
|
ReadBook.upMsg(null) |
|
|
|
|
|
|
|
ReadBook.loadContent(resetPageOffset = true) |
|
|
|
|
|
|
|
}.onError { |
|
|
|
|
|
|
|
ReadBook.upMsg(context.getString(R.string.error_load_toc)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
WebBook.getChapterList(viewModelScope, it, book) |
|
|
|
|
|
|
|
.onSuccess(IO) { cList -> |
|
|
|
|
|
|
|
appDb.bookChapterDao.insert(*cList.toTypedArray()) |
|
|
|
|
|
|
|
appDb.bookDao.update(book) |
|
|
|
|
|
|
|
ReadBook.chapterSize = cList.size |
|
|
|
|
|
|
|
ReadBook.upMsg(null) |
|
|
|
|
|
|
|
ReadBook.loadContent(resetPageOffset = true) |
|
|
|
|
|
|
|
}.onError { |
|
|
|
|
|
|
|
ReadBook.upMsg(context.getString(R.string.error_load_toc)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|