diff --git a/OsmAnd/res/layout/map_marker_item.xml b/OsmAnd/res/layout/map_marker_item.xml index 58d93922f4..da513b80a9 100644 --- a/OsmAnd/res/layout/map_marker_item.xml +++ b/OsmAnd/res/layout/map_marker_item.xml @@ -114,7 +114,6 @@ android:layout_width="48dp" android:layout_height="48dp" android:layout_gravity="center_vertical" - android:layout_marginRight="2dp" android:focusable="false" android:clickable="false" android:scaleType="center" diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 2b8e42135d..1357a564a4 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1706,7 +1706,9 @@ public class OsmandSettings { int index = ps.indexOf(new LatLon(latitude, longitude)); ds.set(index, PointDescription.serializeToString(historyDescription)); cs.set(index, colorIndex); - ns.set(index, pos); + if (ns.size() > index) { + ns.set(index, pos); + } if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 9fa89644f0..79146ea952 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -41,7 +41,6 @@ import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnRowItemClick; import net.osmand.plus.IconsCache; -import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener; import net.osmand.plus.OsmandApplication; @@ -58,6 +57,7 @@ import net.osmand.plus.dialogs.RasterMapMenu; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.MapMarkerDialogHelper; +import net.osmand.plus.helpers.MapMarkerDialogHelper.MapMarkersDialogHelperCallbacks; import net.osmand.plus.helpers.WaypointDialogHelper; import net.osmand.plus.helpers.WaypointDialogHelper.WaypointDialogHelperCallbacks; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; @@ -88,7 +88,8 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP; /** */ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicListViewCallbacks, - IRouteInformationListener, WaypointDialogHelperCallbacks, MapMarkerChangedListener { + IRouteInformationListener, WaypointDialogHelperCallbacks, MapMarkersDialogHelperCallbacks, + MapMarkerChangedListener { private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(DashboardOnMap.class); private static final String TAG = "DashboardOnMap"; @@ -190,8 +191,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis public void createDashboardView() { baseColor = mapActivity.getResources().getColor(R.color.osmand_orange) & 0x00ffffff; waypointDialogHelper = new WaypointDialogHelper(mapActivity); - waypointDialogHelper.setWaypointDialogHelperCallbacks(this); + waypointDialogHelper.setHelperCallbacks(this); mapMarkerDialogHelper = new MapMarkerDialogHelper(mapActivity); + mapMarkerDialogHelper.setHelperCallbacks(this); landscape = !AndroidUiHelper.isOrientationPortrait(mapActivity); dashboardView = (FrameLayout) mapActivity.findViewById(R.id.dashboard); final View.OnClickListener listener = new View.OnClickListener() { @@ -220,9 +222,14 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis public boolean canDismiss(int position) { boolean res = false; if (listAdapter instanceof StableArrayAdapter) { - List activeObjects = ((StableArrayAdapter) listAdapter).getActiveObjects(); - Object obj = listAdapter.getItem(position); - res = activeObjects.contains(obj); + if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) { + List activeObjects = ((StableArrayAdapter) listAdapter).getActiveObjects(); + Object obj = listAdapter.getItem(position); + res = activeObjects.contains(obj); + } else if (visibleType == DashboardType.MAP_MARKERS) { + Object obj = listAdapter.getItem(position); + res = obj instanceof MapMarker; + } } return res; } @@ -785,10 +792,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running, listAdapter); - DynamicListView dynamicListView = (DynamicListView) listView; - dynamicListView.setItemsList(listAdapter.getObjects()); - dynamicListView.setActiveItemsList(listAdapter.getActiveObjects()); - + setDynamicListItems((DynamicListView) listView, listAdapter); updateListAdapter(listAdapter, listener); } else if (DashboardType.MAP_MARKERS == visibleType) { @@ -797,10 +801,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis StableArrayAdapter listAdapter = mapMarkerDialogHelper.getMapMarkersListAdapter(); OnItemClickListener listener = mapMarkerDialogHelper.getItemClickListener(listAdapter); - DynamicListView dynamicListView = (DynamicListView) listView; - dynamicListView.setItemsList(listAdapter.getObjects()); - dynamicListView.setActiveItemsList(listAdapter.getActiveObjects()); - + setDynamicListItems((DynamicListView) listView, listAdapter); updateListAdapter(listAdapter, listener); } else { @@ -852,6 +853,21 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis } } + private void setDynamicListItems(DynamicListView listView, StableArrayAdapter listAdapter) { + listView.setItemsList(listAdapter.getObjects()); + + if (DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType) { + listView.setActiveItemsList(listAdapter.getActiveObjects()); + } else if (DashboardType.MAP_MARKERS == visibleType) { + List activeMarkers = new ArrayList<>(); + for (Object obj : listAdapter.getActiveObjects()) { + if (obj instanceof MapMarker && !((MapMarker) obj).history) { + activeMarkers.add(obj); + } + } + listView.setActiveItemsList(activeMarkers); + } + } private OnItemClickListener getOptionsMenuOnClickListener(final ContextMenuAdapter cm, final ArrayAdapter listAdapter) { @@ -1288,6 +1304,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis } } + @SuppressWarnings("unchecked") @Override public void onItemsSwapped(final List items) { getMyApplication().runInUIThread(new Runnable() { @@ -1316,9 +1333,13 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis newRouteIsCalculated(false, new ValueHolder()); getMyApplication().getTargetPointsHelper().updateRouteAndRefresh(true); - if (swipeDismissListener != null) { - swipeDismissListener.setEnabled(true); - } + } else if (visibleType == DashboardType.MAP_MARKERS) { + List markers = (List)(Object)items; + getMyApplication().getMapMarkersHelper().saveMapMarkers(markers, null); + } + + if (swipeDismissListener != null) { + swipeDismissListener.setEnabled(true); } } }, 50); @@ -1355,17 +1376,24 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis mapMarkerDialogHelper.reloadListAdapter(stableAdapter); } if (listView instanceof DynamicListView) { - DynamicListView dynamicListView = (DynamicListView) listView; - dynamicListView.setItemsList(stableAdapter.getObjects()); - dynamicListView.setActiveItemsList(stableAdapter.getActiveObjects()); + setDynamicListItems((DynamicListView) listView, stableAdapter); } } } + private void deleteSwipeItem(int position) { + if (swipeDismissListener != null) { + swipeDismissListener.delete(position); + } + } + @Override public void deleteWaypoint(int position) { - if (swipeDismissListener != null) { - swipeDismissListener.delete(position); - } + deleteSwipeItem(position); + } + + @Override + public void deleteMapMarker(int position) { + deleteSwipeItem(position); } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java index 700c80a6b3..91c475444a 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java @@ -33,11 +33,11 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.views.DirectionDrawable; +import net.osmand.plus.views.controls.DynamicListView; import net.osmand.plus.views.controls.ListDividerShape; import net.osmand.plus.views.controls.StableArrayAdapter; import net.osmand.util.Algorithms; @@ -59,6 +59,7 @@ public class MapMarkerDialogHelper { private MapActivity mapActivity; private OsmandApplication app; private MapMarkersHelper markersHelper; + private MapMarkersDialogHelperCallbacks helperCallbacks; private boolean sorted; private boolean nightMode; @@ -69,12 +70,21 @@ public class MapMarkerDialogHelper { private boolean reloading; private long lastUpdateTime; + public interface MapMarkersDialogHelperCallbacks { + void reloadAdapter(); + void deleteMapMarker(int position); + } + public MapMarkerDialogHelper(MapActivity mapActivity) { this.mapActivity = mapActivity; app = mapActivity.getMyApplication(); markersHelper = app.getMapMarkersHelper(); } + public void setHelperCallbacks(MapMarkersDialogHelperCallbacks helperCallbacks) { + this.helperCallbacks = helperCallbacks; + } + public boolean isNightMode() { return nightMode; } @@ -116,7 +126,7 @@ public class MapMarkerDialogHelper { final List objects = getListObjects(); List activeObjects = getActiveObjects(objects); - final StableArrayAdapter listAdapter = new StableArrayAdapter(mapActivity, + return new StableArrayAdapter(mapActivity, R.layout.map_marker_item, R.id.title, objects, activeObjects) { @Override @@ -147,14 +157,12 @@ public class MapMarkerDialogHelper { v = mapActivity.getLayoutInflater().inflate(R.layout.card_bottom_divider, null); } else if (obj instanceof MapMarker) { MapMarker marker = (MapMarker) obj; - v = updateMapMarkerItemView(v, marker); + v = updateMapMarkerItemView(this, v, marker); AndroidUtils.setListItemBackground(mapActivity, v, nightMode); } return v; } }; - - return listAdapter; } private List getCustomDividers(List points) { @@ -308,7 +316,7 @@ public class MapMarkerDialogHelper { return v; } - protected View updateMapMarkerItemView(View v, final MapMarker marker) { + protected View updateMapMarkerItemView(final StableArrayAdapter adapter, View v, final MapMarker marker) { if (v == null || v.findViewById(R.id.info_close) == null) { v = mapActivity.getLayoutInflater().inflate(R.layout.map_marker_item, null); } @@ -317,8 +325,38 @@ public class MapMarkerDialogHelper { final View move = v.findViewById(R.id.info_move); final View remove = v.findViewById(R.id.info_close); remove.setVisibility(View.GONE); - move.setVisibility(View.GONE); more.setVisibility(View.GONE); + if (!marker.history) { + move.setVisibility(View.VISIBLE); + ((ImageView) move).setImageDrawable(app.getIconsCache().getContentIcon( + R.drawable.ic_action_reorder, !nightMode)); + move.setTag(new DynamicListView.DragIcon() { + @Override + public void onClick() { + final PopupMenu optionsMenu = new PopupMenu(mapActivity, move); + DirectionsDialogs.setupPopUpMenuIcon(optionsMenu); + MenuItem item; + item = optionsMenu.getMenu().add( + R.string.shared_string_remove).setIcon(app.getIconsCache(). + getContentIcon(R.drawable.ic_action_remove_dark)); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + if (helperCallbacks != null) { + int pos = adapter.getPosition(marker); + if (pos != -1) { + helperCallbacks.deleteMapMarker(pos); + } + } + return true; + } + }); + optionsMenu.show(); + } + }); + } else { + move.setVisibility(View.GONE); + } return v; } diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index e182657d31..990707076f 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -73,7 +73,7 @@ public class WaypointDialogHelper { } } - public void setWaypointDialogHelperCallbacks(WaypointDialogHelperCallbacks callbacks) { + public void setHelperCallbacks(WaypointDialogHelperCallbacks callbacks) { this.helperCallbacks = callbacks; }