From fc8d25684e967ffb1692ab1f4009743c9480efb8 Mon Sep 17 00:00:00 2001 From: woesss Date: Sat, 6 Jul 2024 10:07:37 +0300 Subject: [PATCH] Fix language region selection --- .../j2meloader/settings/SettingsFragment.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/ru/playsoftware/j2meloader/settings/SettingsFragment.java b/app/src/main/java/ru/playsoftware/j2meloader/settings/SettingsFragment.java index 26fe0d85..4c32ec63 100644 --- a/app/src/main/java/ru/playsoftware/j2meloader/settings/SettingsFragment.java +++ b/app/src/main/java/ru/playsoftware/j2meloader/settings/SettingsFragment.java @@ -78,28 +78,22 @@ private void initLanguages() { @SuppressLint("DiscouragedApi") int id = resources.getIdentifier("_generated_res_locale_config", "xml", context.getPackageName()); try (XmlResourceParser parser = resources.getXml(id)) { - if (XmlUtils.nextElement(parser, "locale")) { - sb.append(parser.getAttributeValue(0)); - } while (XmlUtils.nextElement(parser, "locale")) { sb.append(',').append(parser.getAttributeValue(0)); } } catch (Exception e) { Log.e(TAG, "loadLanguagesList: ", e); } + String[] languageTags = sb.toString().split(","); LocaleListCompat locales = LocaleListCompat.forLanguageTags(sb.toString()); - int size = locales.size(); - String[] languageTags = new String[size + 1]; - String[] languageNames = new String[size + 1]; - languageTags[0] = ""; + int size = languageTags.length; + String[] languageNames = new String[size]; languageNames[0] = context.getString(R.string.pref_theme_system); - for (int i = 0; i < size; ) { - Locale l = locales.get(i++); - if (l == null) { - break; + for (int i = 1; i < size; i++) { + Locale l = locales.get(i); + if (l != null) { + languageNames[i] = l.getDisplayName(l); } - languageTags[i] = l.getLanguage(); - languageNames[i] = l.getDisplayName(l); } prefLanguage.setEntryValues(languageTags); prefLanguage.setEntries(languageNames);