This commit is contained in:
Victor Shcherb 2017-04-04 01:05:58 +02:00
parent 17e9590518
commit a5c225875b
4 changed files with 29 additions and 18 deletions

View file

@ -167,7 +167,7 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment
editPoiData.setIsInEdit(true);
for (Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG)
|| tag.getKey().equals(OSMSettings.OSMTagKey.NAME.getValue()))
|| tag.getKey().equals(OSMSettings.OSMTagKey.NAME.getValue()) || tag.getKey().startsWith(EditPoiData.REMOVE_TAG_PREFIX))
continue;
addTagView(tag.getKey(), tag.getValue());
}

View file

@ -23,6 +23,8 @@ public class EditPoiData {
private Node entity;
public static final String POI_TYPE_TAG = "poi_type_tag";
public static final String REMOVE_TAG_PREFIX = "----";
public static final String REMOVE_TAG_VALUE = "DELETE";
private boolean hasChangesBeenMade = false;
private Map<String, PoiType> allTranslatedSubTypes;
private PoiCategory category;
@ -99,7 +101,6 @@ public class EditPoiData {
}
}
public Map<String, String> getTagValues() {
return Collections.unmodifiableMap(tagValues);
}
@ -109,6 +110,7 @@ public class EditPoiData {
checkNotInEdit();
try {
isInEdit = true;
tagValues.remove(REMOVE_TAG_PREFIX+tag);
tagValues.put(tag, value);
notifyDatasetChanged(tag);
} finally {
@ -137,6 +139,7 @@ public class EditPoiData {
checkNotInEdit();
try {
isInEdit = true;
tagValues.put(REMOVE_TAG_PREFIX+tag, REMOVE_TAG_VALUE);
tagValues.remove(tag);
notifyDatasetChanged(tag);
} finally {
@ -185,6 +188,8 @@ public class EditPoiData {
retrieveType();
PoiType pt = getPoiTypeDefined();
if(pt != null) {
tagValues.put(REMOVE_TAG_PREFIX+pt.getOsmTag(), REMOVE_TAG_VALUE);
tagValues.put(REMOVE_TAG_PREFIX+pt.getOsmTag2(), REMOVE_TAG_VALUE);
tagValues.remove(pt.getOsmTag());
tagValues.remove(pt.getOsmTag2());
category = pt.getCategory();

View file

@ -426,24 +426,29 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
Node node = new Node(original.getLatitude(), original.getLongitude(), original.getId());
OsmPoint.Action action = node.getId() < 0 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) {
final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(tag.getValue().trim().toLowerCase());
if (poiType != null) {
node.putTagNoLC(poiType.getOsmTag(), poiType.getOsmValue());
if (poiType.getOsmTag2() != null) {
node.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
}
} else if (!Algorithms.isEmpty(tag.getValue())) {
node.putTagNoLC(editPoiData.getPoiCategory().getDefaultTag(), tag.getValue());
}
if (offlineEdit && !Algorithms.isEmpty(tag.getValue())) {
node.putTagNoLC(tag.getKey(), tag.getValue());
}
} else if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue())) {
if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue()) &&
!tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) {
node.putTagNoLC(tag.getKey(), tag.getValue());
}
}
String poiTypeTag = editPoiData.getTagValues().get(EditPoiData.POI_TYPE_TAG);
if (poiTypeTag != null) {
final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(poiTypeTag.trim().toLowerCase());
if (poiType != null) {
node.putTagNoLC(poiType.getOsmTag(), poiType.getOsmValue());
node.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getOsmTag());
if (poiType.getOsmTag2() != null) {
node.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
node.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getOsmTag2());
}
} else if (!Algorithms.isEmpty(poiTypeTag)) {
node.putTagNoLC(editPoiData.getPoiCategory().getDefaultTag(), poiTypeTag);
}
if (offlineEdit && !Algorithms.isEmpty(poiTypeTag)) {
node.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiTypeTag);
}
}
commitNode(action, node, mOpenstreetmapUtil.getEntityInfo(node.getId()), "", false,
new CallbackWithObject<Node>() {

View file

@ -222,7 +222,8 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
for (String k : n.getTagKeySet()) {
String val = n.getTag(k);
if (val.length() == 0 || k.length() == 0 || "poi_type_tag".equals(k))
if (val.length() == 0 || k.length() == 0 || EditPoiData.POI_TYPE_TAG.equals(k) ||
k.startsWith(EditPoiData.REMOVE_TAG_PREFIX) || n.getTag(EditPoiData.REMOVE_TAG_PREFIX + k) != null)
continue;
ser.startTag(null, "tag"); //$NON-NLS-1$
ser.attribute(null, "k", k); //$NON-NLS-1$