[iOS]Fixes for new bookmark's logic

This commit is contained in:
Kirill Zhdanovich 2013-03-20 10:03:38 +03:00 committed by Alex Zolotarev
parent dae5129316
commit eaa62b1d27
6 changed files with 32 additions and 66 deletions

View file

@ -31,8 +31,11 @@
if (text.length)
{
m_balloon.setName = text;
// Create category if it doesn't exist
(void)GetFramework().GetBmCategory([text UTF8String]);
[m_balloon deleteBookmark];
Framework &f = GetFramework();
size_t pos = f.AddCategory([text UTF8String]);
[m_balloon addBookmarkToCategory:pos];
// Show Place Page dialog with new set selected
[self onCancelClicked];

View file

@ -38,4 +38,6 @@
// and does nothing if called for "new", not added bookmark
- (void) deleteBookmark;
- (void) addBookmarkToCategory:(size_t)index;
@end

View file

@ -223,11 +223,12 @@
- (void) addOrEditBookmark
{
// If coordinates are be the same, bookmark is automatically replaced
Bookmark bm(m2::PointD(self.globalPosition.x, self.globalPosition.y),
[self.title UTF8String], [self.color UTF8String]);
Framework &f = GetFramework();
Bookmark bm(m2::PointD(globalPosition.x, globalPosition.y),
[title UTF8String], [color UTF8String]);
f.GetBmCategory(editedBookmark.first)->ReplaceBookmark(editedBookmark.second, bm);
BookmarkCategory * cat = GetFramework().AddBookmark([self.setName UTF8String], bm);
BookmarkCategory * cat = f.GetBmCategory(editedBookmark.first);
// Enable category visibility if it was turned off, so user can see newly added or edited bookmark
if (!cat->IsVisible())
@ -252,4 +253,14 @@
}
}
- (void) addBookmarkToCategory:(size_t)index
{
Framework &f = GetFramework();
Bookmark bm(m2::PointD(globalPosition.x, globalPosition.y),
[title UTF8String], [color UTF8String]);
size_t newPosition = f.AddBookmark(index, bm);
self.editedBookmark = pair <int, int> (index, newPosition);
self.setName = [NSString stringWithUTF8String:f.GetBmCategory(index)->GetName().c_str()];
}
@end

View file

@ -2,7 +2,6 @@
#import "CustomNavigationView.h"
#import "BalloonView.h"
#import "MapsAppDelegate.h"
#import "SelectSetVC.h"
#import "CompassView.h"
#import "BookmarkCell.h"
#import "MapViewController.h"

View file

@ -11,26 +11,12 @@
if (self)
{
m_balloon = view;
// Always autocreate bookmark category if it's absent
GetFramework().GetBmCategory([m_balloon.setName UTF8String]);
self.title = NSLocalizedString(@"bookmark_sets", @"Bookmark Sets dialog title");
}
return self;
}
- (void)viewWillAppear:(BOOL)animated
{
// Do not show Edit button if we have only one bookmarks set
if (GetFramework().GetBmCategoriesCount() > 1)
self.navigationItem.rightBarButtonItem = self.editButtonItem;
else
self.navigationItem.rightBarButtonItem = nil;
[super viewWillAppear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
@ -68,7 +54,7 @@
if (cat)
cell.textLabel.text = [NSString stringWithUTF8String:cat->GetName().c_str()];
if ([m_balloon.setName isEqualToString:cell.textLabel.text])
if (m_balloon.editedBookmark.first == indexPath.row)
cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
cell.accessoryType = UITableViewCellAccessoryNone;
@ -91,52 +77,11 @@
}
else
{
if (![m_balloon.setName isEqualToString:cell.textLabel.text])
m_balloon.setName = cell.textLabel.text;
[m_balloon deleteBookmark];
[m_balloon addBookmarkToCategory:indexPath.row];
[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;
// Disable deleting of the last remaining set (can be activated by swipe right on a set item)
if (GetFramework().GetBmCategoriesCount() > 1)
return YES;
return NO;
}
- (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 (f.DeleteBmCategory(indexPath.row))
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
if (f.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

View file

@ -257,6 +257,12 @@
}
else
{
Framework &f = GetFramework();
int categoryPos = f.LastEditedCategory();
if (!IsValid(m_balloonView.editedBookmark))
{
[m_balloonView addBookmarkToCategory:categoryPos];
}
PlacePageVC * placePageVC = [[PlacePageVC alloc] initWithBalloonView:m_balloonView];
[self.navigationController pushViewController:placePageVC animated:YES];
[placePageVC release];