pull/90/head^2
kunfei 5 years ago
parent b2339ed043
commit 3ac6d9807b
  1. 3
      app/src/main/java/io/legado/app/help/AppConfig.kt
  2. 4
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  3. 45
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt
  4. 1
      app/src/main/res/values/strings.xml
  5. 2
      app/src/main/res/xml/pref_config_aloud.xml

@ -56,6 +56,9 @@ object AppConfig {
App.INSTANCE.putPrefInt(PreferKey.ttsSpeechRate, value) App.INSTANCE.putPrefInt(PreferKey.ttsSpeechRate, value)
} }
val ttsSpeechPer: String
get() = App.INSTANCE.getPrefString(PreferKey.ttsSpeechPer) ?: "0"
val isEInkMode: Boolean val isEInkMode: Boolean
get() = App.INSTANCE.getPrefBoolean("isEInkMode") get() = App.INSTANCE.getPrefBoolean("isEInkMode")

@ -3,7 +3,6 @@ package io.legado.app.service
import android.app.PendingIntent import android.app.PendingIntent
import android.media.MediaPlayer import android.media.MediaPlayer
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
@ -11,7 +10,6 @@ import io.legado.app.help.http.api.HttpPostApi
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
import io.legado.app.utils.LogUtils import io.legado.app.utils.LogUtils
import io.legado.app.utils.getPrefString
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@ -114,7 +112,7 @@ class HttpReadAloudService : BaseReadAloudService(),
return mapOf( return mapOf(
Pair("tex", encodeTwo(content)), Pair("tex", encodeTwo(content)),
Pair("spd", ((AppConfig.ttsSpeechRate + 5) / 10 + 4).toString()), Pair("spd", ((AppConfig.ttsSpeechRate + 5) / 10 + 4).toString()),
Pair("per", getPrefString(PreferKey.ttsSpeechPer) ?: "0"), Pair("per", AppConfig.ttsSpeechPer),
Pair("cuid", "baidu_speech_demo"), Pair("cuid", "baidu_speech_demo"),
Pair("idx", "1"), Pair("idx", "1"),
Pair("cod", "2"), Pair("cod", "2"),

@ -14,11 +14,11 @@ import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadAloud
import io.legado.app.ui.book.read.Help import io.legado.app.ui.book.read.Help
import io.legado.app.utils.getPrefString
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
class ReadAloudConfigDialog : DialogFragment() { class ReadAloudConfigDialog : DialogFragment() {
@ -59,17 +59,19 @@ class ReadAloudConfigDialog : DialogFragment() {
} }
class ReadAloudPreferenceFragment : PreferenceFragmentCompat(), class ReadAloudPreferenceFragment : PreferenceFragmentCompat(),
SharedPreferences.OnSharedPreferenceChangeListener, SharedPreferences.OnSharedPreferenceChangeListener {
Preference.OnPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_aloud) addPreferencesFromResource(R.xml.pref_config_aloud)
upPreferenceSummary(
findPreference<ListPreference>(PreferKey.ttsSpeechPer),
AppConfig.ttsSpeechPer
)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
ATH.applyEdgeEffectColor(listView) ATH.applyEdgeEffectColor(listView)
bindPreferenceSummaryToValue(findPreference(PreferKey.ttsSpeechPer))
} }
override fun onResume() { override fun onResume() {
@ -97,32 +99,25 @@ class ReadAloudConfigDialog : DialogFragment() {
ReadAloud.aloudClass = ReadAloud.getReadAloudClass() ReadAloud.aloudClass = ReadAloud.getReadAloudClass()
} }
PreferKey.ttsSpeechPer -> { PreferKey.ttsSpeechPer -> {
upPreferenceSummary(
findPreference<ListPreference>(PreferKey.ttsSpeechPer),
AppConfig.ttsSpeechPer
)
ReadAloud.upTtsSpeechRate(requireContext()) ReadAloud.upTtsSpeechRate(requireContext())
} }
} }
} }
override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { private fun upPreferenceSummary(preference: Preference?, value: String) {
val stringValue = newValue.toString() when (preference) {
is ListPreference -> {
if (preference is ListPreference) { val index = preference.findIndexOfValue(value)
val index = preference.findIndexOfValue(stringValue) // Set the summary to reflect the new value.
// Set the summary to reflect the new value. preference.summary = if (index >= 0) preference.entries[index] else null
preference.setSummary(if (index >= 0) preference.entries[index] else null) }
} else { else -> {
// For all other preferences, set the summary to the value's preference?.summary = value
preference?.summary = stringValue }
}
return false
}
private fun bindPreferenceSummaryToValue(preference: Preference?) {
preference?.apply {
onPreferenceChangeListener = this@ReadAloudPreferenceFragment
onPreferenceChange(
this,
context.getPrefString(key)
)
} }
} }

@ -590,5 +590,6 @@
<string name="auto_dark_mode">自动切换夜间模式</string> <string name="auto_dark_mode">自动切换夜间模式</string>
<string name="auto_dark_mode_s">夜间模式跟随系统</string> <string name="auto_dark_mode_s">夜间模式跟随系统</string>
<string name="go_back">上级</string> <string name="go_back">上级</string>
<string name="tone_colour">在线朗读音色</string>
</resources> </resources>

@ -16,7 +16,7 @@
<androidx.preference.ListPreference <androidx.preference.ListPreference
android:key="ttsSpeechPer" android:key="ttsSpeechPer"
android:title="在线朗读音色" android:title="@string/tone_colour"
android:defaultValue="0" android:defaultValue="0"
android:entries="@array/tts_speech_per" android:entries="@array/tts_speech_per"
android:entryValues="@array/tts_speech_per_value" android:entryValues="@array/tts_speech_per_value"

Loading…
Cancel
Save