feat: 优化代码

pull/178/head 3.20.032622
kunfei 5 years ago
parent ef1c7ad698
commit 1cd1892d98
  1. 19
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  2. 2
      app/src/main/res/values/strings.xml
  3. 7
      app/src/main/res/xml/pref_config_other.xml

@ -8,9 +8,14 @@ import io.legado.app.App
import io.legado.app.constant.EventBus
import io.legado.app.data.entities.Book
import io.legado.app.help.ActivityHelp
import io.legado.app.service.AudioPlayService
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.AudioPlay
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
@ -50,11 +55,23 @@ class MediaButtonReceiver : BroadcastReceiver() {
private fun readAloud(context: Context) {
when {
BaseReadAloudService.isRun -> if (BaseReadAloudService.isPlay()) {
ReadAloud.pause(context)
AudioPlay.pause(context)
} else {
ReadAloud.resume(context)
AudioPlay.resume(context)
}
AudioPlayService.isRun -> if (AudioPlayService.pause) {
AudioPlay.resume(context)
} else {
AudioPlay.pause(context)
}
ActivityHelp.isExist(AudioPlayActivity::class.java) ->
postEvent(EventBus.MEDIA_BUTTON, true)
ActivityHelp.isExist(ReadBookActivity::class.java) ->
postEvent(EventBus.MEDIA_BUTTON, true)
else -> {
else -> if (context.getPrefBoolean("mediaButtonOnExit", true)) {
GlobalScope.launch(Main) {
val lastBook: Book? = withContext(IO) {
App.db.bookDao().lastReadBook

@ -648,4 +648,6 @@
<string name="alouding_disable">全文朗读中不能朗读选中文字</string>
<string name="read_body_to_lh">扩展到刘海</string>
<string name="toc_updateing">更新目录中</string>
<string name="media_button_on_exit_title">全程响应耳机按键</string>
<string name="media_button_on_exit_summary">即使退出软件也响应耳机按键</string>
</resources>

@ -45,6 +45,13 @@
android:title="@string/threads_num_title"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true"
android:key="mediaButtonOnExit"
android:title="@string/media_button_on_exit_title"
android:summary="@string/media_button_on_exit_summary"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference
android:key="webPort"
android:title="@string/web_port_title"

Loading…
Cancel
Save