This commit is contained in:
Horis
2025-11-13 08:36:48 +08:00
parent 43a89baf00
commit e13c12f00c
6 changed files with 36 additions and 17 deletions
@@ -447,10 +447,15 @@ object ReadBook : CoroutineScope by MainScope() {
} }
} }
fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) { fun openChapter(
index: Int,
durChapterPos: Int = 0,
upContent: Boolean = true,
success: (() -> Unit)? = null
) {
if (index < chapterSize) { if (index < chapterSize) {
clearTextChapter() clearTextChapter()
callBack?.upContent() if (upContent) callBack?.upContent()
durChapterIndex = index durChapterIndex = index
ReadBook.durChapterPos = durChapterPos ReadBook.durChapterPos = durChapterPos
saveRead() saveRead()
@@ -1329,10 +1329,17 @@ class ReadBookActivity : BaseReadBookActivity(),
ReadAloud.upReadAloudClass() ReadAloud.upReadAloudClass()
val scrollPageAnim = ReadBook.pageAnim() == 3 val scrollPageAnim = ReadBook.pageAnim() == 3
if (scrollPageAnim) { if (scrollPageAnim) {
val line = binding.readView.getCurVisibleFirstLine() val pos = binding.readView.getReadAloudPos()
if (line != null) { if (pos != null) {
ReadBook.durChapterPos = line.chapterPosition val (index, line) = pos
ReadBook.readAloud(startPos = line.pagePosition) if (ReadBook.durChapterIndex != index) {
ReadBook.openChapter(index, line.chapterPosition, false) {
ReadBook.readAloud(startPos = line.pagePosition)
}
} else {
ReadBook.durChapterPos = line.chapterPosition
ReadBook.readAloud(startPos = line.pagePosition)
}
} else { } else {
ReadBook.readAloud() ReadBook.readAloud()
} }
@@ -1345,10 +1352,17 @@ class ReadBookActivity : BaseReadBookActivity(),
val scrollPageAnim = ReadBook.pageAnim() == 3 val scrollPageAnim = ReadBook.pageAnim() == 3
if (scrollPageAnim && pageChanged) { if (scrollPageAnim && pageChanged) {
pageChanged = false pageChanged = false
val line = binding.readView.getCurVisibleFirstLine() val pos = binding.readView.getReadAloudPos()
if (line != null) { if (pos != null) {
ReadBook.durChapterPos = line.chapterPosition val (index, line) = pos
ReadBook.readAloud(startPos = line.pagePosition) if (ReadBook.durChapterIndex != index) {
ReadBook.openChapter(index, line.chapterPosition, false) {
ReadBook.readAloud(startPos = line.pagePosition)
}
} else {
ReadBook.durChapterPos = line.chapterPosition
ReadBook.readAloud(startPos = line.pagePosition)
}
} else { } else {
ReadBook.readAloud() ReadBook.readAloud()
} }
@@ -328,7 +328,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) {
ReadBook.openChapter(index, durChapterPos, success) ReadBook.openChapter(index, durChapterPos, success = success)
} }
fun removeFromBookshelf(success: (() -> Unit)?) { fun removeFromBookshelf(success: (() -> Unit)?) {
@@ -449,7 +449,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
return visiblePage return visiblePage
} }
fun getCurVisibleFirstLine(): TextLine? { fun getReadAloudPos(): Pair<Int, TextLine>? {
var relativeOffset: Float var relativeOffset: Float
for (relativePos in 0..2) { for (relativePos in 0..2) {
relativeOffset = relativeOffset(relativePos) relativeOffset = relativeOffset(relativePos)
@@ -467,7 +467,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
lineTop += relativeOffset lineTop += relativeOffset
lineBottom += relativeOffset lineBottom += relativeOffset
} }
return visibleLine return textPage.chapterIndex to visibleLine
} }
} }
} }
@@ -426,8 +426,8 @@ class PageView(context: Context) : FrameLayout(context) {
return binding.contentTextView.getCurVisiblePage() return binding.contentTextView.getCurVisiblePage()
} }
fun getCurVisibleFirstLine(): TextLine? { fun getReadAloudPos(): Pair<Int, TextLine>? {
return binding.contentTextView.getCurVisibleFirstLine() return binding.contentTextView.getReadAloudPos()
} }
fun markAsMainView() { fun markAsMainView() {
@@ -675,8 +675,8 @@ class ReadView(context: Context, attrs: AttributeSet) :
return curPage.getCurVisiblePage() return curPage.getCurVisiblePage()
} }
fun getCurVisibleFirstLine(): TextLine? { fun getReadAloudPos(): Pair<Int, TextLine>? {
return curPage.getCurVisibleFirstLine() return curPage.getReadAloudPos()
} }
fun invalidateTextPage() { fun invalidateTextPage() {