diff --git a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java index 963e24db23..aa982640fe 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java @@ -77,20 +77,26 @@ public class MapPoiTypes { return otherCategory; } - public Map getAllTranslatedNames() { + public Map getAllTranslatedNames(boolean onlyTranslation) { Map translation = new TreeMap(); for(PoiCategory pc : categories) { for(PoiType pt : pc.getPoiTypes()) { translation.put(pt.getTranslation(), pt); + if (!onlyTranslation) { + translation.put(Algorithms.capitalizeFirstLetterAndLowercase(pt.getKeyName().replace('_', ' ')), pt); + } } } return translation; } - public Map getAllTranslatedNames(PoiCategory pc) { + public Map getAllTranslatedNames(PoiCategory pc, boolean onlyTranslation) { Map translation = new TreeMap(); for (PoiType pt : pc.getPoiTypes()) { translation.put(pt.getTranslation(), pt); + if (!onlyTranslation) { + translation.put(pt.getKeyName(), pt); + } } return translation; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java index d01c08e419..13df80791c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java @@ -2,6 +2,7 @@ package net.osmand.plus.osmedit; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -45,6 +46,8 @@ import android.text.method.LinkMovementMethod; import android.view.Gravity; import android.view.View; import android.view.WindowManager; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; @@ -97,7 +100,7 @@ public class EditingPOIActivity implements DialogProvider { this.ctx = uiContext; poiTypes = uiContext.getMyApplication().getPoiTypes(); - allTranslatedSubTypes = poiTypes.getAllTranslatedNames(); + allTranslatedSubTypes = poiTypes.getAllTranslatedNames(false); settings = ((OsmandApplication) uiContext.getApplication()).getSettings(); if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) { this.openstreetmapUtil = new OpenstreetmapLocalUtil(ctx); @@ -462,7 +465,7 @@ public class EditingPOIActivity implements DialogProvider { .getString(R.string.poi_action_change); OsmPoint.Action action = n.getId() == -1 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY; String subType = typeText.getText().toString(); - if(allTranslatedSubTypes.get(subType) != null) { + if(allTranslatedSubTypes.get(subType.trim()) != null) { PoiType pt = allTranslatedSubTypes.get(subType); n.putTag(pt.getOsmTag() , pt.getOsmValue()); if(pt.getOsmTag2() != null) { @@ -527,14 +530,34 @@ public class EditingPOIActivity implements DialogProvider { } private void updateSubTypesAdapter(PoiCategory poiCategory) { - Set subCategories = new LinkedHashSet(poiTypes.getAllTranslatedNames(poiCategory).keySet()); - for (String s : poiTypes.getAllTranslatedNames().keySet()) { - if (!subCategories.contains(s)) { - subCategories.add(s); + final Map subCategories = getSubCategoriesMap(poiCategory); + final ArrayAdapter adapter = new ArrayAdapter(ctx, R.layout.list_textview, subCategories.keySet().toArray()); + typeText.setAdapter(adapter); + typeText.setOnItemSelectedListener(new OnItemSelectedListener() { + + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + Object item = parent.getAdapter().getItem(position); + if(subCategories.containsKey(item)) { + String kn = subCategories.get(item).getKeyName(); + typeText.setText(kn); + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }); + } + + private Map getSubCategoriesMap(PoiCategory poiCategory) { + Map subCategories = new LinkedHashMap<>(poiTypes.getAllTranslatedNames(poiCategory, false)); + for (Map.Entry s : poiTypes.getAllTranslatedNames(false).entrySet()) { + if (!subCategories.containsKey(s.getKey())) { + subCategories.put(s.getKey(), s.getValue()); } } - ArrayAdapter adapter = new ArrayAdapter(ctx, R.layout.list_textview, subCategories.toArray()); - typeText.setAdapter(adapter); + return subCategories; } private void updateType(Amenity a){ @@ -627,12 +650,14 @@ public class EditingPOIActivity implements DialogProvider { case DIALOG_SUB_CATEGORIES: { Builder builder = new AlertDialog.Builder(ctx); final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); - final String[] subCats = poiTypes.getAllTranslatedNames(a.getType()).keySet().toArray(new String[0]); + final Map allTranslatedNames = poiTypes.getAllTranslatedNames(a.getType(), true); + final String[] subCats = allTranslatedNames.keySet().toArray(new String[0]); builder.setItems(subCats, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - typeText.setText(subCats[which]); - a.setSubType(subCats[which]); + PoiType poiType = allTranslatedNames.get(subCats[which]); + typeText.setText(poiType.getKeyName()); + a.setSubType(poiType.getKeyName()); ctx.removeDialog(DIALOG_SUB_CATEGORIES); } }); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java index 8f09462989..f16233db5c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java @@ -2,7 +2,6 @@ package net.osmand.plus.osmedit; import java.io.Serializable; -import net.osmand.data.AmenityType; import net.osmand.osm.edit.Node; import net.osmand.osm.edit.OSMSettings.OSMTagKey;