feat: 优化代码

pull/133/head
kunfei 5 years ago
parent b791d443bf
commit 59793be8c5
  1. 12
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 16
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  3. 9
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt

@ -271,18 +271,18 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
} }
} }
KeyEvent.KEYCODE_SPACE -> { KeyEvent.KEYCODE_SPACE -> {
page_view.moveToNextPage() page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT)
return true return true
} }
getPrefInt(PreferKey.prevKey) -> { getPrefInt(PreferKey.prevKey) -> {
if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
page_view.moveToPrevPage() page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.PREV)
return true return true
} }
} }
getPrefInt(PreferKey.nextKey) -> { getPrefInt(PreferKey.nextKey) -> {
if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
page_view.moveToNextPage() page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT)
return true return true
} }
} }
@ -440,11 +440,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
if (getPrefBoolean("volumeKeyPageOnPlay") if (getPrefBoolean("volumeKeyPageOnPlay")
|| BaseReadAloudService.pause || BaseReadAloudService.pause
) { ) {
when (direction) { page_view.pageDelegate?.keyTurnPage(direction)
PageDelegate.Direction.PREV -> page_view.moveToPrevPage()
PageDelegate.Direction.NEXT -> page_view.moveToNextPage()
else -> return true
}
return true return true
} }
} }

@ -117,22 +117,6 @@ class PageView(context: Context, attrs: AttributeSet) :
callBack.screenOffTimerStart() 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() { fun upStyle() {
ChapterProvider.upStyle() ChapterProvider.upStyle()
curPage.upStyle() curPage.upStyle()

@ -169,6 +169,15 @@ abstract class PageDelegate(protected val pageView: PageView) :
abort() abort()
} }
open fun keyTurnPage(direction: Direction) {
if (isRunning) return
when (direction) {
Direction.NEXT -> nextPageByAnim()
Direction.PREV -> prevPageByAnim()
else -> return
}
}
@CallSuper @CallSuper
open fun setDirection(direction: Direction) { open fun setDirection(direction: Direction) {
mDirection = direction mDirection = direction

Loading…
Cancel
Save