diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index dfaa208ba..38b9f2d0b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -156,6 +156,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } pageOffset += offset + if (pageOffset > 0) { + pageFactory.moveToPrev() + pageOffset -= textPage.height + } else if (pageOffset < -textPage.height) { + pageOffset += textPage.height + pageFactory.moveToNext() + } invalidate() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt index a335505ff..db504b6f4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt @@ -8,7 +8,7 @@ abstract class PageFactory(protected val dataSource: DataSource) { abstract fun moveToNext():Boolean - abstract fun moveToPrevious(): Boolean + abstract fun moveToPrev(): Boolean abstract val nextPage: DATA? 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 4b5ee7dbd..a4841e3f0 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 @@ -74,7 +74,7 @@ class PageView(context: Context, attrs: AttributeSet) : fun fillPage(direction: PageDelegate.Direction) { when (direction) { PageDelegate.Direction.PREV -> { - pageFactory.moveToPrevious() + pageFactory.moveToPrev() upContent() } PageDelegate.Direction.NEXT -> { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt index cfcf3f6c9..db28bd813 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt @@ -29,8 +29,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource override fun moveToNext(): Boolean = with(dataSource) { return if (hasNext()) { - if (getCurrentChapter()?.isLastIndex(pageIndex) == true - ) { + if (getCurrentChapter()?.isLastIndex(pageIndex) == true) { ReadBook.moveToNextChapter(false) } else { setPageIndex(pageIndex.plus(1)) @@ -40,7 +39,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource false } - override fun moveToPrevious(): Boolean = with(dataSource) { + override fun moveToPrev(): Boolean = with(dataSource) { return if (hasPrev()) { if (pageIndex <= 0) { ReadBook.moveToPrevChapter(false) @@ -54,26 +53,26 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource override val currentPage: TextPage? get() = with(dataSource) { - return getCurrentChapter()?.page(pageIndex) - } + return getCurrentChapter()?.page(pageIndex) + } override val nextPage: TextPage? get() = with(dataSource) { - getCurrentChapter()?.let { - if (pageIndex < it.pageSize() - 1) { - return getCurrentChapter()?.page(pageIndex + 1)?.removePageAloudSpan() + getCurrentChapter()?.let { + if (pageIndex < it.pageSize() - 1) { + return getCurrentChapter()?.page(pageIndex + 1)?.removePageAloudSpan() + } } + return getNextChapter()?.page(0)?.removePageAloudSpan() } - return getNextChapter()?.page(0)?.removePageAloudSpan() - } override val prevPage: TextPage? get() = with(dataSource) { - if (pageIndex > 0) { - return getCurrentChapter()?.page(pageIndex - 1)?.removePageAloudSpan() + if (pageIndex > 0) { + return getCurrentChapter()?.page(pageIndex - 1)?.removePageAloudSpan() + } + return getPreviousChapter()?.lastPage()?.removePageAloudSpan() } - return getPreviousChapter()?.lastPage()?.removePageAloudSpan() - } }