其他设置添加默认的tts引擎

pull/1601/head
Xwite 3 years ago
parent 21dc1f63af
commit f909c0a579
  1. 1
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 14
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt
  3. 10
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  4. 19
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  5. 1
      app/src/main/res/values-es-rES/strings.xml
  6. 1
      app/src/main/res/values-ja-rJP/strings.xml
  7. 1
      app/src/main/res/values-pt-rBR/strings.xml
  8. 1
      app/src/main/res/values-zh-rHK/strings.xml
  9. 1
      app/src/main/res/values-zh-rTW/strings.xml
  10. 1
      app/src/main/res/values-zh/strings.xml
  11. 1
      app/src/main/res/values/strings.xml
  12. 4
      app/src/main/res/xml/pref_config_other.xml

@ -192,7 +192,6 @@ data class Book(
get() = config().ttsEngine get() = config().ttsEngine
set(value) { set(value) {
config().ttsEngine = value config().ttsEngine = value
AppConfig.ttsEngine = value
save() save()
} }

@ -55,7 +55,8 @@ class ReadAloudConfigDialog : DialogFragment() {
.commit() .commit()
} }
class ReadAloudPreferenceFragment : BasePreferenceFragment(), class ReadAloudPreferenceFragment : SpeakEngineDialog.CallBack,
BasePreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener {
private val speakEngineSummary: String private val speakEngineSummary: String
@ -95,7 +96,7 @@ class ReadAloudConfigDialog : DialogFragment() {
override fun onPreferenceTreeClick(preference: Preference): Boolean { override fun onPreferenceTreeClick(preference: Preference): Boolean {
when (preference.key) { when (preference.key) {
PreferKey.ttsEngine -> showDialogFragment(SpeakEngineDialog()) PreferKey.ttsEngine -> showDialogFragment(SpeakEngineDialog(this))
} }
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }
@ -110,9 +111,6 @@ class ReadAloudConfigDialog : DialogFragment() {
postEvent(EventBus.MEDIA_BUTTON, false) postEvent(EventBus.MEDIA_BUTTON, false)
} }
} }
PreferKey.ttsEngine -> {
upPreferenceSummary(findPreference(key), speakEngineSummary)
}
} }
} }
@ -128,5 +126,11 @@ class ReadAloudConfigDialog : DialogFragment() {
} }
} }
override fun upSummary() {
upPreferenceSummary(
findPreference(PreferKey.ttsEngine),
speakEngineSummary
)
}
} }
} }

@ -17,6 +17,7 @@ import io.legado.app.data.entities.HttpTTS
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemHttpTtsBinding import io.legado.app.databinding.ItemHttpTtsBinding
import io.legado.app.help.AppConfig
import io.legado.app.help.DirectLinkUpload import io.legado.app.help.DirectLinkUpload
import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
@ -30,7 +31,7 @@ import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), class SpeakEngineDialog(val callBack: CallBack? = null) : BaseDialogFragment(R.layout.dialog_recycler_view),
Toolbar.OnMenuItemClickListener { Toolbar.OnMenuItemClickListener {
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
@ -88,6 +89,8 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
tvOk.visible() tvOk.visible()
tvOk.setOnClickListener { tvOk.setOnClickListener {
ReadBook.book?.ttsEngine = ttsEngine ReadBook.book?.ttsEngine = ttsEngine
callBack?.upSummary()
if (callBack == null) AppConfig.ttsEngine = ttsEngine
dismissAllowingStateLoss() dismissAllowingStateLoss()
} }
tvCancel.visible() tvCancel.visible()
@ -137,6 +140,8 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
} }
context?.selector(R.string.system_tts, ttsItems) { _, item, _ -> context?.selector(R.string.system_tts, ttsItems) { _, item, _ ->
ReadBook.book?.ttsEngine = GSON.toJson(item) ReadBook.book?.ttsEngine = GSON.toJson(item)
callBack?.upSummary()
if (callBack == null) AppConfig.ttsEngine = GSON.toJson(item)
ttsEngine = null ttsEngine = null
adapter.notifyItemRangeChanged(0, adapter.itemCount) adapter.notifyItemRangeChanged(0, adapter.itemCount)
dismissAllowingStateLoss() dismissAllowingStateLoss()
@ -212,4 +217,7 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
} }
interface CallBack {
fun upSummary()
}
} }

@ -13,13 +13,16 @@ import io.legado.app.base.BasePreferenceFragment
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.model.CheckSource import io.legado.app.model.CheckSource
import io.legado.app.data.appDb
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.receiver.SharedReceiverActivity
import io.legado.app.service.WebService import io.legado.app.service.WebService
import io.legado.app.ui.book.read.config.SpeakEngineDialog
import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.number.NumberPickerDialog
import io.legado.app.utils.* import io.legado.app.utils.*
@ -39,6 +42,17 @@ class OtherConfigFragment : BasePreferenceFragment(),
AppConfig.defaultBookTreeUri = treeUri.toString() AppConfig.defaultBookTreeUri = treeUri.toString()
} }
} }
private val speakEngineSummary: String
get() {
val ttsEngine = AppConfig.ttsEngine
?: return getString(R.string.system_tts)
if (StringUtils.isNumeric(ttsEngine)) {
return appDb.httpTTSDao.getName(ttsEngine.toLong())
?: getString(R.string.system_tts)
}
return GSON.fromJsonObject<SelectItem<String>>(ttsEngine)?.title
?: getString(R.string.system_tts)
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
putPrefBoolean(PreferKey.processText, isProcessTextEnabled()) putPrefBoolean(PreferKey.processText, isProcessTextEnabled())
@ -54,6 +68,7 @@ class OtherConfigFragment : BasePreferenceFragment(),
upPreferenceSummary(PreferKey.defaultBookTreeUri, it) upPreferenceSummary(PreferKey.defaultBookTreeUri, it)
} }
upPreferenceSummary(PreferKey.checkSource, CheckSource.summary) upPreferenceSummary(PreferKey.checkSource, CheckSource.summary)
upPreferenceSummary(PreferKey.ttsEngine, speakEngineSummary)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -102,6 +117,7 @@ class OtherConfigFragment : BasePreferenceFragment(),
PreferKey.cleanCache -> clearCache() PreferKey.cleanCache -> clearCache()
PreferKey.uploadRule -> showDialogFragment<DirectLinkUploadConfig>() PreferKey.uploadRule -> showDialogFragment<DirectLinkUploadConfig>()
PreferKey.checkSource -> showDialogFragment<CheckSourceConfig>() PreferKey.checkSource -> showDialogFragment<CheckSourceConfig>()
PreferKey.ttsEngine -> showDialogFragment(SpeakEngineDialog())
} }
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }
@ -139,6 +155,9 @@ class OtherConfigFragment : BasePreferenceFragment(),
PreferKey.checkSource -> listView.post { PreferKey.checkSource -> listView.post {
upPreferenceSummary(PreferKey.checkSource, CheckSource.summary) upPreferenceSummary(PreferKey.checkSource, CheckSource.summary)
} }
PreferKey.ttsEngine -> {
upPreferenceSummary(PreferKey.ttsEngine, speakEngineSummary)
}
} }
} }

@ -928,5 +928,6 @@
<string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string> <string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string>
<string name="record_debug_log">记录调试日志</string> <string name="record_debug_log">记录调试日志</string>
<string name="sub_dir">子文件夹</string> <string name="sub_dir">子文件夹</string>
<string name="default_tts_engine">Default TTS engine</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -931,5 +931,6 @@
<string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string> <string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string>
<string name="record_debug_log">记录调试日志</string> <string name="record_debug_log">记录调试日志</string>
<string name="sub_dir">子文件夹</string> <string name="sub_dir">子文件夹</string>
<string name="default_tts_engine">Default TTS engine</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -929,5 +929,6 @@
<string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string> <string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string>
<string name="record_debug_log">记录调试日志</string> <string name="record_debug_log">记录调试日志</string>
<string name="sub_dir">子文件夹</string> <string name="sub_dir">子文件夹</string>
<string name="default_tts_engine">Default TTS engine</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -928,5 +928,6 @@
<string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string> <string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string>
<string name="record_debug_log">记录调试日志</string> <string name="record_debug_log">记录调试日志</string>
<string name="sub_dir">子文件夹</string> <string name="sub_dir">子文件夹</string>
<string name="default_tts_engine">默认朗读引擎</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -930,5 +930,6 @@
<string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string> <string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string>
<string name="record_debug_log">记录调试日志</string> <string name="record_debug_log">记录调试日志</string>
<string name="sub_dir">子文件夹</string> <string name="sub_dir">子文件夹</string>
<string name="default_tts_engine">默认朗读引擎</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -930,5 +930,6 @@
<string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string> <string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string>
<string name="record_debug_log">记录调试日志</string> <string name="record_debug_log">记录调试日志</string>
<string name="sub_dir">子文件夹</string> <string name="sub_dir">子文件夹</string>
<string name="default_tts_engine">默认朗读引擎</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -931,5 +931,6 @@
<string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string> <string name="check_source_config_summary">校验超时: %1$s秒\n校验项目:%2$s</string>
<string name="record_debug_log">记录调试日志</string> <string name="record_debug_log">记录调试日志</string>
<string name="sub_dir">Sub dir</string> <string name="sub_dir">Sub dir</string>
<string name="default_tts_engine">Default TTS engine</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -56,6 +56,10 @@
android:key="userAgent" android:key="userAgent"
android:title="@string/user_agent" /> android:title="@string/user_agent" />
<io.legado.app.ui.widget.prefs.Preference
android:key="appTtsEngine"
android:title="@string/default_tts_engine" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:key="defaultBookTreeUri" android:key="defaultBookTreeUri"
android:summary="@string/book_tree_uri_s" android:summary="@string/book_tree_uri_s"

Loading…
Cancel
Save