Merge pull request #2627 from osmandapp/testing_hardy2

Sort Preferred Locale menu alphabetically in all languages
This commit is contained in:
Hardy 2016-05-30 14:59:15 +02:00
commit d79b56d5de
2 changed files with 16 additions and 8 deletions

View file

@ -262,14 +262,17 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
getString(R.string.lang_uk),
getString(R.string.lang_vi) + incompleteSuffix,
getString(R.string.lang_cy) + incompleteSuffix,};
registerListPreference(settings.PREFERRED_LOCALE, screen, entries, entrieValues);
String[] valuesPl = ConfigureMapMenu.getSortedMapNamesIds(this, entries, entries);
String[] idsPl = ConfigureMapMenu.getSortedMapNamesIds(this, entrieValues, entries);
registerListPreference(settings.PREFERRED_LOCALE, screen, valuesPl, idsPl);
// Display "Device language" in Latin for all non-en languages
if (!getResources().getString(R.string.preferred_locale).equals(getResources().getString(R.string.preferred_locale_no_translate))) {
((ListPreference) screen.findPreference(settings.PREFERRED_LOCALE.getId())).setTitle(getString(R.string.preferred_locale) + " (" + getString(R.string.preferred_locale_no_translate) + ")");
}
String[] ids = ConfigureMapMenu.getSortedMapNamesIds(this);
String[] values = ConfigureMapMenu.getMapNamesValues(this, ConfigureMapMenu.mapNamesIds);
String[] ids = ConfigureMapMenu.getSortedMapNamesIds(this, ConfigureMapMenu.mapNamesIds, values);
registerListPreference(settings.MAP_PREFERRED_LOCALE, screen, ConfigureMapMenu.getMapNamesValues(this, ids), ids);
}

View file

@ -475,7 +475,7 @@ public class ConfigureMapMenu {
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
b.setTitle(R.string.map_preferred_locale);
final String[] txtIds = getSortedMapNamesIds(activity);
final String[] txtIds = getSortedMapNamesIds(activity, mapNamesIds, getMapNamesValues(activity, mapNamesIds));
final String[] txtValues = getMapNamesValues(activity, txtIds);
int selected = -1;
for (int i = 0; i < txtIds.length; i++) {
@ -533,14 +533,14 @@ public class ConfigureMapMenu {
public static String[] mapNamesIds = new String[]{"", "en", "als", "af", "ar", "az", "be", "bg", "bn", "bpy", "br", "bs", "ca", "ceb", "cs", "cy", "da", "de", "el", "eo", "et", "es", "eu", "fa", "fi", "fr", "fy", "ga", "gl", "he", "hi", "hr", "ht", "hu", "hy", "id", "is", "it", "ja", "ka", "ko", "ku", "la", "lb", "lt", "lv", "mk", "ml", "mr", "ms", "nds", "new", "nl", "nn", "no", "nv", "os", "pl", "pms", "pt", "ro", "ru", "sh", "sc", "sk", "sl", "sq", "sr", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "vi", "vo", "zh"};
public static String[] getSortedMapNamesIds(Context ctx) {
String[] vls = getMapNamesValues(ctx, mapNamesIds);
public static String[] getSortedMapNamesIds(Context ctx, String[] ids, String[] values) {
final Map<String, String> mp = new HashMap<>();
for (int i = 0; i < mapNamesIds.length; i++) {
mp.put(mapNamesIds[i], vls[i]);
for (int i = 0; i < ids.length; i++) {
mp.put(ids[i], values[i]);
}
ArrayList<String> lst = new ArrayList<>(mp.keySet());
final String systemLocale = ctx.getString(R.string.system_locale) + " (" + ctx.getString(R.string.system_locale_no_translate) + ")";
final String englishLocale = ctx.getString(R.string.lang_en);
Collections.sort(lst, new Comparator<String>() {
@Override
public int compare(String lhs, String rhs) {
@ -549,6 +549,11 @@ public class ConfigureMapMenu {
if (i1 != i2) {
return i1 < i2 ? -1 : 1;
}
i1 = systemLocale.equals(lhs) ? 0 : (englishLocale.equals(lhs) ? 1 : 2);
i2 = systemLocale.equals(rhs) ? 0 : (englishLocale.equals(rhs) ? 1 : 2);
if (i1 != i2) {
return i1 < i2 ? -1 : 1;
}
return mp.get(lhs).compareTo(mp.get(rhs));
}
});