diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 9f549dec40..5ddd5eeba2 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -201,23 +201,21 @@ public class MapMarkersHelper { public void moveMapMarkerToHistory(MapMarker marker) { if (marker != null) { - marker.history = true; + cancelPointAddressRequests(marker.point); markersDbHelper.moveMarkerToHistory(marker); mapMarkers.remove(marker); + marker.history = true; mapMarkersHistory.add(marker); - cancelPointAddressRequests(marker.point); refresh(); } } public void restoreMarkerFromHistory(MapMarker marker, int position) { if (marker != null) { - MapMarker next = position >= mapMarkers.size() ? null : mapMarkers.get(position); - marker.history = false; - mapMarkersHistory.remove(marker); - mapMarkers.add(position, marker); + MapMarker next = position == mapMarkers.size() ? null : mapMarkers.get(position); markersDbHelper.restoreMapMarkerFromHistory(marker); markersDbHelper.changeActiveMarkerPosition(marker, next); + loadMarkers(); refresh(); } } @@ -326,7 +324,7 @@ public class MapMarkersHelper { } if (colorIndex == -1) { if (mapMarkers.size() > 0) { - colorIndex = (mapMarkers.get(0).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; + colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT; } else { colorIndex = 0; } @@ -360,6 +358,13 @@ public class MapMarkersHelper { } } + public void changeActiveMarkerPositionInDb(int currentPos) { + MapMarker moved = mapMarkers.get(currentPos); + markersDbHelper.changeActiveMarkerPosition(moved, + currentPos == mapMarkers.size() - 1 ? null : mapMarkers.get(currentPos + 1)); + loadMarkers(); + } + public void saveMapMarkers(List markers, List markersHistory) { if (markers != null) { List ls = new ArrayList<>(markers.size()); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 3b2fb3d96d..6a8da180ba 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -67,7 +67,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL public void onDragEnded(RecyclerView.ViewHolder holder) { toPosition = holder.getAdapterPosition(); if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { - mapActivity.getMyApplication().getMapMarkersHelper().saveMapMarkers(adapter.getItems(), null); + mapActivity.getMyApplication().getMapMarkersHelper().changeActiveMarkerPositionInDb(toPosition); } } }); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 0f06b5c028..aa4e828b58 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -227,7 +227,7 @@ public class MapMarkersDbHelper { private void buildLinkedList(LongSparseArray markers, List res, MapMarker marker) { if (marker != null) { - res.add(marker); + res.add(0, marker); MapMarker prev = markers.get(marker.id); if (prev != null) { buildLinkedList(markers, res, prev);