pull/51/head
kunfei 5 years ago
parent 2aa7ceba02
commit eaedae175b
  1. 12
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 13
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 25
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt

@ -157,6 +157,18 @@ object ReadBook {
return durPageIndex
}
/**
* chapterOnDur: 0为当前页,1为下一页,-1为上一页
*/
fun textChapter(chapterOnDur: Int = 0): TextChapter? {
return when (chapterOnDur) {
0 -> curTextChapter
1 -> nextTextChapter
-1 -> prevTextChapter
else -> null
}
}
fun loadContent(index: Int) {
book?.let { book ->
if (addLoading(index)) {

@ -35,7 +35,6 @@ import io.legado.app.ui.replacerule.ReplaceRuleActivity
import io.legado.app.ui.replacerule.edit.ReplaceEditDialog
import io.legado.app.ui.widget.page.ChapterProvider
import io.legado.app.ui.widget.page.PageView
import io.legado.app.ui.widget.page.TextChapter
import io.legado.app.ui.widget.page.delegate.PageDelegate
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_read.*
@ -302,18 +301,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
ReadBook.curPageChanged()
}
/**
* chapterOnDur: 0为当前页,1为下一页,-1为上一页
*/
override fun textChapter(chapterOnDur: Int): TextChapter? {
return when (chapterOnDur) {
0 -> ReadBook.curTextChapter
1 -> ReadBook.nextTextChapter
-1 -> ReadBook.prevTextChapter
else -> null
}
}
override fun clickCenter() {
if (BaseReadAloudService.isRun) {
showReadAloudDialog()

@ -112,10 +112,8 @@ class PageView(context: Context, attrs: AttributeSet) :
curPage?.setContent(it.currentPage())
nextPage?.setContent(it.nextPage())
prevPage?.setContent(it.previousPage())
callBack?.let { callback ->
if (isScrollDelegate) {
curPage?.scrollTo(callback.textChapter()?.getStartLine(ReadBook.durChapterPos()))
}
curPage?.scrollTo(ReadBook.textChapter()?.getStartLine(ReadBook.durChapterPos()))
}
}
}
@ -129,7 +127,7 @@ class PageView(context: Context, attrs: AttributeSet) :
fun moveToPrevPage(noAnim: Boolean = true) {
if (noAnim) {
if (isScrollDelegate) {
callBack?.textChapter()?.let {
ReadBook.textChapter()?.let {
curPage?.scrollTo(it.getStartLine(pageIndex - 1))
}
} else {
@ -141,7 +139,7 @@ class PageView(context: Context, attrs: AttributeSet) :
fun moveToNextPage(noAnim: Boolean = true) {
if (noAnim) {
if (isScrollDelegate) {
callBack?.textChapter()?.let {
ReadBook.textChapter()?.let {
curPage?.scrollTo(it.getStartLine(pageIndex + 1))
}
} else {
@ -192,19 +190,19 @@ class PageView(context: Context, attrs: AttributeSet) :
}
override fun getChapter(position: Int): TextChapter? {
return callBack?.textChapter(position)
return ReadBook.textChapter(position)
}
override fun getCurrentChapter(): TextChapter? {
return callBack?.textChapter(0)
return ReadBook.textChapter(0)
}
override fun getNextChapter(): TextChapter? {
return callBack?.textChapter(1)
return ReadBook.textChapter(1)
}
override fun getPreviousChapter(): TextChapter? {
return callBack?.textChapter(-1)
return ReadBook.textChapter(-1)
}
override fun hasNextChapter(): Boolean {
@ -220,7 +218,7 @@ class PageView(context: Context, attrs: AttributeSet) :
override fun scrollToLine(line: Int) {
if (isScrollDelegate) {
callBack?.textChapter()?.let {
ReadBook.textChapter()?.let {
val pageIndex = it.getPageIndex(line)
curPage?.setPageIndex(pageIndex)
callBack?.setPageIndex(pageIndex)
@ -230,7 +228,7 @@ class PageView(context: Context, attrs: AttributeSet) :
override fun scrollToLast() {
if (isScrollDelegate) {
callBack?.textChapter()?.let {
ReadBook.textChapter()?.let {
callBack?.setPageIndex(it.lastIndex())
curPage?.setPageIndex(it.lastIndex())
}
@ -239,11 +237,6 @@ class PageView(context: Context, attrs: AttributeSet) :
interface CallBack {
/**
* chapterOnDur: 0为当前页,1为下一页,-1为上一页
*/
fun textChapter(chapterOnDur: Int = 0): TextChapter?
/**
* 保存页数
*/

Loading…
Cancel
Save