From 6f7581a254401eb53936121472b4a02ab3815875 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 6 Sep 2022 20:39:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/PageView.kt | 54 +++++++++++++++++++ .../legado/app/ui/book/read/page/ReadView.kt | 4 +- 2 files changed, 57 insertions(+), 1 deletion(-) 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 f8d86fa9e..0b15507c7 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 @@ -104,6 +104,9 @@ class PageView(context: Context) : FrameLayout(context) { isGone = ReadBookConfig.hideStatusBar || readBookActivity?.isInMultiWindow == true } + /** + * 更新阅读信息 + */ private fun upTipStyle() = binding.run { tvHeaderLeft.tag = null tvHeaderMiddle.tag = null @@ -189,6 +192,10 @@ class PageView(context: Context) : FrameLayout(context) { } } + /** + * 获取信息视图 + * @param tip 信息类型 + */ private fun getTipView(tip: Int): BatteryView? = binding.run { return when (tip) { ReadTipConfig.tipHeaderLeft -> tvHeaderLeft @@ -201,6 +208,9 @@ class PageView(context: Context) : FrameLayout(context) { } } + /** + * 更新背景 + */ fun upBg() { if (ReadBookConfig.bgAlpha < 100) { binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor @@ -211,15 +221,24 @@ class PageView(context: Context) : FrameLayout(context) { upBgAlpha() } + /** + * 更新背景透明度 + */ fun upBgAlpha() { binding.vwBg.alpha = ReadBookConfig.bgAlpha / 100f } + /** + * 更新时间信息 + */ fun upTime() { tvTime?.text = timeFormat.format(Date(System.currentTimeMillis())) upTimeBattery() } + /** + * 更新电池信息 + */ @SuppressLint("SetTextI18n") fun upBattery(battery: Int) { this.battery = battery @@ -228,6 +247,9 @@ class PageView(context: Context) : FrameLayout(context) { upTimeBattery() } + /** + * 更新电池信息 + */ @SuppressLint("SetTextI18n") private fun upTimeBattery() { val time = timeFormat.format(Date(System.currentTimeMillis())) @@ -235,6 +257,9 @@ class PageView(context: Context) : FrameLayout(context) { tvTimeBatteryP?.text = "$time $battery%" } + /** + * 设置内容 + */ fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) { setProgress(textPage) if (resetPageOffset) { @@ -243,14 +268,23 @@ class PageView(context: Context) : FrameLayout(context) { binding.contentTextView.setContent(textPage) } + /** + * 设置无障碍文本 + */ fun setContentDescription(content: String) { binding.contentTextView.contentDescription = content } + /** + * 重置滚动位置 + */ fun resetPageOffset() { binding.contentTextView.resetPageOffset() } + /** + * 设置进度 + */ @SuppressLint("SetTextI18n") fun setProgress(textPage: TextPage) = textPage.apply { tvBookName?.text = ReadBook.book?.name @@ -260,14 +294,31 @@ class PageView(context: Context) : FrameLayout(context) { tvPageAndTotal?.text = "${index.plus(1)}/$pageSize $readProgress" } + /** + * 滚动事件 + */ fun scroll(offset: Int) { binding.contentTextView.scroll(offset) } + /** + * 更新是否开启选择功能 + */ fun upSelectAble(selectAble: Boolean) { binding.contentTextView.selectAble = selectAble } + /** + * 优先处理页面内单击 + * @return true:已处理, false:未处理 + */ + fun onClick(x: Float, y: Float): Boolean { + return false + } + + /** + * 长按事件 + */ fun longPress( x: Float, y: Float, select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit, @@ -275,6 +326,9 @@ class PageView(context: Context) : FrameLayout(context) { return binding.contentTextView.longPress(x, y - headerHeight, select) } + /** + * 选择文本 + */ fun selectText( x: Float, y: Float, select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt index 6a8abc9bf..b4fef733a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt @@ -222,7 +222,9 @@ class ReadView(context: Context, attrs: AttributeSet) : pressDown = false if (!isPageMove) { if (!longPressed && !pressOnTextSelected) { - onSingleTapUp() + if (!curPage.onClick(startX, startY)) { + onSingleTapUp() + } return true } }