|
@@ -19,7 +19,9 @@ import io.legado.app.model.localBook.TextFile
|
|
|
import io.legado.app.model.webBook.WebBook
|
|
import io.legado.app.model.webBook.WebBook
|
|
|
import io.legado.app.service.BaseReadAloudService
|
|
import io.legado.app.service.BaseReadAloudService
|
|
|
import io.legado.app.ui.book.read.page.entities.TextChapter
|
|
import io.legado.app.ui.book.read.page.entities.TextChapter
|
|
|
|
|
+import io.legado.app.ui.book.read.page.entities.TextPage
|
|
|
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
|
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
|
|
|
|
+import io.legado.app.ui.book.read.page.provider.LayoutProgressListener
|
|
|
import io.legado.app.utils.stackTraceStr
|
|
import io.legado.app.utils.stackTraceStr
|
|
|
import io.legado.app.utils.toastOnUi
|
|
import io.legado.app.utils.toastOnUi
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
import kotlinx.coroutines.CoroutineScope
|
|
@@ -214,6 +216,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|
|
durChapterPos = 0
|
|
durChapterPos = 0
|
|
|
durChapterIndex++
|
|
durChapterIndex++
|
|
|
prevTextChapter?.cancelLayout()
|
|
prevTextChapter?.cancelLayout()
|
|
|
|
|
+ curTextChapter?.setProgressListener(null)
|
|
|
prevTextChapter = curTextChapter
|
|
prevTextChapter = curTextChapter
|
|
|
curTextChapter = nextTextChapter
|
|
curTextChapter = nextTextChapter
|
|
|
nextTextChapter = null
|
|
nextTextChapter = null
|
|
@@ -230,7 +233,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|
|
callBack?.upMenuView()
|
|
callBack?.upMenuView()
|
|
|
AppLog.putDebug("moveToNextChapter-curPageChanged()")
|
|
AppLog.putDebug("moveToNextChapter-curPageChanged()")
|
|
|
curPageChanged()
|
|
curPageChanged()
|
|
|
- curTextChapter?.let { callBack?.onCurrentTextChapterChanged(it) }
|
|
|
|
|
|
|
+ curTextChapter?.let { callBack?.onCurrentTextChapterChanged(it, upContent) }
|
|
|
return true
|
|
return true
|
|
|
} else {
|
|
} else {
|
|
|
AppLog.putDebug("跳转下一章失败,没有下一章")
|
|
AppLog.putDebug("跳转下一章失败,没有下一章")
|
|
@@ -247,6 +250,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|
|
durChapterPos = if (toLast) prevTextChapter?.lastReadLength ?: Int.MAX_VALUE else 0
|
|
durChapterPos = if (toLast) prevTextChapter?.lastReadLength ?: Int.MAX_VALUE else 0
|
|
|
durChapterIndex--
|
|
durChapterIndex--
|
|
|
nextTextChapter?.cancelLayout()
|
|
nextTextChapter?.cancelLayout()
|
|
|
|
|
+ curTextChapter?.setProgressListener(null)
|
|
|
nextTextChapter = curTextChapter
|
|
nextTextChapter = curTextChapter
|
|
|
curTextChapter = prevTextChapter
|
|
curTextChapter = prevTextChapter
|
|
|
prevTextChapter = null
|
|
prevTextChapter = null
|
|
@@ -260,7 +264,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|
|
saveRead()
|
|
saveRead()
|
|
|
callBack?.upMenuView()
|
|
callBack?.upMenuView()
|
|
|
curPageChanged()
|
|
curPageChanged()
|
|
|
- curTextChapter?.let { callBack?.onCurrentTextChapterChanged(it) }
|
|
|
|
|
|
|
+ curTextChapter?.let { callBack?.onCurrentTextChapterChanged(it, upContent) }
|
|
|
return true
|
|
return true
|
|
|
} else {
|
|
} else {
|
|
|
return false
|
|
return false
|
|
@@ -495,24 +499,52 @@ object ReadBook : CoroutineScope by MainScope() {
|
|
|
when (val offset = chapter.index - durChapterIndex) {
|
|
when (val offset = chapter.index - durChapterIndex) {
|
|
|
0 -> {
|
|
0 -> {
|
|
|
curTextChapter?.cancelLayout()
|
|
curTextChapter?.cancelLayout()
|
|
|
|
|
+ curTextChapter?.setProgressListener(null)
|
|
|
curTextChapter = textChapter
|
|
curTextChapter = textChapter
|
|
|
- if (upContent) callBack?.upContent(offset, resetPageOffset)
|
|
|
|
|
|
|
+ if (textChapter.isCompleted) {
|
|
|
|
|
+ if (upContent) callBack?.upContent(offset, resetPageOffset)
|
|
|
|
|
+ } else if (resetPageOffset) {
|
|
|
|
|
+ callBack?.resetPageOffset()
|
|
|
|
|
+ }
|
|
|
callBack?.upMenuView()
|
|
callBack?.upMenuView()
|
|
|
curPageChanged()
|
|
curPageChanged()
|
|
|
callBack?.contentLoadFinish()
|
|
callBack?.contentLoadFinish()
|
|
|
- callBack?.onCurrentTextChapterChanged(textChapter)
|
|
|
|
|
|
|
+ callBack?.onCurrentTextChapterChanged(textChapter, upContent)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-1 -> {
|
|
-1 -> {
|
|
|
prevTextChapter?.cancelLayout()
|
|
prevTextChapter?.cancelLayout()
|
|
|
prevTextChapter = textChapter
|
|
prevTextChapter = textChapter
|
|
|
- if (upContent) callBack?.upContent(offset, resetPageOffset)
|
|
|
|
|
|
|
+ if (upContent) {
|
|
|
|
|
+ if (textChapter.isCompleted) {
|
|
|
|
|
+ callBack?.upContent(offset, resetPageOffset)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ textChapter.setProgressListener(object : LayoutProgressListener {
|
|
|
|
|
+ override fun onLayoutCompleted() {
|
|
|
|
|
+ callBack?.upContent(offset, resetPageOffset)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
1 -> {
|
|
1 -> {
|
|
|
nextTextChapter?.cancelLayout()
|
|
nextTextChapter?.cancelLayout()
|
|
|
nextTextChapter = textChapter
|
|
nextTextChapter = textChapter
|
|
|
- if (upContent) callBack?.upContent(offset, resetPageOffset)
|
|
|
|
|
|
|
+ if (upContent) {
|
|
|
|
|
+ if (textChapter.isCompleted) {
|
|
|
|
|
+ callBack?.upContent(offset, resetPageOffset)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ textChapter.setProgressListener(object : LayoutProgressListener {
|
|
|
|
|
+ override fun onLayoutPageCompleted(index: Int, page: TextPage) {
|
|
|
|
|
+ if (index > 1) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ callBack?.upContent(offset, resetPageOffset)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
Unit
|
|
Unit
|
|
@@ -650,7 +682,9 @@ object ReadBook : CoroutineScope by MainScope() {
|
|
|
|
|
|
|
|
fun notifyBookChanged()
|
|
fun notifyBookChanged()
|
|
|
|
|
|
|
|
- fun onCurrentTextChapterChanged(textChapter: TextChapter)
|
|
|
|
|
|
|
+ fun onCurrentTextChapterChanged(textChapter: TextChapter, upContent: Boolean = true)
|
|
|
|
|
+
|
|
|
|
|
+ fun resetPageOffset()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|