[ios] New UI for Bookmarks Manager

This commit is contained in:
Alex Zolotarev 2012-10-05 12:16:40 +03:00 committed by Alex Zolotarev
parent dccbcdfe3c
commit 9a989f47b2
10 changed files with 254 additions and 130 deletions

View file

@ -35,8 +35,6 @@
self.setName = [BalloonView getDefaultSetName];
// Load bookmarks from kml files
GetFramework().LoadBookmarks();
// Display only one category of bookmarks. User can change visible category from BookmarksVC Dialog.
GetFramework().SetVisibleBmCategory([self.setName UTF8String]);
self.pinImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:self.color]] autorelease];
isDisplayed = NO;
m_target = target;

View file

@ -0,0 +1,13 @@
#import <UIKit/UIKit.h>
@class BalloonView;
@interface BookmarksRootVC : UITableViewController
{
// @TODO store as a property to retain reference
BalloonView * m_balloon;
}
- (id) initWithBalloonView:(BalloonView *)view;
@end

View file

@ -0,0 +1,142 @@
#import "BookmarksRootVC.h"
#import "BookmarksVC.h"
#include "Framework.h"
@implementation BookmarksRootVC
- (id) initWithBalloonView:(BalloonView *)view
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self)
{
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];
}
return self;
}
- (void)onCloseButton:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
// Used to display bookmarks hint when no any bookmarks are added
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 1)
{
// Display hint only if at least one category with bookmarks is present
if (GetFramework().GetBmCategoriesCount())
return 0.;
return tableView.bounds.size.height / 2.;
}
return 0.;
}
// Used to display hint when no any categories with bookmarks are present
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 1)
{
if (GetFramework().GetBmCategoriesCount())
return nil;
CGRect rect = tableView.bounds;
rect.size.height /= 2.;
rect.size.width = rect.size.width * 2./3.;
UILabel * hint = [[[UILabel alloc] initWithFrame:rect] autorelease];
hint.textAlignment = UITextAlignmentCenter;
hint.lineBreakMode = UILineBreakModeWordWrap;
hint.numberOfLines = 0;
hint.text = NSLocalizedString(@"bookmarks_usage_hint", @"Text hint in Bookmarks dialog, displayed if it's empty");
hint.backgroundColor = [UIColor clearColor];
return hint;
}
return nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return GetFramework().GetBmCategoriesCount();
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarksRootVCSetCell"];
if (!cell)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"BookmarksRootVCSetCell"] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
BookmarkCategory * cat = GetFramework().GetBmCategory(indexPath.row);
if (cat)
{
cell.textLabel.text = [NSString stringWithUTF8String:cat->GetName().c_str()];
// @TODO: add checkmark icon
//cell.imageView.image = cat->IsVisible() ? checkedImage : nil;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld", cat->GetBookmarksCount()];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Remove cell selection
[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO animated:YES];
BookmarksVC * bvc = [[BookmarksVC alloc] initWithBalloonView:m_balloon andCategory:indexPath.row];
[self.navigationController pushViewController:bvc animated:YES];
[bvc release];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
Framework & f = GetFramework();
f.DeleteBmCategory(indexPath.row);
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
// Disable edit mode if no categories are left
if (!f.GetBmCategoriesCount())
{
self.navigationItem.rightBarButtonItem = nil;
[self setEditing:NO animated:YES];
}
}
}
- (void)viewWillAppear:(BOOL)animated
{
// Display Edit button only if table is not empty
if (GetFramework().GetBmCategoriesCount())
self.navigationItem.rightBarButtonItem = self.editButtonItem;
else
self.navigationItem.rightBarButtonItem = nil;
[super viewWillAppear:animated];
}
@end

View file

@ -9,8 +9,9 @@
BalloonView * m_balloon;
LocationManager * m_locationManager;
size_t m_categoryIndex;
}
- (id) initWithBalloonView:(BalloonView *)view;
- (id) initWithBalloonView:(BalloonView *)view andCategory:(size_t)categoryIndex;
@end

View file

@ -7,84 +7,29 @@
#include "Framework.h"
#include "../../../geometry/distance_on_sphere.hpp"
#include "../../../platform/platform.hpp"
@implementation BookmarksVC
- (id) initWithBalloonView:(BalloonView *)view
- (id) initWithBalloonView:(BalloonView *)view andCategory:(size_t)categoryIndex
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self)
{
m_locationManager = [MapsAppDelegate theApp].m_locationManager;
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];
m_categoryIndex = categoryIndex;
self.title = [NSString stringWithUTF8String:GetFramework().GetBmCategory(categoryIndex)->GetName().c_str()];
}
return self;
}
- (void)onCloseButton:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
// Returns bookmarks count in the active bookmark set (category)
- (size_t) getBookmarksCount
{
BookmarkCategory * cat = GetFramework().GetBmCategory([m_balloon.setName UTF8String]);
if (cat)
return cat->GetBookmarksCount();
return 0;
}
// Used to display bookmarks hint when no any bookmarks are added
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 1)
{
// Do not display any hint if bookmarks are present
if ([self getBookmarksCount])
return 0.;
return tableView.bounds.size.height / 2.;
}
return 0.;
}
// Used to display bookmarks hint when no any bookmarks are added
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 1)
{
// Do not display any hint if bookmarks are present
if ([self getBookmarksCount])
return nil;
CGRect rect = tableView.bounds;
rect.size.height /= 2.;
rect.size.width = rect.size.width * 2./3.;
UILabel * hint = [[[UILabel alloc] initWithFrame:rect] autorelease];
hint.textAlignment = UITextAlignmentCenter;
hint.lineBreakMode = UILineBreakModeWordWrap;
hint.numberOfLines = 0;
hint.text = NSLocalizedString(@"bookmarks_usage_hint", @"Text hint in Bookmarks dialog, displayed if it's empty");
hint.backgroundColor = [UIColor clearColor];
return hint;
}
return nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
@ -94,94 +39,122 @@
{
switch (section)
{
case 0: return 1;
case 1: return [self getBookmarksCount];
case 0: return 2;
case 1: return GetFramework().GetBmCategory(m_categoryIndex)->GetBookmarksCount();
default: return 0;
}
}
- (void)onVisibilitySwitched:(UISwitch *)sender
{
BookmarkCategory * cat = GetFramework().GetBmCategory(m_categoryIndex);
cat->SetVisible(sender.on);
cat->SaveToKMLFileAtPath(GetPlatform().WritableDir());
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BookmarkCategory * cat = GetFramework().GetBmCategory(m_categoryIndex);
if (!cat)
return nil;
UITableViewCell * cell = nil;
if (indexPath.section == 0)
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarkSetCell"];
if (!cell)
if (indexPath.row == 0)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"BookmarkSetCell"] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = NSLocalizedString(@"set", @"Bookmarks dialog - Bookmark set cell");
cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarksVCSetNameCell"];
if (!cell)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"BookmarksVCSetNameCell"] autorelease];
cell.textLabel.text = NSLocalizedString(@"name", @"Bookmarks dialog - Bookmark set cell");
// @TODO insert text editor
}
cell.detailTextLabel.text = [NSString stringWithUTF8String:cat->GetName().c_str()];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarksVCSetVisibilityCell"];
if (!cell)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"BookmarksVCSetVisibilityCell"] autorelease];
cell.textLabel.text = NSLocalizedString(@"visible", @"Bookmarks dialog - Bookmark set cell");
cell.accessoryView = [[[UISwitch alloc] init] autorelease];
}
UISwitch * sw = (UISwitch *)cell.accessoryView;
sw.on = cat->IsVisible();
[sw addTarget:self action:@selector(onVisibilitySwitched:) forControlEvents:UIControlEventValueChanged];
}
cell.detailTextLabel.text = m_balloon.setName;
return cell;
}
else
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarkItemCell"];
cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarksVCBookmarkItemCell"];
if (!cell)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"BookmarkItemCell"] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"BookmarksVCBookmarkItemCell"] autorelease];
}
BookmarkCategory * cat = GetFramework().GetBmCategory([m_balloon.setName UTF8String]);
if (cat)
Bookmark const * bm = cat->GetBookmark(indexPath.row);
if (bm)
{
Bookmark const * bm = cat->GetBookmark(indexPath.row);
if (bm)
cell.textLabel.text = [NSString stringWithUTF8String:bm->GetName().c_str()];
cell.imageView.image = [UIImage imageNamed:[NSString stringWithUTF8String:bm->GetType().c_str()]];
CompassView * compass;
// Try to reuse existing compass view
if ([cell.accessoryView isKindOfClass:[CompassView class]])
compass = (CompassView *)cell.accessoryView;
else
{
cell.textLabel.text = [NSString stringWithUTF8String:bm->GetName().c_str()];
cell.imageView.image = [UIImage imageNamed:[NSString stringWithUTF8String:bm->GetType().c_str()]];
// Create compass view
float const h = (int)(tableView.rowHeight * 0.6);
compass = [[[CompassView alloc] initWithFrame:CGRectMake(0, 0, h, h)] autorelease];
cell.accessoryView = compass;
}
CompassView * compass;
// Try to reuse existing compass view
if ([cell.accessoryView isKindOfClass:[CompassView class]])
compass = (CompassView *)cell.accessoryView;
else
double lat, lon, northR;
if ([m_locationManager getLat:lat Lon:lon])
{
m2::PointD const center = bm->GetOrg();
double const metres = ms::DistanceOnEarth(lat, lon, MercatorBounds::YToLat(center.y), MercatorBounds::XToLon(center.x));
cell.detailTextLabel.text = [LocationManager formatDistance:metres];
if ([m_locationManager getNorthRad:northR])
{
// Create compass view
float const h = (int)(tableView.rowHeight * 0.6);
compass = [[[CompassView alloc] initWithFrame:CGRectMake(0, 0, h, h)] autorelease];
cell.accessoryView = compass;
}
double lat, lon, northR;
if ([m_locationManager getLat:lat Lon:lon])
{
m2::PointD const center = bm->GetOrg();
double const metres = ms::DistanceOnEarth(lat, lon,
MercatorBounds::YToLat(center.y), MercatorBounds::XToLon(center.x));
cell.detailTextLabel.text = [LocationManager formatDistance:metres];
if ([m_locationManager getNorthRad:northR])
{
compass.angle = ang::AngleTo(m2::PointD(MercatorBounds::LonToX(lon),
compass.angle = ang::AngleTo(m2::PointD(MercatorBounds::LonToX(lon),
MercatorBounds::LatToY(lat)), center) + northR;
compass.showArrow = YES;
}
else
compass.showArrow = NO;
compass.showArrow = YES;
}
else
{
compass.showArrow = NO;
cell.detailTextLabel.text = nil;
}
}
else
{
compass.showArrow = NO;
cell.detailTextLabel.text = nil;
}
}
return cell;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Remove cell selection
[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO animated:YES];
if (indexPath.section == 0)
{
SelectSetVC * ssVC = [[SelectSetVC alloc] initWithBalloonView:m_balloon andEditMode:NO];
[self.navigationController pushViewController:ssVC animated:YES];
[ssVC release];
if (indexPath.row == 0)
{
// Edit name
// @TODO
}
}
else
{
BookmarkCategory * cat = GetFramework().GetBmCategory([m_balloon.setName UTF8String]);
Framework & f = GetFramework();
BookmarkCategory * cat = f.GetBmCategory(m_categoryIndex);
if (cat)
{
Bookmark const * bm = cat->GetBookmark(indexPath.row);
@ -189,7 +162,8 @@
{
// Same as "Close".
[self dismissModalViewControllerAnimated:YES];
GetFramework().ShowRect(bm->GetViewport());
[self.navigationController.visibleViewController dismissModalViewControllerAnimated:YES];
f.ShowRect(bm->GetViewport());
}
}
}
@ -210,7 +184,7 @@
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
BookmarkCategory * cat = GetFramework().GetBmCategory([m_balloon.setName UTF8String]);
BookmarkCategory * cat = GetFramework().GetBmCategory(m_categoryIndex);
if (cat)
{
cat->DeleteBookmark(indexPath.row);

View file

@ -3,7 +3,7 @@
#import "MapsAppDelegate.h"
#import "EAGLView.h"
#import "BalloonView.h"
#import "BookmarksVC.h"
#import "BookmarksRootVC.h"
#import "PlacePageVC.h"
#import "../Settings/SettingsManager.h"
#import "../../Common/CustomAlertView.h"
@ -107,7 +107,7 @@
- (IBAction)OnBookmarksClicked:(id)sender
{
BookmarksVC * bVC = [[BookmarksVC alloc] initWithBalloonView:m_balloonView];
BookmarksRootVC * bVC = [[BookmarksRootVC alloc] initWithBalloonView:m_balloonView];
UINavigationController * navC = [[UINavigationController alloc] initWithRootViewController:bVC];
[self presentModalViewController:navC animated:YES];
[bVC release];

View file

@ -174,6 +174,8 @@
FAA7A73514055351009F76D8 /* location-selected@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FAA7A73314055351009F76D8 /* location-selected@2x.png */; };
FAAEA7D1161BD26600CCD661 /* synonyms.txt in Resources */ = {isa = PBXBuildFile; fileRef = FAAEA7D0161BD26600CCD661 /* synonyms.txt */; };
FAAEA7D2161BD26600CCD661 /* synonyms.txt in Resources */ = {isa = PBXBuildFile; fileRef = FAAEA7D0161BD26600CCD661 /* synonyms.txt */; };
FAAEA7D5161D8D3100CCD661 /* BookmarksRootVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAAEA7D3161D8D3100CCD661 /* BookmarksRootVC.mm */; };
FAAEA7D6161D8D3100CCD661 /* BookmarksRootVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAAEA7D3161D8D3100CCD661 /* BookmarksRootVC.mm */; };
FAAFD697139D9BE2000AE70C /* categories.txt in Resources */ = {isa = PBXBuildFile; fileRef = FAAFD696139D9BE2000AE70C /* categories.txt */; };
FAAFD699139D9C6B000AE70C /* libsearch.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FAAFD698139D9C6B000AE70C /* libsearch.a */; };
FAB2D51615DAB53F00C706C3 /* arrow.png in Resources */ = {isa = PBXBuildFile; fileRef = FAB2D50C15DAB53F00C706C3 /* arrow.png */; };
@ -1476,6 +1478,8 @@
FAA7A73314055351009F76D8 /* location-selected@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "location-selected@2x.png"; sourceTree = "<group>"; };
FAAE8D5D1338FF8B003ECAD5 /* GetActiveConnectionType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetActiveConnectionType.h; sourceTree = "<group>"; };
FAAEA7D0161BD26600CCD661 /* synonyms.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = synonyms.txt; path = ../../data/synonyms.txt; sourceTree = "<group>"; };
FAAEA7D3161D8D3100CCD661 /* BookmarksRootVC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = BookmarksRootVC.mm; path = Bookmarks/BookmarksRootVC.mm; sourceTree = SOURCE_ROOT; };
FAAEA7D4161D8D3100CCD661 /* BookmarksRootVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BookmarksRootVC.h; path = Bookmarks/BookmarksRootVC.h; sourceTree = SOURCE_ROOT; };
FAAFD696139D9BE2000AE70C /* categories.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = categories.txt; path = ../../data/categories.txt; sourceTree = SOURCE_ROOT; };
FAAFD698139D9C6B000AE70C /* libsearch.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libsearch.a; sourceTree = SOURCE_ROOT; };
FAB09895148E2F1500892860 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
@ -2316,6 +2320,8 @@
FA36B80415403A4F004560CC /* BalloonView.mm */,
FA36B80515403A4F004560CC /* BookmarksVC.h */,
FA36B80615403A4F004560CC /* BookmarksVC.mm */,
FAAEA7D4161D8D3100CCD661 /* BookmarksRootVC.h */,
FAAEA7D3161D8D3100CCD661 /* BookmarksRootVC.mm */,
);
name = Bookmarks;
path = Classes;
@ -4289,6 +4295,7 @@
FA054612155C465E001F4E37 /* SelectSetVC.mm in Sources */,
FAA614B8155F16950031C345 /* AddSetVC.mm in Sources */,
FA77353C15615E2300DB495F /* SelectColorVC.mm in Sources */,
FAAEA7D5161D8D3100CCD661 /* BookmarksRootVC.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -4321,6 +4328,7 @@
FA054613155C465E001F4E37 /* SelectSetVC.mm in Sources */,
FAA614B9155F16950031C345 /* AddSetVC.mm in Sources */,
FA77353D15615E2300DB495F /* SelectColorVC.mm in Sources */,
FAAEA7D6161D8D3100CCD661 /* BookmarksRootVC.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -292,8 +292,7 @@ void BookmarkCategory::SaveToKML(ostream & s)
s << kmlHeader;
s << " <name>" << GetName() <<"</name>\n";
// Do not save bookmarks visibility. It is dynamic runtime property.
// s << " <visibility>" << (IsVisible() ? "1" : "0") <<"</visibility>\n";
s << " <visibility>" << (IsVisible() ? "1" : "0") <<"</visibility>\n";
for (size_t i = 0; i < m_bookmarks.size(); ++i)
{

View file

@ -373,15 +373,6 @@ bool Framework::DeleteBmCategory(size_t index)
else return false;
}
void Framework::SetVisibleBmCategory(string const & name)
{
for (size_t i = 0; i < m_bookmarks.size(); ++i)
{
BookmarkCategory * cat = m_bookmarks[i];
cat->SetVisible(cat->GetName() == name);
}
}
BookmarkAndCategory Framework::GetBookmark(m2::PointD pt) const
{
// @TODO Refactor. Why bookmarks can't be retrieved? Change pixel point to global point.

View file

@ -175,8 +175,6 @@ public:
/// Delete bookmarks category with all bookmarks
/// @return true if category was deleted
bool DeleteBmCategory(size_t index);
/// Makes given category visible and hides all other categories
void SetVisibleBmCategory(string const & name);
/// Get bookmark by touch.
/// @param[in] pixPt Coordinates of touch point in pixels.