feat: 优化代码

pull/379/head
kunfei 5 years ago
parent 55d7b65075
commit 5944c994cb
  1. 1
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 15
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
  3. 18
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  4. 8
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt
  5. 2
      app/src/main/res/xml/pref_config_read.xml

@ -43,6 +43,7 @@ object ReadBookConfig {
App.INSTANCE.putPrefInt(PreferKey.pageAnim, value)
}
var isScroll = pageAnim == 3
val clickTurnPage get() = App.INSTANCE.getPrefBoolean(PreferKey.clickTurnPage, true)
var bg: Drawable? = null
init {

@ -52,4 +52,19 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie
}
}
override fun nextPageByAnim() {
if (!hasNext()) return
setDirection(Direction.NEXT)
setBitmap()
setTouchPoint(viewWidth.toFloat(), 0f)
onAnimStart()
}
override fun prevPageByAnim() {
if (!hasPrev()) return
setDirection(Direction.PREV)
setBitmap()
setTouchPoint(0f, 0f)
onAnimStart()
}
}

@ -12,6 +12,7 @@ import android.widget.Scroller
import androidx.annotation.CallSuper
import com.google.android.material.snackbar.Snackbar
import io.legado.app.help.AppConfig
import io.legado.app.help.ReadBookConfig
import io.legado.app.ui.book.read.page.ContentView
import io.legado.app.ui.book.read.page.PageView
import io.legado.app.utils.screenshot
@ -193,6 +194,10 @@ abstract class PageDelegate(protected val pageView: PageView) :
open fun onScroll() {}//移动contentView, slidePage
abstract fun nextPageByAnim()
abstract fun prevPageByAnim()
@CallSuper
open fun setDirection(direction: Direction) {
mDirection = direction
@ -260,21 +265,14 @@ abstract class PageDelegate(protected val pageView: PageView) :
if (centerRectF.contains(x, y)) {
pageView.callBack.clickCenter()
setTouchPoint(x, y)
} else {
} else if (ReadBookConfig.clickTurnPage) {
if (x > viewWidth / 2 ||
AppConfig.clickAllNext
) {
//设置动画方向
if (!hasNext()) return true
setDirection(Direction.NEXT)
setBitmap()
nextPageByAnim()
} else {
if (!hasPrev()) return true
setDirection(Direction.PREV)
setBitmap()
prevPageByAnim()
}
setTouchPoint(x, y)
onAnimStart()
}
return true
}

@ -58,4 +58,12 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) {
super.onDestroy()
mVelocity.recycle()
}
override fun nextPageByAnim() {
}
override fun prevPageByAnim() {
}
}

@ -29,7 +29,7 @@
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false"
android:defaultValue="true"
android:title="@string/click_turn_page"
android:key="clickTurnPage"
app:iconSpaceReserved="false" />

Loading…
Cancel
Save