Do some refactoring

This commit is contained in:
Alexander Sytnyk 2017-08-22 11:59:06 +03:00
parent 53e20809e1
commit 8e391b1925

View file

@ -122,12 +122,12 @@ public class MeasurementToolFragment extends Fragment {
private int previousMapPosition;
private NewGpxLine newGpxLine;
private boolean gpxPointsAdded;
private boolean snapToRoadEnabled;
private ApplicationMode snapToRoadAppMode;
private boolean inMovePointMode;
private boolean inAddPointAfterMode;
private boolean inAddPointBeforeMode;
private boolean isInSnapToRoadMode;
private int selectedPointPos = -1;
private WptPt selectedCachedPoint;
@ -293,7 +293,7 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void onClick(View view) {
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
fragment.setSnapToRoadEnabled(snapToRoadEnabled);
fragment.setSnapToRoadEnabled(isInSnapToRoadMode);
fragment.setListener(createOptionsFragmentListener());
fragment.setAddLineMode(newGpxLine != null);
fragment.show(mapActivity.getSupportFragmentManager(), OptionsBottomSheetDialogFragment.TAG);
@ -456,7 +456,7 @@ public class MeasurementToolFragment extends Fragment {
enterMeasurementMode();
if (snapToRoadEnabled) {
if (isInSnapToRoadMode) {
enableSnapToRoadMode(true);
}
@ -547,7 +547,7 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void snapToRoadOnCLick() {
if (!snapToRoadEnabled) {
if (!isInSnapToRoadMode) {
showSnapToRoadMenu(true);
} else {
disableSnapToRoadMode();
@ -754,7 +754,7 @@ public class MeasurementToolFragment extends Fragment {
if (snapToRoadAppMode != null) {
toolBarController.setTopBarSwitchVisible(true);
toolBarController.setTopBarSwitchChecked(true);
snapToRoadEnabled = true;
isInSnapToRoadMode = true;
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_snap_to_road));
final MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
@ -775,7 +775,7 @@ public class MeasurementToolFragment extends Fragment {
if (measurementPoints.size() > 1) {
if (!enableAfterRotating) {
snapToRoadProgressBar.setProgress(0);
doSnapToRoad(mapActivity);
doSnapToRoad();
}
}
@ -784,7 +784,9 @@ public class MeasurementToolFragment extends Fragment {
}
}
private void doSnapToRoad(final MapActivity mapActivity) {
private void doSnapToRoad() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
Location start = new Location("");
WptPt first = measurementPoints.get(0);
start.setLatitude(first.getLatitude());
@ -844,11 +846,12 @@ public class MeasurementToolFragment extends Fragment {
mapActivity.getMyApplication().getRoutingHelper().recalculateSnapToRoad(start, end, intermediates, params);
}
}
private void disableSnapToRoadMode() {
toolBarController.setTopBarSwitchVisible(false);
toolBarController.setTitle(previousToolBarTitle);
snapToRoadEnabled = false;
isInSnapToRoadMode = false;
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
calculationProgress.isCancelled = true;
MapActivity mapActivity = getMapActivity();
@ -1571,7 +1574,7 @@ public class MeasurementToolFragment extends Fragment {
if (pointsListOpened) {
hidePointsList();
}
if (snapToRoadEnabled) {
if (isInSnapToRoadMode) {
disableSnapToRoadMode();
}
if (newGpxLine != null) {