pull/2250/head
kunfei 2 years ago
parent 4e5a4d434e
commit 6f7581a254
  1. 54
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.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,

@ -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
}
}

Loading…
Cancel
Save