Add some changes

This commit is contained in:
Alexander Sytnyk 2017-09-06 18:16:08 +03:00
parent 9a3573cae9
commit a8d90e4525
3 changed files with 14 additions and 9 deletions

View file

@ -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<MapMarker> markers, List<MapMarker> markersHistory) {
if (markers != null) {
List<LatLon> ls = new ArrayList<>(markers.size());

View file

@ -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);
}
}
});

View file

@ -227,7 +227,7 @@ public class MapMarkersDbHelper {
private void buildLinkedList(LongSparseArray<MapMarker> markers, List<MapMarker> 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);