From 78043d1d134ac121a0c3c11d181ba62bb2028a90 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Tue, 10 Oct 2017 14:24:03 +0300 Subject: [PATCH] Add navigate logic --- .../plus/mapmarkers/PlanRouteFragment.java | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index ae1748118a..44a0cc1f82 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -41,6 +41,8 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.TargetPointsHelper; +import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener; @@ -48,6 +50,7 @@ import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback; import net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter; import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment; import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment.SnapToRoadFragmentListener; +import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.MapMarkersLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; @@ -380,7 +383,35 @@ public class PlanRouteFragment extends Fragment { @Override public void navigateOnClick() { if (mapActivity != null) { - Toast.makeText(mapActivity, "navigate", Toast.LENGTH_SHORT).show(); + boolean hasTargets = false; + TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper(); + List markers = markersHelper.getSelectedMarkers(); + if (markers.size() > 0) { + int i = 0; + if (markersHelper.isStartFromMyLocation()) { + targetPointsHelper.clearStartPoint(false); + } else { + MapMarker m = markers.get(i++); + targetPointsHelper.setStartPoint(new LatLon(m.getLatitude(), m.getLongitude()), + false, m.getPointDescription(mapActivity)); + } + List targetPoints = new ArrayList<>(); + for (int k = i; k < markers.size(); k++) { + MapMarker m = markers.get(k); + TargetPoint t = new TargetPoint(new LatLon(m.getLatitude(), m.getLongitude()), + m.getPointDescription(mapActivity)); + targetPoints.add(t); + } + RoutingHelper routingHelper = mapActivity.getRoutingHelper(); + boolean updateRoute = routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode(); + targetPointsHelper.reorderAllTargetPoints(targetPoints, updateRoute); + hasTargets = true; + } else { + targetPointsHelper.clearStartPoint(false); + targetPointsHelper.clearPointToNavigate(false); + } + dismiss(); + mapActivity.getMapLayers().getMapControlsLayer().doRoute(hasTargets); } } @@ -682,14 +713,17 @@ public class PlanRouteFragment extends Fragment { showHideMarkersList(); return false; } else { - dismiss(getMapActivity()); + dismiss(); return true; } } - private void dismiss(MapActivity activity) { - planRouteContext.setFragmentVisible(false); - activity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss(); + private void dismiss() { + MapActivity activity = getMapActivity(); + if (activity != null) { + planRouteContext.setFragmentVisible(false); + activity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss(); + } } public static boolean showInstance(MapActivity mapActivity) {