diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index e39a68c11e..74b56dc966 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -301,6 +301,20 @@ public class MapMarkersHelper { } } + public void addMarker(MapMarker marker) { + if (marker != null) { + markersDbHelper.addMarker(marker); + if (marker.history) { + mapMarkersHistory.add(marker); + sortMarkers(mapMarkersHistory, true); + } else { + mapMarkers.add(marker); + checkAndFixActiveMarkersOrderIfNeeded(); + } + refresh(); + } + } + public void restoreMarkerFromHistory(MapMarker marker, int position) { if (marker != null) { markersDbHelper.restoreMapMarkerFromHistory(marker); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index cf570549c9..06028476be 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -106,6 +106,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm activeFragment.startLocationUpdate(); if (viewPager.getCurrentItem() != 0) { activeFragment.updateAdapter(); + historyFragment.hideSnackbar(); } viewPager.setCurrentItem(0); optionsButton.setVisibility(View.VISIBLE); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 5541e4f5f6..32c98aadda 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -9,12 +9,12 @@ import android.graphics.PorterDuffColorFilter; import android.graphics.Rect; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -35,6 +35,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel private Paint backgroundPaint = new Paint(); private Paint iconPaint = new Paint(); private Paint textPaint = new Paint(); + private Snackbar snackbar; @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -140,16 +141,29 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel } @Override - public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { - int pos = viewHolder.getAdapterPosition(); + public void onSwiped(RecyclerView.ViewHolder viewHolder, final int direction) { + final int pos = viewHolder.getAdapterPosition(); Object item = adapter.getItem(pos); if (item instanceof MapMarker) { + final MapMarker marker = (MapMarker) item; if (direction == ItemTouchHelper.LEFT) { app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0); } else { app.getMapMarkersHelper().removeMarkerFromHistory((MapMarker) item); } adapter.notifyItemRemoved(pos); + snackbar = Snackbar.make(viewHolder.itemView, R.string.item_removed, Snackbar.LENGTH_LONG) + .setAction(R.string.shared_string_undo, new View.OnClickListener() { + @Override + public void onClick(View view) { + if (direction == ItemTouchHelper.LEFT) { + app.getMapMarkersHelper().moveMapMarkerToHistory(marker); + } else { + app.getMapMarkersHelper().addMarker(marker); + } + } + }); + snackbar.show(); } } }; @@ -183,6 +197,12 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel return recyclerView; } + void hideSnackbar() { + if (snackbar != null && snackbar.isShown()) { + snackbar.dismiss(); + } + } + private HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener createHistoryMarkerMenuListener() { return new HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener() { @Override