From e9496526c21ab5d878262e97354e3c5181aa6b51 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 21 Feb 2020 08:45:06 +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 --- .../java/io/legado/app/constant/EventBus.kt | 2 +- .../app/service/HttpReadAloudService.kt | 4 ++-- .../legado/app/service/TTSReadAloudService.kt | 4 ++-- .../app/ui/book/read/ReadBookActivity.kt | 24 +++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index ad49cb3e0..402827cb4 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -5,7 +5,7 @@ object EventBus { const val RECREATE = "RECREATE" const val UP_BOOK = "sourceDebugLog" const val ALOUD_STATE = "aloud_state" - const val TTS_START = "ttsStart" + const val TTS_PROGRESS = "ttsStart" const val TTS_DS = "ttsDs" const val BATTERY_CHANGED = "batteryChanged" const val TIME_CHANGED = "timeChanged" diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 5d34a345c..2cf46831c 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -96,7 +96,7 @@ class HttpReadAloudService : BaseReadAloudService(), mediaPlayer.setDataSource(fd) mediaPlayer.prepareAsync() playingIndex = nowSpeak - postEvent(EventBus.TTS_START, readAloudNumber + 1) + postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) } catch (e: Exception) { e.printStackTrace() } @@ -190,7 +190,7 @@ class HttpReadAloudService : BaseReadAloudService(), ReadBook.moveToNextPage() } } - postEvent(EventBus.TTS_START, readAloudNumber + 1) + postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) } override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 1b1f40bcc..6fd32219d 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -152,7 +152,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener ReadBook.moveToNextPage() } } - postEvent(EventBus.TTS_START, readAloudNumber + 1) + postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) } override fun onDone(s: String) { @@ -169,7 +169,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) { pageIndex++ ReadBook.moveToNextPage() - postEvent(EventBus.TTS_START, readAloudNumber + start) + postEvent(EventBus.TTS_PROGRESS, readAloudNumber + start) } } } 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 9b05b7308..53dd7e605 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 @@ -501,17 +501,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override fun observeLiveBus() { super.observeLiveBus() - observeEvent(EventBus.ALOUD_STATE) { - if (it == Status.STOP || it == Status.PAUSE) { - ReadBook.curTextChapter?.let { textChapter -> - val page = textChapter.page(ReadBook.durPageIndex) - if (page != null) { - page.removePageAloudSpan() - page_view.upContent() - } - } - } - } observeEvent(EventBus.TIME_CHANGED) { page_view.upTime() } observeEvent(EventBus.BATTERY_CHANGED) { page_view.upBattery(it) } observeEvent(EventBus.OPEN_CHAPTER) { @@ -537,7 +526,18 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo page_view.upContent() } } - observeEventSticky(EventBus.TTS_START) { chapterStart -> + observeEvent(EventBus.ALOUD_STATE) { + if (it == Status.STOP || it == Status.PAUSE) { + ReadBook.curTextChapter?.let { textChapter -> + val page = textChapter.page(ReadBook.durPageIndex) + if (page != null) { + page.removePageAloudSpan() + page_view.upContent() + } + } + } + } + observeEventSticky(EventBus.TTS_PROGRESS) { chapterStart -> launch(IO) { if (BaseReadAloudService.isPlay()) { ReadBook.curTextChapter?.let { textChapter ->