pull/32/head
kunfei 5 years ago
parent c5837f74fd
commit 61cfd284b7
  1. 74
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt

@ -97,6 +97,44 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
}
fun moveToNextChapter() {
durChapterIndex++
prevTextChapter = curTextChapter
curTextChapter = nextTextChapter
nextTextChapter = null
bookData.value?.let {
loadContent(it, durChapterIndex)
loadContent(it, durChapterIndex.plus(1))
launch(IO) {
for (i in 2..10) {
delay(100)
bookData.value?.let { book ->
download(book, durChapterIndex + i)
}
}
}
}
}
fun moveToPrevChapter() {
durChapterIndex--
nextTextChapter = curTextChapter
curTextChapter = prevTextChapter
prevTextChapter = null
bookData.value?.let {
loadContent(it, durChapterIndex)
loadContent(it, durChapterIndex.minus(1))
launch(IO) {
for (i in -5..-2) {
delay(100)
bookData.value?.let { book ->
download(book, durChapterIndex + i)
}
}
}
}
}
fun loadContent(book: Book, index: Int) {
synchronized(loadingLock) {
if (loadingChapters.contains(index)) return
@ -230,42 +268,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
}
fun moveToNextChapter() {
durChapterIndex++
prevTextChapter = curTextChapter
curTextChapter = nextTextChapter
nextTextChapter = null
bookData.value?.let {
loadContent(it, durChapterIndex.plus(1))
launch(IO) {
for (i in 2..10) {
delay(100)
bookData.value?.let { book ->
download(book, durChapterIndex + i)
}
}
}
}
}
fun moveToPrevChapter() {
durChapterIndex--
nextTextChapter = curTextChapter
curTextChapter = prevTextChapter
prevTextChapter = null
bookData.value?.let {
loadContent(it, durChapterIndex.minus(1))
launch(IO) {
for (i in -5..-2) {
delay(100)
bookData.value?.let { book ->
download(book, durChapterIndex + i)
}
}
}
}
}
fun refreshContent(book: Book) {
execute {
App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter ->

Loading…
Cancel
Save