|
|
@@ -36,7 +36,6 @@ import io.legado.app.model.ReadBook
|
|
|
import io.legado.app.receiver.MediaButtonReceiver
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity
|
|
|
import io.legado.app.ui.book.read.page.entities.TextChapter
|
|
|
-import io.legado.app.utils.LogUtils
|
|
|
import io.legado.app.utils.activityPendingIntent
|
|
|
import io.legado.app.utils.broadcastPendingIntent
|
|
|
import io.legado.app.utils.getPrefBoolean
|
|
|
@@ -112,7 +111,6 @@ abstract class BaseReadAloudService : BaseService(),
|
|
|
private var cover: Bitmap =
|
|
|
BitmapFactory.decodeResource(appCtx.resources, R.drawable.icon_read_book)
|
|
|
var pageChanged = false
|
|
|
- private var ttsProgress = 0
|
|
|
private var toLast = false
|
|
|
var paragraphStartPos = 0
|
|
|
private var readAloudByPage = false
|
|
|
@@ -186,7 +184,6 @@ abstract class BaseReadAloudService : BaseService(),
|
|
|
IntentAction.pause -> pauseReadAloud()
|
|
|
IntentAction.resume -> resumeReadAloud()
|
|
|
IntentAction.upTtsSpeechRate -> upSpeechRate(true)
|
|
|
- IntentAction.upTtsProgress -> upTtsProgress(ttsProgress)
|
|
|
IntentAction.prevParagraph -> prevP()
|
|
|
IntentAction.nextParagraph -> nextP()
|
|
|
IntentAction.addTimer -> addTimer()
|
|
|
@@ -201,6 +198,9 @@ abstract class BaseReadAloudService : BaseService(),
|
|
|
this@BaseReadAloudService.pageIndex = pageIndex
|
|
|
textChapter = ReadBook.curTextChapter
|
|
|
val textChapter = textChapter ?: return@execute
|
|
|
+ if (!textChapter.isCompleted) {
|
|
|
+ return@execute
|
|
|
+ }
|
|
|
readAloudNumber = textChapter.getReadLength(pageIndex) + startPos
|
|
|
readAloudByPage = getPrefBoolean(PreferKey.readAloudByPage)
|
|
|
contentList = textChapter.getNeedReadAloud(0, readAloudByPage, 0)
|
|
|
@@ -216,13 +216,6 @@ abstract class BaseReadAloudService : BaseService(),
|
|
|
}
|
|
|
}
|
|
|
nowSpeak = textChapter.getParagraphNum(readAloudNumber + 1, readAloudByPage) - 1
|
|
|
- if (nowSpeak < 0) {
|
|
|
- LogUtils.d(TAG) {
|
|
|
- "nowSpeak:$nowSpeak readAloudNumber:$readAloudNumber isCompleted:${textChapter.isCompleted} " +
|
|
|
- "pageSize:${textChapter.pageSize} \np1:${textChapter.paragraphsInternal}\n" +
|
|
|
- "p2:${textChapter.pageParagraphsInternal}"
|
|
|
- }
|
|
|
- }
|
|
|
if (!readAloudByPage && startPos == 0 && !toLast) {
|
|
|
pos = page.lines.first().chapterPosition -
|
|
|
textChapter.paragraphs[nowSpeak].chapterPosition
|
|
|
@@ -289,7 +282,6 @@ abstract class BaseReadAloudService : BaseService(),
|
|
|
abstract fun upSpeechRate(reset: Boolean = false)
|
|
|
|
|
|
fun upTtsProgress(progress: Int) {
|
|
|
- ttsProgress = progress
|
|
|
postEvent(EventBus.TTS_PROGRESS, progress)
|
|
|
}
|
|
|
|
|
|
@@ -300,11 +292,7 @@ abstract class BaseReadAloudService : BaseService(),
|
|
|
readAloudNumber -= contentList[nowSpeak].length + 1 + paragraphStartPos
|
|
|
paragraphStartPos = 0
|
|
|
textChapter?.let {
|
|
|
- val paragraphs = if (readAloudByPage) {
|
|
|
- it.pageParagraphs
|
|
|
- } else {
|
|
|
- it.paragraphs
|
|
|
- }
|
|
|
+ val paragraphs = it.getParagraphs(readAloudByPage)
|
|
|
if (!paragraphs[nowSpeak].isParagraphEnd) readAloudNumber++
|
|
|
if (readAloudNumber < it.getReadLength(pageIndex)) {
|
|
|
pageIndex--
|
|
|
@@ -325,6 +313,14 @@ abstract class BaseReadAloudService : BaseService(),
|
|
|
readAloudNumber += contentList[nowSpeak].length.plus(1) - paragraphStartPos
|
|
|
paragraphStartPos = 0
|
|
|
nowSpeak++
|
|
|
+ textChapter?.let {
|
|
|
+ val paragraphs = it.getParagraphs(readAloudByPage)
|
|
|
+ if (!paragraphs[nowSpeak].isParagraphEnd) readAloudNumber--
|
|
|
+ if (readAloudNumber >= it.getReadLength(pageIndex + 1)) {
|
|
|
+ pageIndex++
|
|
|
+ ReadBook.moveToNextPage()
|
|
|
+ }
|
|
|
+ }
|
|
|
upTtsProgress(readAloudNumber + 1)
|
|
|
play()
|
|
|
} else {
|