优化
This commit is contained in:
@@ -104,6 +104,9 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
isGone = ReadBookConfig.hideStatusBar || readBookActivity?.isInMultiWindow == true
|
isGone = ReadBookConfig.hideStatusBar || readBookActivity?.isInMultiWindow == true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新阅读信息
|
||||||
|
*/
|
||||||
private fun upTipStyle() = binding.run {
|
private fun upTipStyle() = binding.run {
|
||||||
tvHeaderLeft.tag = null
|
tvHeaderLeft.tag = null
|
||||||
tvHeaderMiddle.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 {
|
private fun getTipView(tip: Int): BatteryView? = binding.run {
|
||||||
return when (tip) {
|
return when (tip) {
|
||||||
ReadTipConfig.tipHeaderLeft -> tvHeaderLeft
|
ReadTipConfig.tipHeaderLeft -> tvHeaderLeft
|
||||||
@@ -201,6 +208,9 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新背景
|
||||||
|
*/
|
||||||
fun upBg() {
|
fun upBg() {
|
||||||
if (ReadBookConfig.bgAlpha < 100) {
|
if (ReadBookConfig.bgAlpha < 100) {
|
||||||
binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor
|
binding.vwRoot.backgroundColor = ReadBookConfig.bgMeanColor
|
||||||
@@ -211,15 +221,24 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
upBgAlpha()
|
upBgAlpha()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新背景透明度
|
||||||
|
*/
|
||||||
fun upBgAlpha() {
|
fun upBgAlpha() {
|
||||||
binding.vwBg.alpha = ReadBookConfig.bgAlpha / 100f
|
binding.vwBg.alpha = ReadBookConfig.bgAlpha / 100f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间信息
|
||||||
|
*/
|
||||||
fun upTime() {
|
fun upTime() {
|
||||||
tvTime?.text = timeFormat.format(Date(System.currentTimeMillis()))
|
tvTime?.text = timeFormat.format(Date(System.currentTimeMillis()))
|
||||||
upTimeBattery()
|
upTimeBattery()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新电池信息
|
||||||
|
*/
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
fun upBattery(battery: Int) {
|
fun upBattery(battery: Int) {
|
||||||
this.battery = battery
|
this.battery = battery
|
||||||
@@ -228,6 +247,9 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
upTimeBattery()
|
upTimeBattery()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新电池信息
|
||||||
|
*/
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
private fun upTimeBattery() {
|
private fun upTimeBattery() {
|
||||||
val time = timeFormat.format(Date(System.currentTimeMillis()))
|
val time = timeFormat.format(Date(System.currentTimeMillis()))
|
||||||
@@ -235,6 +257,9 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
tvTimeBatteryP?.text = "$time $battery%"
|
tvTimeBatteryP?.text = "$time $battery%"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置内容
|
||||||
|
*/
|
||||||
fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {
|
fun setContent(textPage: TextPage, resetPageOffset: Boolean = true) {
|
||||||
setProgress(textPage)
|
setProgress(textPage)
|
||||||
if (resetPageOffset) {
|
if (resetPageOffset) {
|
||||||
@@ -243,14 +268,23 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
binding.contentTextView.setContent(textPage)
|
binding.contentTextView.setContent(textPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置无障碍文本
|
||||||
|
*/
|
||||||
fun setContentDescription(content: String) {
|
fun setContentDescription(content: String) {
|
||||||
binding.contentTextView.contentDescription = content
|
binding.contentTextView.contentDescription = content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置滚动位置
|
||||||
|
*/
|
||||||
fun resetPageOffset() {
|
fun resetPageOffset() {
|
||||||
binding.contentTextView.resetPageOffset()
|
binding.contentTextView.resetPageOffset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置进度
|
||||||
|
*/
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
fun setProgress(textPage: TextPage) = textPage.apply {
|
fun setProgress(textPage: TextPage) = textPage.apply {
|
||||||
tvBookName?.text = ReadBook.book?.name
|
tvBookName?.text = ReadBook.book?.name
|
||||||
@@ -260,14 +294,31 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
tvPageAndTotal?.text = "${index.plus(1)}/$pageSize $readProgress"
|
tvPageAndTotal?.text = "${index.plus(1)}/$pageSize $readProgress"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 滚动事件
|
||||||
|
*/
|
||||||
fun scroll(offset: Int) {
|
fun scroll(offset: Int) {
|
||||||
binding.contentTextView.scroll(offset)
|
binding.contentTextView.scroll(offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新是否开启选择功能
|
||||||
|
*/
|
||||||
fun upSelectAble(selectAble: Boolean) {
|
fun upSelectAble(selectAble: Boolean) {
|
||||||
binding.contentTextView.selectAble = selectAble
|
binding.contentTextView.selectAble = selectAble
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优先处理页面内单击
|
||||||
|
* @return true:已处理, false:未处理
|
||||||
|
*/
|
||||||
|
fun onClick(x: Float, y: Float): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 长按事件
|
||||||
|
*/
|
||||||
fun longPress(
|
fun longPress(
|
||||||
x: Float, y: Float,
|
x: Float, y: Float,
|
||||||
select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit,
|
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)
|
return binding.contentTextView.longPress(x, y - headerHeight, select)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选择文本
|
||||||
|
*/
|
||||||
fun selectText(
|
fun selectText(
|
||||||
x: Float, y: Float,
|
x: Float, y: Float,
|
||||||
select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit,
|
select: (relativePagePos: Int, lineIndex: Int, charIndex: Int) -> Unit,
|
||||||
|
|||||||
@@ -222,7 +222,9 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
pressDown = false
|
pressDown = false
|
||||||
if (!isPageMove) {
|
if (!isPageMove) {
|
||||||
if (!longPressed && !pressOnTextSelected) {
|
if (!longPressed && !pressOnTextSelected) {
|
||||||
onSingleTapUp()
|
if (!curPage.onClick(startX, startY)) {
|
||||||
|
onSingleTapUp()
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user