issue #1500, POI dialog fix

This commit is contained in:
GaidamakUA 2015-07-28 14:03:19 +03:00
parent 362aecfc7a
commit 97754ea50c

View file

@ -29,14 +29,13 @@ import android.widget.TableLayout;
import android.widget.TableRow; import android.widget.TableRow;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.MapRenderingTypes;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType; import net.osmand.osm.PoiType;
import net.osmand.osm.edit.EntityInfo; import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.EntityParser;
import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings.OSMTagKey; import net.osmand.osm.edit.OSMSettings.OSMTagKey;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
@ -151,23 +150,23 @@ public class EditingPOIDialogProvider implements DialogProvider {
showPOIDialog(DIALOG_CREATE_POI, n, null); showPOIDialog(DIALOG_CREATE_POI, n, null);
} }
private void showPOIDialog(int dialogID, Node n, Amenity a) { private void showPOIDialog(int dialogID, Node node, Amenity amenity) {
Amenity am; Amenity localAmenity;
if(a == null) { if(amenity == null) {
am = new Amenity(); localAmenity = new Amenity();
am.setType(poiTypes.getOtherPoiCategory()); localAmenity.setType(poiTypes.getOtherPoiCategory());
am.setSubType(""); localAmenity.setSubType("");
am.setAdditionalInfo(OSMTagKey.OPENING_HOURS.getValue(), ""); localAmenity.setAdditionalInfo(OSMTagKey.OPENING_HOURS.getValue(), "");
} else { } else {
am = new Amenity(); localAmenity = new Amenity();
am.copyNames(a); localAmenity.copyNames(amenity);
am.setType(a.getType()); localAmenity.setType(amenity.getType());
am.setSubType(a.getSubType()); localAmenity.setSubType(amenity.getSubType());
am.setAdditionalInfo(a.getAdditionalInfo()); localAmenity.setAdditionalInfo(amenity.getAdditionalInfo());
} }
// Amenity a = EntityParser.parseAmenity(n, n.getTags(), type, subType, MapRenderingTypes.getDefault()); // Amenity amenity = EntityParser.parseAmenity(node, node.getTags(), type, subType, MapRenderingTypes.getDefault());
dialogBundle.putSerializable(KEY_AMENITY, a); dialogBundle.putSerializable(KEY_AMENITY, localAmenity);
dialogBundle.putSerializable(KEY_AMENITY_NODE, n); dialogBundle.putSerializable(KEY_AMENITY_NODE, node);
createPOIDialog(dialogID, dialogBundle).show(); createPOIDialog(dialogID, dialogBundle).show();
} }
@ -405,8 +404,8 @@ public class EditingPOIDialogProvider implements DialogProvider {
}); });
linkToOsmDoc.setMovementMethod(LinkMovementMethod.getInstance()); linkToOsmDoc.setMovementMethod(LinkMovementMethod.getInstance());
final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); final Amenity amenity = (Amenity) args.getSerializable(KEY_AMENITY);
final Node n = (Node) args.getSerializable(KEY_AMENITY_NODE); final Node node = (Node) args.getSerializable(KEY_AMENITY_NODE);
dlg.setNegativeButton(R.string.shared_string_cancel, null); dlg.setNegativeButton(R.string.shared_string_cancel, null);
dlg.setPositiveButton( dlg.setPositiveButton(
isLocalEdit ? R.string.shared_string_save : isLocalEdit ? R.string.shared_string_save :
@ -414,53 +413,53 @@ public class EditingPOIDialogProvider implements DialogProvider {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Resources resources = view.getResources(); Resources resources = view.getResources();
final String msg = n.getId() == -1 ? resources.getString(R.string.poi_action_add) : resources final String msg = node.getId() == -1 ? resources.getString(R.string.poi_action_add) : resources
.getString(R.string.poi_action_change); .getString(R.string.poi_action_change);
OsmPoint.Action action = n.getId() == -1 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY; OsmPoint.Action action = node.getId() == -1 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
String subType = typeText.getText().toString().trim().toLowerCase(); String subType = typeText.getText().toString().trim().toLowerCase();
if (allTranslatedSubTypes.get(subType) != null) { if (allTranslatedSubTypes.get(subType) != null) {
PoiType pt = allTranslatedSubTypes.get(subType); PoiType pt = allTranslatedSubTypes.get(subType);
n.putTag(pt.getOsmTag(), pt.getOsmValue()); node.putTag(pt.getOsmTag(), pt.getOsmValue());
if (pt.getOsmTag2() != null) { if (pt.getOsmTag2() != null) {
n.putTag(pt.getOsmTag2(), pt.getOsmValue2()); node.putTag(pt.getOsmTag2(), pt.getOsmValue2());
} }
} else { } else {
n.putTag(a.getType().getDefaultTag(), subType); node.putTag(amenity.getType().getDefaultTag(), subType);
} }
String name = nameText.getText().toString(); String name = nameText.getText().toString();
if(name.length() > 0) { if(name.length() > 0) {
n.putTag(OSMTagKey.NAME.getValue(), name); node.putTag(OSMTagKey.NAME.getValue(), name);
} }
if (openingHours.getText().toString().length() == 0) { if (openingHours.getText().toString().length() == 0) {
n.removeTag(OSMTagKey.OPENING_HOURS.getValue()); node.removeTag(OSMTagKey.OPENING_HOURS.getValue());
} else { } else {
n.putTag(OSMTagKey.OPENING_HOURS.getValue(), openingHours.getText().toString()); node.putTag(OSMTagKey.OPENING_HOURS.getValue(), openingHours.getText().toString());
} }
String website = websiteText.getText().toString(); String website = websiteText.getText().toString();
if (website.length() > 0 ){ if (website.length() > 0 ){
n.putTag(OSMTagKey.WEBSITE.getValue(),website); node.putTag(OSMTagKey.WEBSITE.getValue(), website);
} else { } else {
n.removeTag(OSMTagKey.WEBSITE.getValue()); node.removeTag(OSMTagKey.WEBSITE.getValue());
} }
String phone = phoneText.getText().toString(); String phone = phoneText.getText().toString();
if (phone.length() > 0 ){ if (phone.length() > 0 ){
n.putTag(OSMTagKey.PHONE.getValue(),phone); node.putTag(OSMTagKey.PHONE.getValue(), phone);
} else { } else {
n.removeTag(OSMTagKey.PHONE.getValue()); node.removeTag(OSMTagKey.PHONE.getValue());
} }
String str = streetNameText.getText().toString(); String str = streetNameText.getText().toString();
if (str .length() > 0 ){ if (str .length() > 0 ){
n.putTag(OSMTagKey.ADDR_STREET.getValue(),str); node.putTag(OSMTagKey.ADDR_STREET.getValue(), str);
} else { } else {
n.removeTag(OSMTagKey.ADDR_STREET.getValue()); node.removeTag(OSMTagKey.ADDR_STREET.getValue());
} }
String hno = hnoText.getText().toString(); String hno = hnoText.getText().toString();
if (hno .length() > 0 ){ if (hno .length() > 0 ){
n.putTag(OSMTagKey.ADDR_HOUSE_NUMBER.getValue(),hno); node.putTag(OSMTagKey.ADDR_HOUSE_NUMBER.getValue(), hno);
} else { } else {
n.removeTag(OSMTagKey.ADDR_HOUSE_NUMBER.getValue()); node.removeTag(OSMTagKey.ADDR_HOUSE_NUMBER.getValue());
} }
commitNode(action, n, openstreetmapUtil.getEntityInfo(), commentText.getText().toString(), closeChange.isSelected(), commitNode(action, node, openstreetmapUtil.getEntityInfo(), commentText.getText().toString(), closeChange.isSelected(),
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
@ -485,8 +484,8 @@ public class EditingPOIDialogProvider implements DialogProvider {
} }
}); });
preparePOIDialog(view, args); preparePOIDialog(view, args);
attachListeners(view, a, n); attachListeners(view, amenity, node);
updateOsmTagValue(a); updateOsmTagValue(amenity);
return dlg; return dlg;
} }
@ -787,4 +786,3 @@ public class EditingPOIDialogProvider implements DialogProvider {
} }
} }