From b65bbdc779a18827ce4dd11a81b4f87efb541ad1 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Mon, 31 Aug 2015 15:30:20 +0300 Subject: [PATCH] Fix for Edit/Delete existing POI broken functionality. Deletion now implemented with dialog fragment. And editing is working with new editing screen. Editing screen fixed to work with existing poi --- OsmAnd-java/src/net/osmand/data/LatLon.java | 3 +- .../plus/osmedit/BasicDataFragment.java | 1 + .../osmand/plus/osmedit/EditPoiFragment.java | 49 ++++++++++++++++--- .../osmedit/EditingPOIDialogProvider.java | 4 +- .../osmand/plus/osmedit/OsmEditingPlugin.java | 11 ++--- .../src/net/osmand/plus/osmedit/data/Tag.java | 1 - 6 files changed, 52 insertions(+), 17 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/data/LatLon.java b/OsmAnd-java/src/net/osmand/data/LatLon.java index ff4b718ea3..370da00b01 100644 --- a/OsmAnd-java/src/net/osmand/data/LatLon.java +++ b/OsmAnd-java/src/net/osmand/data/LatLon.java @@ -1,7 +1,8 @@ package net.osmand.data; +import java.io.Serializable; -public class LatLon { +public class LatLon implements Serializable { private final double longitude; private final double latitude; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/BasicDataFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/BasicDataFragment.java index 15382822a1..5ad86c0c06 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/BasicDataFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/BasicDataFragment.java @@ -140,6 +140,7 @@ public class BasicDataFragment extends Fragment { mIsUserInput = true; } }; + mTagsChangedListener.onTagsChanged(); getData().addListener(mTagsChangedListener); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java index 0227d1e8cf..eb5acc4f94 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java @@ -61,8 +61,8 @@ public class EditPoiFragment extends Fragment { public static final String TAG = "EditPoiFragment"; private static final Log LOG = PlatformUtil.getLog(EditPoiFragment.class); - private static final String KEY_AMENITY_NODE = "amenity_node"; - private static final String KEY_AMENITY = "amenity"; + private static final String KEY_AMENITY_NODE = "key_amenity_node"; + private static final String KEY_AMENITY = "key_amenity"; private static final String TAGS_LIST = "tags_list"; private final EditPoiData editPoiData = new EditPoiData(); @@ -114,6 +114,34 @@ public class EditPoiFragment extends Fragment { editPoiData.tags = (LinkedHashSet) savedInstanceState.getSerializable(TAGS_LIST); } else { editPoiData.tags = new LinkedHashSet<>(); + LOG.debug("node.tags=" + node.getTags()); + + tryAddTag(OSMSettings.OSMTagKey.ADDR_STREET.getValue(), + node.getTag(OSMSettings.OSMTagKey.ADDR_STREET)); + tryAddTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue(), + node.getTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER)); + tryAddTag(OSMSettings.OSMTagKey.PHONE.getValue(), + editPoiData.amenity.getPhone()); + tryAddTag(OSMSettings.OSMTagKey.WEBSITE.getValue(), + editPoiData.amenity.getSite()); + for (String tag : node.getTagKeySet()) { + tryAddTag(tag, node.getTag(tag)); + } + String subType = editPoiData.amenity.getSubType(); + String key; + String value; + if (allTranslatedSubTypes.get(subType) != null) { + PoiType pt = allTranslatedSubTypes.get(subType); + key = pt.getOsmTag(); + value = pt.getOsmValue(); + } else { + key = editPoiData.amenity.getType().getDefaultTag(); + value = subType; + } + final Tag tag = new Tag(key, value); + editPoiData.tags.remove(tag); + tag.tag = POI_TYPE_TAG; + editPoiData.tags.add(tag); } View view = inflater.inflate(R.layout.fragment_edit_poi, container, false); @@ -193,6 +221,7 @@ public class EditPoiFragment extends Fragment { } } }); + poiNameEditText.setText(node.getTag(OSMSettings.OSMTagKey.NAME)); poiTypeTextInputLayout = (TextInputLayout) view.findViewById(R.id.poiTypeTextInputLayout); poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText); poiTypeEditText.addTextChangedListener(new TextWatcher() { @@ -305,6 +334,12 @@ public class EditPoiFragment extends Fragment { return view; } + private void tryAddTag(String key, String value) { + if (!Algorithms.isEmpty(value)) { + editPoiData.tags.add(new Tag(key, value)); + } + } + @Override public void onSaveInstanceState(Bundle outState) { outState.putSerializable(TAGS_LIST, editPoiData.tags); @@ -412,8 +447,9 @@ public class EditPoiFragment extends Fragment { }); } - public static void showEditInstance(final Amenity amenity, OsmandSettings settings, + public static void showEditInstance(final Amenity amenity, final MapActivity mapActivity) { + final OsmandSettings settings = mapActivity.getMyApplication().getSettings(); final OpenstreetmapUtil openstreetmapUtilToLoad; if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) { OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); @@ -427,15 +463,16 @@ public class EditPoiFragment extends Fragment { @Override protected Node doInBackground(Void... params) { - return openstreetmapUtilToLoad.loadNode((Amenity) amenity); + return openstreetmapUtilToLoad.loadNode(amenity); } protected void onPostExecute(Node n) { if (n != null) { EditPoiFragment fragment = - EditPoiFragment.createInstance(n, (Amenity) amenity); + EditPoiFragment.createInstance(n, amenity); mapActivity.getSupportFragmentManager().beginTransaction() - .add(fragment, "EditPoiFragment").commit(); + .add(R.id.fragmentContainer, fragment, "EditPoiFragment") + .addToBackStack(null).commit(); } else { AccessibleToast.makeText(mapActivity, mapActivity.getString(R.string.poi_error_poi_not_found), diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java index 3ba7302529..3da58d4d2c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java @@ -139,9 +139,9 @@ public class EditingPOIDialogProvider implements DialogProvider { } else { AccessibleToast.makeText(activity, activity.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_SHORT).show(); } - }; + } - }.execute(new Void[0]); + }.execute(); } public void showCreateDialog(double latitude, double longitude){ diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index c6bd4d19f5..312eb1ee3a 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -28,7 +28,6 @@ import net.osmand.plus.activities.EnumAdapter; import net.osmand.plus.activities.EnumAdapter.IEnumWithResource; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TabActivity; -import net.osmand.plus.dashboard.DashPluginsFragment; import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.myplaces.AvailableGPXFragment; import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; @@ -171,13 +170,11 @@ public class OsmEditingPlugin extends OsmandPlugin { osmBugsLayer.openBug(latitude, longitude); } else if (resId == R.string.poi_context_menu_delete) { LOG.debug("delete poi"); -// new EditPoiFragment.ShowDeleteDialogAsyncTask(mapActivity) -// .execute((Amenity) selectedObj); - // TODO implement delete - getPoiActions(mapActivity).showDeleteDialog((Amenity) selectedObj); + new EditPoiFragment.ShowDeleteDialogAsyncTask(mapActivity) + .execute((Amenity) selectedObj); } else if (resId == R.string.poi_context_menu_modify) { - // TODO implement edit - getPoiActions(mapActivity).showEditDialog((Amenity) selectedObj); + LOG.debug("edit poi"); + EditPoiFragment.showEditInstance((Amenity) selectedObj, mapActivity); } return true; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/data/Tag.java b/OsmAnd/src/net/osmand/plus/osmedit/data/Tag.java index 9fa98c83f5..f215033cb0 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/data/Tag.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/data/Tag.java @@ -21,7 +21,6 @@ public class Tag implements Serializable { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Tag tag1 = (Tag) o; - LOG.debug("this=" + this + "; that=" + tag1); return tag.equals(tag1.tag); }