From b5f0af881b8231f7f0878c6a1ffddcdf97cef0a5 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 25 Aug 2017 17:15:07 +0300 Subject: [PATCH] Refactor --- .../MeasurementEditingContext.java | 35 ++++--------------- .../MeasurementToolFragment.java | 11 ------ .../measurementtool/MeasurementToolLayer.java | 2 +- 3 files changed, 8 insertions(+), 40 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index ff5570f7da..6dd9175e06 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -135,30 +135,6 @@ public class MeasurementEditingContext { return after; } -// public void recreateSegments() { -// List points = new ArrayList<>(); -// points.addAll(before.points); -// points.addAll(after.points); -// before.points.clear(); -// if (points.size() > 1) { -// for (int i = 0; i < points.size() - 1; i++) { -// Pair pair = new Pair<>(points.get(i), points.get(i + 1)); -// List pts = snappedToRoadPoints.get(pair); -// if (pts != null) { -// before.points.addAll(pts); -// } else { -// if (inSnapToRoadMode) { -// scheduleRouteCalculateIfNotEmpty(); -// } -// before.points.addAll(Arrays.asList(pair.first, pair.second)); -// } -// } -// } else { -// before.points.addAll(points); -// } -// after.points.clear(); -// } - public List getPoints() { return getBeforePoints(); } @@ -168,7 +144,7 @@ public class MeasurementEditingContext { } public List getAfterPoints() { - return after.points; + return after.points; } public int getPointsCount() { @@ -180,9 +156,13 @@ public class MeasurementEditingContext { points.addAll(before.points); points.addAll(after.points); before.points.clear(); - before.points.addAll(points.subList(0, position)); after.points.clear(); - after.points.addAll(points.subList(position, points.size())); + if (position == before.points.size() + after.points.size()) { + before.points.addAll(points); + } else { + before.points.addAll(points.subList(0, position)); + after.points.addAll(points.subList(position, points.size())); + } } public void addPoint(WptPt pt) { @@ -283,7 +263,6 @@ public class MeasurementEditingContext { pts.add(pt); } snappedToRoadPoints.put(currentPair, pts); -// recreateSegments(); progressListener.refreshMap(); if (!snapToRoadPairsToCalculate.isEmpty()) { application.getRoutingHelper().startRouteCalculationThread(getParams(), true, true); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index bf28d1123a..50483dab0f 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -303,7 +303,6 @@ public class MeasurementToolFragment extends Fragment { @Override public void onClick(View view) { editingCtx.getCommandManager().undo(); -// editingCtx.recreateSegments(); if (editingCtx.getCommandManager().canUndo()) { enable(undoBtn); } else { @@ -324,7 +323,6 @@ public class MeasurementToolFragment extends Fragment { @Override public void onClick(View view) { editingCtx.getCommandManager().redo(); -// editingCtx.recreateSegments(); if (editingCtx.getCommandManager().canRedo()) { enable(redoBtn); } else { @@ -595,7 +593,6 @@ public class MeasurementToolFragment extends Fragment { @Override public void clearAllOnClick() { editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer)); - editingCtx.clearSegments(); editingCtx.cancelSnapToRoad(); if (pointsListOpened) { hidePointsList(); @@ -625,7 +622,6 @@ public class MeasurementToolFragment extends Fragment { if (measurementLayer != null) { removePoint(measurementLayer, editingCtx.getSelectedPointPosition()); } -// editingCtx.recreateSegments(); editingCtx.setSelectedPointPosition(-1); } @@ -682,7 +678,6 @@ public class MeasurementToolFragment extends Fragment { private void removePoint(MeasurementToolLayer layer, int position) { editingCtx.getCommandManager().execute(new RemovePointCommand(layer, position)); -// editingCtx.recreateSegments(); adapter.notifyDataSetChanged(); disable(redoBtn); updateText(); @@ -749,7 +744,6 @@ public class MeasurementToolFragment extends Fragment { toPosition = holder.getAdapterPosition(); if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { editingCtx.getCommandManager().execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition)); -// editingCtx.recreateSegments(); adapter.notifyDataSetChanged(); disable(redoBtn); updateText(); @@ -868,7 +862,6 @@ public class MeasurementToolFragment extends Fragment { WptPt oldPoint = editingCtx.getOriginalPointToMove(); int position = editingCtx.getSelectedPointPosition(); editingCtx.getCommandManager().execute(new MovePointCommand(measurementLayer, oldPoint, newPoint, position)); - editingCtx.addPoint(newPoint); doAddOrMovePointCommonStuff(); measurementLayer.exitMovePointMode(false); measurementLayer.refreshMap(); @@ -898,7 +891,6 @@ public class MeasurementToolFragment extends Fragment { private void applyAddPointAfterMode() { switchAddPointAfterMode(false); editingCtx.setSelectedPointPosition(-1); -// editingCtx.recreateSegments(); MeasurementToolLayer measurementLayer = getMeasurementLayer(); if (measurementLayer != null) { measurementLayer.exitAddPointAfterMode(); @@ -909,7 +901,6 @@ public class MeasurementToolFragment extends Fragment { private void cancelAddPointAfterMode() { switchAddPointAfterMode(false); editingCtx.setSelectedPointPosition(-1); -// editingCtx.recreateSegments(); MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); if (measurementToolLayer != null) { measurementToolLayer.exitAddPointAfterMode(); @@ -930,7 +921,6 @@ public class MeasurementToolFragment extends Fragment { private void applyAddPointBeforeMode() { switchAddPointBeforeMode(false); editingCtx.setSelectedPointPosition(-1); -// editingCtx.recreateSegments(); MeasurementToolLayer measurementLayer = getMeasurementLayer(); if (measurementLayer != null) { measurementLayer.exitAddPointBeforeMode(); @@ -941,7 +931,6 @@ public class MeasurementToolFragment extends Fragment { private void cancelAddPointBeforeMode() { switchAddPointBeforeMode(false); editingCtx.setSelectedPointPosition(-1); -// editingCtx.recreateSegments(); MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); if (measurementToolLayer != null) { measurementToolLayer.exitAddPointBeforeMode(); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 93846d1737..e02ed487a5 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -327,9 +327,9 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL WptPt pt = editingCtx.getOriginalPointToMove(); editingCtx.addPoint(pt); } -// editingCtx.recreateSegments(); editingCtx.setOriginalPointToMove(null); editingCtx.setSelectedPointPosition(-1); + editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size()); } void exitAddPointAfterMode() {