From 388270533232dad7040dfacce21264dbfcd941f3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 29 Aug 2019 16:00:38 +0800 Subject: [PATCH] up --- .../java/io/legado/app/service/ReadAloudService.kt | 14 +++++++++++--- .../io/legado/app/ui/readbook/ReadBookActivity.kt | 8 +++++++- .../app/ui/readbook/config/ReadAloudDialog.kt | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) 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 69f451a6e..bb138ad9f 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -206,11 +206,19 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, private fun newReadAloud(dataKey: String?, play: Boolean) { dataKey?.let { textChapter = IntentDataHelp.getData(dataKey) as? TextChapter - textChapter?.let { + textChapter?.let { textChapter -> nowSpeak = 0 - readAloudNumber = it.getReadLength(pageIndex) + readAloudNumber = textChapter.getReadLength(pageIndex) contentList.clear() - contentList.addAll(it.getUnRead(pageIndex).split("\n")) + if (getPrefBoolean("readAloudByPage")) { + for (index in pageIndex..textChapter.lastIndex()) { + textChapter.page(index)?.text?.split("\n")?.let { + contentList.addAll(it) + } + } + } else { + contentList.addAll(textChapter.getUnRead(pageIndex).split("\n")) + } if (play) playTTS() } ?: stopSelf() } ?: stopSelf() 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 bb30ba243..7c0da36d6 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 @@ -460,7 +460,13 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea viewModel.openChapter(it) page_view.upContent() } - observeEvent(Bus.READ_ALOUD_BUTTON) { onClickReadAloud() } + observeEvent(Bus.READ_ALOUD_BUTTON) { + if (it) { + onClickReadAloud() + } else { + readAloud() + } + } observeEvent(Bus.UP_CONFIG) { Help.upSystemUiVisibility(window, !read_menu.isVisible) page_view.upBg() diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt index d182cfa11..0069e748d 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt @@ -71,6 +71,7 @@ class ReadAloudDialog : DialogFragment() { cb_by_page.setOnCheckedChangeListener { buttonView, isChecked -> if (buttonView.isPressed) { requireContext().putPrefBoolean("readAloudByPage", isChecked) + postEvent(Bus.READ_ALOUD_BUTTON, false) } } cb_tts_follow_sys.setOnCheckedChangeListener { buttonView, isChecked ->