pull/34/head
kunfei 5 years ago
parent 7d0bdd52d3
commit 84efd785af
  1. 12
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  3. 8
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  4. 8
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt

@ -375,10 +375,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
/** /**
* 下一页 * 下一页
*/ */
override fun moveToNextChapter(): Boolean { override fun moveToNextChapter(upContent: Boolean): Boolean {
return if (viewModel.durChapterIndex < viewModel.chapterSize - 1) { return if (viewModel.durChapterIndex < viewModel.chapterSize - 1) {
viewModel.durPageIndex = 0 viewModel.durPageIndex = 0
viewModel.moveToNextChapter() viewModel.moveToNextChapter(upContent)
viewModel.saveRead() viewModel.saveRead()
curChapterChanged() curChapterChanged()
true true
@ -390,10 +390,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
/** /**
* 上一页 * 上一页
*/ */
override fun moveToPrevChapter(last: Boolean): Boolean { override fun moveToPrevChapter(upContent: Boolean, last: Boolean): Boolean {
return if (viewModel.durChapterIndex > 0) { return if (viewModel.durChapterIndex > 0) {
viewModel.durPageIndex = if (last) viewModel.prevTextChapter?.lastIndex() ?: 0 else 0 viewModel.durPageIndex = if (last) viewModel.prevTextChapter?.lastIndex() ?: 0 else 0
viewModel.moveToPrevChapter() viewModel.moveToPrevChapter(upContent)
viewModel.saveRead() viewModel.saveRead()
curChapterChanged() curChapterChanged()
true true
@ -586,14 +586,14 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
page_view.upContent() page_view.upContent()
viewModel.saveRead() viewModel.saveRead()
} }
2 -> if (!moveToNextChapter()) ReadAloud.stop(this) 2 -> if (!moveToNextChapter(true)) ReadAloud.stop(this)
-1 -> { -1 -> {
if (viewModel.durPageIndex > 0) { if (viewModel.durPageIndex > 0) {
viewModel.durPageIndex = viewModel.durPageIndex - 1 viewModel.durPageIndex = viewModel.durPageIndex - 1
page_view.upContent() page_view.upContent()
viewModel.saveRead() viewModel.saveRead()
} else { } else {
moveToPrevChapter() moveToPrevChapter(true)
} }
} }
-2 -> moveToPrevChapter(false) -2 -> moveToPrevChapter(false)

@ -108,7 +108,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun moveToNextChapter() { fun moveToNextChapter(upContent: Boolean) {
durChapterIndex++ durChapterIndex++
prevTextChapter = curTextChapter prevTextChapter = curTextChapter
curTextChapter = nextTextChapter curTextChapter = nextTextChapter
@ -116,7 +116,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
bookData.value?.let { bookData.value?.let {
if (curTextChapter == null) { if (curTextChapter == null) {
loadContent(it, durChapterIndex) loadContent(it, durChapterIndex)
} else { } else if (upContent) {
callBack?.upContent() callBack?.upContent()
} }
loadContent(it, durChapterIndex.plus(1)) loadContent(it, durChapterIndex.plus(1))
@ -131,7 +131,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun moveToPrevChapter() { fun moveToPrevChapter(upContent: Boolean) {
durChapterIndex-- durChapterIndex--
nextTextChapter = curTextChapter nextTextChapter = curTextChapter
curTextChapter = prevTextChapter curTextChapter = prevTextChapter
@ -139,7 +139,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
bookData.value?.let { bookData.value?.let {
if (curTextChapter == null) { if (curTextChapter == null) {
loadContent(it, durChapterIndex) loadContent(it, durChapterIndex)
} else { } else if (upContent) {
callBack?.upContent() callBack?.upContent()
} }
loadContent(it, durChapterIndex.minus(1)) loadContent(it, durChapterIndex.minus(1))

@ -153,10 +153,10 @@ class ReadMenu : FrameLayout {
} }
//上一章 //上一章
tv_pre.onClick { callBack?.moveToPrevChapter(false) } tv_pre.onClick { callBack?.moveToPrevChapter(upContent = true, last = false) }
//下一章 //下一章
tv_next.onClick { callBack?.moveToNextChapter() } tv_next.onClick { callBack?.moveToNextChapter(true) }
//目录 //目录
ll_catalog.onClick { ll_catalog.onClick {
@ -250,8 +250,8 @@ class ReadMenu : FrameLayout {
interface CallBack { interface CallBack {
fun autoPage() fun autoPage()
fun skipToPage(page: Int) fun skipToPage(page: Int)
fun moveToPrevChapter(last: Boolean): Boolean fun moveToPrevChapter(upContent: Boolean, last: Boolean): Boolean
fun moveToNextChapter(): Boolean fun moveToNextChapter(upContent: Boolean): Boolean
fun openReplaceRule() fun openReplaceRule()
fun openChapterList() fun openChapterList()
fun showReadStyle() fun showReadStyle()

@ -208,11 +208,11 @@ class PageView(context: Context, attrs: AttributeSet) :
} }
override fun moveToNextChapter() { override fun moveToNextChapter() {
callback?.moveToNextChapter() callback?.moveToNextChapter(false)
} }
override fun moveToPrevChapter() { override fun moveToPrevChapter() {
callback?.moveToPrevChapter() callback?.moveToPrevChapter(false)
} }
override fun scrollToLine(line: Int) { override fun scrollToLine(line: Int) {
@ -241,12 +241,12 @@ class PageView(context: Context, attrs: AttributeSet) :
/** /**
* 下一章 * 下一章
*/ */
fun moveToNextChapter(): Boolean fun moveToNextChapter(upContent: Boolean): Boolean
/** /**
* 上一章 * 上一章
*/ */
fun moveToPrevChapter(last: Boolean = true): Boolean fun moveToPrevChapter(upContent: Boolean, last: Boolean = true): Boolean
/** /**
* 保存页数 * 保存页数

Loading…
Cancel
Save