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. 33
      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 preDownload get() = appCtx.getPrefBoolean(PreferKey.preDownload, true)
val mediaButtonOnExit get() = appCtx.getPrefBoolean("mediaButtonOnExit", true)
private fun getPrefUserAgent(): String { private fun getPrefUserAgent(): String {
val ua = appCtx.getPrefString(PreferKey.userAgent) val ua = appCtx.getPrefString(PreferKey.userAgent)
if (ua.isNullOrBlank()) { if (ua.isNullOrBlank()) {

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

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

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

Loading…
Cancel
Save