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 e8835130a..6d39baa83 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 @@ -85,7 +85,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo private val mHandler = Handler() private val keepScreenRunnable: Runnable = Runnable { Help.keepScreenOn(window, false) } - + private val autoPageRunnable: Runnable = Runnable { autoPagePlus() } + private var autoPageProgress = 0 + private var isAutoPage = false private var screenTimeOut: Long = 0 private var timeBatteryReceiver: TimeBatteryReceiver? = null override val pageFactory: TextPageFactory get() = page_view.pageFactory @@ -558,7 +560,25 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo * 自动翻页 */ override fun autoPage() { + if (isAutoPage) { + isAutoPage = false + mHandler.removeCallbacks(autoPageRunnable) + page_view.upContent() + } else { + isAutoPage = true + autoPagePlus() + } + read_menu.setAutoPage(isAutoPage) + } + private fun autoPagePlus() { + mHandler.removeCallbacks(autoPageRunnable) + autoPageProgress++ + if (autoPageProgress >= 46) { + autoPageProgress = 0 + ReadBook.moveToNextPage() + } + mHandler.postDelayed(autoPageRunnable, 100) } /** diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index f8f9bec74..774f522be 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -104,7 +104,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie } override fun nextPageByAnim() { - super.nextPageByAnim() + abort() if (!hasNext()) return setDirection(Direction.NEXT) setTouchPoint(viewWidth.toFloat(), 0f) @@ -112,7 +112,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie } override fun prevPageByAnim() { - super.prevPageByAnim() + abort() if (!hasPrev()) return setDirection(Direction.PREV) setTouchPoint(0f, 0f) 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 cd455b641..2f3bf9728 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 @@ -170,13 +170,9 @@ abstract class PageDelegate(protected val pageView: PageView) : open fun onScroll() {}//移动contentView, slidePage - open fun nextPageByAnim() { - abort() - } + abstract fun nextPageByAnim() - open fun prevPageByAnim() { - abort() - } + abstract fun prevPageByAnim() open fun keyTurnPage(direction: Direction) { if (isRunning) return diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 3fa333cbf..b00578ec2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -79,12 +79,12 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } override fun nextPageByAnim() { - super.nextPageByAnim() + abort() startScroll(0, 0, 0, -ChapterProvider.visibleHeight) } override fun prevPageByAnim() { - super.prevPageByAnim() + abort() startScroll(0, 0, 0, ChapterProvider.visibleHeight) } } \ No newline at end of file