Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Jan 10, 2022
1 parent 95e0d64 commit f94ce73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
15 changes: 7 additions & 8 deletions app/src/main/java/io/legado/app/model/ReadBook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,14 @@ object ReadBook : CoroutineScope by MainScope() {
}

fun setProgress(progress: BookProgress) {
if (durChapterIndex != progress.durChapterIndex
|| durChapterPos != progress.durChapterPos
if (progress.durChapterIndex > chapterSize &&
(durChapterIndex != progress.durChapterIndex
|| durChapterPos != progress.durChapterPos)
) {
if (progress.durChapterIndex > chapterSize) {
durChapterIndex = progress.durChapterIndex
durChapterPos = progress.durChapterPos
clearTextChapter()
loadContent(resetPageOffset = true)
}
durChapterIndex = progress.durChapterIndex
durChapterPos = progress.durChapterPos
clearTextChapter()
loadContent(resetPageOffset = true)
}
}

Expand Down
20 changes: 11 additions & 9 deletions app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,17 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}

fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) {
ReadBook.clearTextChapter()
ReadBook.callBack?.upContent()
if (index != ReadBook.durChapterIndex) {
ReadBook.durChapterIndex = index
ReadBook.durChapterPos = durChapterPos
}
ReadBook.saveRead()
ReadBook.loadContent(resetPageOffset = true) {
success?.invoke()
if (index < ReadBook.chapterSize) {
ReadBook.clearTextChapter()
ReadBook.callBack?.upContent()
if (index != ReadBook.durChapterIndex) {
ReadBook.durChapterIndex = index
ReadBook.durChapterPos = durChapterPos
}
ReadBook.saveRead()
ReadBook.loadContent(resetPageOffset = true) {
success?.invoke()
}
}
}

Expand Down

0 comments on commit f94ce73

Please sign in to comment.