Save snapped points and mode in markers helper

This commit is contained in:
Alexander Sytnyk 2017-10-05 13:03:51 +03:00
parent 7c362fd4f1
commit 783b0f64b2
2 changed files with 21 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.Pair;
import net.osmand.IndexConstants;
import net.osmand.data.FavouritePoint;
@ -27,6 +28,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
@ -42,6 +44,9 @@ public class MapMarkersHelper {
private MapMarkersDbHelper markersDbHelper;
private boolean startFromMyLocation;
private final Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints = new ConcurrentHashMap<>();
private ApplicationMode snappedMode;
public interface MapMarkerChangedListener {
void onMapMarkerChanged(MapMarker mapMarker);
@ -231,6 +236,18 @@ public class MapMarkersHelper {
createMapMarkersGroups();
}
public Map<Pair<WptPt, WptPt>, List<WptPt>> getSnappedToRoadPoints() {
return snappedToRoadPoints;
}
public ApplicationMode getSnappedMode() {
return snappedMode;
}
public void setSnappedMode(ApplicationMode snappedMode) {
this.snappedMode = snappedMode;
}
public boolean isStartFromMyLocation() {
return startFromMyLocation;
}

View file

@ -63,7 +63,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
@ -96,7 +95,7 @@ public class PlanRouteFragment extends Fragment {
private TextView countTv;
private final Queue<Pair<WptPt, WptPt>> snapToRoadPairsToCalculate = new ConcurrentLinkedQueue<>();
private final Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints = new ConcurrentHashMap<>();
private Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints;
private TrkSegment snapTrkSegment = new TrkSegment();
private RouteCalculationProgress calculationProgress;
private int calculatedPairs;
@ -107,6 +106,7 @@ public class PlanRouteFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final MapActivity mapActivity = getMapActivity();
markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
snappedToRoadPoints = markersHelper.getSnappedToRoadPoints();
// Handling screen rotation
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
@ -363,6 +363,7 @@ public class PlanRouteFragment extends Fragment {
if (appMode != null && !appMode.getStringKey().equals(mode.getStringKey())) {
appMode = mode;
snappedToRoadPoints.clear();
markersHelper.setSnappedMode(mode);
recreateSnapTrkSegment();
setupAppModesBtn();
}
@ -426,7 +427,7 @@ public class PlanRouteFragment extends Fragment {
wasCollapseButtonVisible = false;
}
if (appMode == null) {
if ((appMode = markersHelper.getSnappedMode()) == null) {
appMode = ApplicationMode.DEFAULT;
}
setupAppModesBtn();