[iOS] Api preparation

This commit is contained in:
Kirill Zhdanovich 2013-05-28 16:02:36 +03:00 committed by Alex Zolotarev
parent 4210eae75c
commit 6785171944
4 changed files with 69 additions and 3 deletions

View file

@ -26,6 +26,7 @@
- (void)viewWillAppear:(BOOL)animated
{
m_hideNavBar = YES;
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
[self.navigationController setNavigationBarHidden:NO animated:YES];
// Update the table - we can display it after changing set or color
[self.tableView reloadData];
@ -49,7 +50,12 @@
- (void)viewWillDisappear:(BOOL)animated
{
if (m_hideNavBar)
[self.navigationController setNavigationBarHidden:YES animated:YES];
{
if (![[MapsAppDelegate theApp].m_mapViewController shouldShowNavBar])
[self.navigationController setNavigationBarHidden:YES animated:YES];
else
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
}
// Handle 3 scenarios:
// 1. User pressed Remove Pin and goes back to the map - bookmark was deleted on click, do nothing
// 2. User goes back to the map by pressing Map (Back) button - save possibly edited title, add bookmark

View file

@ -44,7 +44,10 @@
- (void)showBalloonWithText:(NSString *)text andGlobalPoint:(m2::PointD) point;
- (void)dismissPopoverAndSaveBookmark:(BOOL)save;
- (void)prepareForApi;
- (BOOL)shouldShowNavBar;
@property (nonatomic, retain) IBOutlet UIButton * m_myPositionButton;
@property (nonatomic, assign) BOOL isApiMode;
@end

View file

@ -444,6 +444,8 @@ const long long LITE_IDL = 431183278L;
if (!f.LoadState())
f.SetMaxWorldRect();
_isApiMode = NO;
f.Invalidate();
}
@ -894,4 +896,44 @@ NSInteger compareAddress(id l, id r, void * context)
[popover presentPopoverFromRect:CGRectMake(pt.x, pt.y, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
- (void)prepareForApi
{
_isApiMode = YES;
if ([self shouldShowNavBar])
{
self.navigationController.navigationBarHidden = NO;
UIBarButtonItem * closeButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"back", nil) style: UIBarButtonItemStyleDone target:self action:@selector(returnToApiApp)] autorelease];
self.navigationItem.leftBarButtonItem = closeButton;
// UIBarButtonItem * hide = [[[UIBarButtonItem alloc] initWithTitle:@"hide" style: UIBarButtonItemStyleDone target:self action:@selector(onHideClicked)] autorelease];
// self.navigationItem.rightBarButtonItem = hide;
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
self.navigationItem.title = [NSString stringWithUTF8String:GetFramework().GetMapApiAppTitle().c_str()];
}
}
- (void) clearApiBar
{
self.navigationController.navigationBarHidden = YES;
_isApiMode = NO;
self.navigationController.navigationItem.title = @"";
GetFramework().ClearMapApiPoints();
[self Invalidate];
}
-(void)returnToApiApp
{
NSString * backUrl = [NSString stringWithUTF8String:GetFramework().GetMapApiBackUrl().c_str()];
[self clearApiBar];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:backUrl]];
}
-(BOOL) shouldShowNavBar
{
Framework & f = GetFramework();
NSString * backUrl = [NSString stringWithUTF8String:f.GetMapApiBackUrl().c_str()];
return (_isApiMode && [backUrl length] && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:backUrl]]);
}
@end

View file

@ -190,6 +190,17 @@ void InitLocalizedStrings()
return YES;
}
}
if ([scheme isEqualToString:@"mapswithme"])
{
url_api::Request request;
if (GetFramework().SetViewportByURL([[url.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] UTF8String], request));
{
[self showMap];
[m_mapViewController prepareForApi];
return YES;
}
}
if ([scheme isEqualToString:@"file"])
{
if (!GetFramework().AddBookmarksFile([[url relativePath] UTF8String]))
@ -231,14 +242,18 @@ void InitLocalizedStrings()
m_loadingAlertView = nil;
}
-(void) showParsedBookmarkOnMap:(url_api::Request) request
-(void)showMap
{
[m_navController popToRootViewControllerAnimated:YES];
if (![m_navController.visibleViewController isMemberOfClass:NSClassFromString(@"MapViewController")])
[m_mapViewController dismissModalViewControllerAnimated:YES];
[m_mapViewController dismissPopoverAndSaveBookmark:YES];
m_navController.navigationBarHidden = YES;
}
-(void) showParsedBookmarkOnMap:(url_api::Request) request
{
[self showMap];
m2::PointD point(MercatorBounds::LonToX(request.m_viewportLon),
MercatorBounds::LatToY(request.m_viewportLat));