From 94ef331b222e28575ddda2f1d35f6b201a9a0be9 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:07:24 +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 --- .../java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 6 +++--- .../main/java/io/legado/app/service/AudioPlayService.kt | 7 ++++++- .../java/io/legado/app/service/BaseReadAloudService.kt | 7 ++++++- app/src/main/java/io/legado/app/utils/LogUtils.kt | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index b8a4a1c12a78..1aaebb21be0b 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -806,15 +806,15 @@ class AnalyzeUrl( fun setBody(value: String?) { body = when { value.isNullOrBlank() -> null - value.isJsonObject() -> GSON.fromJsonObject>(value) - value.isJsonArray() -> GSON.fromJsonArray>(value) + value.isJsonObject() -> GSON.fromJsonObject>(value).getOrNull() + value.isJsonArray() -> GSON.fromJsonArray>(value).getOrNull() else -> value } } fun getBody(): String? { return body?.let { - if (it is String) it else GSON.toJson(it) + it as? String ?: GSON.toJson(it) } } 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 2e5c75a6b018..2b60784e0449 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -31,6 +31,7 @@ import io.legado.app.constant.NotificationId import io.legado.app.constant.Status import io.legado.app.help.MediaHelp import io.legado.app.help.config.AppConfig +import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.exoplayer.ExoPlayerHelper import io.legado.app.help.glide.ImageLoader import io.legado.app.model.AudioPlay @@ -109,6 +110,7 @@ class AudioPlayService : BaseService(), private var needResumeOnAudioFocusGain = false private var position = AudioPlay.book?.durChapterPos ?: 0 private var dsJob: Job? = null + private var upNotificationJob: Coroutine<*>? = null private var upPlayProgressJob: Job? = null private var playSpeed: Float = 1f private var cover: Bitmap = @@ -196,6 +198,9 @@ class AudioPlayService : BaseService(), AudioPlay.status = Status.STOP postEvent(EventBus.AUDIO_STATE, Status.STOP) AudioPlay.unregisterService() + upNotificationJob?.invokeOnCompletion { + notificationManager.cancel(NotificationId.AudioPlayService) + } } /** @@ -602,7 +607,7 @@ class AudioPlayService : BaseService(), } private fun upAudioPlayNotification() { - execute { + upNotificationJob = execute { try { val notification = createNotification() notificationManager.notify(NotificationId.AudioPlayService, notification.build()) 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 09a9332c5b87..38f7729a6811 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -34,6 +34,7 @@ import io.legado.app.constant.PreferKey import io.legado.app.constant.Status import io.legado.app.help.MediaHelp import io.legado.app.help.config.AppConfig +import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.glide.ImageLoader import io.legado.app.lib.permission.Permissions import io.legado.app.lib.permission.PermissionsCompat @@ -123,6 +124,7 @@ abstract class BaseReadAloudService : BaseService(), private var needResumeOnCallStateIdle = false private var registeredPhoneStateListener = false private var dsJob: Job? = null + private var upNotificationJob: Coroutine<*>? = null private var cover: Bitmap = BitmapFactory.decodeResource(appCtx.resources, R.drawable.icon_read_book) var pageChanged = false @@ -198,6 +200,9 @@ abstract class BaseReadAloudService : BaseService(), mediaSessionCompat.release() ReadBook.uploadProgress() unregisterPhoneStateListener(phoneStateListener) + upNotificationJob?.invokeOnCompletion { + notificationManager.cancel(NotificationId.ReadAloudService) + } } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -504,7 +509,7 @@ abstract class BaseReadAloudService : BaseService(), } private fun upReadAloudNotification() { - execute { + upNotificationJob = execute { try { val notification = createNotification() notificationManager.notify(NotificationId.ReadAloudService, notification.build()) diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt index 6d136659b416..c190c146aa78 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -40,7 +40,7 @@ object LogUtils { } val logger: Logger by lazy { - Logger.getLogger("Leagdo").apply { + Logger.getLogger("Legado").apply { fileHandler?.let { addHandler(it) }