diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 845fccbb2..207c34ec6 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -312,7 +312,7 @@ object ReadBook { } interface CallBack { - fun upContent(relativePosition: Int = 0, resetScrollOffset: Boolean = true) + fun upContent(relativePosition: Int = 0) fun upView() fun upPageProgress() fun contentLoadFinish() 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 abe5f1925..16b198626 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 @@ -456,9 +456,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 更新内容 */ - override fun upContent(relativePosition: Int, resetScrollOffset: Boolean) { + override fun upContent(relativePosition: Int) { launch { - page_view.upContent(relativePosition, resetScrollOffset) + page_view.upContent(relativePosition) } } 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 bb759b079..33388fc63 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 @@ -17,6 +17,8 @@ import io.legado.app.utils.getPrefBoolean class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) { + var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) + var upView: ((TextPage) -> Unit)? = null private val selectedPaint by lazy { Paint().apply { color = context.getCompatColor(R.color.btn_bg_press_2) @@ -24,7 +26,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } private var callBack: CallBack - var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) private var selectLineStart = 0 private var selectCharStart = 0 private var selectLineEnd = 0 @@ -159,12 +160,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at pageFactory.moveToPrev() textPage = pageFactory.currentPage ?: TextPage().format() pageOffset -= textPage.height - callBack.upContent(0, false) + upView?.invoke(textPage) } else if (pageOffset < -textPage.height) { pageOffset += textPage.height pageFactory.moveToNext() textPage = pageFactory.currentPage ?: TextPage().format() - callBack.upContent(0, false) + upView?.invoke(textPage) } invalidate() } @@ -302,7 +303,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } interface CallBack { - fun upContent(relativePosition: Int, resetScrollOffset: Boolean) fun upSelectedStart(x: Float, y: Float) fun upSelectedEnd(x: Float, y: Float) fun onCancelSelect() 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 45fa4c1d7..3613f17bd 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 @@ -25,6 +25,11 @@ class ContentView(context: Context) : FrameLayout(context) { upStyle() upTime() + content_text_view.upView = { + tv_bottom_left.text = it.title + pageSize = it.pageSize + setPageIndex(it.index) + } } fun upStyle() { @@ -91,17 +96,13 @@ class ContentView(context: Context) : FrameLayout(context) { tv_top_right.text = context.getString(R.string.battery_show, battery) } - fun setContent(textPage: TextPage?, resetScrollOffset: Boolean = true) { + fun setContent(textPage: TextPage?) { if (textPage != null) { tv_bottom_left.text = textPage.title pageSize = textPage.pageSize setPageIndex(textPage.index) - if (resetScrollOffset) { - content_text_view.resetPageOffset() - content_text_view.setContent(textPage) - } else { - content_text_view.invalidate() - } + content_text_view.resetPageOffset() + content_text_view.setContent(textPage) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt b/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt index 6fe49e43f..106e2e4db 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt @@ -16,5 +16,4 @@ interface DataSource { fun hasNextChapter(): Boolean fun hasPrevChapter(): Boolean - } \ No newline at end of file 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 8421b68d9..f115eabce 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 @@ -98,9 +98,9 @@ class PageView(context: Context, attrs: AttributeSet) : upContent() } - fun upContent(relativePosition: Int = 0, resetScrollOffset: Boolean = true) { + fun upContent(relativePosition: Int = 0) { if (ReadBookConfig.isScroll) { - curPage.setContent(pageFactory.currentPage, resetScrollOffset) + curPage.setContent(pageFactory.currentPage) } else { when (relativePosition) { -1 -> prevPage.setContent(pageFactory.prevPage)