diff --git a/OsmAnd/res/layout/map_marker_item_header.xml b/OsmAnd/res/layout/map_marker_item_header.xml index 4c5287e5c0..8a535b1332 100644 --- a/OsmAnd/res/layout/map_marker_item_header.xml +++ b/OsmAnd/res/layout/map_marker_item_header.xml @@ -38,6 +38,18 @@ android:textColor="?android:textColorPrimary" tools:text="Today"/> + + { @@ -34,6 +36,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter items = new ArrayList<>(); + private Map> markerGroups = new HashMap<>(); private MapMarkersHistoryAdapterListener listener; private Snackbar snackbar; private boolean night; @@ -46,6 +49,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter(); + markerGroups = new HashMap<>(); List markersHistory = app.getMapMarkersHelper().getMapMarkersHistory(); int previousHeader = -1; int monthsDisplayed = 0; @@ -84,10 +88,22 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter group = markerGroups.get(groupHeader); + if (group != null) { + group.add(marker); + } else { + group = new ArrayList<>(); + group.add(marker); + markerGroups.put(groupHeader, group); + } + } + public void setAdapterListener(MapMarkersHistoryAdapterListener listener) { this.listener = listener; } @@ -112,7 +128,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter group = markerGroups.get(dateHeader); + if (group == null) { + return; + } + for (MapMarker marker : group) { + app.getMapMarkersHelper().removeMarker((MapMarker) marker); + } + snackbar = Snackbar.make(holder.itemView, app.getString(R.string.n_items_removed), Snackbar.LENGTH_LONG) + .setAction(R.string.shared_string_undo, new View.OnClickListener() { + @Override + public void onClick(View view) { + for (MapMarker marker : group) { + app.getMapMarkersHelper().addMarker(marker); + } + } + }); + UiUtilities.setupSnackbar(snackbar, night); + snackbar.show(); + } + }); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java index ee19d38c48..5e18b89f8a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersItemTouchHelperCallback.java @@ -1,7 +1,6 @@ package net.osmand.plus.mapmarkers.adapters; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuff; @@ -13,6 +12,7 @@ import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; +import net.osmand.AndroidUtils; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -47,8 +47,8 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback this.mapActivity = mapActivity; this.adapter = adapter; marginSides = mapActivity.getResources().getDimension(R.dimen.list_content_padding); - deleteBitmap = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.ic_action_delete_dark); - historyBitmap = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.ic_action_history); + deleteBitmap = AndroidUtils.bitmapFromDrawableRes(mapActivity, R.drawable.ic_action_delete_dark); + historyBitmap = AndroidUtils.bitmapFromDrawableRes(mapActivity, R.drawable.ic_action_history); night = !mapActivity.getMyApplication().getSettings().isLightContent(); backgroundPaint.setColor(ContextCompat.getColor(mapActivity, night ? R.color.divider_color_dark : R.color.divider_color_light));