|
|
|
@ -8,9 +8,14 @@ import io.legado.app.App |
|
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
|
import io.legado.app.help.ActivityHelp |
|
|
|
|
import io.legado.app.service.AudioPlayService |
|
|
|
|
import io.legado.app.service.BaseReadAloudService |
|
|
|
|
import io.legado.app.service.help.AudioPlay |
|
|
|
|
import io.legado.app.service.help.ReadAloud |
|
|
|
|
import io.legado.app.ui.audio.AudioPlayActivity |
|
|
|
|
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 kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
@ -50,11 +55,23 @@ class MediaButtonReceiver : BroadcastReceiver() { |
|
|
|
|
|
|
|
|
|
private fun readAloud(context: Context) { |
|
|
|
|
when { |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
ActivityHelp.isExist(AudioPlayActivity::class.java) -> |
|
|
|
|
postEvent(EventBus.MEDIA_BUTTON, true) |
|
|
|
|
ActivityHelp.isExist(ReadBookActivity::class.java) -> |
|
|
|
|
postEvent(EventBus.MEDIA_BUTTON, true) |
|
|
|
|
else -> { |
|
|
|
|
else -> if (context.getPrefBoolean("mediaButtonOnExit", true)) { |
|
|
|
|
GlobalScope.launch(Main) { |
|
|
|
|
val lastBook: Book? = withContext(IO) { |
|
|
|
|
App.db.bookDao().lastReadBook |
|
|
|
|