From b924cff588e2bd630d05a263e45bb713099d3293 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 19:34:07 +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/ReadBookActivity.kt | 3 +- .../app/ui/book/read/page/ContentTextView.kt | 15 +++++----- .../app/ui/book/read/page/TextPageFactory.kt | 28 +++---------------- .../book/read/page/delegate/PageDelegate.kt | 11 ++------ 4 files changed, 16 insertions(+), 41 deletions(-) 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 903dc3ebd..7d3d747aa 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 @@ -36,6 +36,7 @@ import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.ContentTextView import io.legado.app.ui.book.read.page.PageView +import io.legado.app.ui.book.read.page.TextPageFactory import io.legado.app.ui.book.read.page.delegate.PageDelegate import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.changesource.ChangeSourceDialog @@ -80,7 +81,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo private var screenTimeOut: Long = 0 private var timeElectricityReceiver: TimeElectricityReceiver? = null - + override val pageFactory: TextPageFactory get() = page_view.pageFactory override val headerHeight: Int get() = page_view.curPage.headerHeight override fun onActivityCreated(savedInstanceState: Bundle?) { 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 6902ae399..eeae9d33b 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 @@ -11,7 +11,6 @@ import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.accentColor -import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.activity import io.legado.app.utils.getCompatColor @@ -25,7 +24,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at style = Paint.Style.FILL } } - private var activityCallBack: CallBack + private var callBack: CallBack var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) private var selectLineStart = 0 private var selectCharStart = 0 @@ -33,13 +32,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private var selectCharEnd = 0 private var textPage: TextPage = TextPage() //滚动参数 + private val pageFactory: TextPageFactory get() = callBack.pageFactory private val maxScrollOffset = 100f private var pageOffset = 0f private var linePos = 0 private var isLastPage = false init { - activityCallBack = activity as CallBack + callBack = activity as CallBack contentDescription = textPage.text } @@ -127,7 +127,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at isLastPage = false } // 首页 - if (pageOffset < 0 && ReadBook.durChapterIndex == 0 && ReadBook.durPageIndex == 0) { + if (pageOffset < 0 && !pageFactory.hasPrev()) { pageOffset = 0f } @@ -245,11 +245,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } private fun upSelectedStart(x: Float, y: Float) { - activityCallBack.upSelectedStart(x, y + activityCallBack.headerHeight) + callBack.upSelectedStart(x, y + callBack.headerHeight) } private fun upSelectedEnd(x: Float, y: Float) { - activityCallBack.upSelectedEnd(x, y + activityCallBack.headerHeight) + callBack.upSelectedEnd(x, y + callBack.headerHeight) } fun cancelSelect() { @@ -259,7 +259,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } invalidate() - activityCallBack.onCancelSelect() + callBack.onCancelSelect() } val selectedText: String @@ -295,5 +295,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at fun upSelectedEnd(x: Float, y: Float) fun onCancelSelect() val headerHeight: Int + val pageFactory: TextPageFactory } } 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 03a222b94..018f75bab 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 @@ -6,20 +6,11 @@ import io.legado.app.ui.book.read.page.entities.TextPage class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource) { override fun hasPrev(): Boolean = with(dataSource) { - return if (isScrollDelegate) { - hasPrevChapter() - } else { - hasPrevChapter() || pageIndex > 0 - } + return hasPrevChapter() || pageIndex > 0 } override fun hasNext(): Boolean = with(dataSource) { - return if (isScrollDelegate) { - hasNextChapter() - } else { - hasNextChapter() - || getCurrentChapter()?.isLastIndex(pageIndex) != true - } + return hasNextChapter() || getCurrentChapter()?.isLastIndex(pageIndex) != true } override fun moveToFirst() { @@ -39,7 +30,6 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource override fun moveToNext(): Boolean = with(dataSource) { return if (hasNext()) { if (getCurrentChapter()?.isLastIndex(pageIndex) == true - || isScrollDelegate ) { ReadBook.moveToNextChapter(false) } else { @@ -52,7 +42,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource override fun moveToPrevious(): Boolean = with(dataSource) { return if (hasPrev()) { - if (pageIndex <= 0 || isScrollDelegate) { + if (pageIndex <= 0) { ReadBook.moveToPrevChapter(false) } else { setPageIndex(pageIndex.minus(1)) @@ -63,17 +53,10 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource } override fun currentPage(): TextPage? = with(dataSource) { - return if (isScrollDelegate) { - getCurrentChapter()?.scrollPage() - } else { - getCurrentChapter()?.page(pageIndex) - } + return getCurrentChapter()?.page(pageIndex) } override fun nextPage(): TextPage? = with(dataSource) { - if (isScrollDelegate) { - return getNextChapter()?.scrollPage() - } getCurrentChapter()?.let { if (pageIndex < it.pageSize() - 1) { return getCurrentChapter()?.page(pageIndex + 1)?.removePageAloudSpan() @@ -83,9 +66,6 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource } override fun previousPage(): TextPage? = with(dataSource) { - if (isScrollDelegate) { - return getPreviousChapter()?.scrollPage() - } if (pageIndex > 0) { return getCurrentChapter()?.page(pageIndex - 1)?.removePageAloudSpan() } 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 8075ce49c..2a90c79f1 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 @@ -134,15 +134,8 @@ abstract class PageDelegate(protected val pageView: PageView) : isRunning = false isStarted = false invalidate() - if (pageView.isScrollDelegate) { - pageView.postDelayed({ - bitmap?.recycle() - bitmap = null - }, 100) - } else { - bitmap?.recycle() - bitmap = null - } + bitmap?.recycle() + bitmap = null } fun setViewSize(width: Int, height: Int) {