Skip to content

Commit

Permalink
优化,修复在线朗读遇到单行标点时停止朗读的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Feb 25, 2022
1 parent f31ef33 commit 67f64a8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
8 changes: 3 additions & 5 deletions app/src/main/java/io/legado/app/model/ReadBook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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为上一页
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand All @@ -675,7 +675,7 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun pageChanged() {
launch {
autoPageProgress = 0
binding.readMenu.setSeekPage(ReadBook.durPageIndex())
binding.readMenu.setSeekPage(ReadBook.durPageIndex)
startBackupJob()
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down

0 comments on commit 67f64a8

Please sign in to comment.