This commit is contained in:
Horis
2023-08-24 23:44:43 +08:00
parent 3d92fa27ad
commit b7e4bb0193
6 changed files with 62 additions and 7 deletions

View File

@@ -263,7 +263,12 @@ object ReadBook : CoroutineScope by MainScope() {
private fun curPageChanged() {
callBack?.pageChanged()
if (BaseReadAloudService.isRun) {
readAloud(!BaseReadAloudService.pause)
val scrollPageAnim = pageAnim() == 3
if (scrollPageAnim) {
ReadAloud.pause(appCtx)
} else {
readAloud(!BaseReadAloudService.pause)
}
}
upReadTime()
preDownload()
@@ -272,9 +277,9 @@ object ReadBook : CoroutineScope by MainScope() {
/**
* 朗读
*/
fun readAloud(play: Boolean = true) {
fun readAloud(play: Boolean = true, startPos: Int = 0) {
book?.let {
ReadAloud.play(appCtx, play)
ReadAloud.play(appCtx, play, startPos = startPos)
}
}

View File

@@ -186,16 +186,20 @@ abstract class BaseReadAloudService : BaseService(),
}
}
nowSpeak = textChapter.getParagraphNum(readAloudNumber + 1, readAloudByPage) - 1
if (!readAloudByPage && pos == 0) {
if (!readAloudByPage && startPos == 0 && !toLast) {
pos = page.lines.first().chapterPosition -
textChapter.paragraphs[nowSpeak].chapterPosition
}
paragraphStartPos = pos
if (toLast) {
toLast = false
readAloudNumber = textChapter.getLastParagraphPosition()
nowSpeak = contentList.lastIndex
if (page.paragraphs.size == 1) {
pos = page.lines.first().chapterPosition -
textChapter.paragraphs[nowSpeak].chapterPosition
}
}
paragraphStartPos = pos
launch(Main) {
if (play) play() else pageChanged = true
}

View File

@@ -1135,10 +1135,24 @@ class ReadBookActivity : BaseReadBookActivity(),
when {
!BaseReadAloudService.isRun -> {
ReadAloud.upReadAloudClass()
ReadBook.readAloud()
val scrollPageAnim = ReadBook.pageAnim() == 3
if (scrollPageAnim) {
val startPos = binding.readView.getCurPagePosition()
ReadBook.readAloud(startPos = startPos)
} else {
ReadBook.readAloud()
}
}
BaseReadAloudService.pause -> ReadAloud.resume(this)
BaseReadAloudService.pause -> {
val scrollPageAnim = ReadBook.pageAnim() == 3
if (scrollPageAnim) {
val startPos = binding.readView.getCurPagePosition()
ReadAloud.play(this, startPos = startPos)
} else {
ReadAloud.resume(this)
}
}
else -> ReadAloud.pause(this)
}
}

View File

@@ -519,6 +519,29 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
return visiblePage
}
fun getCurVisibleFirstLine(): TextLine? {
var relativeOffset: Float
for (relativePos in 0..2) {
relativeOffset = relativeOffset(relativePos)
if (relativePos > 0) {
//滚动翻页
if (!callBack.isScroll) break
if (relativeOffset >= ChapterProvider.visibleHeight) break
}
val textPage = relativePage(relativePos)
for (textLine in textPage.lines) {
if (textLine.isVisible(relativeOffset)) {
val visibleLine = textLine.copy().apply {
lineTop += relativeOffset
lineBottom += relativeOffset
}
return visibleLine
}
}
}
return null
}
/**
* 选择开始文字
*/

View File

@@ -14,6 +14,7 @@ import io.legado.app.help.config.ReadBookConfig
import io.legado.app.help.config.ReadTipConfig
import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.read.page.entities.TextLine
import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.ui.book.read.page.entities.TextPos
import io.legado.app.ui.book.read.page.provider.ChapterProvider
@@ -352,6 +353,10 @@ class PageView(context: Context) : FrameLayout(context) {
return binding.contentTextView.getCurVisiblePage()
}
fun getCurVisibleFirstLine(): TextLine? {
return binding.contentTextView.getCurVisibleFirstLine()
}
fun markAsMainView() {
binding.contentTextView.isMainView = true
}

View File

@@ -626,6 +626,10 @@ class ReadView(context: Context, attrs: AttributeSet) :
return curPage.getCurVisiblePage()
}
fun getCurPagePosition(): Int {
return curPage.getCurVisibleFirstLine()?.pagePosition ?: 0
}
override val currentChapter: TextChapter?
get() {
return if (callBack.isInitFinish) ReadBook.textChapter(0) else null