diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index eaf619d83..efafce804 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -37,6 +37,7 @@ import io.legado.app.ui.sourceedit.SourceEditActivity 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_read_book.* import kotlinx.android.synthetic.main.view_book_page.* @@ -248,10 +249,17 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } } KeyEvent.KEYCODE_VOLUME_UP -> { + if (volumeKeyPage(PageDelegate.Direction.PREV)) { + return true + } } KeyEvent.KEYCODE_VOLUME_DOWN -> { + if (volumeKeyPage(PageDelegate.Direction.NEXT)) { + return true + } } KeyEvent.KEYCODE_SPACE -> { + } } return super.onKeyDown(keyCode, event) @@ -260,12 +268,35 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean { when (keyCode) { KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN -> { - + if (volumeKeyPage(PageDelegate.Direction.NONE)) { + return true + } } } return super.onKeyUp(keyCode, event) } + private fun volumeKeyPage(direction: PageDelegate.Direction): Boolean { + if (!read_menu.isVisible) { + if (getPrefBoolean("volumeKeyPage", true)) { + if (getPrefBoolean("volumeKeyPageOnPlay") + || readAloudStatus != Status.PLAY + ) { + when (direction) { + PageDelegate.Direction.PREV -> { + + } + PageDelegate.Direction.NEXT -> { + + } + } + return true + } + } + } + return false + } + /** * 加载章节内容 */ diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index f10eeda81..6f211bf0b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -156,11 +156,11 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att } override fun hasNext(): Boolean { - return true + return pageFactory?.hasNext() == true } override fun hasPrev(): Boolean { - return true + return pageFactory?.hasPrev() == true } fun upStyle() { diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt index 60df9a04a..801f23ea7 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt @@ -26,7 +26,7 @@ data class TextChapter( } fun isLastIndex(index: Int): Boolean { - return index == pages.size - 1 + return index >= pages.size - 1 } fun pageSize(): Int { diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt index 96d646c3d..332537f48 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt @@ -10,11 +10,12 @@ class TextPageFactory private constructor(dataSource: DataSource) : } override fun hasPrev(): Boolean { - return true + return dataSource.hasPrevChapter() || dataSource.pageIndex() > 0 } override fun hasNext(): Boolean { - return true + return dataSource.hasNextChapter() + || dataSource.getCurrentChapter()?.isLastIndex(dataSource.pageIndex()) != true } override fun pageAt(index: Int): TextPage {