diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index 2af0be2b3..30e2b86a0 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -215,6 +215,7 @@ object ReadBook : CoroutineScope by MainScope() { */ fun readAloud(play: Boolean = true) { book?.let { + ReadAloud.upReadAloudClass() ReadAloud.play(appCtx, play) } } @@ -352,7 +353,7 @@ object ReadBook : CoroutineScope by MainScope() { if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { val contentProcessor = ContentProcessor.get(book.name, book.origin) val displayTitle = chapter.getDisplayTitle( - contentProcessor.getContentReplaceRules(), + contentProcessor.getTitleReplaceRules(), book.getUseReplaceRule() ) val contents = contentProcessor.getContent(book, chapter, content) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/HttpTtsEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/config/HttpTtsEditViewModel.kt index ffeee7050..0559b7ff9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/HttpTtsEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/HttpTtsEditViewModel.kt @@ -37,7 +37,6 @@ class HttpTtsEditViewModel(app: Application) : BaseViewModel(app) { id = httpTTS.id execute { appDb.httpTTSDao.insert(httpTTS) - ReadAloud.upReadAloudClass() }.onSuccess { success?.invoke() } 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 2bcd7490a..51f3c8be9 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 @@ -56,11 +56,12 @@ class ReadAloudConfigDialog : DialogFragment() { } class ReadAloudPreferenceFragment : BasePreferenceFragment(), + SpeakEngineDialog.CallBack, SharedPreferences.OnSharedPreferenceChangeListener { private val speakEngineSummary: String get() { - val ttsEngine = AppConfig.ttsEngine + val ttsEngine = ReadAloud.ttsEngine ?: return getString(R.string.system_tts) if (StringUtils.isNumeric(ttsEngine)) { return appDb.httpTTSDao.getName(ttsEngine.toLong()) @@ -72,10 +73,7 @@ class ReadAloudConfigDialog : DialogFragment() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_config_aloud) - upPreferenceSummary( - findPreference(PreferKey.ttsEngine), - speakEngineSummary - ) + upSpeakEngineSummary() } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -95,7 +93,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,10 +108,7 @@ class ReadAloudConfigDialog : DialogFragment() { postEvent(EventBus.MEDIA_BUTTON, false) } } - PreferKey.ttsEngine -> { - upPreferenceSummary(findPreference(key), speakEngineSummary) - ReadAloud.upReadAloudClass() - } + PreferKey.ttsEngine -> upSpeakEngineSummary() } } @@ -129,5 +124,11 @@ class ReadAloudConfigDialog : DialogFragment() { } } + override fun upSpeakEngineSummary() { + 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 58a91d19f..05dbf478e 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 @@ -33,7 +33,7 @@ import kotlinx.coroutines.launch /** * tts引擎管理 */ -class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), +class SpeakEngineDialog(val callBack: CallBack) : BaseDialogFragment(R.layout.dialog_recycler_view), Toolbar.OnMenuItemClickListener { private val binding by viewBinding(DialogRecyclerViewBinding::bind) @@ -104,6 +104,7 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), tvFooterLeft.visible() tvFooterLeft.setOnClickListener { ReadBook.book?.setTtsEngine(ttsEngine) + callBack.upSpeakEngineSummary() dismissAllowingStateLoss() } tvOk.setText(R.string.general) @@ -230,4 +231,8 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), } + interface CallBack { + fun upSpeakEngineSummary() + } + } \ No newline at end of file