From f909c0a57950189efd59aa08c758c6cabe04e337 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 9 Feb 2022 23:22:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B6=E4=BB=96=E8=AE=BE=E7=BD=AE=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=BB=98=E8=AE=A4=E7=9A=84tts=E5=BC=95=E6=93=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/Book.kt | 1 - .../book/read/config/ReadAloudConfigDialog.kt | 14 +++++++++----- .../ui/book/read/config/SpeakEngineDialog.kt | 10 +++++++++- .../app/ui/config/OtherConfigFragment.kt | 19 +++++++++++++++++++ app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_config_other.xml | 4 ++++ 12 files changed, 48 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 18dedb468..cfa3e261d 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -192,7 +192,6 @@ data class Book( get() = config().ttsEngine set(value) { config().ttsEngine = value - AppConfig.ttsEngine = value save() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index 48be01d34..3ee99c777 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -55,7 +55,8 @@ class ReadAloudConfigDialog : DialogFragment() { .commit() } - class ReadAloudPreferenceFragment : BasePreferenceFragment(), + class ReadAloudPreferenceFragment : SpeakEngineDialog.CallBack, + BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { private val speakEngineSummary: String @@ -95,7 +96,7 @@ class ReadAloudConfigDialog : DialogFragment() { override fun onPreferenceTreeClick(preference: Preference): Boolean { when (preference.key) { - PreferKey.ttsEngine -> showDialogFragment(SpeakEngineDialog()) + PreferKey.ttsEngine -> showDialogFragment(SpeakEngineDialog(this)) } return super.onPreferenceTreeClick(preference) } @@ -110,9 +111,6 @@ class ReadAloudConfigDialog : DialogFragment() { 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 + ) + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index d5d01e6e5..5deae59ba 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -17,6 +17,7 @@ import io.legado.app.data.entities.HttpTTS import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.ItemHttpTtsBinding +import io.legado.app.help.AppConfig import io.legado.app.help.DirectLinkUpload import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.alert @@ -30,7 +31,7 @@ import kotlinx.coroutines.flow.collect 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 { private val binding by viewBinding(DialogRecyclerViewBinding::bind) @@ -88,6 +89,8 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), tvOk.visible() tvOk.setOnClickListener { ReadBook.book?.ttsEngine = ttsEngine + callBack?.upSummary() + if (callBack == null) AppConfig.ttsEngine = ttsEngine dismissAllowingStateLoss() } tvCancel.visible() @@ -137,6 +140,8 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), } context?.selector(R.string.system_tts, ttsItems) { _, item, _ -> ReadBook.book?.ttsEngine = GSON.toJson(item) + callBack?.upSummary() + if (callBack == null) AppConfig.ttsEngine = GSON.toJson(item) ttsEngine = null adapter.notifyItemRangeChanged(0, adapter.itemCount) dismissAllowingStateLoss() @@ -212,4 +217,7 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), } + interface CallBack { + fun upSummary() + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index a965a939b..cd2cb6e92 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -13,13 +13,16 @@ import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.model.CheckSource +import io.legado.app.data.appDb import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp 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.receiver.SharedReceiverActivity 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.widget.number.NumberPickerDialog import io.legado.app.utils.* @@ -39,6 +42,17 @@ class OtherConfigFragment : BasePreferenceFragment(), 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>(ttsEngine)?.title + ?: getString(R.string.system_tts) + } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { putPrefBoolean(PreferKey.processText, isProcessTextEnabled()) @@ -54,6 +68,7 @@ class OtherConfigFragment : BasePreferenceFragment(), upPreferenceSummary(PreferKey.defaultBookTreeUri, it) } upPreferenceSummary(PreferKey.checkSource, CheckSource.summary) + upPreferenceSummary(PreferKey.ttsEngine, speakEngineSummary) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -102,6 +117,7 @@ class OtherConfigFragment : BasePreferenceFragment(), PreferKey.cleanCache -> clearCache() PreferKey.uploadRule -> showDialogFragment() PreferKey.checkSource -> showDialogFragment() + PreferKey.ttsEngine -> showDialogFragment(SpeakEngineDialog()) } return super.onPreferenceTreeClick(preference) } @@ -139,6 +155,9 @@ class OtherConfigFragment : BasePreferenceFragment(), PreferKey.checkSource -> listView.post { upPreferenceSummary(PreferKey.checkSource, CheckSource.summary) } + PreferKey.ttsEngine -> { + upPreferenceSummary(PreferKey.ttsEngine, speakEngineSummary) + } } } diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 1a404a11c..c2a225579 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -928,5 +928,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + Default TTS engine diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 118b873f2..3a848c5d2 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -931,5 +931,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + Default TTS engine diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 94949dc6d..afcf660fd 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -929,5 +929,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + Default TTS engine diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 2158736f8..4c6bbbd88 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -928,5 +928,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + 默认朗读引擎 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index c99dc1ecc..0894d4ddb 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -930,5 +930,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + 默认朗读引擎 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 26ac234e2..d68fe8b3e 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -930,5 +930,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + 默认朗读引擎 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d10a2350d..7dc43c14d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -931,5 +931,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 Sub dir + Default TTS engine diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 9388b4878..0a81518b1 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -56,6 +56,10 @@ android:key="userAgent" android:title="@string/user_agent" /> + +