|
|
@ -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 -> { |
|
|
|
ReadAloud.pause(context) |
|
|
|
if (BaseReadAloudService.isPlay()) { |
|
|
|
AudioPlay.pause(context) |
|
|
|
ReadAloud.pause(context) |
|
|
|
} else { |
|
|
|
AudioPlay.pause(context) |
|
|
|
ReadAloud.resume(context) |
|
|
|
} else { |
|
|
|
AudioPlay.resume(context) |
|
|
|
ReadAloud.resume(context) |
|
|
|
|
|
|
|
AudioPlay.resume(context) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
AudioPlayService.isRun -> if (AudioPlayService.pause) { |
|
|
|
AudioPlayService.isRun -> { |
|
|
|
AudioPlay.resume(context) |
|
|
|
if (AudioPlayService.pause) { |
|
|
|
} else { |
|
|
|
AudioPlay.resume(context) |
|
|
|
AudioPlay.pause(context) |
|
|
|
} else { |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|