[android] Implemented add/remove stop points logic

This commit is contained in:
Александр Зацепин 2017-06-14 16:09:28 +03:00
parent cec685c635
commit 36b8700533
4 changed files with 78 additions and 36 deletions

View file

@ -1866,6 +1866,18 @@ public class MwmActivity extends BaseMwmFragmentActivity
ThemeSwitcher.restart(isMapRendererActive());
}
@Override
public void onAddedStop()
{
closePlacePage();
}
@Override
public void onRemovedStop()
{
closePlacePage();
}
private void updateSearchBar()
{
if (!TextUtils.isEmpty(SearchEngine.getQuery()))

View file

@ -10,9 +10,24 @@ import java.lang.annotation.RetentionPolicy;
public class RoutePointInfo implements Parcelable
{
public static final int ROUTE_MARK_START = 0;
public static final int ROUTE_MARK_INTERMEDIATE = 1;
public static final int ROUTE_MARK_FINISH = 2;
public static final Creator<RoutePointInfo> CREATOR = new Creator<RoutePointInfo>()
{
@Override
public RoutePointInfo createFromParcel(Parcel in)
{
return new RoutePointInfo(in);
}
@Override
public RoutePointInfo[] newArray(int size)
{
return new RoutePointInfo[size];
}
};
static final int ROUTE_MARK_START = 0;
static final int ROUTE_MARK_INTERMEDIATE = 1;
static final int ROUTE_MARK_FINISH = 2;
@Retention(RetentionPolicy.SOURCE)
@IntDef({ ROUTE_MARK_START, ROUTE_MARK_INTERMEDIATE, ROUTE_MARK_FINISH })
@ -35,20 +50,20 @@ public class RoutePointInfo implements Parcelable
this(in.readInt() /* mMarkType */, in.readInt() /* mIntermediateIndex */);
}
public static final Creator<RoutePointInfo> CREATOR = new Creator<RoutePointInfo>()
boolean isIntermediatePoint()
{
@Override
public RoutePointInfo createFromParcel(Parcel in)
{
return new RoutePointInfo(in);
}
return mMarkType == ROUTE_MARK_INTERMEDIATE;
}
@Override
public RoutePointInfo[] newArray(int size)
{
return new RoutePointInfo[size];
}
};
boolean isFinishPoint()
{
return mMarkType == ROUTE_MARK_FINISH;
}
boolean isStartPoint()
{
return mMarkType == ROUTE_MARK_START;
}
@Override
public int describeContents()

View file

@ -73,6 +73,8 @@ public class RoutingController
void onUberError(@NonNull Uber.ErrorCode code);
void onNavigationCancelled();
void onNavigationStarted();
void onAddedStop();
void onRemovedStop();
/**
* @param progress progress to be displayed.
@ -93,8 +95,6 @@ public class RoutingController
private MapObject mStartPoint;
@Nullable
private MapObject mEndPoint;
@Nullable
private MapObject mStopPoint;
private int mLastBuildProgress;
@Framework.RouterType
@ -279,7 +279,10 @@ public class RoutingController
RoutePoint[] routePoints = Framework.nativeGetRoutePoints();
if (routePoints.length < 2)
{
setBuildState(BuildState.NONE);
return;
}
mLogger.d(TAG, "build");
mUberRequestHandled = false;
@ -437,28 +440,45 @@ public class RoutingController
public void addStop(@NonNull MapObject mapObject)
{
mStopPoint = mapObject;
// TODO call api method
RoutePointInfo info = new RoutePointInfo(RoutePointInfo.ROUTE_MARK_INTERMEDIATE, 0);
Framework.nativeAddRoutePoint(mapObject.getLat(), mapObject.getLon(),
MapObject.isOfType(MapObject.MY_POSITION, mapObject), info);
build();
if (mContainer != null)
mContainer.onAddedStop();
}
public void removeStop()
public void removeStop(@NonNull MapObject mapObject)
{
mStopPoint = null;
// TODO call api method
RoutePointInfo info = mapObject.getRoutePointInfo();
if (info == null)
throw new AssertionError("A stop point must have the route point info!");
Framework.nativeRemoveRoutePoint(info);
if (info.isFinishPoint())
mEndPoint = null;
if (info.isStartPoint())
mStartPoint = null;
build();
if (mContainer != null)
mContainer.onRemovedStop();
}
public boolean hasStopPoint()
public boolean isStopPointAllowed()
{
return mStopPoint != null;
return Framework.nativeCouldAddIntermediatePoint();
}
public boolean isStopPoint(@NonNull MapObject mapObject)
public boolean isRoutePoint(@NonNull MapObject mapObject)
{
return mStopPoint != null && mStopPoint.equals(mapObject);
return mapObject.getRoutePointInfo() != null;
}
private void suggestRebuildRoute()
{
if (mContainer == null)
return;
final AlertDialog.Builder builder = new AlertDialog.Builder(mContainer.getActivity())
.setMessage(R.string.p2p_reroute_from_current)
.setCancelable(false)
@ -508,7 +528,6 @@ public class RoutingController
mStartPoint = null;
mEndPoint = null;
mStopPoint = null;
setPointsInternal();
mWaitingPoiPickSlot = NO_SLOT;
mUberRequestHandled = false;

View file

@ -523,17 +523,13 @@ public class PlacePageView extends RelativeLayout
break;
case ROUTE_ADD:
if (mMapObject != null
&& (RoutingController.get().isPlanning() || RoutingController.get().isNavigating()))
{
if (mMapObject != null)
RoutingController.get().addStop(mMapObject);
setMapObject(mMapObject, true, null);
}
break;
case ROUTE_REMOVE:
RoutingController.get().removeStop();
setMapObject(mMapObject, true, null);
if (mMapObject != null)
RoutingController.get().removeStop(mMapObject);
break;
case BOOKING:
@ -1402,7 +1398,7 @@ public class PlacePageView extends RelativeLayout
private void setButtons(@NonNull MapObject mapObject, boolean showBackButton, boolean showRoutingButton)
{
List<PlacePageButtons.Item> buttons = new ArrayList<>();
if (RoutingController.get().isStopPoint(mapObject))
if (RoutingController.get().isRoutePoint(mapObject))
{
buttons.add(PlacePageButtons.Item.ROUTE_REMOVE);
mButtons.setItems(buttons);
@ -1441,7 +1437,7 @@ public class PlacePageView extends RelativeLayout
{
buttons.add(PlacePageButtons.Item.ROUTE_FROM);
buttons.add(PlacePageButtons.Item.ROUTE_TO);
if (RoutingController.get().isBuilt() && !RoutingController.get().hasStopPoint())
if (RoutingController.get().isStopPointAllowed())
buttons.add(PlacePageButtons.Item.ROUTE_ADD);
}