Merge pull request #1606 from Xwite/master

fix bugs
pull/1612/head
kunfei 3 years ago committed by GitHub
commit 4005fda609
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/src/main/java/io/legado/app/model/ReadBook.kt
  2. 1
      app/src/main/java/io/legado/app/ui/book/read/config/HttpTtsEditViewModel.kt
  3. 21
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt
  4. 7
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.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)

@ -37,7 +37,6 @@ class HttpTtsEditViewModel(app: Application) : BaseViewModel(app) {
id = httpTTS.id
execute {
appDb.httpTTSDao.insert(httpTTS)
ReadAloud.upReadAloudClass()
}.onSuccess {
success?.invoke()
}

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

@ -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()
}
}
Loading…
Cancel
Save