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 -> {
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<ReadBookViewModel>(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
}
}

@ -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()

@ -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

Loading…
Cancel
Save