From 27e4d1acbfa05a19eff1f5454eda08f7ce0c0876 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 11 Sep 2021 10:52:10 +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 --- .../app/receiver/MediaButtonReceiver.kt | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 18f8dce68..78309fbab 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -18,6 +18,7 @@ import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.main.MainActivity import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.postEvent +import io.legado.app.utils.startActivity /** @@ -66,34 +67,36 @@ class MediaButtonReceiver : BroadcastReceiver() { fun readAloud(context: Context, isMediaKey: Boolean = true) { when { - BaseReadAloudService.isRun -> if (BaseReadAloudService.isPlay()) { - ReadAloud.pause(context) - AudioPlay.pause(context) - } else { - ReadAloud.resume(context) - AudioPlay.resume(context) + BaseReadAloudService.isRun -> { + if (BaseReadAloudService.isPlay()) { + ReadAloud.pause(context) + AudioPlay.pause(context) + } else { + ReadAloud.resume(context) + AudioPlay.resume(context) + } } - AudioPlayService.isRun -> if (AudioPlayService.pause) { - AudioPlay.resume(context) - } else { - AudioPlay.pause(context) + AudioPlayService.isRun -> { + if (AudioPlayService.pause) { + AudioPlay.resume(context) + } else { + AudioPlay.pause(context) + } } LifecycleHelp.isExistActivity(ReadBookActivity::class.java) -> postEvent(EventBus.MEDIA_BUTTON, true) LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) -> postEvent(EventBus.MEDIA_BUTTON, true) - else -> if (AppConfig.mediaButtonOnExit || !isMediaKey) { + else -> if (AppConfig.mediaButtonOnExit || !isMediaKey || LifecycleHelp.activitySize() > 0) { appDb.bookDao.lastReadBook?.let { if (!LifecycleHelp.isExistActivity(MainActivity::class.java)) { - Intent(context, MainActivity::class.java).let { - it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(it) + context.startActivity { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } } - Intent(context, ReadBookActivity::class.java).let { - it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - it.putExtra("readAloud", true) - context.startActivity(it) + context.startActivity { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + putExtra("readAloud", true) } } }