Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Sep 19, 2023
1 parent 3037df7 commit 4592ee4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 10 additions & 2 deletions app/src/main/java/io/legado/app/model/ReadBook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,16 @@ object ReadBook : CoroutineScope by MainScope() {
* @param resetPageOffset 滚动阅读是否重置滚动位置
* @param success 当前章节加载完成回调
*/
fun loadContent(resetPageOffset: Boolean, success: (() -> Unit)? = null) {
loadContent(durChapterIndex, resetPageOffset = resetPageOffset) {
fun loadContent(
resetPageOffset: Boolean,
pageChanged: Boolean = false,
success: (() -> Unit)? = null
) {
loadContent(
durChapterIndex,
resetPageOffset = resetPageOffset,
pageChanged = pageChanged
) {
success?.invoke()
}
loadContent(durChapterIndex + 1, resetPageOffset = resetPageOffset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
appDb.bookChapterDao.insert(*toc.toTypedArray())
ReadBook.resetData(book)
ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true)
ReadBook.loadContent(resetPageOffset = true, pageChanged = true)
}.onError {
context.toastOnUi("换源失败\n${it.localizedMessage}")
ReadBook.upMsg(null)
Expand Down Expand Up @@ -284,7 +284,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.durChapterIndex = index
ReadBook.durChapterPos = durChapterPos
ReadBook.saveRead()
ReadBook.loadContent(resetPageOffset = true) {
ReadBook.loadContent(resetPageOffset = true, pageChanged = true) {
success?.invoke()
}
}
Expand Down Expand Up @@ -313,7 +313,11 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?.let { chapter ->
BookHelp.delContent(book, chapter)
ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false)
ReadBook.loadContent(
ReadBook.durChapterIndex,
resetPageOffset = false,
pageChanged = true
)
}
}
}
Expand Down

0 comments on commit 4592ee4

Please sign in to comment.