From 94701cd5a8f7f2b05aee166412c45b135c68bc8a Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Tue, 15 May 2018 09:42:25 +0300 Subject: [PATCH] Fix add/remove waypoints from markers --- .../plus/myplaces/TrackPointFragment.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index b06c242e4e..f24339421f 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -455,15 +455,19 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements if (activity == null) { return; } - GPXFile gpxFile = getGpx(); + final GPXFile gpxFile = getGpx(); MapMarkersGroup markersSearch = markersHelper.getMarkersGroup(gpxFile); final MapMarkersGroup markersGr; + final boolean markersRemoved; if (markersSearch != null) { markersGr = markersSearch; markersHelper.removeMarkersGroup(markersGr); + markersRemoved = true; } else if (gpxFile != null) { markersGr = markersHelper.addOrEnableGroup(gpxFile); + markersRemoved = false; } else { + markersRemoved = false; markersGr = null; } if (markersGr != null) { @@ -476,14 +480,24 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements fragmentAdapter.closeFabMenu(activity); fragmentAdapter.updateMenuFabVisibility(false); } - Snackbar snackbar = Snackbar.make(mainView, R.string.waypoints_removed_from_map_markers, + Snackbar snackbar = Snackbar.make(mainView, markersRemoved ? + R.string.waypoints_removed_from_map_markers : R.string.waypoints_added_to_map_markers, Snackbar.LENGTH_LONG) .setAction(R.string.shared_string_undo, new View.OnClickListener() { @Override public void onClick(View v) { TrackActivity trackActivity = getTrackActivity(); if (trackActivity != null) { - markersHelper.removeMarkersGroup(markersGr); + if (markersRemoved) { + if (gpxFile != null) { + markersHelper.addOrEnableGroup(gpxFile); + } + } else { + MapMarkersGroup group = markersHelper.getMarkersGroup(gpxFile); + if (group != null) { + markersHelper.removeMarkersGroup(group); + } + } trackActivity.invalidateOptionsMenu(); } }