diff --git a/iphone/Maps/Bookmarks/AddSetVC.h b/iphone/Maps/Bookmarks/AddSetVC.h index 3a71c9d4de..402d4e60c6 100644 --- a/iphone/Maps/Bookmarks/AddSetVC.h +++ b/iphone/Maps/Bookmarks/AddSetVC.h @@ -6,11 +6,8 @@ { // @TODO store as a property to retain reference BalloonView * m_balloon; - // Used to correctly display the most root view after pressing Save - // We don't use self.navigationController because it's another one :) - UINavigationController * m_rootNavigationController; } -- (id) initWithBalloonView:(BalloonView *)view andRootNavigationController:(UINavigationController *)navC; +- (id) initWithBalloonView:(BalloonView *)view; @end diff --git a/iphone/Maps/Bookmarks/AddSetVC.mm b/iphone/Maps/Bookmarks/AddSetVC.mm index aa5015e36b..bb1b8f4feb 100644 --- a/iphone/Maps/Bookmarks/AddSetVC.mm +++ b/iphone/Maps/Bookmarks/AddSetVC.mm @@ -6,13 +6,12 @@ @implementation AddSetVC -- (id) initWithBalloonView:(BalloonView *)view andRootNavigationController:(UINavigationController *)navC +- (id) initWithBalloonView:(BalloonView *)view { self = [super initWithStyle:UITableViewStyleGrouped]; if (self) { m_balloon = view; - m_rootNavigationController = navC; self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(onSaveClicked)] autorelease]; self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onCancelClicked)] autorelease]; @@ -23,7 +22,7 @@ - (void)onCancelClicked { - [self dismissModalViewControllerAnimated:YES]; + [self.navigationController popViewControllerAnimated:YES]; } - (void)onSaveClicked @@ -38,12 +37,13 @@ Framework &f = GetFramework(); size_t pos = f.AddCategory([text UTF8String]); [m_balloon addBookmarkToCategory:pos]; - - // Show Place Page dialog with new set selected - [self onCancelClicked]; - NSArray * vcs = m_rootNavigationController.viewControllers; - UITableViewController * addBookmarkVC = (UITableViewController *)[vcs objectAtIndex:[vcs count] - 2]; - [m_rootNavigationController popToViewController:addBookmarkVC animated:YES]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + [self.navigationController popToRootViewControllerAnimated:YES]; + else + { + UIViewController * t = [self.navigationController.viewControllers objectAtIndex:1]; + [self.navigationController popToViewController:t animated:YES]; + } } } diff --git a/iphone/Maps/Bookmarks/BalloonView.mm b/iphone/Maps/Bookmarks/BalloonView.mm index 6e383d3cdd..75417bb984 100644 --- a/iphone/Maps/Bookmarks/BalloonView.mm +++ b/iphone/Maps/Bookmarks/BalloonView.mm @@ -167,7 +167,6 @@ { if (isDisplayed) { - CGFloat const pinHeight = self.pinImage.bounds.size.height; CGFloat const w2 = m_titleView.bounds.size.width; CGFloat const h2 = m_titleView.bounds.size.height; @@ -184,7 +183,7 @@ { isDisplayed = NO; [m_titleView removeFromSuperview]; - editedBookmark = MakeEmptyBookmarkAndCategory(); + self.notes = nil; } } diff --git a/iphone/Maps/Bookmarks/EditDescriptionVC.mm b/iphone/Maps/Bookmarks/EditDescriptionVC.mm index 56703eb0bb..cc5bf0d3ef 100644 --- a/iphone/Maps/Bookmarks/EditDescriptionVC.mm +++ b/iphone/Maps/Bookmarks/EditDescriptionVC.mm @@ -33,11 +33,15 @@ tv.font = tmpCell.detailTextLabel.font; [tmpCell release]; self.view = tv; + [tv release]; } - (void)viewWillAppear:(BOOL)animated { - [self registerForKeyboardNotifications]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + self.contentSizeForViewInPopover = self.view.frame.size; + else + [self registerForKeyboardNotifications]; UITextView * tv = (UITextView *)self.view; tv.text = m_balloon.notes; [tv becomeFirstResponder]; @@ -48,22 +52,23 @@ UITextView * tv = (UITextView *)self.view; m_balloon.notes = tv.text.length ? tv.text : nil; [tv resignFirstResponder]; - [self unregisterKeyboardNotifications]; + if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) + [self unregisterKeyboardNotifications]; } - (void)registerForKeyboardNotifications { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(keyboardWasShown:) - name:UIKeyboardDidShowNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(keyboardWillBeHidden:) - name:UIKeyboardWillHideNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWasShown:) + name:UIKeyboardDidShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillBeHidden:) + name:UIKeyboardWillHideNotification object:nil]; } - (void)unregisterKeyboardNotifications { - [[NSNotificationCenter defaultCenter] removeObserver:self]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)keyboardWasShown:(NSNotification*)aNotification diff --git a/iphone/Maps/Bookmarks/PlacePageVC.mm b/iphone/Maps/Bookmarks/PlacePageVC.mm index 63e877815d..9b698d1733 100644 --- a/iphone/Maps/Bookmarks/PlacePageVC.mm +++ b/iphone/Maps/Bookmarks/PlacePageVC.mm @@ -4,6 +4,8 @@ #import "SelectColorVC.h" #import "EditDescriptionVC.h" #import "Statistics.h" +#import "MapsAppDelegate.h" +#import "MapViewController.h" #define TEXTFIELD_TAG 999 @@ -35,6 +37,12 @@ if ([m_balloon.title isEqualToString:NSLocalizedString(@"dropped_pin", nil)]) [[[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].contentView viewWithTag:TEXTFIELD_TAG] becomeFirstResponder]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + { + CGSize size = CGSizeMake(320, 480); + self.contentSizeForViewInPopover = size; + } + [super viewWillAppear:animated]; } @@ -50,14 +58,14 @@ { UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; UITextField * f = (UITextField *)[cell viewWithTag:TEXTFIELD_TAG]; - if (f.text.length) + if (f && f.text.length) m_balloon.title = f.text; // We're going back to the map - if ([self.navigationController.viewControllers indexOfObject:self] == NSNotFound) + if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad && [self.navigationController.viewControllers indexOfObject:self] == NSNotFound) { [m_balloon addOrEditBookmark]; - [m_balloon hide]; + m_balloon.editedBookmark = MakeEmptyBookmarkAndCategory(); } } [super viewWillDisappear:animated]; @@ -200,7 +208,7 @@ - (void)onRemoveClicked { [m_balloon deleteBookmark]; - [m_balloon hide]; + m_balloon.editedBookmark = MakeEmptyBookmarkAndCategory(); } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath @@ -215,7 +223,7 @@ { m_hideNavBar = NO; SelectSetVC * vc = [[SelectSetVC alloc] initWithBalloonView:m_balloon]; - [self.navigationController pushViewController:vc animated:YES]; + [self pushToNavigationControllerAndSetControllerToPopoverSize:vc]; [vc release]; } break; @@ -224,7 +232,7 @@ { m_hideNavBar = NO; SelectColorVC * vc = [[SelectColorVC alloc] initWithBalloonView:m_balloon]; - [self.navigationController pushViewController:vc animated:YES]; + [self pushToNavigationControllerAndSetControllerToPopoverSize:vc]; [vc release]; } break; @@ -234,7 +242,7 @@ { m_hideNavBar = NO; EditDescriptionVC * vc = [[EditDescriptionVC alloc] initWithBalloonView:m_balloon]; - [self.navigationController pushViewController:vc animated:YES]; + [self pushToNavigationControllerAndSetControllerToPopoverSize:vc]; [vc release]; } else if (indexPath.section == 2 && ([self canShare])) @@ -251,11 +259,15 @@ } else { - // Remove pin - [self onRemoveClicked]; m_removePinOnClose = YES; - // Close place page - [self.navigationController popViewControllerAnimated:YES]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + [[MapsAppDelegate theApp].m_mapViewController dismissPopoverAndSaveBookmark:NO]; + else + { + // Remove pin + [self onRemoveClicked]; + [self.navigationController popViewControllerAnimated:YES]; + } } } @@ -356,4 +368,11 @@ [name UTF8String])).c_str()]; } +-(void)pushToNavigationControllerAndSetControllerToPopoverSize:(UIViewController *)vc +{ + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + [vc setContentSizeForViewInPopover:[self contentSizeForViewInPopover]]; + [self.navigationController pushViewController:vc animated:YES]; +} + @end diff --git a/iphone/Maps/Bookmarks/SelectSetVC.mm b/iphone/Maps/Bookmarks/SelectSetVC.mm index d3dfa32c98..d54af4242a 100644 --- a/iphone/Maps/Bookmarks/SelectSetVC.mm +++ b/iphone/Maps/Bookmarks/SelectSetVC.mm @@ -67,11 +67,10 @@ [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; if (indexPath.section == 0) { - AddSetVC * asVC = [[AddSetVC alloc] initWithBalloonView:m_balloon andRootNavigationController:self.navigationController]; - // Use temporary navigation controller to display nav bar in modal view controller - UINavigationController * navC = [[UINavigationController alloc] initWithRootViewController:asVC]; - [self.navigationController presentModalViewController:navC animated:YES]; - [navC release]; + AddSetVC * asVC = [[AddSetVC alloc] initWithBalloonView:m_balloon]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + [asVC setContentSizeForViewInPopover:[self contentSizeForViewInPopover]]; + [self.navigationController pushViewController:asVC animated:YES]; [asVC release]; } else diff --git a/iphone/Maps/Classes/MapViewController.h b/iphone/Maps/Classes/MapViewController.h index 095aa955cc..55278f33ac 100644 --- a/iphone/Maps/Classes/MapViewController.h +++ b/iphone/Maps/Classes/MapViewController.h @@ -8,7 +8,7 @@ @class BalloonView; -@interface MapViewController : UIViewController +@interface MapViewController : UIViewController { enum Action { @@ -24,6 +24,7 @@ BalloonView * m_balloonView; /// Temporary solution to improve long touch detection. m2::PointD m_touchDownPoint; + UIPopoverController * popover; } - (void) SetupMeasurementSystem; @@ -42,6 +43,8 @@ - (void)showBalloonWithCategoryIndex:(int)index andBookmarkIndex:(int)bmIndex; - (void)showBalloonWithText:(NSString *)text andGlobalPoint:(m2::PointD) point; +- (void)dismissPopoverAndSaveBookmark:(BOOL)save; + @property (nonatomic, retain) IBOutlet UIButton * m_myPositionButton; @end diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 27ed8e7e7d..65825f0c89 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -103,6 +103,7 @@ const long long LITE_IDL = 431183278L; m_balloonView.globalPosition = CGPointMake(newCenter.x, newCenter.y); [m_balloonView updatePosition:self.view atPoint:[(EAGLView *)self.view globalPoint2ViewPoint:m_balloonView.globalPosition]]; } + [self showPopoverFromBalloonData]; } - (void) onCompassUpdate:(location::CompassInfo const &)info @@ -263,18 +264,45 @@ const long long LITE_IDL = 431183278L; } else { - Framework &f = GetFramework(); - int categoryPos = f.LastEditedCategory(); + Framework & f = GetFramework(); if (!IsValid(m_balloonView.editedBookmark)) { + int categoryPos = f.LastEditedCategory(); [m_balloonView addBookmarkToCategory:categoryPos]; } - PlacePageVC * placePageVC = [[PlacePageVC alloc] initWithBalloonView:m_balloonView]; - [self.navigationController pushViewController:placePageVC animated:YES]; + + PlacePageVC * placePageVC = nil; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + { + UINavigationController * navC = [[UINavigationController alloc] init]; + popover = [[UIPopoverController alloc] initWithContentViewController:navC]; + popover.delegate = self; + + placePageVC = [[PlacePageVC alloc] initWithBalloonView:m_balloonView]; + [navC pushViewController:placePageVC animated:YES]; + [navC release]; + + [popover setPopoverContentSize:CGSizeMake(320, 480)]; + [self showPopoverFromBalloonData]; + } + else + { + placePageVC = [[PlacePageVC alloc] initWithBalloonView:m_balloonView]; + [self.navigationController pushViewController:placePageVC animated:YES]; + } + [m_balloonView hide]; [placePageVC release]; } } +- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController +{ + [m_balloonView addOrEditBookmark]; + m_balloonView.editedBookmark = MakeEmptyBookmarkAndCategory(); + [self destroyPopover]; + [self Invalidate]; +} + - (void) updatePinTexts:(Framework::AddressInfo const &)info { NSString * res = [NSString stringWithUTF8String:info.m_name.c_str()]; @@ -307,6 +335,7 @@ const long long LITE_IDL = 431183278L; if (m_balloonView.isDisplayed) { [m_balloonView hide]; + m_balloonView.editedBookmark = MakeEmptyBookmarkAndCategory(); wasBalloonDisplayed = YES; // if (!isLongClick) // return; @@ -636,6 +665,7 @@ NSInteger compareAddress(id l, id r, void * context) - (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation { [[MapsAppDelegate theApp].m_locationManager setOrientation:self.interfaceOrientation]; + [self showPopoverFromBalloonData]; [self Invalidate]; } @@ -732,7 +762,8 @@ NSInteger compareAddress(id l, id r, void * context) - (void)showAppStoreRatingMenu { UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"App Store" - message:NSLocalizedString(@"appStore_message", nil) delegate:self + message:NSLocalizedString(@"appStore_message", nil) + delegate:self cancelButtonTitle:NSLocalizedString(@"no_thanks", nil) otherButtonTitles:NSLocalizedString(@"ok", nil), NSLocalizedString(@"remind_me_later", nil), nil]; alertView.tag = APPSTORE_ALERT_VIEW; @@ -824,10 +855,44 @@ NSInteger compareAddress(id l, id r, void * context) m_balloonView.title = text; m_balloonView.isCurrentPosition = NO; m_balloonView.editedBookmark = pair(-1, -1); + m_balloonView.notes = @""; CGFloat const scaleFactor = self.view.contentScaleFactor; point = GetFramework().GtoP(point); [m_balloonView showInView:self.view atPoint:CGPointMake(point.x / scaleFactor, point.y / scaleFactor)]; } +- (void) destroyPopover +{ + [popover release]; + popover = nil; +} + +//if save is NO, we need to delete bookmark +- (void)dismissPopoverAndSaveBookmark:(BOOL)save +{ + if (IsValid(m_balloonView.editedBookmark)) + { + if (save) + [m_balloonView addOrEditBookmark]; + else + [m_balloonView deleteBookmark]; + m_balloonView.editedBookmark = MakeEmptyBookmarkAndCategory(); + } + [popover dismissPopoverAnimated:YES]; + [self destroyPopover]; + [self Invalidate]; +} + +-(void)showPopoverFromBalloonData +{ + m2::PointD pt = GetFramework().GtoP(m2::PointD(m_balloonView.globalPosition.x, m_balloonView.globalPosition.y)); + pt.y -= m_balloonView.pinImage.frame.size.height; + //TODO We should always remember about scale factor, solve this problem + double sf = self.view.contentScaleFactor; + pt.x /= sf; + pt.y /= sf; + [popover presentPopoverFromRect:CGRectMake(pt.x, pt.y, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; +} + @end diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 00213d4f8b..e6bdb63317 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -226,6 +226,7 @@ void InitLocalizedStrings() -(void) showParsedBookmarkOnMap:(url_api::Request) request { + [m_mapViewController dismissPopoverAndSaveBookmark:YES]; [m_navController popToRootViewControllerAnimated:YES]; if (![m_navController.visibleViewController isMemberOfClass:NSClassFromString(@"MapViewController")]) [m_mapViewController dismissModalViewControllerAnimated:YES];