Fix some issues with "Use values from the openstreetmap for all tags, except for changed" commit
This commit is contained in:
parent
b791749281
commit
ea3fa0cc37
4 changed files with 37 additions and 22 deletions
|
@ -201,9 +201,11 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment
|
||||||
if (!hasFocus) {
|
if (!hasFocus) {
|
||||||
if (!editPoiData.isInEdit()) {
|
if (!editPoiData.isInEdit()) {
|
||||||
String s = tagEditText.getText().toString();
|
String s = tagEditText.getText().toString();
|
||||||
editPoiData.removeTag(previousTag[0]);
|
if (!previousTag[0].equals(s)) {
|
||||||
editPoiData.putTag(s.toString(), valueEditText.getText().toString());
|
editPoiData.removeTag(previousTag[0]);
|
||||||
previousTag[0] = s.toString();
|
editPoiData.putTag(s, valueEditText.getText().toString());
|
||||||
|
previousTag[0] = s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tagAdapter.getFilter().filter(tagEditText.getText());
|
tagAdapter.getFilter().filter(tagEditText.getText());
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class EditPoiData {
|
||||||
category = app.getPoiTypes().getOtherPoiCategory();
|
category = app.getPoiTypes().getOtherPoiCategory();
|
||||||
entity = node;
|
entity = node;
|
||||||
initTags(node);
|
initTags(node);
|
||||||
updateTypeTag(getPoiTypeString());
|
updateTypeTag(getPoiTypeString(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, PoiType> getAllTranslatedSubTypes() {
|
public Map<String, PoiType> getAllTranslatedSubTypes() {
|
||||||
|
@ -109,15 +109,18 @@ public class EditPoiData {
|
||||||
public Map<String, String> getTagValues() {
|
public Map<String, String> getTagValues() {
|
||||||
return Collections.unmodifiableMap(tagValues);
|
return Collections.unmodifiableMap(tagValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void putTag(String tag, String value) {
|
public void putTag(String tag, String value) {
|
||||||
checkNotInEdit();
|
checkNotInEdit();
|
||||||
try {
|
try {
|
||||||
isInEdit = true;
|
isInEdit = true;
|
||||||
tagValues.remove(REMOVE_TAG_PREFIX+tag);
|
tagValues.remove(REMOVE_TAG_PREFIX+tag);
|
||||||
|
String oldValue = tagValues.get(tag);
|
||||||
|
if (oldValue == null || !oldValue.equals(value)) {
|
||||||
|
changedTags.add(tag);
|
||||||
|
}
|
||||||
tagValues.put(tag, value);
|
tagValues.put(tag, value);
|
||||||
changedTags.add(tag);
|
|
||||||
notifyDatasetChanged(tag);
|
notifyDatasetChanged(tag);
|
||||||
} finally {
|
} finally {
|
||||||
isInEdit = false;
|
isInEdit = false;
|
||||||
|
@ -193,9 +196,11 @@ public class EditPoiData {
|
||||||
return hasChangesBeenMade;
|
return hasChangesBeenMade;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTypeTag(String string) {
|
public void updateTypeTag(String string, boolean userChanges) {
|
||||||
tagValues.put(POI_TYPE_TAG, string);
|
tagValues.put(POI_TYPE_TAG, string);
|
||||||
changedTags.add(POI_TYPE_TAG);
|
if (userChanges) {
|
||||||
|
changedTags.add(POI_TYPE_TAG);
|
||||||
|
}
|
||||||
retrieveType();
|
retrieveType();
|
||||||
PoiType pt = getPoiTypeDefined();
|
PoiType pt = getPoiTypeDefined();
|
||||||
if(pt != null) {
|
if(pt != null) {
|
||||||
|
|
|
@ -258,6 +258,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
|
||||||
poiNameEditText.setText(editPoiData.getTag(OSMSettings.OSMTagKey.NAME.getValue()));
|
poiNameEditText.setText(editPoiData.getTag(OSMSettings.OSMTagKey.NAME.getValue()));
|
||||||
poiTypeTextInputLayout = (TextInputLayout) view.findViewById(R.id.poiTypeTextInputLayout);
|
poiTypeTextInputLayout = (TextInputLayout) view.findViewById(R.id.poiTypeTextInputLayout);
|
||||||
poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText);
|
poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText);
|
||||||
|
poiTypeEditText.setText(editPoiData.getPoiTypeString());
|
||||||
poiTypeEditText.addTextChangedListener(new TextWatcher() {
|
poiTypeEditText.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
@ -270,7 +271,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
if (!getEditPoiData().isInEdit()) {
|
if (!getEditPoiData().isInEdit()) {
|
||||||
getEditPoiData().updateTypeTag(s.toString());
|
getEditPoiData().updateTypeTag(s.toString(), true);
|
||||||
if (!getMyApplication().isApplicationInitializing()) {
|
if (!getMyApplication().isApplicationInitializing()) {
|
||||||
poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation());
|
poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation());
|
||||||
}
|
}
|
||||||
|
@ -279,7 +280,6 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
|
||||||
});
|
});
|
||||||
poiNameEditText.setOnEditorActionListener(mOnEditorActionListener);
|
poiNameEditText.setOnEditorActionListener(mOnEditorActionListener);
|
||||||
poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener);
|
poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener);
|
||||||
poiTypeEditText.setText(editPoiData.getPoiTypeString());
|
|
||||||
poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {
|
poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(final View v, MotionEvent event) {
|
public boolean onTouch(final View v, MotionEvent event) {
|
||||||
|
|
|
@ -37,6 +37,7 @@ import java.io.StringWriter;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -330,11 +331,20 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
|
||||||
EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
|
EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
|
||||||
Node entity = (Node) st.getRegisteredEntities().get(id);
|
Node entity = (Node) st.getRegisteredEntities().get(id);
|
||||||
// merge non existing tags
|
// merge non existing tags
|
||||||
for (String rtag : entity.getTagKeySet()) {
|
Map<String, String> updatedTags = new HashMap<>();
|
||||||
if (!deletedTag(n, rtag) && (!containsTag(n, rtag) || !tagChanged(n, rtag))) {
|
for (String tagKey : entity.getTagKeySet()) {
|
||||||
n.putTagNoLC(rtag, entity.getTag(rtag));
|
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) {
|
if(MapUtils.getDistance(n.getLatLon(), entity.getLatLon()) < 10) {
|
||||||
// avoid shifting due to round error
|
// avoid shifting due to round error
|
||||||
n.setLatitude(entity.getLatitude());
|
n.setLatitude(entity.getLatitude());
|
||||||
|
@ -353,18 +363,16 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
|
||||||
return null;
|
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) {
|
private boolean deletedTag(Node node, String tag) {
|
||||||
return node.getTagKeySet().contains(EditPoiData.REMOVE_TAG_PREFIX + 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
|
@Override
|
||||||
public Node loadNode(Amenity n) {
|
public Node loadNode(Amenity n) {
|
||||||
if (n.getId() % 2 == 1) {
|
if (n.getId() % 2 == 1) {
|
||||||
|
|
Loading…
Reference in a new issue