pull/49/head
kunfei 5 years ago
parent f0ad1cd0d9
commit c728fed744
  1. 30
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 10
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 23
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -35,6 +35,7 @@ object ReadBook {
fun moveToNextChapter(upContent: Boolean): Boolean {
if (durChapterIndex < chapterSize - 1) {
durPageIndex = 0
durChapterIndex++
prevTextChapter = curTextChapter
curTextChapter = nextTextChapter
@ -61,6 +62,35 @@ object ReadBook {
}
}
fun moveToPrevChapter(upContent: Boolean, toLast: Boolean): Boolean {
if (durChapterIndex > 0) {
durPageIndex = if (toLast) prevTextChapter?.lastIndex() ?: 0 else 0
durChapterIndex--
nextTextChapter = curTextChapter
curTextChapter = prevTextChapter
prevTextChapter = null
book?.let {
if (curTextChapter == null) {
loadContent(durChapterIndex)
} else if (upContent) {
callBack?.upContent()
}
loadContent(durChapterIndex.minus(1))
GlobalScope.launch(Dispatchers.IO) {
for (i in -5..-2) {
delay(100)
download(durChapterIndex + i)
}
}
}
saveRead()
callBack?.curChapterChanged()
return true
} else {
return false
}
}
fun loadContent(index: Int) {
book?.let { book ->
if (addLoading(index)) {

@ -380,15 +380,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
* 上一页
*/
override fun moveToPrevChapter(upContent: Boolean, last: Boolean): Boolean {
return if (ReadBook.durChapterIndex > 0) {
ReadBook.durPageIndex = if (last) ReadBook.prevTextChapter?.lastIndex() ?: 0 else 0
viewModel.moveToPrevChapter(upContent)
ReadBook.saveRead()
curChapterChanged()
true
} else {
false
}
return ReadBook.moveToPrevChapter(upContent, last)
}
override fun clickCenter() {

@ -15,8 +15,6 @@ import io.legado.app.service.help.ReadAloud
import io.legado.app.service.help.ReadBook
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class ReadBookViewModel(application: Application) : BaseViewModel(application) {
@ -100,27 +98,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
}
fun moveToPrevChapter(upContent: Boolean) {
ReadBook.durChapterIndex--
ReadBook.nextTextChapter = ReadBook.curTextChapter
ReadBook.curTextChapter = ReadBook.prevTextChapter
ReadBook.prevTextChapter = null
ReadBook.book?.let {
if (ReadBook.curTextChapter == null) {
ReadBook.loadContent(ReadBook.durChapterIndex)
} else if (upContent) {
ReadBook.callBack?.upContent()
}
ReadBook.loadContent(ReadBook.durChapterIndex.minus(1))
launch(IO) {
for (i in -5..-2) {
delay(100)
ReadBook.download(ReadBook.durChapterIndex + i)
}
}
}
}
fun changeTo(book1: Book) {
execute {
ReadBook.book?.let {

Loading…
Cancel
Save