diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 0c954dbb0..e8e64d16a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -271,18 +271,18 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } } KeyEvent.KEYCODE_SPACE -> { - page_view.moveToNextPage() + page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT) return true } getPrefInt(PreferKey.prevKey) -> { if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { - page_view.moveToPrevPage() + page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.PREV) return true } } getPrefInt(PreferKey.nextKey) -> { if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { - page_view.moveToNextPage() + page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT) return true } } @@ -440,11 +440,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo if (getPrefBoolean("volumeKeyPageOnPlay") || BaseReadAloudService.pause ) { - when (direction) { - PageDelegate.Direction.PREV -> page_view.moveToPrevPage() - PageDelegate.Direction.NEXT -> page_view.moveToNextPage() - else -> return true - } + page_view.pageDelegate?.keyTurnPage(direction) return true } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 18c9cb491..7f89a98a7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -117,22 +117,6 @@ class PageView(context: Context, attrs: AttributeSet) : callBack.screenOffTimerStart() } - fun moveToPrevPage(noAnim: Boolean = false) { - if (noAnim) { - fillPage(PageDelegate.Direction.PREV) - } else { - pageDelegate?.prevPageByAnim() - } - } - - fun moveToNextPage(noAnim: Boolean = false) { - if (noAnim) { - fillPage(PageDelegate.Direction.NEXT) - } else { - pageDelegate?.nextPageByAnim() - } - } - fun upStyle() { ChapterProvider.upStyle() curPage.upStyle() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 7b649c958..fef7e5b0e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -169,6 +169,15 @@ abstract class PageDelegate(protected val pageView: PageView) : abort() } + open fun keyTurnPage(direction: Direction) { + if (isRunning) return + when (direction) { + Direction.NEXT -> nextPageByAnim() + Direction.PREV -> prevPageByAnim() + else -> return + } + } + @CallSuper open fun setDirection(direction: Direction) { mDirection = direction