Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Sep 26, 2024
1 parent 45252a2 commit bd671f4
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/io/legado/app/constant/PreferKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ object PreferKey {
const val updateToVariant = "updateToVariant"
const val streamReadAloudAudio = "streamReadAloudAudio"
const val pauseReadAloudWhilePhoneCalls = "pauseReadAloudWhilePhoneCalls"
const val readAloudByMediaButton = "readAloudByMediaButton"

const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/io/legado/app/help/config/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {

val mediaButtonOnExit get() = appCtx.getPrefBoolean("mediaButtonOnExit", true)

val readAloudByMediaButton
get() = appCtx.getPrefBoolean(PreferKey.readAloudByMediaButton, false)

val replaceEnableDefault get() = appCtx.getPrefBoolean(PreferKey.replaceEnableDefault, true)

val webDavDir get() = appCtx.getPrefString(PreferKey.webDavDir, "legado")
Expand Down
13 changes: 4 additions & 9 deletions app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,13 @@ class MediaButtonReceiver : BroadcastReceiver() {
}
}

KeyEvent.KEYCODE_MEDIA_PAUSE -> {
pauseReadAloud(context)
}

else -> readAloud(context)
}
}
}
return true
}

private fun pauseReadAloud(context: Context) {
ReadAloud.pause(context)
AudioPlay.pause(context)
}

fun readAloud(context: Context, isMediaKey: Boolean = true) {
when {
BaseReadAloudService.isRun -> {
Expand All @@ -99,6 +90,10 @@ class MediaButtonReceiver : BroadcastReceiver() {
}
}

isMediaKey && !AppConfig.readAloudByMediaButton -> {
// break
}

LifecycleHelp.isExistActivity(ReadBookActivity::class.java) ->
postEvent(EventBus.MEDIA_BUTTON, true)

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-es-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1164,4 +1164,6 @@
<string name="pause_read_aloud_while_phone_calls_title">来电期间暂停朗读</string>
<string name="pause_read_aloud_while_phone_calls_summary">在通话期间暂停朗读,需要读取手机状态权限</string>
<string name="read_aloud_read_phone_state_permission_rationale">阅读需要读取手机状态实现来电期间暂停朗读功能</string>
<string name="read_aloud_by_media_button_title">耳机按键启动朗读</string>
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1167,4 +1167,6 @@
<string name="pause_read_aloud_while_phone_calls_title">来电期间暂停朗读</string>
<string name="pause_read_aloud_while_phone_calls_summary">在通话期间暂停朗读,需要读取手机状态权限</string>
<string name="read_aloud_read_phone_state_permission_rationale">阅读需要读取手机状态实现来电期间暂停朗读功能</string>
<string name="read_aloud_by_media_button_title">耳机按键启动朗读</string>
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1167,4 +1167,6 @@
<string name="pause_read_aloud_while_phone_calls_title">来电期间暂停朗读</string>
<string name="pause_read_aloud_while_phone_calls_summary">在通话期间暂停朗读,需要读取手机状态权限</string>
<string name="read_aloud_read_phone_state_permission_rationale">阅读需要读取手机状态实现来电期间暂停朗读功能</string>
<string name="read_aloud_by_media_button_title">耳机按键启动朗读</string>
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1163,4 +1163,6 @@ Còn </string>
<string name="pause_read_aloud_while_phone_calls_title">来电期间暂停朗读</string>
<string name="pause_read_aloud_while_phone_calls_summary">在通话期间暂停朗读,需要读取手机状态权限</string>
<string name="read_aloud_read_phone_state_permission_rationale">阅读需要读取手机状态实现来电期间暂停朗读功能</string>
<string name="read_aloud_by_media_button_title">耳机按键启动朗读</string>
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1164,4 +1164,6 @@
<string name="pause_read_aloud_while_phone_calls_title">来电期间暂停朗读</string>
<string name="pause_read_aloud_while_phone_calls_summary">在通话期间暂停朗读,需要读取手机状态权限</string>
<string name="read_aloud_read_phone_state_permission_rationale">阅读需要读取手机状态实现来电期间暂停朗读功能</string>
<string name="read_aloud_by_media_button_title">耳机按键启动朗读</string>
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1166,4 +1166,6 @@
<string name="pause_read_aloud_while_phone_calls_title">来电期间暂停朗读</string>
<string name="pause_read_aloud_while_phone_calls_summary">在通话期间暂停朗读,需要读取手机状态权限</string>
<string name="read_aloud_read_phone_state_permission_rationale">阅读需要读取手机状态实现来电期间暂停朗读功能</string>
<string name="read_aloud_by_media_button_title">耳机按键启动朗读</string>
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1166,4 +1166,6 @@
<string name="pause_read_aloud_while_phone_calls_title">来电期间暂停朗读</string>
<string name="pause_read_aloud_while_phone_calls_summary">在通话期间暂停朗读,需要读取手机状态权限</string>
<string name="read_aloud_read_phone_state_permission_rationale">阅读需要读取手机状态实现来电期间暂停朗读功能</string>
<string name="read_aloud_by_media_button_title">耳机按键启动朗读</string>
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1167,4 +1167,6 @@
<string name="pause_read_aloud_while_phone_calls_title">来电期间暂停朗读</string>
<string name="pause_read_aloud_while_phone_calls_summary">在通话期间暂停朗读,需要读取手机状态权限</string>
<string name="read_aloud_read_phone_state_permission_rationale">阅读需要读取手机状态实现来电期间暂停朗读功能</string>
<string name="read_aloud_by_media_button_title">耳机按键启动朗读</string>
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/xml/pref_config_other.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@
android:title="@string/media_button_on_exit_title"
app:iconSpaceReserved="false" />

<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false"
android:key="readAloudByMediaButton"
android:summary="@string/read_aloud_by_media_button_summary"
android:title="@string/read_aloud_by_media_button_title"
app:iconSpaceReserved="false" />

<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false"
android:key="ignoreAudioFocus"
Expand Down

0 comments on commit bd671f4

Please sign in to comment.