Fix reordering bug

This commit is contained in:
Alex 2017-08-11 18:07:50 +03:00
parent 6714afb316
commit bad41b8c66
2 changed files with 2 additions and 9 deletions

View file

@ -334,7 +334,7 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void onDragEnded(RecyclerView.ViewHolder holder) {
toPosition = holder.getAdapterPosition();
if (toPosition != fromPosition) {
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
commandManager.execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition));
adapter.notifyDataSetChanged();
disable(redoBtn);

View file

@ -32,14 +32,7 @@ public class ReorderPointCommand implements Command {
}
private void swap() {
// todo: fix exception
try {
Collections.swap(measurementLayer.getMeasurementPoints(), from, to);
} catch (Exception e) {
// index out of bounds
// an exception occurs when to == -1 basically
// but maybe from == measurementPoints.size() sometimes so there is an exception
}
measurementLayer.refreshMap();
}
}