Merge pull request #4561 from VladiMihaylenko/master

[ios] Uber's error handling
This commit is contained in:
Илья Гречухин 2016-10-26 15:53:26 +03:00 committed by GitHub
commit 62129140e1
16 changed files with 68 additions and 23 deletions

View file

@ -691,7 +691,6 @@ CGFloat constexpr kTimeWidthRegular = 128;
self.progressView.hidden = YES;
self.routingView.hidden = NO;
self.routingAdditionalView.hidden = YES;
self.estimateLabel.text = [MWMRouter isTaxi] ? L(@"taxi_not_found") : L(@"routing_planning_error");
break;
case MWMBottomMenuStateRouting:
self.menuButton.hidden = NO;

View file

@ -28,5 +28,6 @@
- (void)mwm_refreshUI;
- (void)refreshLayout;
- (MWMTaxiCollectionView *)taxiCollectionView;
- (void)setRoutingErrorMessage:(NSString *)routingErrorMessage;
@end

View file

@ -71,6 +71,8 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) {
@property(weak, nonatomic) MWMNavigationDashboardEntity * navigationInfo;
@property(copy, nonatomic) NSString * routingErrorMessage;
@property(weak, nonatomic) IBOutlet UILabel * speedLabel;
@property(weak, nonatomic) IBOutlet UILabel * timeLabel;
@property(weak, nonatomic) IBOutlet UILabel * distanceLabel;
@ -140,6 +142,9 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) {
- (void)updateNavigationInfo:(MWMNavigationDashboardEntity *)info
{
if ([MWMRouter isTaxi])
return;
NSDictionary * routingNumberAttributes = @{
NSForegroundColorAttributeName : [UIColor blackPrimaryText],
NSFontAttributeName : [UIFont bold24]
@ -532,6 +537,9 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) {
self.restoreState = state;
else
view.state = state;
if (state == MWMBottomMenuStateRoutingError)
self.estimateLabel.text = self.routingErrorMessage;
}
- (MWMBottomMenuState)state { return ((MWMBottomMenuView *)self.view).state; }

View file

@ -510,6 +510,11 @@ extern NSString * const kAlohalyticsTapEventKey;
self.menuController.state = self.hidden ? MWMBottomMenuStateHidden : menuState;
}
- (void)setRoutingErrorMessage:(NSString *)message
{
[self.menuController setRoutingErrorMessage:message];
}
- (MWMBottomMenuState)menuState
{
MWMBottomMenuState const state = self.menuController.state;

View file

@ -24,6 +24,7 @@ typedef NS_ENUM(NSUInteger, MWMNavigationDashboardState) {
- (void)didStartEditingRoutePoint:(BOOL)isSource;
- (void)setMenuState:(MWMBottomMenuState)menuState;
- (void)setMenuRestoreState:(MWMBottomMenuState)menuState;
- (void)setRoutingErrorMessage:(NSString *)errorMessage;
- (MWMTaxiCollectionView *)taxiCollectionView;
@end

View file

@ -13,6 +13,8 @@
#import "MapsAppDelegate.h"
#import "Statistics.h"
#include "platform/platform.hpp"
namespace
{
NSString * const kRoutePreviewXibName = @"MWMRoutePreview";
@ -155,22 +157,33 @@ using TInfoDisplays = NSHashTable<__kindof TInfoDisplay>;
if (![MWMRouter isTaxi])
return;
auto showError = ^(NSString * errorMessage)
{
[self.routePreview stateError];
[self.routePreview router:routing::RouterType::Taxi setState:MWMCircularProgressStateFailed];
[self setMenuErrorStateWithErrorMessage:errorMessage];
};
auto r = [MWMRouter router];
auto const & start = r.startPoint;
auto const & finish = r.finishPoint;
if (start.IsValid() && finish.IsValid())
{
if (!Platform::IsConnected())
{
[[MapViewController controller].alertController presentNoConnectionAlert];
showError(L(@"dialog_taxi_offline"));
return;
}
[self.taxiDataSource requestTaxiFrom:start to:finish completion:^
{
[self setMenuState:MWMBottomMenuStateGo];
[self.routePreview stateReady];
[self setRouteBuilderProgress:100.];
}
failure:^
failure:^(NSString * errorMessage)
{
[self.routePreview stateError];
[self.routePreview router:routing::RouterType::Taxi setState:MWMCircularProgressStateFailed];
[self setMenuState:MWMBottomMenuStateRoutingError];
showError(errorMessage);
}];
}
}
@ -200,6 +213,12 @@ using TInfoDisplays = NSHashTable<__kindof TInfoDisplay>;
[startButton setTitle:t forState:UIControlStateDisabled];
}
- (void)setMenuErrorStateWithErrorMessage:(NSString *)message
{
[self.delegate setRoutingErrorMessage:message];
[self setMenuState:MWMBottomMenuStateRoutingError];
}
- (void)setMenuState:(MWMBottomMenuState)menuState
{
id<MWMNavigationDashboardManagerProtocol> delegate = self.delegate;

View file

@ -14,7 +14,7 @@ class MWMRoutePoint;
- (void)requestTaxiFrom:(MWMRoutePoint const &)from
to:(MWMRoutePoint const &)to
completion:(TMWMVoidBlock)completion
failure:(TMWMVoidBlock)failure;
failure:(MWMStringBlock)failure;
- (NSURL *)taxiURL;

View file

@ -89,7 +89,7 @@ using namespace uber;
- (void)requestTaxiFrom:(MWMRoutePoint const &)from
to:(MWMRoutePoint const &)to
completion:(TMWMVoidBlock)completion
failure:(TMWMVoidBlock)failure
failure:(MWMStringBlock)failure
{
NSAssert(completion && failure, @"Completion and failure blocks must be not nil!");
m_products.clear();
@ -98,23 +98,15 @@ using namespace uber;
auto cv = self.collectionView;
cv.hidden = YES;
cv.pageControl.hidden = YES;
auto const errorCallback = [](uber::ErrorCode const code, uint64_t const requestId) {};
m_requestId = m_api.GetAvailableProducts(m_from, m_to, [self, completion, failure](vector<Product> const & products,
m_requestId = m_api.GetAvailableProducts(m_from, m_to, [self, completion](vector<Product> const & products,
uint64_t const requestId)
{
dispatch_async(dispatch_get_main_queue(), [products, requestId, self, completion, failure]
dispatch_async(dispatch_get_main_queue(), [products, requestId, self, completion]
{
if (self->m_requestId != requestId)
return;
if (products.empty())
{
failure();
return;
}
self->m_products = products;
auto cv = self.collectionView;
cv.hidden = NO;
@ -125,7 +117,25 @@ using namespace uber;
cv.currentPage = 0;
completion();
});
}, errorCallback);
},
[self, failure](uber::ErrorCode const code, uint64_t const requestId)
{
dispatch_async(dispatch_get_main_queue(), ^
{
if (self->m_requestId != requestId)
return;
switch (code)
{
case uber::ErrorCode::NoProducts:
failure(L(@"taxi_not_found"));
break;
case uber::ErrorCode::RemoteError:
failure(L(@"dialog_taxi_error"));
break;
}
});
});
}
- (BOOL)isTaxiInstalled

View file

@ -374,7 +374,9 @@ bool isMarkerPoint(MWMRoutePoint const & point) { return point.IsValid() && !poi
else
[[MWMMapViewControlsManager manager] onRouteReady];
[self updateFollowingInfo];
[[MWMNavigationDashboardManager manager] setRouteBuilderProgress:100];
if (![MWMRouter isTaxi])
[[MWMNavigationDashboardManager manager] setRouteBuilderProgress:100];
[MWMMapViewControlsManager manager].searchHidden = YES;
break;
}

View file

@ -2,17 +2,17 @@
"images" : [
{
"idiom" : "universal",
"filename" : "ic_route_type_taxi.png",
"filename" : "ic_taxi.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_route_type_taxi@2x.png",
"filename" : "ic_taxi@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_route_type_taxi@3x.png",
"filename" : "ic_taxi@3x.png",
"scale" : "3x"
}
],

Binary file not shown.

Before

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B