pull/885/head^2
gedoor 4 years ago
parent d3f158e206
commit 8b4829996a
  1. 2
      app/src/main/java/io/legado/app/help/AppConfig.kt
  2. 19
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  3. 4
      app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt
  4. 2
      app/src/main/res/xml/shortcuts.xml

@ -175,6 +175,8 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
val preDownload get() = appCtx.getPrefBoolean(PreferKey.preDownload, true)
val mediaButtonOnExit get() = appCtx.getPrefBoolean("mediaButtonOnExit", true)
private fun getPrefUserAgent(): String {
val ua = appCtx.getPrefString(PreferKey.userAgent)
if (ua.isNullOrBlank()) {

@ -6,8 +6,8 @@ import android.content.Intent
import android.view.KeyEvent
import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.help.ActivityHelp
import io.legado.app.help.AppConfig
import io.legado.app.service.AudioPlayService
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.AudioPlay
@ -15,13 +15,7 @@ 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
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
/**
@ -61,7 +55,7 @@ class MediaButtonReceiver : BroadcastReceiver() {
return true
}
fun readAloud(context: Context) {
fun readAloud(context: Context, isMediaKey: Boolean = true) {
when {
BaseReadAloudService.isRun -> if (BaseReadAloudService.isPlay()) {
ReadAloud.pause(context)
@ -79,12 +73,8 @@ class MediaButtonReceiver : BroadcastReceiver() {
postEvent(EventBus.MEDIA_BUTTON, true)
ActivityHelp.isExist(AudioPlayActivity::class.java) ->
postEvent(EventBus.MEDIA_BUTTON, true)
else -> if (context.getPrefBoolean("mediaButtonOnExit", true)) {
GlobalScope.launch(Main) {
val lastBook: Book? = withContext(IO) {
appDb.bookDao.lastReadBook
}
lastBook?.let {
else -> if (AppConfig.mediaButtonOnExit || !isMediaKey) {
appDb.bookDao.lastReadBook?.let {
if (!ActivityHelp.isExist(MainActivity::class.java)) {
Intent(context, MainActivity::class.java).let {
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
@ -101,6 +91,5 @@ class MediaButtonReceiver : BroadcastReceiver() {
}
}
}
}
}

@ -41,8 +41,8 @@ class SharedReceiverActivity : AppCompatActivity() {
}
}
}
intent.getStringExtra("action") == "mediaButton" -> {
MediaButtonReceiver.readAloud(appCtx)
intent.getStringExtra("action") == "readAloud" -> {
MediaButtonReceiver.readAloud(appCtx, false)
}
}
}

@ -36,7 +36,7 @@
android:targetClass="io.legado.app.receiver.SharedReceiverActivity">
<extra
android:name="action"
android:value="mediaButton" />
android:value="readAloud" />
</intent>
<categories android:name="android.shortcut.conversation" />
</shortcut>

Loading…
Cancel
Save