diff --git a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java index 151d9e2913..d2f14e9f36 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java @@ -146,6 +146,9 @@ public class MapPoiTypes { public Map getAllTranslatedNames(boolean skipNonEditable) { Map translation = new HashMap(); for(PoiCategory pc : categories) { + if(skipNonEditable && pc.isNotEditableOsm()) { + continue; + } for(PoiType pt : pc.getPoiTypes()) { if(pt.isReference() ) { continue; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index dd632e82e4..dd989f1f6e 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -44,7 +44,6 @@ import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; - import net.osmand.CallbackWithObject; import net.osmand.PlatformUtil; import net.osmand.access.AccessibleToast; @@ -253,17 +252,35 @@ public class EditPoiDialogFragment extends DialogFragment { @Override public void afterTextChanged(Editable s) { if (!getEditPoiData().isInEdit()) { - PoiType pt = getEditPoiData().getAllTranslatedSubTypes().get(s.toString().toLowerCase()); - if(pt != null) { - poiTypeTextInputLayout.setHint(pt.getCategory().getTranslation()); - } getEditPoiData().updateTypeTag(s.toString()); + poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation()); } } }); poiNameEditText.setOnEditorActionListener(mOnEditorActionListener); poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener); poiTypeEditText.setText(editPoiData.getPoiTypeString()); + poiTypeEditText.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(final View v, MotionEvent event) { + final EditText editText = (EditText) v; + final int DRAWABLE_RIGHT = 2; + if (event.getAction() == MotionEvent.ACTION_UP) { + if (event.getX() >= (editText.getRight() + - editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width() + - editText.getPaddingRight())) { + if (editPoiData.getPoiCategory() != null) { + DialogFragment dialogFragment = + PoiSubTypeDialogFragment.createInstance(editPoiData.getPoiCategory()); + dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment"); + } + + return true; + } + } + return false; + } + }); Button saveButton = (Button) view.findViewById(R.id.saveButton); saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil @@ -299,7 +316,7 @@ public class EditPoiDialogFragment extends DialogFragment { HashSet tagsCopy = new HashSet<>(); tagsCopy.addAll(editPoiData.getTagValues().keySet()); tagsCopy.removeAll(BASIC_TAGS); - if (tagsCopy.isEmpty()) { + if (tagsCopy.isEmpty() || editPoiData.getPoiCategory() == getMyApplication().getPoiTypes().getOtherPoiCategory()) { poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type)); } else { new SaveWithAdvancedTagsDialogFragment().show(getChildFragmentManager(), "dialog"); @@ -446,41 +463,26 @@ public class EditPoiDialogFragment extends DialogFragment { }.execute(); } - public void updateType(PoiCategory type) { + public void setPoiCategory(PoiCategory type) { editPoiData.updateType(type); poiTypeEditText.setText(editPoiData.getPoiTypeString()); - poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation()); setAdapterForPoiTypeEditText(); - poiTypeEditText.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(final View v, MotionEvent event) { - final EditText editText = (EditText) v; - final int DRAWABLE_RIGHT = 2; - if (event.getAction() == MotionEvent.ACTION_UP) { - if (event.getX() >= (editText.getRight() - - editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width() - - editText.getPaddingRight())) { - if (editPoiData.getPoiCategory() != null) { - DialogFragment dialogFragment = - PoiSubTypeDialogFragment.createInstance(editPoiData.getPoiCategory()); - dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment"); - } - - return true; - } - } - return false; - } - }); } private void setAdapterForPoiTypeEditText() { final Map subCategories = new LinkedHashMap<>(); - for (Map.Entry s : editPoiData.getAllTranslatedSubTypes().entrySet()) { - if (!subCategories.containsKey(s.getKey())) { - subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(s.getKey()), s.getValue()); + PoiCategory ct = editPoiData.getPoiCategory(); + if(ct != null) { + for (PoiType s : ct.getPoiTypes()) { + if(!s.isReference() && !s.isNotEditableOsm() && s.getBaseLangType() == null) { + addMapEntryAdapter(subCategories, s.getTranslation(), s); + addMapEntryAdapter(subCategories, s.getKeyName().replace('_', ' '), s); + } } } + for (Map.Entry s : editPoiData.getAllTranslatedSubTypes().entrySet()) { + addMapEntryAdapter(subCategories, s.getKey(), s.getValue()); + } final ArrayAdapter adapter; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { adapter = new ArrayAdapter<>(getActivity(), @@ -518,7 +520,7 @@ public class EditPoiDialogFragment extends DialogFragment { //noinspection SuspiciousMethodCalls PoiType pt = subCategories.get(item); String keyName = pt.getKeyName(); - poiTypeTextInputLayout.setHint(pt.getCategory().getTranslation()); + setAdapterForPoiTypeEditText(); poiTypeEditText.setText(keyName); } } @@ -530,6 +532,12 @@ public class EditPoiDialogFragment extends DialogFragment { } + private void addMapEntryAdapter(final Map subCategories, String key, PoiType v) { + if (!subCategories.containsKey(key.toLowerCase())) { + subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(key), v); + } + } + private OsmandApplication getMyApplication() { return (OsmandApplication) getActivity().getApplication(); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java index 1b4cd7495d..a25295985f 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java @@ -1,7 +1,7 @@ package net.osmand.plus.osmedit.dialogs; -import java.util.Map; -import java.util.Set; +import java.util.ArrayList; +import java.util.List; import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; @@ -24,8 +24,12 @@ public class PoiSubTypeDialogFragment extends DialogFragment { MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes(); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final PoiCategory a = poiTypes.getPoiCategoryByName((String) getArguments().getSerializable(KEY_POI_CATEGORY)); - final Map allTranslatedNames = poiTypes.getAllTranslatedNames(a, true); - Set strings = allTranslatedNames.keySet(); + List strings = new ArrayList<>(); + for (PoiType s : a.getPoiTypes()) { + if (!s.isReference() && !s.isNotEditableOsm() && s.getBaseLangType() == null) { + strings.add(s.getTranslation()); + } + } final String[] subCats = strings.toArray(new String[strings.size()]); builder.setItems(subCats, new DialogInterface.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java index 87503ca636..287d9b27a9 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java @@ -36,7 +36,7 @@ public class PoiTypeDialogFragment extends DialogFragment { @Override public void onClick(DialogInterface dialog, int which) { PoiCategory aType = categories.get(which); - ((EditPoiDialogFragment) getParentFragment()).updateType(aType); + ((EditPoiDialogFragment) getParentFragment()).setPoiCategory(aType); dismiss(); } });