Add undo/redo for clear all; add some improvements
This commit is contained in:
parent
c286fa8506
commit
17ccf0c16b
4 changed files with 56 additions and 20 deletions
|
@ -44,6 +44,7 @@ import net.osmand.plus.helpers.AndroidUiHelper;
|
|||
import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter;
|
||||
import net.osmand.plus.measurementtool.adapter.MeasurementToolItemTouchHelperCallback;
|
||||
import net.osmand.plus.measurementtool.command.AddPointCommand;
|
||||
import net.osmand.plus.measurementtool.command.ClearPointsCommand;
|
||||
import net.osmand.plus.measurementtool.command.CommandManager;
|
||||
import net.osmand.plus.measurementtool.command.RemovePointCommand;
|
||||
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
|
||||
|
@ -145,9 +146,9 @@ public class MeasurementToolFragment extends Fragment {
|
|||
if (commandManager.canUndo()) {
|
||||
enable(undoBtn);
|
||||
} else {
|
||||
disable(undoBtn, upDownBtn);
|
||||
hidePointsList();
|
||||
disable(undoBtn);
|
||||
}
|
||||
hidePointsListIfNeeded();
|
||||
adapter.notifyDataSetChanged();
|
||||
enable(redoBtn);
|
||||
updateText();
|
||||
|
@ -164,8 +165,9 @@ public class MeasurementToolFragment extends Fragment {
|
|||
} else {
|
||||
disable(redoBtn);
|
||||
}
|
||||
hidePointsListIfNeeded();
|
||||
adapter.notifyDataSetChanged();
|
||||
enable(undoBtn, upDownBtn);
|
||||
enable(undoBtn);
|
||||
updateText();
|
||||
}
|
||||
});
|
||||
|
@ -232,11 +234,10 @@ public class MeasurementToolFragment extends Fragment {
|
|||
}
|
||||
return true;
|
||||
case R.id.action_clear_all:
|
||||
measurementLayer.clearPoints();
|
||||
hidePointsList();
|
||||
disable(undoBtn, redoBtn, upDownBtn);
|
||||
commandManager.execute(new ClearPointsCommand(measurementLayer));
|
||||
hidePointsListIfNeeded();
|
||||
disable(redoBtn);
|
||||
updateText();
|
||||
commandManager.clear();
|
||||
saved = false;
|
||||
return true;
|
||||
}
|
||||
|
@ -265,13 +266,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
disable(redoBtn);
|
||||
updateText();
|
||||
saved = false;
|
||||
if (measurementLayer.getPointsCount() < 1) {
|
||||
hidePointsList();
|
||||
disable(upDownBtn);
|
||||
if (!commandManager.canUndo()) {
|
||||
disable(undoBtn);
|
||||
}
|
||||
}
|
||||
hidePointsListIfNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -303,6 +298,18 @@ public class MeasurementToolFragment extends Fragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
private void hidePointsListIfNeeded() {
|
||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null) {
|
||||
if (measurementLayer.getPointsCount() < 1) {
|
||||
disable(upDownBtn);
|
||||
if (pointsListOpened) {
|
||||
hidePointsList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addPoint() {
|
||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null) {
|
||||
|
|
|
@ -89,7 +89,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
return OsmAndFormatter.getFormattedDistance(dist, view.getApplication());
|
||||
}
|
||||
|
||||
void clearPoints() {
|
||||
public void clearPoints() {
|
||||
measurementPoints.clear();
|
||||
view.refreshMap();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package net.osmand.plus.measurementtool.command;
|
||||
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.measurementtool.MeasurementToolLayer;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class ClearPointsCommand implements Command {
|
||||
|
||||
private final MeasurementToolLayer measurementLayer;
|
||||
private List<GPXUtilities.WptPt> points;
|
||||
|
||||
public ClearPointsCommand(MeasurementToolLayer measurementLayer) {
|
||||
this.measurementLayer = measurementLayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
points = new LinkedList<>(measurementLayer.getMeasurementPoints());
|
||||
measurementLayer.clearPoints();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
measurementLayer.getMeasurementPoints().addAll(points);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redo() {
|
||||
measurementLayer.clearPoints();
|
||||
}
|
||||
}
|
|
@ -38,9 +38,4 @@ public class CommandManager {
|
|||
command.redo();
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
undoCommands.clear();
|
||||
redoCommands.clear();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue