|
|
@ -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 { |
|
|
|
postEvent(Bus.AUDIO_PLAY_BUTTON, true) |
|
|
|
ActivityHelp.isExist(AudioPlayActivity::class.java) -> |
|
|
|
} else if (!ActivityHelp.isExist(ReadBookActivity::class.java)) { |
|
|
|
postEvent(Bus.AUDIO_PLAY_BUTTON, true) |
|
|
|
val intent = Intent(context, ReadBookActivity::class.java) |
|
|
|
ActivityHelp.isExist(ReadBookActivity::class.java) -> |
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
|
|
|
postEvent(Bus.READ_ALOUD_BUTTON, true) |
|
|
|
intent.putExtra("readAloud", true) |
|
|
|
else -> { |
|
|
|
context.startActivity(intent) |
|
|
|
GlobalScope.launch(Main) { |
|
|
|
} else { |
|
|
|
val lastBook: Book? = withContext(IO) { |
|
|
|
postEvent(Bus.READ_ALOUD_BUTTON, true) |
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|