mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
00a42a05ef
commit
2d7e3cfe04
@ -294,14 +294,27 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
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()
|
||||
if (BaseReadAloudService.isRun) {
|
||||
val scrollPageAnim = pageAnim() == 3
|
||||
if (scrollPageAnim && pauseReadAloud) {
|
||||
if (scrollPageAnim && pageChanged) {
|
||||
ReadAloud.pause(appCtx)
|
||||
} else {
|
||||
readAloud(!BaseReadAloudService.pause)
|
||||
|
@ -1381,11 +1381,8 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
override fun onLayoutPageCompleted(index: Int, page: TextPage) {
|
||||
upSeekBarThrottle.invoke()
|
||||
if (upContent) {
|
||||
val line = page.lines.first()
|
||||
val durChapterPos = ReadBook.durChapterPos
|
||||
val startPos = line.chapterPosition
|
||||
val endPos = startPos + line.charSize
|
||||
if (durChapterPos in startPos..<endPos) {
|
||||
if (page.containPos(durChapterPos)) {
|
||||
runOnUiThread {
|
||||
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) {
|
||||
if (index < ReadBook.chapterSize) {
|
||||
ReadBook.clearTextChapter()
|
||||
ReadBook.callBack?.upContent()
|
||||
ReadBook.durChapterIndex = index
|
||||
ReadBook.durChapterPos = durChapterPos
|
||||
ReadBook.saveRead()
|
||||
ReadBook.loadContent(resetPageOffset = true) {
|
||||
success?.invoke()
|
||||
}
|
||||
}
|
||||
ReadBook.openChapter(index, durChapterPos, success)
|
||||
}
|
||||
|
||||
fun removeFromBookshelf(success: (() -> Unit)?) {
|
||||
|
@ -47,6 +47,7 @@ data class TextPage(
|
||||
var doublePage = false
|
||||
var paddingTop = 0
|
||||
var isCompleted = false
|
||||
|
||||
@JvmField
|
||||
var textChapter = emptyTextChapter
|
||||
val pageSize get() = textChapter.pageSize
|
||||
@ -256,6 +257,19 @@ data class TextPage(
|
||||
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) {
|
||||
render(view)
|
||||
canvas.withTranslation(0f, relativeOffset + paddingTop) {
|
||||
|
Loading…
Reference in New Issue
Block a user