forked from organicmaps/organicmaps
[android] Added stub uber error processing on Java side
This commit is contained in:
parent
52890356c8
commit
6b435fdf47
5 changed files with 70 additions and 21 deletions
|
@ -28,6 +28,7 @@ import com.mapswithme.maps.api.ParsedMwmRequest;
|
|||
import com.mapswithme.maps.api.ParsedRoutingData;
|
||||
import com.mapswithme.maps.api.ParsedUrlMwmRequest;
|
||||
import com.mapswithme.maps.api.RoutePoint;
|
||||
import com.mapswithme.maps.uber.Uber;
|
||||
import com.mapswithme.maps.uber.UberInfo;
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
import com.mapswithme.maps.base.OnBackPressListener;
|
||||
|
@ -1343,7 +1344,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
final RoutingController controller = RoutingController.get();
|
||||
|
||||
if (controller.isBuilt() || controller.isUberInfoObtained())
|
||||
if (controller.isBuilt() || controller.isUberRequestHandled())
|
||||
{
|
||||
mMainMenu.showLineFrame(true);
|
||||
return;
|
||||
|
@ -1444,6 +1445,21 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUberError(@NonNull Uber.ErrorCode code)
|
||||
{
|
||||
if (mIsFragmentContainer)
|
||||
{
|
||||
RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class);
|
||||
if (fragment != null)
|
||||
fragment.showUberError(code);
|
||||
}
|
||||
else
|
||||
{
|
||||
mRoutingPlanInplaceController.showUberError(code);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isFirstStart()
|
||||
{
|
||||
boolean res = mFirstStart;
|
||||
|
|
|
@ -67,6 +67,7 @@ public class RoutingController
|
|||
void updateMenu();
|
||||
void updatePoints();
|
||||
void onUberInfoReceived(@NonNull UberInfo info);
|
||||
void onUberError(@NonNull Uber.ErrorCode code);
|
||||
|
||||
/**
|
||||
* @param progress progress to be displayed.
|
||||
|
@ -98,7 +99,7 @@ public class RoutingController
|
|||
private String[] mLastMissingMaps;
|
||||
@Nullable
|
||||
private RoutingInfo mCachedRoutingInfo;
|
||||
private boolean mUberInfoObtained;
|
||||
private boolean mUberRequestHandled;
|
||||
private boolean mUberPlanning;
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
|
@ -263,7 +264,7 @@ public class RoutingController
|
|||
private void build()
|
||||
{
|
||||
mLogger.d("build");
|
||||
mUberInfoObtained = false;
|
||||
mUberRequestHandled = false;
|
||||
mLastBuildProgress = 0;
|
||||
setBuildState(BuildState.BUILDING);
|
||||
updatePlan();
|
||||
|
@ -513,9 +514,9 @@ public class RoutingController
|
|||
return (mWaitingPoiPickSlot != NO_SLOT);
|
||||
}
|
||||
|
||||
public boolean isUberInfoObtained()
|
||||
public boolean isUberRequestHandled()
|
||||
{
|
||||
return mUberInfoObtained;
|
||||
return mUberRequestHandled;
|
||||
}
|
||||
|
||||
BuildState getBuildState()
|
||||
|
@ -803,7 +804,7 @@ public class RoutingController
|
|||
if (mLastRouterType == Framework.ROUTER_TYPE_TAXI && mContainer != null)
|
||||
{
|
||||
mContainer.onUberInfoReceived(info);
|
||||
mUberInfoObtained = true;
|
||||
mUberRequestHandled = true;
|
||||
mContainer.updateBuildProgress(100, mLastRouterType);
|
||||
mContainer.updateMenu();
|
||||
}
|
||||
|
@ -816,6 +817,15 @@ public class RoutingController
|
|||
@MainThread
|
||||
private void onUberError(@NonNull String errorCode)
|
||||
{
|
||||
mLogger.e("onUberError error = " + Uber.ErrorCode.valueOf(errorCode));
|
||||
mUberPlanning = false;
|
||||
Uber.ErrorCode code = Uber.ErrorCode.valueOf(errorCode);
|
||||
mLogger.e("onUberError error = " + code);
|
||||
if (mLastRouterType == Framework.ROUTER_TYPE_TAXI && mContainer != null)
|
||||
{
|
||||
mContainer.onUberError(code);
|
||||
mUberRequestHandled = true;
|
||||
mContainer.updateBuildProgress(100, mLastRouterType);
|
||||
mContainer.updateMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,13 @@ import android.widget.ImageView;
|
|||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.uber.Uber;
|
||||
import com.mapswithme.maps.uber.UberAdapter;
|
||||
import com.mapswithme.maps.uber.UberInfo;
|
||||
import com.mapswithme.maps.uber.UberLinks;
|
||||
|
@ -31,6 +33,7 @@ import com.mapswithme.maps.widget.DotPager;
|
|||
import com.mapswithme.maps.widget.RotateDrawable;
|
||||
import com.mapswithme.maps.widget.ToolbarController;
|
||||
import com.mapswithme.maps.widget.WheelProgressView;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
import com.mapswithme.util.Graphics;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
@ -134,6 +137,12 @@ public class RoutingPlanController extends ToolbarController
|
|||
{
|
||||
AlohaHelper.logClick(AlohaHelper.ROUTING_TAXI_SET);
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.ROUTING_TAXI_SET);
|
||||
if (!ConnectionState.isConnected())
|
||||
{
|
||||
//TODO: show uber error about offline mode showUberError(R.id.no_internet_connection);
|
||||
Toast.makeText(mActivity, "Заказ такси недоступен в оффлайн-режиме", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
RoutingController.get().setRouterType(Framework.ROUTER_TYPE_TAXI);
|
||||
}
|
||||
});
|
||||
|
@ -280,7 +289,7 @@ public class RoutingPlanController extends ToolbarController
|
|||
|
||||
updateProgressLabels();
|
||||
|
||||
if (!RoutingController.get().isBuilding() || RoutingController.get().isUberInfoObtained())
|
||||
if (!RoutingController.get().isBuilding() || RoutingController.get().isUberRequestHandled())
|
||||
return;
|
||||
|
||||
UiUtils.show(progressView);
|
||||
|
@ -386,15 +395,10 @@ public class RoutingPlanController extends ToolbarController
|
|||
|
||||
public void showUberInfo(@NonNull UberInfo info)
|
||||
{
|
||||
final UberInfo.Product[] products = info.getProducts();
|
||||
if (products == null || products.length == 0)
|
||||
{
|
||||
UiUtils.hide(mUberFrame);
|
||||
showError(R.string.taxi_not_found);
|
||||
return;
|
||||
}
|
||||
|
||||
UiUtils.hide(getViewById(R.id.error));
|
||||
UiUtils.hide(mAltitudeChartFrame);
|
||||
|
||||
final UberInfo.Product[] products = info.getProducts();
|
||||
mUberInfo = info;
|
||||
mUberProduct = products[0];
|
||||
final PagerAdapter adapter = new UberAdapter(mActivity, products);
|
||||
|
@ -411,11 +415,24 @@ public class RoutingPlanController extends ToolbarController
|
|||
pager.show();
|
||||
|
||||
setStartButton();
|
||||
|
||||
UiUtils.hide(mAltitudeChartFrame);
|
||||
UiUtils.show(mUberFrame);
|
||||
}
|
||||
|
||||
public void showUberError(@NonNull Uber.ErrorCode code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case NoProducts:
|
||||
showError(R.string.taxi_not_found);
|
||||
break;
|
||||
case RemoteError:
|
||||
//TODO:showError(R.string.remote_error);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Unsupported uber error: " + code);
|
||||
}
|
||||
}
|
||||
|
||||
private void showError(@StringRes int message)
|
||||
{
|
||||
TextView error = (TextView) getViewById(R.id.error);
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.view.ViewGroup;
|
|||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.uber.Uber;
|
||||
import com.mapswithme.maps.uber.UberInfo;
|
||||
import com.mapswithme.maps.base.BaseMwmFragment;
|
||||
import com.mapswithme.maps.base.OnBackPressListener;
|
||||
|
@ -55,6 +56,11 @@ public class RoutingPlanFragment extends BaseMwmFragment
|
|||
mPlanController.showUberInfo(info);
|
||||
}
|
||||
|
||||
public void showUberError(@NonNull Uber.ErrorCode code)
|
||||
{
|
||||
mPlanController.showUberError(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed()
|
||||
{
|
||||
|
|
|
@ -24,10 +24,10 @@ public class UberInfo implements Parcelable
|
|||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
private final Product[] mProducts;
|
||||
|
||||
private UberInfo(@Nullable Product[] products)
|
||||
private UberInfo(@NonNull Product[] products)
|
||||
{
|
||||
mProducts = products;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class UberInfo implements Parcelable
|
|||
mProducts = (Product[]) parcel.readParcelableArray(Product.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
public Product[] getProducts()
|
||||
{
|
||||
return mProducts;
|
||||
|
|
Loading…
Add table
Reference in a new issue