From 7880145313ea324c3f37f1a32be3dd86c67263f7 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 15 Nov 2015 22:48:05 +0100 Subject: [PATCH 1/2] Take into account modification in dialog --- .../plus/osmedit/EditPoiDialogFragment.java | 2 +- .../plus/osmedit/OpenstreetmapsDbHelper.java | 2 + .../osmand/plus/osmedit/OsmEditsFragment.java | 54 +++++++------------ 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index bd91908a80..aac67a9cde 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -402,7 +402,7 @@ public class EditPoiDialogFragment extends DialogFragment { final Runnable successAction, final Activity activity, final OpenstreetmapUtil openstreetmapUtil) { - if (info == null && OsmPoint.Action.CREATE != action) { + if (info == null && OsmPoint.Action.CREATE != action && openstreetmapUtil instanceof OpenstreetmapRemoteUtil) { AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show(); return; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapsDbHelper.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapsDbHelper.java index 3cdc612cf4..59578c54ad 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapsDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapsDbHelper.java @@ -69,6 +69,8 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper { tags.append("$$$"); } } + db.execSQL("DELETE FROM " + OPENSTREETMAP_TABLE_NAME + + " WHERE " + OPENSTREETMAP_COL_ID + " = ?", new Object[] { p.getId() }); //$NON-NLS-1$ //$NON-NLS-2$ db.execSQL("INSERT INTO " + OPENSTREETMAP_TABLE_NAME + " (" + OPENSTREETMAP_COL_ID + ", " + OPENSTREETMAP_COL_LAT + ", " + OPENSTREETMAP_COL_LON + ", " + OPENSTREETMAP_COL_TAGS + ", " + OPENSTREETMAP_COL_ACTION + "," + OPENSTREETMAP_COL_COMMENT + ")" + " VALUES (?, ?, ?, ?, ?, ?)", diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 47ca439f35..9070c7c03d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -68,7 +68,7 @@ public class OsmEditsFragment extends OsmAndListFragment private final static int MODE_UPLOAD = 101; private ActionMode actionMode; - + private long refreshId; private ArrayList osmEditsSelected = new ArrayList<>(); @@ -466,9 +466,13 @@ public class OsmEditsFragment extends OsmAndListFragment item = optionsMenu.getMenu().add(R.string.poi_context_menu_modify_osm_change) .setIcon(app.getIconsCache().getContentIcon(R.drawable.ic_action_edit_dark)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + + @Override public boolean onMenuItemClick(MenuItem item) { - final Node entity = ((OpenstreetmapPoint) info).getEntity(); + OpenstreetmapPoint i = (OpenstreetmapPoint) getPointAfterModify(info); + final Node entity = i.getEntity(); + refreshId = entity.getId(); EditPoiDialogFragment.createInstance(entity, false) .show(getActivity().getSupportFragmentManager(), "edit_poi"); return true; @@ -492,13 +496,25 @@ public class OsmEditsFragment extends OsmAndListFragment item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - uploadItems(new OsmPoint[]{info}); + uploadItems(new OsmPoint[]{getPointAfterModify(info)}); return true; } }); optionsMenu.show(); } + protected OsmPoint getPointAfterModify(OsmPoint info) { + if(info instanceof OpenstreetmapPoint && info.getId() == refreshId) { + for(OpenstreetmapPoint p : plugin.getDBPOI().getOpenstreetmapPoints()) { + if(p.getId() == info.getId()) { + return p; + } + } + } + return info; + } + + public OsmandApplication getMyApplication() { return (OsmandApplication) getActivity().getApplication(); } @@ -710,36 +726,4 @@ public class OsmEditsFragment extends OsmAndListFragment } } -// public static class UploadOsmEditsConfirmDialogFragment extends DialogFragment { -// public static final String TAG = "UploadOsmEditsConfirmDialogFragment"; -// private static final String POINTS_ARRAY = "points_list"; -// -// @NonNull -// @Override -// public Dialog onCreateDialog(Bundle savedInstanceState) { -// final OsmPoint[] points = (OsmPoint[]) getArguments().getSerializable(POINTS_ARRAY); -// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); -// builder.setMessage( -// getString(R.string.local_osm_changes_upload_all_confirm, points.length)); -// builder.setPositiveButton(R.string.shared_string_yes, -// new DialogInterface.OnClickListener() { -// @Override -// public void onClick(DialogInterface dialog, int which) { -// ((OsmEditsFragment) getParentFragment()) -// .showUploadItemsProgressDialog(points); -// } -// }); -// builder.setNegativeButton(R.string.shared_string_cancel, null); -// return builder.create(); -// } -// -// public static UploadOsmEditsConfirmDialogFragment createInstance(OsmPoint[] points) { -// UploadOsmEditsConfirmDialogFragment fragment = -// new UploadOsmEditsConfirmDialogFragment(); -// Bundle args = new Bundle(); -// args.putSerializable(POINTS_ARRAY, points); -// fragment.setArguments(args); -// return fragment; -// } -// } } From a705891a81fc94fcb846513fe7c60fc9fc112b43 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 16 Nov 2015 00:34:06 +0100 Subject: [PATCH 2/2] Add failing test --- OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java index 6aa1d46e35..02fc27c38b 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java @@ -358,6 +358,12 @@ public class GeoPointParserUtil { System.out.println("url: " + url); actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); + + // http://www.google.com/maps/?q=loc:34.99393,-106.61568&z=11 + url = "http://www.google.com/maps/?q=loc:" + dlat + "," + dlon + " (" + name +") "; + System.out.println("url: " + url); + actual = GeoPointParserUtil.parse(url); + assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, name)); // https://www.google.com/maps/preview#!q=paris&data=!4m15!2m14!1m13!1s0x47e66e1f06e2b70f%3A0x40b82c3688c9460!3m8!1m3!1d24383582!2d-95.677068!3d37.0625!3m2!1i1222!2i718!4f13.1!4m2!3d48.856614!4d2.3522219 url = "https://www.google.com/maps/preview#!q=paris&data=!4m15!2m14!1m13!1s0x47e66e1f06e2b70f%3A0x40b82c3688c9460!3m8!1m3!1d24383582!2d-95.677068!3d37.0625!3m2!1i1222!2i718!4f13.1!4m2!3d48.856614!4d2.3522219";