diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index dd3a71a14a..35fa73fccd 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -46,6 +46,7 @@ import net.osmand.plus.measurementtool.adapter.MeasurementToolItemTouchHelperCal import net.osmand.plus.measurementtool.command.AddPointCommand; import net.osmand.plus.measurementtool.command.CommandManager; import net.osmand.plus.measurementtool.command.RemovePointCommand; +import net.osmand.plus.measurementtool.command.ReorderPointCommand; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; @@ -242,6 +243,10 @@ public class MeasurementToolFragment extends Fragment { final ItemTouchHelper touchHelper = new ItemTouchHelper(new MeasurementToolItemTouchHelperCallback(adapter)); touchHelper.attachToRecyclerView(rv); adapter.setAdapterListener(new MeasurementToolAdapter.MeasurementAdapterListener() { + + private int fromPosition; + private int toPosition; + @Override public void onPointRemove(int position) { commandManager.execute(new RemovePointCommand(measurementLayer, position)); @@ -265,8 +270,19 @@ public class MeasurementToolFragment extends Fragment { @Override public void onDragStarted(RecyclerView.ViewHolder holder) { + fromPosition = holder.getAdapterPosition(); touchHelper.startDrag(holder); } + + @Override + public void onDragEnded(RecyclerView.ViewHolder holder) { + toPosition = holder.getAdapterPosition(); + if (toPosition != fromPosition) { + commandManager.execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition)); + adapter.notifyDataSetChanged(); + mapActivity.refreshMap(); + } + } }); rv.setLayoutManager(new LinearLayoutManager(getContext())); rv.setAdapter(adapter); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 63e14c0766..0f24f0d71e 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -74,7 +74,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL return measurementPoints.size(); } - LinkedList getMeasurementPoints() { + public LinkedList getMeasurementPoints() { return measurementPoints; } @@ -195,6 +195,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL } } + public void refreshMap() { + view.refreshMap(); + } + @Override public void destroyLayer() { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java index 50429614a3..f5e893f76d 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java @@ -26,7 +26,7 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter points; - private MeasurementAdapterListener adapterListener; + private MeasurementAdapterListener listener; public MeasurementToolAdapter(MapActivity mapActivity, List points) { this.mapActivity = mapActivity; @@ -34,7 +34,7 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter