diff --git a/iphone/Maps/Bookmarks/AddBookmarkVC.mm b/iphone/Maps/Bookmarks/AddBookmarkVC.mm index cc6c0f80c3..17462e430e 100644 --- a/iphone/Maps/Bookmarks/AddBookmarkVC.mm +++ b/iphone/Maps/Bookmarks/AddBookmarkVC.mm @@ -1,6 +1,7 @@ #import "AddBookmarkVC.h" #import "BalloonView.h" #import "Framework.h" +#import "SelectSetVC.h" @implementation AddBookmarkVC @@ -20,9 +21,9 @@ - (void)onAddClicked { - // TODO Get correct bookmark category. - GetFramework().AddBookmark("Default", - Bookmark(m2::PointD(m_balloon.globalPosition.x, m_balloon.globalPosition.y), [m_balloon.title UTF8String])); + GetFramework().AddBookmark([m_balloon.setName UTF8String], + Bookmark(m2::PointD(m_balloon.globalPosition.x, m_balloon.globalPosition.y), + [m_balloon.title UTF8String])); [m_balloon hide]; // Don't forget to hide navbar [self.navigationController setNavigationBarHidden:YES animated:YES]; @@ -32,6 +33,8 @@ - (void)viewWillAppear:(BOOL)animated { [self.navigationController setNavigationBarHidden:NO animated:YES]; + // Update the table - we can display it after changing set or color + [self.tableView reloadData]; [super viewWillAppear:animated]; } @@ -52,33 +55,57 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell * cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"AddBMCell"] autorelease]; + NSString * cellId = @"DefaultCell"; + switch (indexPath.row) + { + case 0: cellId = @"NameCell"; break; + case 1: cellId = @"SetCell"; break; + case 2: cellId = @"ColorCell"; break; + } + + UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId]; + if (!cell) + { + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId] autorelease]; + switch (indexPath.row) + { + case 0: + { + UITextField * f = [[[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 21)] autorelease]; + f.textAlignment = UITextAlignmentRight; + f.returnKeyType = UIReturnKeyDone; + f.clearButtonMode = UITextFieldViewModeWhileEditing; + f.autocorrectionType = UITextAutocorrectionTypeNo; + f.delegate = self; + f.placeholder = NSLocalizedString(@"Name", @"Add bookmark dialog - bookmark name"); + f.textColor = cell.detailTextLabel.textColor; + cell.accessoryView = f; + cell.textLabel.text = NSLocalizedString(@"Name", @"Add bookmark dialog - bookmark name"); + cell.selectionStyle = UITableViewCellSelectionStyleNone; + } + break; + + case 1: + cell.textLabel.text = NSLocalizedString(@"Set", @"Add bookmark dialog - bookmark set"); + break; + + case 2: + cell.textLabel.text = NSLocalizedString(@"Color", @"Add bookmark dialog - bookmark color"); + break; + } + } + // Update variable cell values switch (indexPath.row) { case 0: - { - UITextField * f = [[[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 21)] autorelease]; - f.textAlignment = UITextAlignmentRight; - f.returnKeyType = UIReturnKeyDone; - f.clearButtonMode = UITextFieldViewModeWhileEditing; - f.delegate = self; - f.placeholder = NSLocalizedString(@"Name", @"Add bookmark dialog - bookmark name"); - f.text = m_balloon.title; - f.textColor = cell.detailTextLabel.textColor; - cell.accessoryView = f; - cell.textLabel.text = NSLocalizedString(@"Name", @"Add bookmark dialog - bookmark name"); - cell.selectionStyle = UITableViewCellSelectionStyleNone; - } + ((UITextField *)(cell.accessoryView)).text = m_balloon.title; break; case 1: - // TODO Get correct bookmark category. - cell.textLabel.text = NSLocalizedString(@"Set", @"Add bookmark dialog - bookmark set"); - cell.detailTextLabel.text = @"Default"; + cell.detailTextLabel.text = [m_balloon setName]; break; case 2: - cell.textLabel.text = NSLocalizedString(@"Color", @"Add bookmark dialog - bookmark color"); cell.accessoryView = [m_balloon pinImage]; break; } @@ -88,6 +115,13 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [[tableView cellForRowAtIndexPath:indexPath] setSelected:NO animated:YES]; + + if (indexPath.row == 1) + { + SelectSetVC * vc = [[SelectSetVC alloc] initWithBalloonView:m_balloon andEditMode:YES]; + [self.navigationController pushViewController:vc animated:YES]; + [vc release]; + } } - (BOOL)textFieldShouldReturn:(UITextField *)textField diff --git a/iphone/Maps/Bookmarks/AddSetVC.h b/iphone/Maps/Bookmarks/AddSetVC.h new file mode 100644 index 0000000000..402d4e60c6 --- /dev/null +++ b/iphone/Maps/Bookmarks/AddSetVC.h @@ -0,0 +1,13 @@ +#import + +@class BalloonView; + +@interface AddSetVC : UITableViewController +{ + // @TODO store as a property to retain reference + BalloonView * m_balloon; +} + +- (id) initWithBalloonView:(BalloonView *)view; + +@end diff --git a/iphone/Maps/Bookmarks/AddSetVC.mm b/iphone/Maps/Bookmarks/AddSetVC.mm new file mode 100644 index 0000000000..96490429fc --- /dev/null +++ b/iphone/Maps/Bookmarks/AddSetVC.mm @@ -0,0 +1,90 @@ +#import "AddSetVC.h" +#import "BalloonView.h" +#import "Framework.h" + +@implementation AddSetVC + +- (id) initWithBalloonView:(BalloonView *)view +{ + self = [super initWithStyle:UITableViewStyleGrouped]; + if (self) + { + m_balloon = view; + + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(onSaveClicked)]; + self.title = NSLocalizedString(@"Add New Set", @"Add New Bookmark Set dialog title"); + } + return self; +} + +- (void)onSaveClicked +{ + UITextField * textField = (UITextField *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].accessoryView; + NSString * text = textField.text; + if (text.length) + { + m_balloon.setName = text; + GetFramework().GetBmCategory([text UTF8String]); + + // Display "Add Bookmark" dialog + NSArray * vcs = self.navigationController.viewControllers; + UITableViewController * addBookmarkVC = (UITableViewController *)[vcs objectAtIndex:[vcs count] - 3]; + [self.navigationController popToViewController:addBookmarkVC animated:YES]; + } +} + +- (void)viewDidAppear:(BOOL)animated +{ + // Set focus to editor + UITextField * textField = (UITextField *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].accessoryView; + [textField becomeFirstResponder]; + + [super viewDidAppear:animated]; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return YES; +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return 1; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell * cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EditSetNameCell"] autorelease]; + UITextField * f = [[[UITextField alloc] initWithFrame:CGRectMake(20, 8, 260, 21)] autorelease]; + f.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + f.returnKeyType = UIReturnKeyDone; + f.clearButtonMode = UITextFieldViewModeWhileEditing; + f.autocorrectionType = UITextAutocorrectionTypeNo; + f.delegate = self; + f.placeholder = NSLocalizedString(@"Bookmark Set Name", @"Add Bookmark Set dialog - hint when set name is empty"); + cell.accessoryView = f; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + return cell; +} + +//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +//{ +// [[tableView cellForRowAtIndexPath:indexPath] setSelected:NO animated:YES]; +//} + +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + if (textField.text.length == 0) + return YES; + + [textField resignFirstResponder]; + [self onSaveClicked]; + return NO; +} + +@end diff --git a/iphone/Maps/Bookmarks/BalloonView.h b/iphone/Maps/Bookmarks/BalloonView.h index fcf08cb7c7..e906d83a2c 100644 --- a/iphone/Maps/Bookmarks/BalloonView.h +++ b/iphone/Maps/Bookmarks/BalloonView.h @@ -15,8 +15,10 @@ // Currently contains automatically updated address info @property(nonatomic, retain) NSString * description; @property(nonatomic, retain) UIImageView * pinImage; -// Stores displayed bookmark icon name +// Stores displayed bookmark icon file name @property(nonatomic, retain) NSString * color; +// Stores last used bookmark Set name +@property(nonatomic, retain) NSString * setName; @property(nonatomic, assign, readonly) BOOL isDisplayed; @property(nonatomic, assign) CGPoint globalPosition; diff --git a/iphone/Maps/Bookmarks/BalloonView.mm b/iphone/Maps/Bookmarks/BalloonView.mm index 5090e6c776..0451541873 100644 --- a/iphone/Maps/Bookmarks/BalloonView.mm +++ b/iphone/Maps/Bookmarks/BalloonView.mm @@ -9,6 +9,7 @@ @synthesize description; @synthesize pinImage; @synthesize color; +@synthesize setName; @synthesize isDisplayed; - (id) initWithTarget:(id)target andSelector:(SEL)selector; @@ -17,6 +18,7 @@ { // Default bookmark pin color color = [[NSString alloc] initWithString:@"purple"]; + setName = [[NSString alloc] initWithString:NSLocalizedString(@"My Places", @"Default bookmarks set name")]; pinImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:self.color]]; m_titleView = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"BookmarkTitle"]; isDisplayed = NO; @@ -31,6 +33,7 @@ [m_titleView release]; self.pinImage = nil; self.color = nil; + self.setName = nil; self.title = nil; self.description = nil; [super dealloc]; diff --git a/iphone/Maps/Bookmarks/BookmarksVC.h b/iphone/Maps/Bookmarks/BookmarksVC.h index bf041d46aa..cf7fb186ed 100644 --- a/iphone/Maps/Bookmarks/BookmarksVC.h +++ b/iphone/Maps/Bookmarks/BookmarksVC.h @@ -1,14 +1,13 @@ #import -class BookmarkCategory; +@class BalloonView; -@interface BookmarksVC : UIViewController +@interface BookmarksVC : UITableViewController { - UITableView * m_table; - // Needed to change Edit/Cancel buttons - UINavigationItem * m_navItem; - - // Current category to show. - BookmarkCategory * m_category; + // @TODO store as a property to retain reference + BalloonView * m_balloon; } + +- (id) initWithBalloonView:(BalloonView *)view; + @end diff --git a/iphone/Maps/Bookmarks/BookmarksVC.mm b/iphone/Maps/Bookmarks/BookmarksVC.mm index 113b1befc4..a23cdd4f78 100644 --- a/iphone/Maps/Bookmarks/BookmarksVC.mm +++ b/iphone/Maps/Bookmarks/BookmarksVC.mm @@ -1,57 +1,31 @@ #import "BookmarksVC.h" #import "SearchCell.h" #import "CustomNavigationView.h" +#import "BalloonView.h" +#import "MapsAppDelegate.h" +#import "SelectSetVC.h" #include "Framework.h" @implementation BookmarksVC -- (void)onCancelEdit +- (id) initWithBalloonView:(BalloonView *)view { - [self setEditing:NO animated:NO]; - [m_table setEditing:NO animated:NO]; - m_navItem.rightBarButtonItem = self.editButtonItem; -} - -- (void)onEdit -{ - [self setEditing:YES animated:YES]; - [m_table setEditing:YES animated:YES]; - m_navItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onCancelEdit)] autorelease]; -} - -- (void)loadView -{ - // TODO Initialize and change m_category. - - UIView * parentView = [[[CustomNavigationView alloc] init] autorelease]; - parentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; - - m_navItem = [[[UINavigationItem alloc] init] autorelease]; - - m_navItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Maps", @"Bookmarks - Close bookmarks button") style: UIBarButtonItemStyleDone - target:self action:@selector(onCloseButton:)] autorelease]; - // Display Edit button only if table is not empty - if (m_category->GetBookmarksCount() > 0) + self = [super initWithStyle:UITableViewStyleGrouped]; + if (self) { - [self.editButtonItem setTarget:self]; - [self.editButtonItem setAction:@selector(onEdit)]; - m_navItem.rightBarButtonItem = self.editButtonItem; + m_balloon = view; + self.title = NSLocalizedString(@"Bookmarks", @"Boormarks - dialog title"); + + self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Maps", @"Bookmarks - Close bookmarks button") style: UIBarButtonItemStyleDone + target:self action:@selector(onCloseButton:)] autorelease]; + // Display Edit button only if table is not empty + BookmarkCategory * cat = GetFramework().GetBmCategory([m_balloon.setName UTF8String]); + if (cat && cat->GetBookmarksCount()) + self.navigationItem.rightBarButtonItem = self.editButtonItem; } - - UINavigationBar * navBar = [[[UINavigationBar alloc] init] autorelease]; - [navBar pushNavigationItem:m_navItem animated:NO]; - - [parentView addSubview:navBar]; - - m_table = [[UITableView alloc] init]; - m_table.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; - m_table.delegate = self; - m_table.dataSource = self; - [parentView addSubview:m_table]; - - self.view = parentView; + return self; } - (void)onCloseButton:(id)sender @@ -66,58 +40,109 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 1; + return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - // Return the number of rows in the section. - return m_category->GetBookmarksCount(); + if (section == 0) + return 1; + BookmarkCategory * cat = GetFramework().GetBmCategory([m_balloon.setName UTF8String]); + if (cat) + return cat->GetBookmarksCount(); + return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - SearchCell * cell = (SearchCell *)[tableView dequeueReusableCellWithIdentifier:@"FeatureCell"]; - if (!cell) - cell = [[[SearchCell alloc] initWithReuseIdentifier:@"FeatureCell"] autorelease]; + if (indexPath.section == 0) + { + UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"CategoryCell"]; + if (!cell) + { + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"CategoryCell"] autorelease]; + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + cell.textLabel.text = NSLocalizedString(@"Set", @"Bookmarks dialog - Bookmark set cell"); + } + cell.detailTextLabel.text = m_balloon.setName; + return cell; + } + else + { + SearchCell * cell = (SearchCell *)[tableView dequeueReusableCellWithIdentifier:@"FeatureCell"]; + if (!cell) + cell = [[[SearchCell alloc] initWithReuseIdentifier:@"FeatureCell"] autorelease]; - Bookmark const * bm = m_category->GetBookmark(indexPath.row); - - cell.featureName.text = [NSString stringWithUTF8String:bm->GetName().c_str()]; - cell.featureCountry.text = [NSString stringWithUTF8String:"Region"]; - cell.featureType.text = [NSString stringWithUTF8String:"Type"]; - cell.featureDistance.text = [NSString stringWithFormat:@"%f", 0.0]; - - return cell; + BookmarkCategory * cat = GetFramework().GetBmCategory([m_balloon.setName UTF8String]); + if (cat) + { + Bookmark const * bm = cat->GetBookmark(indexPath.row); + if (bm) + { + cell.featureName.text = [NSString stringWithUTF8String:bm->GetName().c_str()]; + Framework::AddressInfo info; + GetFramework().GetAddressInfo(bm->GetOrg(), info); + cell.featureCountry.text = [NSString stringWithUTF8String:info.FormatAddress().c_str()]; + cell.featureType.text = [NSString stringWithUTF8String:info.FormatTypes().c_str()]; + cell.featureDistance.text = @"@TODO"; + } + } + return cell; + } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - if (indexPath.row < (NSInteger)m_category->GetBookmarksCount()) + if (indexPath.section == 0) { - Bookmark const * bm = m_category->GetBookmark(indexPath.row); - GetFramework().ShowRect(bm->GetViewport()); - - // Same as "Close". - [self dismissModalViewControllerAnimated:YES]; + SelectSetVC * ssVC = [[SelectSetVC alloc] initWithBalloonView:m_balloon andEditMode:NO]; + [self.navigationController pushViewController:ssVC animated:YES]; + [ssVC release]; + } + else + { + BookmarkCategory * cat = GetFramework().GetBmCategory([m_balloon.setName UTF8String]); + if (cat) + { + Bookmark const * bm = cat->GetBookmark(indexPath.row); + if (bm) + { + // Same as "Close". + [self dismissModalViewControllerAnimated:YES]; + GetFramework().ShowRect(bm->GetViewport()); + } + } } } -/* -// Override to support conditional editing of the table view. + - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { - // Return NO if you do not want the specified item to be editable. - return YES; + // Return NO if you do not want the specified item to be editable. + if (indexPath.section == 0) + return NO; + return YES; } -*/ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { - if (editingStyle == UITableViewCellEditingStyleDelete) + if (indexPath.section == 1) { - m_category->RemoveBookmark(indexPath.row); - [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; + if (editingStyle == UITableViewCellEditingStyleDelete) + { + BookmarkCategory * cat = GetFramework().GetBmCategory([m_balloon.setName UTF8String]); + if (cat) + { + cat->RemoveBookmark(indexPath.row); + [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; + // Disable edit mode if no bookmarks are left + if (cat->GetBookmarksCount() == 0) + { + self.navigationItem.rightBarButtonItem = nil; + [self setEditing:NO animated:YES]; + } + } + } } } diff --git a/iphone/Maps/Bookmarks/SelectSetVC.h b/iphone/Maps/Bookmarks/SelectSetVC.h new file mode 100644 index 0000000000..e8070e978e --- /dev/null +++ b/iphone/Maps/Bookmarks/SelectSetVC.h @@ -0,0 +1,15 @@ +#import + +@class BalloonView; + +@interface SelectSetVC : UITableViewController +{ + // @TODO store as a property to retain reference + BalloonView * m_balloon; + + BOOL m_editModeEnabled; +} + +- (id) initWithBalloonView:(BalloonView *)view andEditMode:(BOOL)enabled; + +@end diff --git a/iphone/Maps/Bookmarks/SelectSetVC.mm b/iphone/Maps/Bookmarks/SelectSetVC.mm new file mode 100644 index 0000000000..6c83834ad7 --- /dev/null +++ b/iphone/Maps/Bookmarks/SelectSetVC.mm @@ -0,0 +1,150 @@ +#import "SelectSetVC.h" +#import "BalloonView.h" +#import "Framework.h" +#import "AddSetVC.h" + +@implementation SelectSetVC + +- (id) initWithBalloonView:(BalloonView *)view andEditMode:(BOOL)enabled +{ + self = [super initWithStyle:UITableViewStyleGrouped]; + if (self) + { + m_balloon = view; + m_editModeEnabled = enabled; + + self.title = NSLocalizedString(@"Bookmark Sets", @"Bookmark Sets dialog title"); + } + return self; +} + +- (void)viewWillAppear:(BOOL)animated +{ + if (m_editModeEnabled) + { + // Do not show Edit button if we have only one bookmarks set + if (GetFramework().GetBmCategoriesCount() > 1) + self.navigationItem.rightBarButtonItem = self.editButtonItem; + } + + [super viewWillAppear:animated]; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return YES; +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + // Hide Add New Set button if Edit is not enabled + return m_editModeEnabled ? 2 : 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + NSInteger count = GetFramework().GetBmCategoriesCount(); + // If no bookmarks are added, display default set + if (count == 0) + count = 1; + + if (section == 0) + return m_editModeEnabled ? 1 : count; + return count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString * kSetCellId = @"AddSetCell"; + UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:kSetCellId]; + if (cell == nil) + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kSetCellId] autorelease]; + // Customize cell + if (indexPath.section == 0 && m_editModeEnabled) + { + cell.textLabel.text = NSLocalizedString(@"Add New Set...", @"Bookmark Sets dialog - Add New Set button"); + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + } + else + { + BookmarkCategory * cat = GetFramework().GetBmCategory(indexPath.row); + if (cat) + cell.textLabel.text = [NSString stringWithUTF8String:cat->GetName().c_str()]; + else + cell.textLabel.text = m_balloon.setName; // Use "not existing" default set + + if ([m_balloon.setName isEqualToString:cell.textLabel.text]) + cell.accessoryType = UITableViewCellAccessoryCheckmark; + else + cell.accessoryType = UITableViewCellAccessoryNone; + } + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath]; + [cell setSelected:NO animated:YES]; + if (indexPath.section == 0 && m_editModeEnabled) + { + AddSetVC * asVC = [[AddSetVC alloc] initWithBalloonView:m_balloon]; + [self.navigationController pushViewController:asVC animated:YES]; + [asVC release]; + } + else + { + if (![m_balloon.setName isEqualToString:cell.textLabel.text]) + { + m_balloon.setName = cell.textLabel.text; + // Update Bookmarks VC if needed + if (!m_editModeEnabled) + { + NSArray * vcs = self.navigationController.viewControllers; + UITableViewController * bmVC = (UITableViewController *)[vcs objectAtIndex:[vcs count] - 2]; + [bmVC.tableView reloadData]; + } + } + [self.navigationController popViewControllerAnimated:YES]; + } +} + +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath +{ + // Return NO if you do not want the specified item to be editable. + if (indexPath.section == 0) + return NO; + return YES; +} + +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (indexPath.section == 1) + { + if (editingStyle == UITableViewCellEditingStyleDelete) + { + // Move checkmark to another category if we're deleting the checked one + Framework & f = GetFramework(); + BookmarkCategory * cat = f.GetBmCategory(indexPath.row); + bool moveCheckMark = false; + if (cat && cat->GetName() == [m_balloon.setName UTF8String]) + moveCheckMark = true; + + if (GetFramework().DeleteBmCategory(indexPath.row)) + [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; + if (GetFramework().GetBmCategoriesCount() == 1) + { + // Disable edit mode to leave at least one bookmarks category + [self setEditing:NO animated:YES]; + self.navigationItem.rightBarButtonItem = nil; + } + if (moveCheckMark) + { + UITableViewCell * cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; + cell.accessoryType = UITableViewCellAccessoryCheckmark; + m_balloon.setName = cell.textLabel.text; + } + } + } +} + +@end diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 50a1c56ff8..b523a30bca 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -98,16 +98,18 @@ - (IBAction)OnSearchClicked:(id)sender { - SearchVC * searchVC = [[SearchVC alloc] initWithLocationManager:[MapsAppDelegate theApp].m_locationManager]; + SearchVC * searchVC = [[SearchVC alloc] init]; [self presentModalViewController:searchVC animated:YES]; [searchVC release]; } - (IBAction)OnBookmarksClicked:(id)sender { - BookmarksVC * bVC = [[BookmarksVC alloc] init]; - [self presentModalViewController:bVC animated:YES]; + BookmarksVC * bVC = [[BookmarksVC alloc] initWithBalloonView:m_bookmark]; + UINavigationController * navC = [[UINavigationController alloc] initWithRootViewController:bVC]; + [self presentModalViewController:navC animated:YES]; [bVC release]; + [navC release]; } - (void)onBookmarkClicked diff --git a/iphone/Maps/Classes/SearchVC.h b/iphone/Maps/Classes/SearchVC.h index 88019eb3c1..7fdbf59e78 100644 --- a/iphone/Maps/Classes/SearchVC.h +++ b/iphone/Maps/Classes/SearchVC.h @@ -30,6 +30,4 @@ namespace search { class Result; } NSInteger m_suggestionsCount; } -- (id)initWithLocationManager:(LocationManager *)lm; - @end diff --git a/iphone/Maps/Classes/SearchVC.mm b/iphone/Maps/Classes/SearchVC.mm index 2bf97a54ad..e408834579 100644 --- a/iphone/Maps/Classes/SearchVC.mm +++ b/iphone/Maps/Classes/SearchVC.mm @@ -4,15 +4,14 @@ #import "SearchCell.h" #import "BookmarksVC.h" #import "CustomNavigationView.h" +#import "MapsAppDelegate.h" #include "Framework.h" #include "../../geometry/angles.hpp" #include "../../geometry/distance_on_sphere.hpp" -#include "../../platform/settings.hpp" #include "../../platform/platform.hpp" #include "../../platform/preferred_languages.hpp" #include "../../indexer/mercator.hpp" -#include "../../map/measurement_utils.hpp" #include "../../search/result.hpp" #define MAPSWITHME_PREMIUM_APPSTORE_URL @"itms://itunes.com/apps/mapswithmepro" @@ -80,12 +79,12 @@ static void OnSearchResultCallback(search::Results const & res, int queryId) @implementation SearchVC -- (id)initWithLocationManager:(LocationManager *)lm +- (id)init { if ((self = [super initWithNibName:nil bundle:nil])) { m_framework = &GetFramework(); - m_locationManager = lm; + m_locationManager = [MapsAppDelegate theApp].m_locationManager; double lat, lon; bool const hasPt = [m_locationManager getLat:lat Lon:lon]; @@ -300,56 +299,6 @@ static void OnSearchResultCallback(search::Results const & res, int queryId) [self searchBar:m_searchBar textDidChange:text]; } -+ (NSString *)formatDistance:(double)meters -{ - if (meters < 0.) - return nil; - - uint64_t shortUnits = (uint64_t)meters; - double longUnits = meters/1000.0; - // @TODO localize measurements - static NSString * shortLabel = @"m"; - static NSString * longLabel = @"km"; - Settings::Units u = Settings::Metric; - Settings::Get("Units", u); - switch (u) - { - case Settings::Foot: - shortUnits = (uint64_t)MeasurementUtils::MetersToFeet(meters); - longUnits = MeasurementUtils::MetersToMiles(meters); - shortLabel = @"ft"; - longLabel = @"mi"; - break; - - case Settings::Yard: - shortUnits = (uint64_t)MeasurementUtils::MetersToYards(meters); - longUnits = MeasurementUtils::MetersToMiles(meters); - shortLabel = @"yd"; - longLabel = @"mi"; - break; - - case Settings::Metric: - shortLabel = @"m"; - longLabel = @"km"; - break; - } - - // NSLocalizedString(@"%.1lf m", @"Search results - Metres") - // NSLocalizedString(@"%.1lf ft", @"Search results - Feet") - // NSLocalizedString(@"%.1lf mi", @"Search results - Miles") - // NSLocalizedString(@"%.1lf yd", @"Search results - Yards") - - if (shortUnits < 1000) - return [NSString stringWithFormat:@"%qu %@", shortUnits, shortLabel]; - - uint64_t const longUnitsRounded = (uint64_t)(longUnits); - // reduce precision for big distances and remove zero for x.0-like numbers - if (longUnitsRounded > 10 || (longUnitsRounded && (uint64_t)(longUnits * 10.0) == longUnitsRounded * 10)) - return [NSString stringWithFormat:@"%qu %@", longUnitsRounded, longLabel]; - - return [NSString stringWithFormat:@"%.1lf %@", longUnits, longLabel]; -} - - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; @@ -410,7 +359,7 @@ static void OnSearchResultCallback(search::Results const & res, int queryId) cell.featureCountry.text = [NSString stringWithUTF8String:r.GetRegionString()]; cell.featureType.text = [NSString stringWithUTF8String:r.GetFeatureType()]; double const distance = r.GetDistanceFromCenter(); - cell.featureDistance.text = [SearchVC formatDistance:distance]; + cell.featureDistance.text = [LocationManager formatDistance:distance]; // Show flags only if feature is too far away and it has the flag if (r.GetRegionFlag() && (distance < 0. || distance > MIN_COMPASS_DISTANCE)) { diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 06ccf9d9e5..d58d10c817 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -86,6 +86,8 @@ FA05460D155C22D4001F4E37 /* yellow.png in Resources */ = {isa = PBXBuildFile; fileRef = FA0545EE155C22D4001F4E37 /* yellow.png */; }; FA05460E155C22D4001F4E37 /* yellow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FA0545EF155C22D4001F4E37 /* yellow@2x.png */; }; FA05460F155C22D4001F4E37 /* yellow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FA0545EF155C22D4001F4E37 /* yellow@2x.png */; }; + FA054612155C465E001F4E37 /* SelectSetVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA054611155C465E001F4E37 /* SelectSetVC.mm */; }; + FA054613155C465E001F4E37 /* SelectSetVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = FA054611155C465E001F4E37 /* SelectSetVC.mm */; }; FA065FED128614C400FEA989 /* MainWindow-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = FA065FEC128614C400FEA989 /* MainWindow-iPad.xib */; }; FA065FFF1286167A00FEA989 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FA065FFD1286167A00FEA989 /* Default@2x.png */; }; FA0660001286167A00FEA989 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = FA065FFE1286167A00FEA989 /* Default.png */; }; @@ -165,6 +167,8 @@ FAA3A879151279DE00C7904C /* 114-lite.png in Resources */ = {isa = PBXBuildFile; fileRef = FAA3A871151279DC00C7904C /* 114-lite.png */; }; FAA3A87A151279DE00C7904C /* 144-lite.png in Resources */ = {isa = PBXBuildFile; fileRef = FAA3A872151279DD00C7904C /* 144-lite.png */; }; FAA5C2A2144F135F005337F6 /* LocationManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAA5C2A1144F135F005337F6 /* LocationManager.mm */; }; + FAA614B8155F16950031C345 /* AddSetVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAA614B7155F16950031C345 /* AddSetVC.mm */; }; + FAA614B9155F16950031C345 /* AddSetVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAA614B7155F16950031C345 /* AddSetVC.mm */; }; FAA7A73414055351009F76D8 /* location-selected.png in Resources */ = {isa = PBXBuildFile; fileRef = FAA7A73214055351009F76D8 /* location-selected.png */; }; FAA7A73514055351009F76D8 /* location-selected@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FAA7A73314055351009F76D8 /* location-selected@2x.png */; }; FAAFD697139D9BE2000AE70C /* categories.txt in Resources */ = {isa = PBXBuildFile; fileRef = FAAFD696139D9BE2000AE70C /* categories.txt */; }; @@ -1370,6 +1374,8 @@ FA0545ED155C22D4001F4E37 /* red@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "red@2x.png"; path = "Bookmarks/red@2x.png"; sourceTree = SOURCE_ROOT; }; FA0545EE155C22D4001F4E37 /* yellow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = yellow.png; path = Bookmarks/yellow.png; sourceTree = SOURCE_ROOT; }; FA0545EF155C22D4001F4E37 /* yellow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "yellow@2x.png"; path = "Bookmarks/yellow@2x.png"; sourceTree = SOURCE_ROOT; }; + FA054610155C465E001F4E37 /* SelectSetVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SelectSetVC.h; path = Bookmarks/SelectSetVC.h; sourceTree = SOURCE_ROOT; }; + FA054611155C465E001F4E37 /* SelectSetVC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SelectSetVC.mm; path = Bookmarks/SelectSetVC.mm; sourceTree = SOURCE_ROOT; }; FA065FEC128614C400FEA989 /* MainWindow-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MainWindow-iPad.xib"; path = "Resources-iPad/MainWindow-iPad.xib"; sourceTree = SOURCE_ROOT; }; FA065FFD1286167A00FEA989 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = SOURCE_ROOT; }; FA065FFE1286167A00FEA989 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = SOURCE_ROOT; }; @@ -1452,6 +1458,8 @@ FAA4B13E13EC1C8C00BCAB63 /* DiskFreeSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiskFreeSpace.h; sourceTree = ""; }; FAA5C2A0144F135F005337F6 /* LocationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LocationManager.h; path = Platform/LocationManager.h; sourceTree = ""; }; FAA5C2A1144F135F005337F6 /* LocationManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = LocationManager.mm; path = Platform/LocationManager.mm; sourceTree = ""; }; + FAA614B6155F16950031C345 /* AddSetVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AddSetVC.h; path = Bookmarks/AddSetVC.h; sourceTree = SOURCE_ROOT; }; + FAA614B7155F16950031C345 /* AddSetVC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AddSetVC.mm; path = Bookmarks/AddSetVC.mm; sourceTree = SOURCE_ROOT; }; FAA7A73214055351009F76D8 /* location-selected.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "location-selected.png"; sourceTree = ""; }; FAA7A73314055351009F76D8 /* location-selected@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "location-selected@2x.png"; sourceTree = ""; }; FAAE8D5D1338FF8B003ECAD5 /* GetActiveConnectionType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetActiveConnectionType.h; sourceTree = ""; }; @@ -2266,6 +2274,10 @@ isa = PBXGroup; children = ( FA36B8171540466A004560CC /* Images */, + FAA614B6155F16950031C345 /* AddSetVC.h */, + FAA614B7155F16950031C345 /* AddSetVC.mm */, + FA054610155C465E001F4E37 /* SelectSetVC.h */, + FA054611155C465E001F4E37 /* SelectSetVC.mm */, FA5D4F131557F79900E7D8BB /* AddBookmarkVC.h */, FA5D4F141557F79900E7D8BB /* AddBookmarkVC.mm */, FA5D4F151557F79900E7D8BB /* PlacePageVC.h */, @@ -4201,6 +4213,8 @@ FA5D4F171557F79900E7D8BB /* AddBookmarkVC.mm in Sources */, FA5D4F191557F79900E7D8BB /* PlacePageVC.mm in Sources */, FAF457E715597D4600DCCC49 /* Framework.cpp in Sources */, + FA054612155C465E001F4E37 /* SelectSetVC.mm in Sources */, + FAA614B8155F16950031C345 /* AddSetVC.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -4231,6 +4245,8 @@ FA5D4F181557F79900E7D8BB /* AddBookmarkVC.mm in Sources */, FA5D4F1A1557F79900E7D8BB /* PlacePageVC.mm in Sources */, FAF457E815597D4600DCCC49 /* Framework.cpp in Sources */, + FA054613155C465E001F4E37 /* SelectSetVC.mm in Sources */, + FAA614B9155F16950031C345 /* AddSetVC.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/iphone/Maps/Platform/LocationManager.h b/iphone/Maps/Platform/LocationManager.h index 64acb07a5b..70318a5cfe 100644 --- a/iphone/Maps/Platform/LocationManager.h +++ b/iphone/Maps/Platform/LocationManager.h @@ -40,4 +40,6 @@ - (bool)getLat:(double &)lat Lon:(double &)lon; - (bool)getNorthRad:(double &)rad; + ++ (NSString *)formatDistance:(double)meters; @end diff --git a/iphone/Maps/Platform/LocationManager.mm b/iphone/Maps/Platform/LocationManager.mm index 46a527b4fb..3e50aaf4ba 100644 --- a/iphone/Maps/Platform/LocationManager.mm +++ b/iphone/Maps/Platform/LocationManager.mm @@ -1,5 +1,7 @@ #import "LocationManager.h" +#include "../../map/measurement_utils.hpp" + #include "../../platform/settings.hpp" #include "../../base/math.hpp" @@ -225,4 +227,54 @@ return false; } ++ (NSString *)formatDistance:(double)meters +{ + if (meters < 0.) + return nil; + + uint64_t shortUnits = (uint64_t)meters; + double longUnits = meters/1000.0; + // @TODO localize measurements + static NSString * shortLabel = @"m"; + static NSString * longLabel = @"km"; + Settings::Units u = Settings::Metric; + Settings::Get("Units", u); + switch (u) + { + case Settings::Foot: + shortUnits = (uint64_t)MeasurementUtils::MetersToFeet(meters); + longUnits = MeasurementUtils::MetersToMiles(meters); + shortLabel = @"ft"; + longLabel = @"mi"; + break; + + case Settings::Yard: + shortUnits = (uint64_t)MeasurementUtils::MetersToYards(meters); + longUnits = MeasurementUtils::MetersToMiles(meters); + shortLabel = @"yd"; + longLabel = @"mi"; + break; + + case Settings::Metric: + shortLabel = @"m"; + longLabel = @"km"; + break; + } + + // NSLocalizedString(@"%.1lf m", @"Search results - Metres") + // NSLocalizedString(@"%.1lf ft", @"Search results - Feet") + // NSLocalizedString(@"%.1lf mi", @"Search results - Miles") + // NSLocalizedString(@"%.1lf yd", @"Search results - Yards") + + if (shortUnits < 1000) + return [NSString stringWithFormat:@"%qu %@", shortUnits, shortLabel]; + + uint64_t const longUnitsRounded = (uint64_t)(longUnits); + // reduce precision for big distances and remove zero for x.0-like numbers + if (longUnitsRounded > 10 || (longUnitsRounded && (uint64_t)(longUnits * 10.0) == longUnitsRounded * 10)) + return [NSString stringWithFormat:@"%qu %@", longUnitsRounded, longLabel]; + + return [NSString stringWithFormat:@"%.1lf %@", longUnits, longLabel]; +} + @end