From 2845e799cc5a975d124a5b25b43bb99b3425a1aa Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 6 Jun 2020 18:49:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/AudioPlayService.kt | 1 - .../legado/app/service/TTSReadAloudService.kt | 27 ++++++++++--------- .../main/bookshelf/books/BooksAdapterList.kt | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index d28ca568c..fa56e85d0 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -520,7 +520,6 @@ class AudioPlayService : BaseService(), ) builder.setStyle( androidx.media.app.NotificationCompat.MediaStyle() - .setMediaSession(mediaSessionCompat?.sessionToken) .setShowActionsInCompactView(0, 1, 2) ) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) 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 0517ca2fc..1e6fcc2dd 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -42,9 +42,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener private fun initTts() { ttsInitFinish = false - textToSpeech = TextToSpeech(this, this).apply { - setOnUtteranceProgressListener(ttsUtteranceListener) - } + textToSpeech = TextToSpeech(this, this) } override fun onDestroy() { @@ -55,6 +53,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener override fun onInit(status: Int) { if (status == TextToSpeech.SUCCESS) { textToSpeech?.let { + it.setOnUtteranceProgressListener(ttsUtteranceListener) it.language = Locale.CHINA ttsInitFinish = true play() @@ -69,16 +68,20 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener @Synchronized override fun play() { if (contentList.isNotEmpty() && ttsInitFinish && requestFocus()) { - MediaHelp.playSilentSound(this) super.play() - textToSpeech?.stop() - for (i in nowSpeak until contentList.size) { - textToSpeech?.speak( - contentList[i], - TextToSpeech.QUEUE_ADD, - null, - AppConst.APP_TAG + i - ) + execute { + MediaHelp.playSilentSound(this@TTSReadAloudService) + textToSpeech?.let { + it.stop() + for (i in nowSpeak until contentList.size) { + it.speak( + contentList[i], + TextToSpeech.QUEUE_ADD, + null, + AppConst.APP_TAG + i + ) + } + } } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt index 783a1f14d..7ed9a7d99 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt @@ -48,8 +48,8 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : rl_loading.show() } else { rl_loading.hide() - bv_unread.setBadgeCount(item.getUnreadChapterNum()) bv_unread.setHighlight(item.lastCheckCount > 0) + bv_unread.setBadgeCount(item.getUnreadChapterNum()) } }