diff --git a/app/src/main/java/io/legado/app/service/ReadAloudService.kt b/app/src/main/java/io/legado/app/service/ReadAloudService.kt index ebb4513da..ed47cb88f 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -28,7 +28,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage val tag: String = ReadAloudService::class.java.simpleName var isRun = false - fun paly(context: Context, title: String, subtitle: String, body: String) { + fun play(context: Context, title: String, subtitle: String, body: String) { val readAloudIntent = Intent(context, ReadAloudService::class.java) readAloudIntent.action = "play" readAloudIntent.putExtra("title", title) diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 75d622e8d..bf91ba595 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -287,16 +287,25 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea SystemUtils.ignoreBatteryOptimization(this) } when (readAloudStatus) { - Status.STOP -> { - viewModel.bookData.value?.let { - ReadAloudService.paly(this, it.name, "", "") - } - } + Status.STOP -> readAloud() Status.PLAY -> ReadAloudService.pause(this) Status.PAUSE -> ReadAloudService.resume(this) } } + private fun readAloud() { + val book = viewModel.bookData.value + val textChapter = viewModel.curTextChapter + if (book != null && textChapter != null) { + ReadAloudService.play( + this, + book.name, + textChapter.title, + "" + ) + } + } + private fun setScreenBrightness(value: Int) { var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE if (this.getPrefBoolean("brightnessAuto").not()) { diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt index 54295f149..5903f9876 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt @@ -31,5 +31,23 @@ data class TextChapter( fun pageSize(): Int { return pages.size } + + fun getReadLength(pageIndex: Int): Int { + var length = 0 + for (index in 0 until pageIndex) { + length += pageLengths[index] + } + return length + } + + fun getUnRead(pageIndex: Int): String { + val stringBuilder = StringBuilder() + if (pageIndex < pages.size) { + for (index in pageIndex..lastIndex()) { + stringBuilder.append(pages[index].text) + } + } + return stringBuilder.toString() + } }