pull/1319/head
gedoor 3 years ago
parent f5f7b46da4
commit 27e4d1acbf
  1. 23
      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.ui.main.MainActivity
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.postEvent 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) { fun readAloud(context: Context, isMediaKey: Boolean = true) {
when { when {
BaseReadAloudService.isRun -> if (BaseReadAloudService.isPlay()) { BaseReadAloudService.isRun -> {
if (BaseReadAloudService.isPlay()) {
ReadAloud.pause(context) ReadAloud.pause(context)
AudioPlay.pause(context) AudioPlay.pause(context)
} else { } else {
ReadAloud.resume(context) ReadAloud.resume(context)
AudioPlay.resume(context) AudioPlay.resume(context)
} }
AudioPlayService.isRun -> if (AudioPlayService.pause) { }
AudioPlayService.isRun -> {
if (AudioPlayService.pause) {
AudioPlay.resume(context) AudioPlay.resume(context)
} else { } else {
AudioPlay.pause(context) AudioPlay.pause(context)
} }
}
LifecycleHelp.isExistActivity(ReadBookActivity::class.java) -> LifecycleHelp.isExistActivity(ReadBookActivity::class.java) ->
postEvent(EventBus.MEDIA_BUTTON, true) postEvent(EventBus.MEDIA_BUTTON, true)
LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) -> LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) ->
postEvent(EventBus.MEDIA_BUTTON, true) postEvent(EventBus.MEDIA_BUTTON, true)
else -> if (AppConfig.mediaButtonOnExit || !isMediaKey) { else -> if (AppConfig.mediaButtonOnExit || !isMediaKey || LifecycleHelp.activitySize() > 0) {
appDb.bookDao.lastReadBook?.let { appDb.bookDao.lastReadBook?.let {
if (!LifecycleHelp.isExistActivity(MainActivity::class.java)) { if (!LifecycleHelp.isExistActivity(MainActivity::class.java)) {
Intent(context, MainActivity::class.java).let { context.startActivity<MainActivity> {
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(it)
} }
} }
Intent(context, ReadBookActivity::class.java).let { context.startActivity<ReadBookActivity> {
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
it.putExtra("readAloud", true) putExtra("readAloud", true)
context.startActivity(it)
} }
} }
} }

Loading…
Cancel
Save