pull/32/head
kunfei 5 years ago
parent 91acb02340
commit 866b2988d8
  1. 2
      app/src/main/java/io/legado/app/help/ActivityHelp.kt
  2. 12
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  3. 2
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt

@ -94,7 +94,7 @@ class ActivityHelp private constructor() {
/**
* 判断指定Activity是否存在
*/
fun isExist(activityClass: Class<*>): Boolean? {
fun isExist(activityClass: Class<*>): Boolean {
var result = false
for (item in activities) {
if (item.get()?.javaClass == activityClass) {

@ -4,6 +4,11 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.view.KeyEvent
import io.legado.app.constant.Bus
import io.legado.app.help.ActivityHelp
import io.legado.app.ui.readbook.ReadBookActivity
import io.legado.app.utils.postEvent
import org.jetbrains.anko.startActivity
/**
@ -41,7 +46,12 @@ class MediaButtonReceiver : BroadcastReceiver() {
}
private fun readAloud(context: Context) {
ActivityHelp.getInstance()?.isExist(ReadBookActivity::class.java)?.let {
if (!it) {
context.startActivity<ReadBookActivity>()
}
}
postEvent(Bus.READ_ALOUD, "")
}
}

@ -246,6 +246,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
observeEvent<Int>(Bus.TTS_RANGE_START) {}
observeEvent<String>(Bus.TIME_CHANGED) {}
observeEvent<Int>(Bus.BATTERY_CHANGED) {}
observeEvent<String>(Bus.READ_ALOUD) { onClickReadAloud() }
observeEventSticky<String>(Bus.READ_ALOUD) { onClickReadAloud() }
}
}
Loading…
Cancel
Save