优化 #5537
This commit is contained in:
@@ -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) {
|
||||
clearTextChapter()
|
||||
callBack?.upContent()
|
||||
if (upContent) callBack?.upContent()
|
||||
durChapterIndex = index
|
||||
ReadBook.durChapterPos = durChapterPos
|
||||
saveRead()
|
||||
|
||||
@@ -1329,10 +1329,17 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
ReadAloud.upReadAloudClass()
|
||||
val scrollPageAnim = ReadBook.pageAnim() == 3
|
||||
if (scrollPageAnim) {
|
||||
val line = binding.readView.getCurVisibleFirstLine()
|
||||
if (line != null) {
|
||||
val pos = binding.readView.getReadAloudPos()
|
||||
if (pos != null) {
|
||||
val (index, line) = pos
|
||||
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 {
|
||||
ReadBook.readAloud()
|
||||
}
|
||||
@@ -1345,10 +1352,17 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
val scrollPageAnim = ReadBook.pageAnim() == 3
|
||||
if (scrollPageAnim && pageChanged) {
|
||||
pageChanged = false
|
||||
val line = binding.readView.getCurVisibleFirstLine()
|
||||
if (line != null) {
|
||||
val pos = binding.readView.getReadAloudPos()
|
||||
if (pos != null) {
|
||||
val (index, line) = pos
|
||||
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 {
|
||||
ReadBook.readAloud()
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
|
||||
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)?) {
|
||||
|
||||
@@ -449,7 +449,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
return visiblePage
|
||||
}
|
||||
|
||||
fun getCurVisibleFirstLine(): TextLine? {
|
||||
fun getReadAloudPos(): Pair<Int, TextLine>? {
|
||||
var relativeOffset: Float
|
||||
for (relativePos in 0..2) {
|
||||
relativeOffset = relativeOffset(relativePos)
|
||||
@@ -467,7 +467,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
lineTop += relativeOffset
|
||||
lineBottom += relativeOffset
|
||||
}
|
||||
return visibleLine
|
||||
return textPage.chapterIndex to visibleLine
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,8 +426,8 @@ class PageView(context: Context) : FrameLayout(context) {
|
||||
return binding.contentTextView.getCurVisiblePage()
|
||||
}
|
||||
|
||||
fun getCurVisibleFirstLine(): TextLine? {
|
||||
return binding.contentTextView.getCurVisibleFirstLine()
|
||||
fun getReadAloudPos(): Pair<Int, TextLine>? {
|
||||
return binding.contentTextView.getReadAloudPos()
|
||||
}
|
||||
|
||||
fun markAsMainView() {
|
||||
|
||||
@@ -675,8 +675,8 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
||||
return curPage.getCurVisiblePage()
|
||||
}
|
||||
|
||||
fun getCurVisibleFirstLine(): TextLine? {
|
||||
return curPage.getCurVisibleFirstLine()
|
||||
fun getReadAloudPos(): Pair<Int, TextLine>? {
|
||||
return curPage.getReadAloudPos()
|
||||
}
|
||||
|
||||
fun invalidateTextPage() {
|
||||
|
||||
Reference in New Issue
Block a user