Merge pull request #26 from jaime-grj/fix-languageselection

fix: show "System default" language option, sort languages alphabetically, include country when showing language in settings
This commit is contained in:
eddyizm 2025-08-09 07:12:28 -07:00 committed by GitHub
commit 04580e380b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 38 additions and 9 deletions

View file

@ -201,12 +201,22 @@ public class SettingsFragment extends PreferenceFragmentCompat {
localePref.setEntries(entries);
localePref.setEntryValues(entryValues);
localePref.setDefaultValue(entryValues[0]);
localePref.setSummary(Locale.forLanguageTag(localePref.getValue()).getDisplayLanguage());
String value = localePref.getValue();
if ("default".equals(value)) {
localePref.setSummary(requireContext().getString(R.string.settings_system_language));
} else {
localePref.setSummary(Locale.forLanguageTag(value).getDisplayName());
}
localePref.setOnPreferenceChangeListener((preference, newValue) -> {
LocaleListCompat appLocale = LocaleListCompat.forLanguageTags((String) newValue);
AppCompatDelegate.setApplicationLocales(appLocale);
if ("default".equals(newValue)) {
AppCompatDelegate.setApplicationLocales(LocaleListCompat.getEmptyLocaleList());
preference.setSummary(requireContext().getString(R.string.settings_system_language));
} else {
LocaleListCompat appLocale = LocaleListCompat.forLanguageTags((String) newValue);
AppCompatDelegate.setApplicationLocales(appLocale);
preference.setSummary(Locale.forLanguageTag((String) newValue).getDisplayName());
}
return true;
});
}