Add variable to measurement context

This commit is contained in:
PavelRatushny 2017-10-30 18:31:25 +02:00
parent 50314a7709
commit 574d7a6c3a
2 changed files with 15 additions and 11 deletions

View file

@ -36,6 +36,7 @@ public class MeasurementEditingContext {
private int selectedPointPosition = -1;
private WptPt originalPointToMove;
private boolean inAddPointMode;
private boolean inSnapToRoadMode;
private boolean needUpdateCacheForSnap;
private int calculatedPairs;
@ -53,6 +54,10 @@ public class MeasurementEditingContext {
return commandManager;
}
boolean isInAddPointMode() {
return inAddPointMode;
}
boolean isInSnapToRoadMode() {
return inSnapToRoadMode;
}
@ -82,6 +87,10 @@ public class MeasurementEditingContext {
this.originalPointToMove = originalPointToMove;
}
void setInAddPointMode(boolean inAddPointMode) {
this.inAddPointMode = inAddPointMode;
}
void setInSnapToRoadMode(boolean inSnapToRoadMode) {
this.inSnapToRoadMode = inSnapToRoadMode;
}

View file

@ -609,6 +609,7 @@ public class MeasurementToolFragment extends Fragment {
public void addPointAfterOnClick() {
if (measurementLayer != null) {
measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition());
editingCtx.setInAddPointMode(true);
editingCtx.splitSegments(editingCtx.getSelectedPointPosition() + 1);
}
((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_after));
@ -620,6 +621,7 @@ public class MeasurementToolFragment extends Fragment {
public void addPointBeforeOnClick() {
if (measurementLayer != null) {
measurementLayer.moveMapToPoint(editingCtx.getSelectedPointPosition());
editingCtx.setInAddPointMode(true);
editingCtx.splitSegments(editingCtx.getSelectedPointPosition());
}
((TextView) mainView.findViewById(R.id.add_point_before_after_text)).setText(mainView.getResources().getString(R.string.add_point_before));
@ -875,7 +877,7 @@ public class MeasurementToolFragment extends Fragment {
private void cancelModes() {
if (editingCtx.getOriginalPointToMove() != null) {
cancelMovePointMode();
} else if (!isSelectedPointMenuOpened() && editingCtx.getSelectedPointPosition() != -1) {
} else if (editingCtx.isInAddPointMode()) {
cancelAddPointBeforeOrAfterMode();
}
}
@ -900,6 +902,7 @@ public class MeasurementToolFragment extends Fragment {
switchAddPointBeforeAfterMode(false);
editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
editingCtx.setSelectedPointPosition(-1);
editingCtx.setInAddPointMode(false);
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
measurementLayer.refreshMap();
@ -911,6 +914,7 @@ public class MeasurementToolFragment extends Fragment {
switchAddPointBeforeAfterMode(false);
editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
editingCtx.setSelectedPointPosition(-1);
editingCtx.setInAddPointMode(false);
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) {
measurementToolLayer.refreshMap();
@ -1397,7 +1401,7 @@ public class MeasurementToolFragment extends Fragment {
if (editingCtx.getOriginalPointToMove() != null) {
cancelMovePointMode();
return;
} else if (editingCtx.getSelectedPointPosition() != -1) {
} else if (editingCtx.isInAddPointMode()) {
cancelAddPointBeforeOrAfterMode();
return;
}
@ -1480,15 +1484,6 @@ public class MeasurementToolFragment extends Fragment {
}
}
private boolean isSelectedPointMenuOpened() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(SelectedPointBottomSheetDialogFragment.TAG);
return fragment != null;
}
return false;
}
public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx) {
try {
MeasurementToolFragment fragment = new MeasurementToolFragment();