From 7768773e65a1e12d2395d8fb724ff940813b2218 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 22:26:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/service/BaseReadAloudService.kt | 4 +- .../app/ui/book/read/ReadBookActivity.kt | 3 -- .../ui/book/read/page/entities/TextChapter.kt | 41 +------------------ 3 files changed, 4 insertions(+), 44 deletions(-) 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 {