优化,修复在线朗读遇到单行标点时停止朗读的bug

This commit is contained in:
kunfei
2022-02-25 09:03:16 +08:00
parent f31ef3337e
commit 67f64a8fd8
6 changed files with 12 additions and 18 deletions

View File

@@ -224,12 +224,10 @@ object ReadBook : CoroutineScope by MainScope() {
/**
* 当前页数
*/
fun durPageIndex(): Int {
curTextChapter?.let {
return it.getPageIndexByCharIndex(durChapterPos)
val durPageIndex: Int
get() {
return curTextChapter?.getPageIndexByCharIndex(durChapterPos) ?: durChapterPos
}
return durChapterPos
}
/**
* chapterOnDur: 0为当前页,1为下一页,-1为上一页

View File

@@ -93,7 +93,7 @@ abstract class BaseReadAloudService : BaseService(),
when (intent?.action) {
IntentAction.play -> {
textChapter = ReadBook.curTextChapter
pageIndex = ReadBook.durPageIndex()
pageIndex = ReadBook.durPageIndex
newReadAloud(
intent.getBooleanExtra("play", true)
)

View File

@@ -110,15 +110,11 @@ class HttpReadAloudService : BaseReadAloudService(),
clearSpeakCache()
removeCacheFile()
val httpTts = ReadAloud.httpTTS ?: return@execute
contentList.forEachIndexed { index, item ->
contentList.forEachIndexed { index, content ->
ensureActive()
val speakText = item.replace(AppPattern.notReadAloudRegex, "")
val fileName =
md5SpeakFileName(
httpTts.url,
AppConfig.ttsSpeechRate.toString(),
speakText
)
md5SpeakFileName(httpTts.url, AppConfig.ttsSpeechRate.toString(), content)
val speakText = content.replace(AppPattern.notReadAloudRegex, "")
if (hasSpeakFile(fileName)) { //已经下载好的语音缓存
if (index == nowSpeak) {
val file = getSpeakFileAsMd5(fileName)

View File

@@ -290,7 +290,7 @@ class ReadBookActivity : BaseReadBookActivity(),
R.id.menu_download -> showDownloadDialog()
R.id.menu_add_bookmark -> {
val book = ReadBook.book
val page = ReadBook.curTextChapter?.page(ReadBook.durPageIndex())
val page = ReadBook.curTextChapter?.page(ReadBook.durPageIndex)
if (book != null && page != null) {
val bookmark = book.createBookMark().apply {
chapterIndex = ReadBook.durChapterIndex
@@ -657,7 +657,7 @@ class ReadBookActivity : BaseReadBookActivity(),
launch {
autoPageProgress = 0
binding.readView.upContent(relativePosition, resetPageOffset)
binding.readMenu.setSeekPage(ReadBook.durPageIndex())
binding.readMenu.setSeekPage(ReadBook.durPageIndex)
loadStates = false
success?.invoke()
}
@@ -675,7 +675,7 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun pageChanged() {
launch {
autoPageProgress = 0
binding.readMenu.setSeekPage(ReadBook.durPageIndex())
binding.readMenu.setSeekPage(ReadBook.durPageIndex)
startBackupJob()
}
}

View File

@@ -376,7 +376,7 @@ class ReadMenu @JvmOverloads constructor(
binding.tvChapterUrl.gone()
}
binding.seekReadPage.max = it.pageSize.minus(1)
binding.seekReadPage.progress = ReadBook.durPageIndex()
binding.seekReadPage.progress = ReadBook.durPageIndex
binding.tvPre.isEnabled = ReadBook.durChapterIndex != 0
binding.tvNext.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1
} ?: let {

View File

@@ -5,7 +5,7 @@ import io.legado.app.ui.book.read.page.entities.TextChapter
interface DataSource {
val pageIndex: Int get() = ReadBook.durPageIndex()
val pageIndex: Int get() = ReadBook.durPageIndex
val currentChapter: TextChapter?