From e1d02fabd22ba819f43ac2c8c453f039495cdc86 Mon Sep 17 00:00:00 2001 From: cepprice Date: Fri, 12 Feb 2021 20:41:23 +0500 Subject: [PATCH 1/2] Don't overwrite GPX file if it's there were no changes --- .../plus/measurementtool/MeasurementToolFragment.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index cc17d2ac9f..5361ebf7cb 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -496,8 +496,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route public void onClick(View v) { if (isFollowTrackMode()) { startTrackNavigation(); - } else { + } else if (editingCtx.isNewData() || editingCtx.hasChanges()) { saveChanges(FinalSaveAction.SHOW_SNACK_BAR_AND_CLOSE, false); + } else { + if (mapActivity != null) { + dismiss(mapActivity, false); + } } } }); From 03d379b0551fb7feecae0258cde3a2f262e2ea09 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sun, 14 Feb 2021 00:56:35 +0200 Subject: [PATCH 2/2] Small fix for final mapActivity --- .../MeasurementToolFragment.java | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 5361ebf7cb..bf6ee212dc 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -231,7 +231,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - final MapActivity mapActivity = (MapActivity) getActivity(); + MapActivity mapActivity = (MapActivity) getActivity(); if (mapActivity == null) { return null; } @@ -375,13 +375,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route mainView.findViewById(R.id.options_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - boolean trackSnappedToRoad = !editingCtx.isApproximationNeeded(); - boolean addNewSegmentAllowed = editingCtx.isAddNewSegmentAllowed(); - OptionsBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), - MeasurementToolFragment.this, - trackSnappedToRoad, addNewSegmentAllowed, - editingCtx.getAppMode().getStringKey() - ); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + boolean trackSnappedToRoad = !editingCtx.isApproximationNeeded(); + boolean addNewSegmentAllowed = editingCtx.isAddNewSegmentAllowed(); + OptionsBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), + MeasurementToolFragment.this, + trackSnappedToRoad, addNewSegmentAllowed, + editingCtx.getAppMode().getStringKey() + ); + } } }); @@ -431,7 +434,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void onSelectPoint(int selectedPointPos) { - if (selectedPointPos != -1) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null && selectedPointPos != -1) { openSelectedPointMenu(mapActivity); } } @@ -440,7 +444,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route measurementLayer.setOnMeasureDistanceToCenterListener(new MeasurementToolLayer.OnMeasureDistanceToCenter() { @Override public void onMeasure(float distance, float bearing) { - String distStr = OsmAndFormatter.getFormattedDistance(distance, mapActivity.getMyApplication()); + String distStr = OsmAndFormatter.getFormattedDistance(distance, app); String azimuthStr = OsmAndFormatter.getFormattedAzimuth(bearing, app); distanceToCenterTv.setText(String.format("%1$s • %2$s", distStr, azimuthStr)); TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration( @@ -499,6 +503,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route } else if (editingCtx.isNewData() || editingCtx.hasChanges()) { saveChanges(FinalSaveAction.SHOW_SNACK_BAR_AND_CLOSE, false); } else { + MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { dismiss(mapActivity, false); } @@ -539,9 +544,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route configBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - RouteOptionsBottomSheet.showInstance( - mapActivity, MeasurementToolFragment.this, DialogMode.PLAN_ROUTE, - editingCtx.getAppMode().getStringKey()); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + RouteOptionsBottomSheet.showInstance( + mapActivity, MeasurementToolFragment.this, DialogMode.PLAN_ROUTE, + editingCtx.getAppMode().getStringKey()); + } } }); @@ -935,7 +943,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route app.getTargetPointsHelper().updateRouteAndRefresh(true); app.getRoutingHelper().onSettingsChanged(true); } else { - mapActivity.getMapActions().stopNavigationActionConfirm(null , new Runnable() { + mapActivity.getMapActions().stopNavigationActionConfirm(null, new Runnable() { @Override public void run() { MapActivity mapActivity = getMapActivity(); @@ -1149,7 +1157,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void onChangeApplicationMode(ApplicationMode mode, RouteBetweenPointsDialogType dialogType, - RouteBetweenPointsDialogMode dialogMode) { + RouteBetweenPointsDialogMode dialogMode) { MeasurementToolLayer measurementLayer = getMeasurementLayer(); if (measurementLayer != null) { ChangeRouteType changeRouteType = ChangeRouteType.NEXT_SEGMENT; @@ -1951,7 +1959,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route } public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx, - boolean followTrackMode) { + boolean followTrackMode) { MeasurementToolFragment fragment = new MeasurementToolFragment(); fragment.setEditingCtx(editingCtx); fragment.setMode(FOLLOW_TRACK_MODE, followTrackMode);