From 9b128ab5f408c3f362aee0133950df3a73682aa9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 22 Feb 2020 19:14:26 +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 | 8 ++++++ .../app/ui/book/read/page/ContentView.kt | 14 ---------- .../legado/app/ui/book/read/page/PageView.kt | 28 ++----------------- 3 files changed, 10 insertions(+), 40 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 fbd4b62be..fe9bb85b6 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 @@ -16,6 +16,7 @@ import io.legado.app.utils.getPrefBoolean class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) { + private val maxScrollOffset = 100f private val selectedPaint by lazy { Paint().apply { color = context.getCompatColor(R.color.btn_bg_press_2) @@ -84,6 +85,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } fun onScroll(offset: Float) { + var mOffset = offset + if (offset > maxScrollOffset) { + mOffset = maxScrollOffset + } else if (offset < -maxScrollOffset) { + mOffset = -maxScrollOffset + } + } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index f3171b8d2..51e3ad850 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -135,20 +135,6 @@ class ContentView(context: Context) : FrameLayout(context) { val selectedText: String get() = content_text_view.selectedText - fun scrollTo(pos: Int?) { - if (pos != null) { - content_text_view.post { - - } - } - } - - fun scrollToBottom() { - content_text_view.post { - - } - } - interface CallBack { fun scrollToLine(line: Int) fun scrollToLast() 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 88d3fb1c1..919de9c54 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 @@ -75,16 +75,10 @@ class PageView(context: Context, attrs: AttributeSet) : PageDelegate.Direction.PREV -> { pageFactory?.moveToPrevious() upContent() - if (isScrollDelegate) { - curPage.scrollToBottom() - } } PageDelegate.Direction.NEXT -> { pageFactory?.moveToNext() upContent() - if (isScrollDelegate) { - curPage.scrollTo(0) - } } else -> Unit } @@ -112,27 +106,15 @@ class PageView(context: Context, attrs: AttributeSet) : curPage.setContent(it.currentPage()) nextPage.setContent(it.nextPage()) prevPage.setContent(it.previousPage()) - if (isScrollDelegate) { - curPage.scrollTo(ReadBook.textChapter()?.getStartLine(ReadBook.durChapterPos())) - } } } - if (isScrollDelegate) { - prevPage.scrollToBottom() - } } callBack?.screenOffTimerStart() } fun moveToPrevPage(noAnim: Boolean = true) { if (noAnim) { - if (isScrollDelegate) { - ReadBook.textChapter()?.let { - curPage.scrollTo(it.getStartLine(pageIndex - 1)) - } - } else { - fillPage(PageDelegate.Direction.PREV) - } + fillPage(PageDelegate.Direction.PREV) } else { pageDelegate?.start(PageDelegate.Direction.PREV) } @@ -140,13 +122,7 @@ class PageView(context: Context, attrs: AttributeSet) : fun moveToNextPage(noAnim: Boolean = true) { if (noAnim) { - if (isScrollDelegate) { - ReadBook.textChapter()?.let { - curPage.scrollTo(it.getStartLine(pageIndex + 1)) - } - } else { - fillPage(PageDelegate.Direction.NEXT) - } + fillPage(PageDelegate.Direction.NEXT) } else { pageDelegate?.start(PageDelegate.Direction.NEXT) }