fix: show "System default" language option, sort languages alphabetically

This commit is contained in:
Jaime García 2025-08-09 02:52:07 +02:00
parent bfd6f28d7a
commit 8a57f8f389
No known key found for this signature in database
GPG key ID: BC4E5F71A71BDA5B
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).getDisplayLanguage());
}
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).getDisplayLanguage());
}
return true;
});
}