From dcd05c455facb38793c06dda9ba5a14e93423450 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 12 Sep 2018 13:46:25 +0300 Subject: [PATCH] Fix #5840 --- .../plus/osmedit/AdvancedEditPoiFragment.java | 3 +- .../net/osmand/plus/osmedit/EditPoiData.java | 62 +++++++++++++++---- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java index dab14a0284..e5b7b407ca 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java @@ -171,8 +171,9 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment public void updateViews() { linearLayout.removeAllViews(); editPoiData.setIsInEdit(true); + PoiType pt = editPoiData.getCurrentPoiType(); for (Entry tag : editPoiData.getTagValues().entrySet()) { - if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG) + if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG) || tag.getKey().equals(pt != null ? pt.getEditOsmTag() : null) || tag.getKey().equals(OSMSettings.OSMTagKey.NAME.getValue()) || tag.getKey().startsWith(EditPoiData.REMOVE_TAG_PREFIX)) continue; addTagView(tag.getKey(), tag.getValue()); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java index a7dde51bd1..255b1bd101 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java @@ -31,6 +31,7 @@ public class EditPoiData { private boolean hasChangesBeenMade = false; private Map allTranslatedSubTypes; private PoiCategory category; + private PoiType currentPoiType; private Set changedTags = new HashSet<>(); @@ -59,6 +60,11 @@ public class EditPoiData { return category; } + @Nullable + public PoiType getCurrentPoiType() { + return currentPoiType; + } + public PoiType getPoiTypeDefined() { return allTranslatedSubTypes.get(getPoiTypeString().toLowerCase()); } @@ -199,20 +205,50 @@ public class EditPoiData { } public void updateTypeTag(String string, boolean userChanges) { - tagValues.put(POI_TYPE_TAG, string); - if (userChanges) { - changedTags.add(POI_TYPE_TAG); + checkNotInEdit(); + try { + tagValues.put(POI_TYPE_TAG, string); + if (userChanges) { + changedTags.add(POI_TYPE_TAG); + } + retrieveType(); + PoiType pt = getPoiTypeDefined(); + if (pt != null) { + removeTypeTagWithPrefix(!tagValues.containsKey(REMOVE_TAG_PREFIX + pt.getEditOsmTag())); + currentPoiType = pt; + tagValues.put(pt.getEditOsmTag(), pt.getEditOsmValue()); + if (userChanges) { + changedTags.add(pt.getEditOsmTag()); + } + category = pt.getCategory(); + } else if (currentPoiType != null) { + removeTypeTagWithPrefix(true); + category = currentPoiType.getCategory(); + } + notifyDatasetChanged(POI_TYPE_TAG); + } finally { + isInEdit = false; } - retrieveType(); - PoiType pt = getPoiTypeDefined(); - if(pt != null) { - tagValues.put(REMOVE_TAG_PREFIX+pt.getEditOsmTag(), REMOVE_TAG_VALUE); - tagValues.put(REMOVE_TAG_PREFIX+pt.getOsmTag2(), REMOVE_TAG_VALUE); - tagValues.remove(pt.getEditOsmTag()); - tagValues.remove(pt.getOsmTag2()); - changedTags.removeAll(Arrays.asList(pt.getEditOsmTag(), pt.getOsmTag2())); - category = pt.getCategory(); + } + + private void removeTypeTagWithPrefix(boolean needRemovePrefix) { + if (currentPoiType != null) { + if (needRemovePrefix) { + tagValues.put(REMOVE_TAG_PREFIX + currentPoiType.getEditOsmTag(), REMOVE_TAG_VALUE); + tagValues.put(REMOVE_TAG_PREFIX + currentPoiType.getOsmTag2(), REMOVE_TAG_VALUE); + } else { + tagValues.remove(REMOVE_TAG_PREFIX + currentPoiType.getEditOsmTag()); + tagValues.remove(REMOVE_TAG_PREFIX + currentPoiType.getOsmTag2()); + } + removeCurrentTypeTag(); + } + } + + private void removeCurrentTypeTag() { + if (currentPoiType != null) { + tagValues.remove(currentPoiType.getEditOsmTag()); + tagValues.remove(currentPoiType.getOsmTag2()); + changedTags.removeAll(Arrays.asList(currentPoiType.getEditOsmTag(), currentPoiType.getOsmTag2())); } - notifyDatasetChanged(POI_TYPE_TAG); } } \ No newline at end of file