优化
This commit is contained in:
@@ -263,7 +263,12 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
private fun curPageChanged() {
|
private fun curPageChanged() {
|
||||||
callBack?.pageChanged()
|
callBack?.pageChanged()
|
||||||
if (BaseReadAloudService.isRun) {
|
if (BaseReadAloudService.isRun) {
|
||||||
readAloud(!BaseReadAloudService.pause)
|
val scrollPageAnim = pageAnim() == 3
|
||||||
|
if (scrollPageAnim) {
|
||||||
|
ReadAloud.pause(appCtx)
|
||||||
|
} else {
|
||||||
|
readAloud(!BaseReadAloudService.pause)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
upReadTime()
|
upReadTime()
|
||||||
preDownload()
|
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 {
|
book?.let {
|
||||||
ReadAloud.play(appCtx, play)
|
ReadAloud.play(appCtx, play, startPos = startPos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,16 +186,20 @@ abstract class BaseReadAloudService : BaseService(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
nowSpeak = textChapter.getParagraphNum(readAloudNumber + 1, readAloudByPage) - 1
|
nowSpeak = textChapter.getParagraphNum(readAloudNumber + 1, readAloudByPage) - 1
|
||||||
if (!readAloudByPage && pos == 0) {
|
if (!readAloudByPage && startPos == 0 && !toLast) {
|
||||||
pos = page.lines.first().chapterPosition -
|
pos = page.lines.first().chapterPosition -
|
||||||
textChapter.paragraphs[nowSpeak].chapterPosition
|
textChapter.paragraphs[nowSpeak].chapterPosition
|
||||||
}
|
}
|
||||||
paragraphStartPos = pos
|
|
||||||
if (toLast) {
|
if (toLast) {
|
||||||
toLast = false
|
toLast = false
|
||||||
readAloudNumber = textChapter.getLastParagraphPosition()
|
readAloudNumber = textChapter.getLastParagraphPosition()
|
||||||
nowSpeak = contentList.lastIndex
|
nowSpeak = contentList.lastIndex
|
||||||
|
if (page.paragraphs.size == 1) {
|
||||||
|
pos = page.lines.first().chapterPosition -
|
||||||
|
textChapter.paragraphs[nowSpeak].chapterPosition
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
paragraphStartPos = pos
|
||||||
launch(Main) {
|
launch(Main) {
|
||||||
if (play) play() else pageChanged = true
|
if (play) play() else pageChanged = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1135,10 +1135,24 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
when {
|
when {
|
||||||
!BaseReadAloudService.isRun -> {
|
!BaseReadAloudService.isRun -> {
|
||||||
ReadAloud.upReadAloudClass()
|
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)
|
else -> ReadAloud.pause(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -519,6 +519,29 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
return visiblePage
|
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
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 选择开始文字
|
* 选择开始文字
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import io.legado.app.help.config.ReadBookConfig
|
|||||||
import io.legado.app.help.config.ReadTipConfig
|
import io.legado.app.help.config.ReadTipConfig
|
||||||
import io.legado.app.model.ReadBook
|
import io.legado.app.model.ReadBook
|
||||||
import io.legado.app.ui.book.read.ReadBookActivity
|
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.TextPage
|
||||||
import io.legado.app.ui.book.read.page.entities.TextPos
|
import io.legado.app.ui.book.read.page.entities.TextPos
|
||||||
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
||||||
@@ -352,6 +353,10 @@ class PageView(context: Context) : FrameLayout(context) {
|
|||||||
return binding.contentTextView.getCurVisiblePage()
|
return binding.contentTextView.getCurVisiblePage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getCurVisibleFirstLine(): TextLine? {
|
||||||
|
return binding.contentTextView.getCurVisibleFirstLine()
|
||||||
|
}
|
||||||
|
|
||||||
fun markAsMainView() {
|
fun markAsMainView() {
|
||||||
binding.contentTextView.isMainView = true
|
binding.contentTextView.isMainView = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -626,6 +626,10 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
|||||||
return curPage.getCurVisiblePage()
|
return curPage.getCurVisiblePage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getCurPagePosition(): Int {
|
||||||
|
return curPage.getCurVisibleFirstLine()?.pagePosition ?: 0
|
||||||
|
}
|
||||||
|
|
||||||
override val currentChapter: TextChapter?
|
override val currentChapter: TextChapter?
|
||||||
get() {
|
get() {
|
||||||
return if (callBack.isInitFinish) ReadBook.textChapter(0) else null
|
return if (callBack.isInitFinish) ReadBook.textChapter(0) else null
|
||||||
|
|||||||
Reference in New Issue
Block a user