private void setLanguage(@NonNull LanguageData lang) { Config.setTtsEnabled(true); TtsPlayer.INSTANCE.setLanguage(lang); mPrefLanguages.setSummary(lang.name); update(); }
private void update() { enableListeners(false); List<LanguageData> languages = TtsPlayer.INSTANCE.refreshLanguages(); mLanguages.clear(); mCurrentLanguage = null; if (languages.isEmpty()) { mPrefEnabled.setChecked(false); mPrefEnabled.setEnabled(false); mPrefEnabled.setSummary(R.string.pref_tts_unavailable); mPrefLanguages.setEnabled(false); mPrefLanguages.setSummary(null); enableListeners(true); return; } mPrefEnabled.setChecked(TtsPlayer.INSTANCE.isEnabled()); mPrefEnabled.setSummary(null); final CharSequence[] entries = new CharSequence[languages.size()]; final CharSequence[] values = new CharSequence[languages.size()]; for (int i = 0; i < languages.size(); i++) { LanguageData lang = languages.get(i); entries[i] = lang.name; values[i] = lang.internalCode; mLanguages.put(lang.internalCode, lang); } mPrefLanguages.setEntries(entries); mPrefLanguages.setEntryValues(values); mCurrentLanguage = TtsPlayer.getSelectedLanguage(languages); boolean available = (mCurrentLanguage != null && mCurrentLanguage.downloaded); mPrefLanguages.setEnabled(available && TtsPlayer.INSTANCE.isEnabled()); mPrefLanguages.setSummary(available ? mCurrentLanguage.name : null); mPrefLanguages.setValue(available ? mCurrentLanguage.internalCode : null); mPrefEnabled.setChecked(available && TtsPlayer.INSTANCE.isEnabled()); enableListeners(true); }