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) { fun readAloud(play: Boolean = true) {
book?.let { book?.let {
ReadAloud.upReadAloudClass()
ReadAloud.play(appCtx, play) ReadAloud.play(appCtx, play)
} }
} }
@ -352,7 +353,7 @@ object ReadBook : CoroutineScope by MainScope() {
if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) {
val contentProcessor = ContentProcessor.get(book.name, book.origin) val contentProcessor = ContentProcessor.get(book.name, book.origin)
val displayTitle = chapter.getDisplayTitle( val displayTitle = chapter.getDisplayTitle(
contentProcessor.getContentReplaceRules(), contentProcessor.getTitleReplaceRules(),
book.getUseReplaceRule() book.getUseReplaceRule()
) )
val contents = contentProcessor.getContent(book, chapter, content) val contents = contentProcessor.getContent(book, chapter, content)

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

@ -56,11 +56,12 @@ class ReadAloudConfigDialog : DialogFragment() {
} }
class ReadAloudPreferenceFragment : BasePreferenceFragment(), class ReadAloudPreferenceFragment : BasePreferenceFragment(),
SpeakEngineDialog.CallBack,
SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener {
private val speakEngineSummary: String private val speakEngineSummary: String
get() { get() {
val ttsEngine = AppConfig.ttsEngine val ttsEngine = ReadAloud.ttsEngine
?: return getString(R.string.system_tts) ?: return getString(R.string.system_tts)
if (StringUtils.isNumeric(ttsEngine)) { if (StringUtils.isNumeric(ttsEngine)) {
return appDb.httpTTSDao.getName(ttsEngine.toLong()) return appDb.httpTTSDao.getName(ttsEngine.toLong())
@ -72,10 +73,7 @@ class ReadAloudConfigDialog : DialogFragment() {
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( upSpeakEngineSummary()
findPreference(PreferKey.ttsEngine),
speakEngineSummary
)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -95,7 +93,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,10 +108,7 @@ class ReadAloudConfigDialog : DialogFragment() {
postEvent(EventBus.MEDIA_BUTTON, false) postEvent(EventBus.MEDIA_BUTTON, false)
} }
} }
PreferKey.ttsEngine -> { PreferKey.ttsEngine -> upSpeakEngineSummary()
upPreferenceSummary(findPreference(key), speakEngineSummary)
ReadAloud.upReadAloudClass()
}
} }
} }
@ -129,5 +124,11 @@ class ReadAloudConfigDialog : DialogFragment() {
} }
} }
override fun upSpeakEngineSummary() {
upPreferenceSummary(
findPreference(PreferKey.ttsEngine),
speakEngineSummary
)
}
} }
} }

@ -33,7 +33,7 @@ import kotlinx.coroutines.launch
/** /**
* tts引擎管理 * tts引擎管理
*/ */
class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), class SpeakEngineDialog(val callBack: CallBack) : BaseDialogFragment(R.layout.dialog_recycler_view),
Toolbar.OnMenuItemClickListener { Toolbar.OnMenuItemClickListener {
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
@ -104,6 +104,7 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
tvFooterLeft.visible() tvFooterLeft.visible()
tvFooterLeft.setOnClickListener { tvFooterLeft.setOnClickListener {
ReadBook.book?.setTtsEngine(ttsEngine) ReadBook.book?.setTtsEngine(ttsEngine)
callBack.upSpeakEngineSummary()
dismissAllowingStateLoss() dismissAllowingStateLoss()
} }
tvOk.setText(R.string.general) tvOk.setText(R.string.general)
@ -230,4 +231,8 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
} }
interface CallBack {
fun upSpeakEngineSummary()
}
} }
Loading…
Cancel
Save