|
|
@ -23,7 +23,9 @@ import io.legado.app.utils.getCompatColor |
|
|
|
import io.legado.app.utils.getPrefBoolean |
|
|
|
import io.legado.app.utils.getPrefBoolean |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 阅读内容界面 |
|
|
|
|
|
|
|
*/ |
|
|
|
class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) { |
|
|
|
class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) { |
|
|
|
var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) |
|
|
|
var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) |
|
|
|
var upView: ((TextPage) -> Unit)? = null |
|
|
|
var upView: ((TextPage) -> Unit)? = null |
|
|
@ -41,7 +43,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
|
|
|
|
|
|
|
|
//滚动参数 |
|
|
|
//滚动参数 |
|
|
|
private val pageFactory: TextPageFactory get() = callBack.pageFactory |
|
|
|
private val pageFactory: TextPageFactory get() = callBack.pageFactory |
|
|
|
private val maxScrollOffset = 100f |
|
|
|
|
|
|
|
private var pageOffset = 0f |
|
|
|
private var pageOffset = 0f |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
@ -173,17 +174,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun onScroll(mOffset: Float) { |
|
|
|
fun onScroll(mOffset: Float) { |
|
|
|
if (mOffset == 0f) return |
|
|
|
if (mOffset == 0f) return |
|
|
|
var offset = mOffset |
|
|
|
pageOffset += mOffset |
|
|
|
if (offset > maxScrollOffset) { |
|
|
|
|
|
|
|
offset = maxScrollOffset |
|
|
|
|
|
|
|
} else if (offset < -maxScrollOffset) { |
|
|
|
|
|
|
|
offset = -maxScrollOffset |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pageOffset += offset |
|
|
|
|
|
|
|
if (!pageFactory.hasPrev() && pageOffset > 0) { |
|
|
|
if (!pageFactory.hasPrev() && pageOffset > 0) { |
|
|
|
pageOffset = 0f |
|
|
|
pageOffset = 0f |
|
|
|
} else if (!pageFactory.hasNext() && pageOffset < 0) { |
|
|
|
} else if (!pageFactory.hasNext() |
|
|
|
|
|
|
|
&& pageOffset < 0 |
|
|
|
|
|
|
|
&& pageOffset + textPage.height < ChapterProvider.visibleHeight |
|
|
|
|
|
|
|
) { |
|
|
|
pageOffset = 0f |
|
|
|
pageOffset = 0f |
|
|
|
} else if (pageOffset > 0) { |
|
|
|
} else if (pageOffset > 0) { |
|
|
|
pageFactory.moveToPrev(false) |
|
|
|
pageFactory.moveToPrev(false) |
|
|
@ -263,7 +260,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
for ((charIndex, textChar) in textLine.textChars.withIndex()) { |
|
|
|
if (x > textChar.start && x < textChar.end) { |
|
|
|
if (x > textChar.start && x < textChar.end) { |
|
|
|
if (selectStart[0] != relativePos || selectStart[1] != lineIndex || selectStart[2] != charIndex) { |
|
|
|
if (selectStart[0] != relativePos || selectStart[1] != lineIndex || selectStart[2] != charIndex) { |
|
|
|
if (selectToInt(relativePos, lineIndex, charIndex) > selectToInt(selectEnd)) { |
|
|
|
if (selectToInt(relativePos, lineIndex, charIndex) > selectToInt( |
|
|
|
|
|
|
|
selectEnd |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
selectStart[0] = relativePos |
|
|
|
selectStart[0] = relativePos |
|
|
@ -306,7 +306,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at |
|
|
|
if (x > textChar.start && x < textChar.end) { |
|
|
|
if (x > textChar.start && x < textChar.end) { |
|
|
|
Log.e("char", "$relativePos $lineIndex $charIndex") |
|
|
|
Log.e("char", "$relativePos $lineIndex $charIndex") |
|
|
|
if (selectEnd[0] != relativePos || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { |
|
|
|
if (selectEnd[0] != relativePos || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { |
|
|
|
if (selectToInt(relativePos, lineIndex, charIndex) < selectToInt(selectStart)) { |
|
|
|
if (selectToInt(relativePos, lineIndex, charIndex) < selectToInt( |
|
|
|
|
|
|
|
selectStart |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
selectEnd[0] = relativePos |
|
|
|
selectEnd[0] = relativePos |
|
|
|