diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java index 990da169d1..19c62eeecd 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java @@ -201,9 +201,11 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment if (!hasFocus) { if (!editPoiData.isInEdit()) { String s = tagEditText.getText().toString(); - editPoiData.removeTag(previousTag[0]); - editPoiData.putTag(s.toString(), valueEditText.getText().toString()); - previousTag[0] = s.toString(); + if (!previousTag[0].equals(s)) { + editPoiData.removeTag(previousTag[0]); + editPoiData.putTag(s, valueEditText.getText().toString()); + previousTag[0] = s; + } } } else { tagAdapter.getFilter().filter(tagEditText.getText()); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java index 146ec426f2..df1b6971b1 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java @@ -37,7 +37,7 @@ public class EditPoiData { category = app.getPoiTypes().getOtherPoiCategory(); entity = node; initTags(node); - updateTypeTag(getPoiTypeString()); + updateTypeTag(getPoiTypeString(), false); } public Map getAllTranslatedSubTypes() { @@ -109,15 +109,18 @@ public class EditPoiData { public Map getTagValues() { return Collections.unmodifiableMap(tagValues); } - + public void putTag(String tag, String value) { checkNotInEdit(); - try { + try { isInEdit = true; tagValues.remove(REMOVE_TAG_PREFIX+tag); + String oldValue = tagValues.get(tag); + if (oldValue == null || !oldValue.equals(value)) { + changedTags.add(tag); + } tagValues.put(tag, value); - changedTags.add(tag); notifyDatasetChanged(tag); } finally { isInEdit = false; @@ -193,9 +196,11 @@ public class EditPoiData { return hasChangesBeenMade; } - public void updateTypeTag(String string) { + public void updateTypeTag(String string, boolean userChanges) { tagValues.put(POI_TYPE_TAG, string); - changedTags.add(POI_TYPE_TAG); + if (userChanges) { + changedTags.add(POI_TYPE_TAG); + } retrieveType(); PoiType pt = getPoiTypeDefined(); if(pt != null) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index 01c5e57447..663faba576 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -258,6 +258,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { poiNameEditText.setText(editPoiData.getTag(OSMSettings.OSMTagKey.NAME.getValue())); poiTypeTextInputLayout = (TextInputLayout) view.findViewById(R.id.poiTypeTextInputLayout); poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText); + poiTypeEditText.setText(editPoiData.getPoiTypeString()); poiTypeEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -270,7 +271,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { @Override public void afterTextChanged(Editable s) { if (!getEditPoiData().isInEdit()) { - getEditPoiData().updateTypeTag(s.toString()); + getEditPoiData().updateTypeTag(s.toString(), true); if (!getMyApplication().isApplicationInitializing()) { poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation()); } @@ -279,7 +280,6 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { }); poiNameEditText.setOnEditorActionListener(mOnEditorActionListener); poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener); - poiTypeEditText.setText(editPoiData.getPoiTypeString()); poiTypeEditText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(final View v, MotionEvent event) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java index a03185e54f..fa8a086283 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java @@ -37,6 +37,7 @@ import java.io.StringWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.text.MessageFormat; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -330,11 +331,20 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { EntityId id = new Entity.EntityId(EntityType.NODE, nodeId); Node entity = (Node) st.getRegisteredEntities().get(id); // merge non existing tags - for (String rtag : entity.getTagKeySet()) { - if (!deletedTag(n, rtag) && (!containsTag(n, rtag) || !tagChanged(n, rtag))) { - n.putTagNoLC(rtag, entity.getTag(rtag)); + Map updatedTags = new HashMap<>(); + for (String tagKey : entity.getTagKeySet()) { + if (tagKey != null && !deletedTag(n, tagKey)) { + addIfNotNull(tagKey, entity.getTag(tagKey), updatedTags); } } + if (n.getChangedTags() != null) { + for (String tagKey : n.getChangedTags()) { + if (tagKey != null) { + addIfNotNull(tagKey, n.getTag(tagKey), updatedTags); + } + } + } + n.replaceTags(updatedTags); if(MapUtils.getDistance(n.getLatLon(), entity.getLatLon()) < 10) { // avoid shifting due to round error n.setLatitude(entity.getLatitude()); @@ -353,18 +363,16 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { return null; } + private void addIfNotNull(String key, String value, Map tags) { + if (value != null) { + tags.put(key, value); + } + } + private boolean deletedTag(Node node, String tag) { return node.getTagKeySet().contains(EditPoiData.REMOVE_TAG_PREFIX + tag); } - private boolean containsTag(Node node, String tag) { - return node.getTagKeySet().contains(tag); - } - - private boolean tagChanged(Node node, String tag) { - return node.getChangedTags() != null && node.getChangedTags().contains(tag); - } - @Override public Node loadNode(Amenity n) { if (n.getId() % 2 == 1) {