From 9e578962608d1494e459360c00b853c6a169ad4d Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 22 Aug 2021 09:27:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/service/BaseReadAloudService.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 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 885d5dbde..c7eb76132 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -68,7 +68,7 @@ abstract class BaseReadAloudService : BaseService(), initBroadcastReceiver() upNotification() upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) - handler.postDelayed(dsRunnable, 60000) + startDs() } override fun onDestroy() { @@ -148,6 +148,7 @@ abstract class BaseReadAloudService : BaseService(), upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) postEvent(EventBus.ALOUD_STATE, Status.PAUSE) ReadBook.uploadProgress() + startDs() } @CallSuper @@ -182,7 +183,7 @@ abstract class BaseReadAloudService : BaseService(), private fun setTimer(minute: Int) { timeMinute = minute - upNotification() + startDs() } private fun addTimer() { @@ -192,6 +193,12 @@ abstract class BaseReadAloudService : BaseService(), timeMinute += 10 if (timeMinute > 180) timeMinute = 180 } + startDs() + } + + private fun startDs() { + handler.removeCallbacks(dsRunnable) + handler.postDelayed(dsRunnable, 60000) postEvent(EventBus.TTS_DS, timeMinute) upNotification() } @@ -201,9 +208,10 @@ abstract class BaseReadAloudService : BaseService(), */ private fun doDs() { if (!pause) { - if (timeMinute > 0) { + if (timeMinute >= 0) { timeMinute-- - } else if (timeMinute == 0) { + } + if (timeMinute == 0) { stopSelf() } }