diff --git a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java index 2d46b63fd1..63d82ecc26 100644 --- a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java +++ b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java @@ -556,6 +556,22 @@ public class TargetPointsHelper { updateRouteAndRefresh(updateRoute); } + public void reorderIntermediatePoints(List points, boolean updateRoute) { + cancelAllIntermediatePointsAddressRequests(); + if (points.size() > 0) { + ArrayList names = new ArrayList<>(points.size()); + ArrayList ls = new ArrayList<>(points.size()); + for (int i = 0; i < points.size(); i++) { + names.add(PointDescription.serializeToString(points.get(i).pointDescription)); + ls.add(points.get(i).point); + } + settings.saveIntermediatePoints(ls, names); + } else { + settings.clearIntermediatePoints(); + } + readFromSettings(); + updateRouteAndRefresh(updateRoute); + } public boolean hasTooLongDistanceToNavigate() { if (routingHelper.getAppMode().getRouteService() != RouteService.OSMAND) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index 8d0d8210c1..91440912d2 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -242,43 +242,45 @@ public class WaypointDialogHelper { } } - // switch start & finish - public static void switchStartAndFinish(TargetPointsHelper targetPointsHelper, TargetPoint finish, - Activity ctx, TargetPoint start, OsmandApplication app, - WaypointDialogHelper helper) { + public static void switchStartAndFinish(OsmandApplication app, Activity ctx, WaypointDialogHelper helper, boolean updateRoute) { + TargetPointsHelper targetsHelper = app.getTargetPointsHelper(); + TargetPoint finish = targetsHelper.getPointToNavigate(); + TargetPoint start = targetsHelper.getPointToStart(); if (finish == null) { app.showShortToastMessage(R.string.mark_final_location_first); } else { - targetPointsHelper.setStartPoint(new LatLon(finish.getLatitude(), - finish.getLongitude()), false, finish.getPointDescription(ctx)); - if (start == null) { - Location loc = app.getLocationProvider().getLastKnownLocation(); - if (loc != null) { - targetPointsHelper.navigateToPoint(new LatLon(loc.getLatitude(), - loc.getLongitude()), true, -1); - } - } else { - targetPointsHelper.navigateToPoint(new LatLon(start.getLatitude(), - start.getLongitude()), true, -1, start.getPointDescription(ctx)); - } + switchStartAndFinish(app, start, finish, updateRoute); updateControls(ctx, helper); } } - public static void reverseAllPoints(OsmandApplication app, Activity ctx, - WaypointDialogHelper helper) { - TargetPointsHelper targets = app.getTargetPointsHelper(); - if (!targets.getAllPoints().isEmpty()) { - List points = targets.getAllPoints(); - Collections.reverse(points); - TargetPoint start = points.get(0); - targets.setStartPoint(start.point, false, start.getOriginalPointDescription()); - points.remove(start); - targets.reorderAllTargetPoints(points, true); - updateControls(ctx, helper); + private static void switchStartAndFinish(OsmandApplication app, TargetPoint start, TargetPoint finish, boolean updateRoute) { + TargetPointsHelper targetsHelper = app.getTargetPointsHelper(); + targetsHelper.setStartPoint(new LatLon(finish.getLatitude(), finish.getLongitude()), + false, finish.getPointDescription(app)); + if (start == null) { + Location loc = app.getLocationProvider().getLastKnownLocation(); + if (loc != null) { + targetsHelper.navigateToPoint(new LatLon(loc.getLatitude(), + loc.getLongitude()), updateRoute, -1); + } + } else { + targetsHelper.navigateToPoint(new LatLon(start.getLatitude(), + start.getLongitude()), updateRoute, -1, start.getPointDescription(app)); } } + public static void reverseAllPoints(OsmandApplication app, Activity ctx, WaypointDialogHelper helper) { + TargetPointsHelper targetsHelper = app.getTargetPointsHelper(); + TargetPoint finish = targetsHelper.getPointToNavigate(); + TargetPoint start = targetsHelper.getPointToStart(); + switchStartAndFinish(app, start, finish, false); + List points = targetsHelper.getIntermediatePoints(); + Collections.reverse(points); + targetsHelper.reorderIntermediatePoints(points, true); + updateControls(ctx, helper); + } + public static void updateControls(Activity ctx, WaypointDialogHelper helper) { if (helper != null && helper.helperCallbacks != null) { for (WaypointDialogHelperCallback callback : helper.helperCallbacks) { @@ -492,15 +494,7 @@ public class WaypointDialogHelper { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { OsmandApplication app = mapActivity.getMyApplication(); - TargetPointsHelper targetsHelper = app.getTargetPointsHelper(); - WaypointDialogHelper.switchStartAndFinish( - targetsHelper, - targetsHelper.getPointToNavigate(), - mapActivity, - targetsHelper.getPointToStart(), - app, - mapActivity.getDashboard().getWaypointDialogHelper() - ); + switchStartAndFinish(app, mapActivity, mapActivity.getDashboard().getWaypointDialogHelper(), true); } dismiss(); } @@ -528,7 +522,7 @@ public class WaypointDialogHelper { }) .create(); int intermediateSize = targetsHelper.getIntermediatePoints().size(); - if (intermediateSize > 2) { + if (intermediateSize > 1) { items.add(reorderAllItems); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java index 7c70ba8dfb..22016f6c9b 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AddPointBottomSheetDialog.java @@ -27,8 +27,6 @@ import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.FavouritesDbHelper; -import net.osmand.plus.mapmarkers.MapMarkersHelper; -import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -46,6 +44,8 @@ import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.MapMarkerDialogHelper; import net.osmand.plus.helpers.WaypointDialogHelper; import net.osmand.plus.mapcontextmenu.other.FavouritesBottomSheetMenuFragment; +import net.osmand.plus.mapmarkers.MapMarker; +import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType; import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.widgets.style.CustomTypefaceSpan; @@ -348,9 +348,8 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment { mapActivity.getMyApplication().showShortToastMessage(R.string.route_add_start_point); return; } - WaypointDialogHelper.switchStartAndFinish(targetsHelper, targetsHelper.getPointToNavigate(), - mapActivity, targetsHelper.getPointToStart(), mapActivity.getMyApplication(), - mapActivity.getDashboard().getWaypointDialogHelper()); + WaypointDialogHelper.switchStartAndFinish(mapActivity.getMyApplication(), mapActivity, + mapActivity.getDashboard().getWaypointDialogHelper(), true); } dismiss(); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 9903d1e77d..a6b69ba124 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -65,6 +65,7 @@ import net.osmand.plus.base.ContextMenuFragment.MenuState; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.GpxUiHelper; +import net.osmand.plus.helpers.WaypointDialogHelper; import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment; import net.osmand.plus.mapmarkers.MapMarker; @@ -1853,9 +1854,13 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActivity.getString(R.string.shared_string_my_location))); } if (startPoint != null) { - targetPointsHelper.navigateToPoint(startPoint.point, false, -1, startPoint.getPointDescription(mapActivity)); - targetPointsHelper.setStartPoint(endPoint.point, false, endPoint.getPointDescription(mapActivity)); - targetPointsHelper.updateRouteAndRefresh(true); + int intermediateSize = targetPointsHelper.getIntermediatePoints().size(); + if (intermediateSize > 1) { + WaypointDialogHelper.reverseAllPoints(app, mapActivity, mapActivity.getDashboard().getWaypointDialogHelper()); + } else { + WaypointDialogHelper.switchStartAndFinish(mapActivity.getMyApplication(), + mapActivity, mapActivity.getDashboard().getWaypointDialogHelper(), true); + } } else { app.showShortToastMessage(R.string.route_add_start_point); }