From 2c314a074590c7f391cc00845d272a7b0043128e Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 12:25:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 7 +++++ .../app/ui/book/read/page/PageFactory.kt | 2 +- .../legado/app/ui/book/read/page/PageView.kt | 2 +- .../app/ui/book/read/page/TextPageFactory.kt | 27 +++++++++---------- 4 files changed, 22 insertions(+), 16 deletions(-) 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() - } }