Simplify the method

This commit is contained in:
Alexander Sytnyk 2017-10-02 17:00:23 +03:00
parent 83eb581760
commit 76fd7ef904

View file

@ -53,9 +53,7 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControll
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT; import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
@ -735,17 +733,9 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
@Override @Override
protected List<MapMarker> doInBackground(Void... voids) { protected List<MapMarker> doInBackground(Void... voids) {
List<MapMarker> selectedMarkers = mapActivity.getMyApplication().getMapMarkersHelper().getSelectedMarkers(); MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
List<LatLon> selectedLatLon = new ArrayList<>(selectedMarkers.size()); List<MapMarker> selectedMarkers = markersHelper.getSelectedMarkers();
LatLon[] keys = new LatLon[selectedMarkers.size()]; List<LatLon> selectedLatLon = markersHelper.getSelectedMarkersLatLon();
Map<LatLon, MapMarker> markersMap = new HashMap<>(selectedMarkers.size());
for (int i = 0; i < selectedMarkers.size(); i++) {
MapMarker m = selectedMarkers.get(i);
markersMap.put(m.point, m);
keys[i] = m.point;
selectedLatLon.add(m.point);
}
LatLon start = startFromLoc ? new LatLon(myLoc.getLatitude(), myLoc.getLongitude()) : selectedLatLon.remove(0); LatLon start = startFromLoc ? new LatLon(myLoc.getLatitude(), myLoc.getLongitude()) : selectedLatLon.remove(0);
LatLon end = selectedLatLon.remove(selectedLatLon.size() - 1); LatLon end = selectedLatLon.remove(selectedLatLon.size() - 1);
@ -758,7 +748,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
continue; continue;
} }
int index = sequence[startFromLoc ? i - 1 : i]; int index = sequence[startFromLoc ? i - 1 : i];
res.add(markersMap.get(keys[index])); res.add(selectedMarkers.get(index));
} }
return res; return res;