Horis 2 лет назад
Родитель
Сommit
46ffc29888

+ 1 - 0
app/src/main/java/io/legado/app/constant/PreferKey.kt

@@ -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"

+ 3 - 0
app/src/main/java/io/legado/app/help/config/AppConfig.kt

@@ -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")

+ 4 - 9
app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt

@@ -63,10 +63,6 @@ class MediaButtonReceiver : BroadcastReceiver() {
                             }
                         }
 
-                        KeyEvent.KEYCODE_MEDIA_PAUSE -> {
-                            pauseReadAloud(context)
-                        }
-
                         else -> readAloud(context)
                     }
                 }
@@ -74,11 +70,6 @@ class MediaButtonReceiver : BroadcastReceiver() {
             return true
         }
 
-        private fun pauseReadAloud(context: Context) {
-            ReadAloud.pause(context)
-            AudioPlay.pause(context)
-        }
-
         fun readAloud(context: Context, isMediaKey: Boolean = true) {
             when {
                 BaseReadAloudService.isRun -> {
@@ -99,6 +90,10 @@ class MediaButtonReceiver : BroadcastReceiver() {
                     }
                 }
 
+                isMediaKey && !AppConfig.readAloudByMediaButton -> {
+                    // break
+                }
+
                 LifecycleHelp.isExistActivity(ReadBookActivity::class.java) ->
                     postEvent(EventBus.MEDIA_BUTTON, true)
 

+ 2 - 0
app/src/main/res/values-es-rES/strings.xml

@@ -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 - 0
app/src/main/res/values-ja-rJP/strings.xml

@@ -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 - 0
app/src/main/res/values-pt-rBR/strings.xml

@@ -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 - 0
app/src/main/res/values-vi/strings.xml

@@ -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 - 0
app/src/main/res/values-zh-rHK/strings.xml

@@ -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 - 0
app/src/main/res/values-zh-rTW/strings.xml

@@ -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 - 0
app/src/main/res/values-zh/strings.xml

@@ -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 - 0
app/src/main/res/values/strings.xml

@@ -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 - 0
app/src/main/res/xml/pref_config_other.xml

@@ -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"