|
|
|
@ -4,11 +4,18 @@ import android.content.BroadcastReceiver |
|
|
|
|
import android.content.Context |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.view.KeyEvent |
|
|
|
|
import io.legado.app.App |
|
|
|
|
import io.legado.app.constant.Bus |
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
|
import io.legado.app.help.ActivityHelp |
|
|
|
|
import io.legado.app.ui.audio.AudioPlayActivity |
|
|
|
|
import io.legado.app.ui.book.read.ReadBookActivity |
|
|
|
|
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) { |
|
|
|
|
if (ActivityHelp.isExist(AudioPlayActivity::class.java)) { |
|
|
|
|
postEvent(Bus.AUDIO_PLAY_BUTTON, true) |
|
|
|
|
} else if (!ActivityHelp.isExist(ReadBookActivity::class.java)) { |
|
|
|
|
val intent = Intent(context, ReadBookActivity::class.java) |
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
|
|
|
|
intent.putExtra("readAloud", true) |
|
|
|
|
context.startActivity(intent) |
|
|
|
|
} else { |
|
|
|
|
postEvent(Bus.READ_ALOUD_BUTTON, true) |
|
|
|
|
when { |
|
|
|
|
ActivityHelp.isExist(AudioPlayActivity::class.java) -> |
|
|
|
|
postEvent(Bus.AUDIO_PLAY_BUTTON, true) |
|
|
|
|
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) |
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
|
|
|
|
intent.putExtra("readAloud", true) |
|
|
|
|
context.startActivity(intent) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|