Fix some issues with "Use values from the openstreetmap for all tags, except for changed" commit

This commit is contained in:
Alexander Sytnyk 2017-12-20 16:36:59 +02:00
parent b791749281
commit ea3fa0cc37
4 changed files with 37 additions and 22 deletions

View file

@ -201,9 +201,11 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment
if (!hasFocus) {
if (!editPoiData.isInEdit()) {
String s = tagEditText.getText().toString();
if (!previousTag[0].equals(s)) {
editPoiData.removeTag(previousTag[0]);
editPoiData.putTag(s.toString(), valueEditText.getText().toString());
previousTag[0] = s.toString();
editPoiData.putTag(s, valueEditText.getText().toString());
previousTag[0] = s;
}
}
} else {
tagAdapter.getFilter().filter(tagEditText.getText());

View file

@ -37,7 +37,7 @@ public class EditPoiData {
category = app.getPoiTypes().getOtherPoiCategory();
entity = node;
initTags(node);
updateTypeTag(getPoiTypeString());
updateTypeTag(getPoiTypeString(), false);
}
public Map<String, PoiType> getAllTranslatedSubTypes() {
@ -116,8 +116,11 @@ public class EditPoiData {
try {
isInEdit = true;
tagValues.remove(REMOVE_TAG_PREFIX+tag);
tagValues.put(tag, value);
String oldValue = tagValues.get(tag);
if (oldValue == null || !oldValue.equals(value)) {
changedTags.add(tag);
}
tagValues.put(tag, value);
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);
if (userChanges) {
changedTags.add(POI_TYPE_TAG);
}
retrieveType();
PoiType pt = getPoiTypeDefined();
if(pt != null) {

View file

@ -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) {

View file

@ -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<String, String> 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<String, String> 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) {