pull/32/head
kunfei 5 years ago
parent 6db709df6a
commit 37666eea94
  1. 8
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 50
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt

@ -113,7 +113,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun skipToPage(page: Int) { override fun skipToPage(page: Int) {
viewModel.durPageIndex = page viewModel.durPageIndex = page
page_view.chapterLoadFinish() page_view.upContent()
} }
override fun skipPreChapter() { override fun skipPreChapter() {
@ -232,17 +232,17 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
ChapterProvider.getTextChapter(content_text_view, bookChapter, content).let { ChapterProvider.getTextChapter(content_text_view, bookChapter, content).let {
viewModel.curTextChapter = it viewModel.curTextChapter = it
page_view.chapterLoadFinish() page_view.upContent()
read_menu.upReadProgress(it.pageSize(), viewModel.durPageIndex) read_menu.upReadProgress(it.pageSize(), viewModel.durPageIndex)
} }
} }
viewModel.durChapterIndex - 1 -> { viewModel.durChapterIndex - 1 -> {
viewModel.prevTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content) viewModel.prevTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
page_view.chapterLoadFinish(-1) page_view.upContent()
} }
viewModel.durChapterIndex + 1 -> { viewModel.durChapterIndex + 1 -> {
viewModel.nextTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content) viewModel.nextTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
page_view.chapterLoadFinish(1) page_view.upContent()
} }
} }
} }

@ -110,40 +110,6 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
return pageDelegate?.onTouch(event) ?: super.onTouchEvent(event) return pageDelegate?.onTouch(event) ?: super.onTouchEvent(event)
} }
fun chapterLoadFinish(chapterOnDur: Int = 0) {
callback?.let { cb ->
when (chapterOnDur) {
0 -> {
cb.textChapter()?.let {
curPage?.setContent(it.page(cb.durChapterPos()))
if (cb.durChapterPos() > 0) {
prevPage?.setContent(it.page(cb.durChapterPos().minus(1)))
}
if (cb.durChapterPos() < it.pageSize().minus(1)) {
nextPage?.setContent(it.page(cb.durChapterPos().plus(1)))
}
}
}
1 -> {
cb.textChapter()?.let {
if (cb.durChapterPos() == it.pageSize().minus(1)) {
nextPage?.setContent(cb.textChapter(1)?.page(0))
}
}
}
-1 -> {
cb.textChapter()?.let {
if (cb.durChapterPos() == 0) {
prevPage?.setContent(cb.textChapter(-1)?.lastPage())
}
}
}
else -> {
}
}
}
}
fun fillPage(direction: PageDelegate.Direction) { fun fillPage(direction: PageDelegate.Direction) {
pageFactory?.let { pageFactory?.let {
when (direction) { when (direction) {
@ -172,14 +138,6 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
upContent() upContent()
} }
override fun hasNext(): Boolean {
return true
}
override fun hasPrev(): Boolean {
return true
}
fun upContent() { fun upContent() {
pageFactory?.let { pageFactory?.let {
prevPage?.setContent(it.previousPage()) prevPage?.setContent(it.previousPage())
@ -188,6 +146,14 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
} }
} }
override fun hasNext(): Boolean {
return true
}
override fun hasPrev(): Boolean {
return true
}
fun upStyle() { fun upStyle() {
curPage?.upStyle() curPage?.upStyle()
prevPage?.upStyle() prevPage?.upStyle()

Loading…
Cancel
Save