pull/47/head
kunfei 5 years ago
parent e62d289f1b
commit f6f472ed48
  1. 24
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt

@ -4,11 +4,18 @@ import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.view.KeyEvent import android.view.KeyEvent
import io.legado.app.App
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.data.entities.Book
import io.legado.app.help.ActivityHelp import io.legado.app.help.ActivityHelp
import io.legado.app.ui.audio.AudioPlayActivity import io.legado.app.ui.audio.AudioPlayActivity
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
/** /**
@ -33,15 +40,24 @@ class MediaButtonReceiver : BroadcastReceiver() {
} }
private fun readAloud(context: Context) { private fun readAloud(context: Context) {
if (ActivityHelp.isExist(AudioPlayActivity::class.java)) { when {
ActivityHelp.isExist(AudioPlayActivity::class.java) ->
postEvent(Bus.AUDIO_PLAY_BUTTON, true) postEvent(Bus.AUDIO_PLAY_BUTTON, true)
} else if (!ActivityHelp.isExist(ReadBookActivity::class.java)) { ActivityHelp.isExist(ReadBookActivity::class.java) ->
postEvent(Bus.READ_ALOUD_BUTTON, true)
else -> {
GlobalScope.launch(Main) {
val lastBook: Book? = withContext(IO) {
App.db.bookDao().lastReadBook
}
lastBook?.let {
val intent = Intent(context, ReadBookActivity::class.java) val intent = Intent(context, ReadBookActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.putExtra("readAloud", true) intent.putExtra("readAloud", true)
context.startActivity(intent) context.startActivity(intent)
} else { }
postEvent(Bus.READ_ALOUD_BUTTON, true) }
}
} }
} }
} }

Loading…
Cancel
Save