Fix adding point after

This commit is contained in:
PavelRatushny 2017-08-18 10:40:11 +03:00
parent 923614a239
commit c9ec0df1d1
2 changed files with 21 additions and 15 deletions

View file

@ -865,13 +865,14 @@ public class MeasurementToolFragment extends Fragment {
private void addPointAfter() {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null && positionToAddPoint != -1) {
addPointToPosition(positionToAddPoint);
selectedPointPos += 1;
selectedCachedPoint = new WptPt(measurementLayer.getMeasurementPoints().get(selectedPointPos));
measurementLayer.setSelectedPointPos(selectedPointPos);
measurementLayer.setSelectedCachedPoint(selectedCachedPoint);
measurementLayer.refreshMap();
positionToAddPoint += 1;
if (addPointToPosition(positionToAddPoint)) {
selectedPointPos += 1;
selectedCachedPoint = new WptPt(measurementLayer.getMeasurementPoints().get(selectedPointPos));
measurementLayer.setSelectedPointPos(selectedPointPos);
measurementLayer.setSelectedCachedPoint(selectedCachedPoint);
measurementLayer.refreshMap();
positionToAddPoint += 1;
}
}
}
@ -906,11 +907,12 @@ public class MeasurementToolFragment extends Fragment {
private void addPointBefore() {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null && positionToAddPoint != -1) {
addPointToPosition(positionToAddPoint);
selectedCachedPoint = new WptPt(measurementLayer.getMeasurementPoints().get(selectedPointPos));
measurementLayer.setSelectedPointPos(selectedPointPos);
measurementLayer.setSelectedCachedPoint(selectedCachedPoint);
measurementLayer.refreshMap();
if (addPointToPosition(positionToAddPoint)) {
selectedCachedPoint = new WptPt(measurementLayer.getMeasurementPoints().get(selectedPointPos));
measurementLayer.setSelectedPointPos(selectedPointPos);
measurementLayer.setSelectedCachedPoint(selectedCachedPoint);
measurementLayer.refreshMap();
}
}
}
@ -1013,16 +1015,18 @@ public class MeasurementToolFragment extends Fragment {
}
}
private void addPointToPosition(int position) {
private boolean addPointToPosition(int position) {
boolean added = false;
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
commandManager.execute(new AddPointCommand(measurementLayer, position));
added = commandManager.execute(new AddPointCommand(measurementLayer, position));
enable(undoBtn, upDownBtn);
disable(redoBtn);
updateText();
adapter.notifyDataSetChanged();
saved = false;
}
return added;
}
private void showPointsList() {

View file

@ -18,11 +18,13 @@ public class MeasurementCommandManager {
return redoCommands.size() > 0;
}
public void execute(MeasurementModeCommand command) {
public boolean execute(MeasurementModeCommand command) {
if (command.execute()) {
undoCommands.push(command);
redoCommands.clear();
return true;
}
return false;
}
public void undo() {