优化
This commit is contained in:
@@ -294,14 +294,27 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
curPageChanged(true)
|
curPageChanged(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) {
|
||||||
|
if (index < chapterSize) {
|
||||||
|
clearTextChapter()
|
||||||
|
callBack?.upContent()
|
||||||
|
durChapterIndex = index
|
||||||
|
ReadBook.durChapterPos = durChapterPos
|
||||||
|
saveRead()
|
||||||
|
loadContent(resetPageOffset = true) {
|
||||||
|
success?.invoke()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前页面变化
|
* 当前页面变化
|
||||||
*/
|
*/
|
||||||
private fun curPageChanged(pauseReadAloud: Boolean = false) {
|
private fun curPageChanged(pageChanged: Boolean = false) {
|
||||||
callBack?.pageChanged()
|
callBack?.pageChanged()
|
||||||
if (BaseReadAloudService.isRun) {
|
if (BaseReadAloudService.isRun) {
|
||||||
val scrollPageAnim = pageAnim() == 3
|
val scrollPageAnim = pageAnim() == 3
|
||||||
if (scrollPageAnim && pauseReadAloud) {
|
if (scrollPageAnim && pageChanged) {
|
||||||
ReadAloud.pause(appCtx)
|
ReadAloud.pause(appCtx)
|
||||||
} else {
|
} else {
|
||||||
readAloud(!BaseReadAloudService.pause)
|
readAloud(!BaseReadAloudService.pause)
|
||||||
|
|||||||
@@ -1381,11 +1381,8 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
override fun onLayoutPageCompleted(index: Int, page: TextPage) {
|
override fun onLayoutPageCompleted(index: Int, page: TextPage) {
|
||||||
upSeekBarThrottle.invoke()
|
upSeekBarThrottle.invoke()
|
||||||
if (upContent) {
|
if (upContent) {
|
||||||
val line = page.lines.first()
|
|
||||||
val durChapterPos = ReadBook.durChapterPos
|
val durChapterPos = ReadBook.durChapterPos
|
||||||
val startPos = line.chapterPosition
|
if (page.containPos(durChapterPos)) {
|
||||||
val endPos = startPos + line.charSize
|
|
||||||
if (durChapterPos in startPos..<endPos) {
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
binding.readView.upContent(0, resetPageOffset = false)
|
binding.readView.upContent(0, resetPageOffset = false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -317,16 +317,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) {
|
fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) {
|
||||||
if (index < ReadBook.chapterSize) {
|
ReadBook.openChapter(index, durChapterPos, success)
|
||||||
ReadBook.clearTextChapter()
|
|
||||||
ReadBook.callBack?.upContent()
|
|
||||||
ReadBook.durChapterIndex = index
|
|
||||||
ReadBook.durChapterPos = durChapterPos
|
|
||||||
ReadBook.saveRead()
|
|
||||||
ReadBook.loadContent(resetPageOffset = true) {
|
|
||||||
success?.invoke()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeFromBookshelf(success: (() -> Unit)?) {
|
fun removeFromBookshelf(success: (() -> Unit)?) {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ data class TextPage(
|
|||||||
var doublePage = false
|
var doublePage = false
|
||||||
var paddingTop = 0
|
var paddingTop = 0
|
||||||
var isCompleted = false
|
var isCompleted = false
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
var textChapter = emptyTextChapter
|
var textChapter = emptyTextChapter
|
||||||
val pageSize get() = textChapter.pageSize
|
val pageSize get() = textChapter.pageSize
|
||||||
@@ -256,6 +257,19 @@ data class TextPage(
|
|||||||
return textChapter
|
return textChapter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断章节字符位置是否在这一页中
|
||||||
|
*
|
||||||
|
* @param chapterPos 章节字符位置
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
fun containPos(chapterPos: Int): Boolean {
|
||||||
|
val line = lines.first()
|
||||||
|
val startPos = line.chapterPosition
|
||||||
|
val endPos = startPos + charSize
|
||||||
|
return chapterPos in startPos..<endPos
|
||||||
|
}
|
||||||
|
|
||||||
fun draw(view: ContentTextView, canvas: Canvas, relativeOffset: Float) {
|
fun draw(view: ContentTextView, canvas: Canvas, relativeOffset: Float) {
|
||||||
render(view)
|
render(view)
|
||||||
canvas.withTranslation(0f, relativeOffset + paddingTop) {
|
canvas.withTranslation(0f, relativeOffset + paddingTop) {
|
||||||
|
|||||||
Reference in New Issue
Block a user