未完成的按钮点击

pull/2250/head
Seidko 2 years ago
parent b21659c23a
commit 4255749968
  1. 2
      app/src/main/java/io/legado/app/data/entities/rule/ReviewRule.kt
  2. 18
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  4. 5
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt

@ -14,7 +14,7 @@ data class ReviewRule(
// 这些功能将在以上功能完成以后实现 // 这些功能将在以上功能完成以后实现
var voteUpUrl: String? = null, // 点赞URL var voteUpUrl: String? = null, // 点赞URL
var voteDownUrl: String? = null, // 点踩URL var voteDownUrl: String? = null, // 点踩URL
var postReviewUrl: String? = null, // 发送回复URL var postReviewUrl: String? = null, // 发送回复URL
var postQuoteUrl: String? = null, // 发送回复段评URL var postQuoteUrl: String? = null, // 发送回复段评URL
var deleteUrl: String? = null, // 删除段评URL var deleteUrl: String? = null, // 删除段评URL
): Parcelable ): Parcelable

@ -51,6 +51,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
private var cacheIncreased = false private var cacheIncreased = false
private val increaseSize = 8 * 1024 * 1024 private val increaseSize = 8 * 1024 * 1024
private val maxCacheSize = 256 * 1024 * 1024 private val maxCacheSize = 256 * 1024 * 1024
private val reviewButtonArea: ArrayList<FloatArray> = arrayListOf()
//滚动参数 //滚动参数
private val pageFactory: TextPageFactory get() = callBack.pageFactory private val pageFactory: TextPageFactory get() = callBack.pageFactory
@ -110,6 +111,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
if (!pageFactory.hasNext()) return if (!pageFactory.hasNext()) return
val textPage1 = relativePage(1) val textPage1 = relativePage(1)
relativeOffset = relativeOffset(1) relativeOffset = relativeOffset(1)
reviewButtonArea.clear()
textPage1.textLines.forEach { textLine -> textPage1.textLines.forEach { textLine ->
draw(canvas, textPage1, textLine, relativeOffset) draw(canvas, textPage1, textLine, relativeOffset)
} }
@ -168,6 +170,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
} }
if (it.charData == "\uD83D\uDCAC" && it.isLineEnd) { if (it.charData == "\uD83D\uDCAC" && it.isLineEnd) {
if (textLine.reviewCount <= 0) return@forEach if (textLine.reviewCount <= 0) return@forEach
reviewButtonArea.add(
floatArrayOf(
it.start, lineBase, it.start + textPaint.textSize * 1.6F,
lineBase - textPaint.textSize * 0.8F,
)
)
canvas.drawLine( canvas.drawLine(
it.start, it.start,
lineBase - textPaint.textSize * 2 / 5, lineBase - textPaint.textSize * 2 / 5,
@ -338,6 +346,16 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
pageOffset = 0 pageOffset = 0
} }
/**
* 点击评论按钮
*/
fun pressReviewButton(x: Float, y: Float): Boolean {
reviewButtonArea.forEach {
if (x in it[0]..it[2] && y + textPage.height in it[3]..it[1]) return true
}
return false
}
/** /**
* 长按 * 长按
*/ */

@ -268,6 +268,10 @@ class PageView(context: Context) : FrameLayout(context) {
binding.contentTextView.selectAble = selectAble binding.contentTextView.selectAble = selectAble
} }
fun pressReviewButton(x: Float, y: Float): Boolean {
return binding.contentTextView.pressReviewButton(x, y)
}
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,

@ -28,6 +28,7 @@ import io.legado.app.ui.book.read.page.provider.TextPageFactory
import io.legado.app.utils.activity import io.legado.app.utils.activity
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import io.legado.app.utils.screenshot import io.legado.app.utils.screenshot
import io.legado.app.utils.toastOnUi
import java.text.BreakIterator import java.text.BreakIterator
import java.util.* import java.util.*
import kotlin.math.abs import kotlin.math.abs
@ -369,6 +370,10 @@ class ReadView(context: Context, attrs: AttributeSet) :
*/ */
private fun onSingleTapUp() { private fun onSingleTapUp() {
when { when {
curPage.pressReviewButton(startX, startY) -> {
context.toastOnUi("Button Pressed!")
ReadBook.upMsg(null)
}
isTextSelected -> Unit isTextSelected -> Unit
mcRect.contains(startX, startY) -> if (!isAbortAnim) { mcRect.contains(startX, startY) -> if (!isAbortAnim) {
click(AppConfig.clickActionMC) click(AppConfig.clickActionMC)

@ -8,7 +8,7 @@ import io.legado.app.utils.textHeight
data class TextLine( data class TextLine(
var text: String = "", var text: String = "",
val textChars: ArrayList<TextChar> = arrayListOf(), val textChars: ArrayList<TextChar> = arrayListOf(),
val reviewCount: Int = 0, val reviewCount: Int = 1,
var lineTop: Float = 0f, var lineTop: Float = 0f,
var lineBase: Float = 0f, var lineBase: Float = 0f,
var lineBottom: Float = 0f, var lineBottom: Float = 0f,

Loading…
Cancel
Save