diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index 3ad351ca7..2d209611c 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -111,7 +111,9 @@ abstract class BaseReadAloudService : BaseService(), if (getPrefBoolean(PreferKey.readAloudByPage)) { for (index in pageIndex..textChapter.lastIndex()) { textChapter.page(index)?.text?.split("\n")?.let { - contentList.addAll(it) + if (it.isNotEmpty()) { + contentList.addAll(it) + } } } } else { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index e81d7cad9..043c419eb 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -609,9 +609,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo * 朗读按钮 */ override fun onClickReadAloud() { - if (!BaseReadAloudService.isRun) { - SystemUtils.ignoreBatteryOptimization(this) - } when { !BaseReadAloudService.isRun -> ReadBook.readAloud() BaseReadAloudService.pause -> ReadAloud.resume(this) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt index e2cbaafde..e05b7746b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt @@ -12,10 +12,7 @@ data class TextChapter( val chaptersSize: Int ) { fun page(index: Int): TextPage? { - if (index >= 0 && index < pages.size) { - return pages[index] - } - return null + return pages.getOrNull(index) } fun lastPage(): TextPage? { @@ -25,20 +22,6 @@ data class TextChapter( return null } - fun scrollPage(): TextPage? { - if (pages.isNotEmpty()) { - val stringBuilder = StringBuilder() - pages.forEach { - stringBuilder.append(it.text) - } - return TextPage( - index = 0, text = stringBuilder.toString(), title = title, - pageSize = pages.size, chapterSize = chaptersSize, chapterIndex = position - ) - } - return null - } - fun lastIndex(): Int { return pages.size - 1 } @@ -70,28 +53,6 @@ data class TextChapter( return stringBuilder.toString() } - fun getStartLine(pageIndex: Int): Int { - if (pageLines.size > pageIndex) { - var lines = 0 - for (index: Int in 0 until pageIndex) { - lines += pageLines[index] + 1 - } - return lines - } - return 0 - } - - fun getPageIndex(line: Int): Int { - var lines = 0 - for (pageIndex in pageLines.indices) { - lines += pageLines[pageIndex] + 1 - if (line < lines) { - return pageIndex - } - } - return 0 - } - fun getContent(): String { val stringBuilder = StringBuilder() pages.forEach {