forked from organicmaps/organicmaps
[iOS] Bookmarks interface.
This commit is contained in:
parent
fa4ec15660
commit
1a74b88de4
9 changed files with 275 additions and 21 deletions
14
iphone/Maps/Classes/BookmarksVC.h
Normal file
14
iphone/Maps/Classes/BookmarksVC.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
class Framework;
|
||||
|
||||
@interface BookmarksVC : UIViewController
|
||||
<UITableViewDelegate, UITableViewDataSource>
|
||||
{
|
||||
Framework * m_framework;
|
||||
UITableView * m_table;
|
||||
}
|
||||
|
||||
- (id)initWithFramework:(Framework *)f;
|
||||
@end
|
175
iphone/Maps/Classes/BookmarksVC.mm
Normal file
175
iphone/Maps/Classes/BookmarksVC.mm
Normal file
|
@ -0,0 +1,175 @@
|
|||
#import "BookmarksVC.h"
|
||||
#import "SearchCell.h"
|
||||
#import "CustomNavigationView.h"
|
||||
|
||||
#include "../../map/Framework.hpp"
|
||||
|
||||
|
||||
@implementation BookmarksVC
|
||||
|
||||
- (id)initWithFramework:(Framework *)f
|
||||
{
|
||||
if (self = [super initWithNibName:nil bundle:nil])
|
||||
{
|
||||
m_framework = f;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)loadView
|
||||
{
|
||||
UIView * parentView = [[[CustomNavigationView alloc] init] autorelease];
|
||||
parentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
|
||||
|
||||
UINavigationBar * navBar = [[[UINavigationBar alloc] init] autorelease];
|
||||
UINavigationItem * item = [[[UINavigationItem alloc] init] autorelease];
|
||||
|
||||
UIBarButtonItem * closeButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"Bookmarks - Close bookmarks button") style: UIBarButtonItemStyleDone
|
||||
target:self action:@selector(onCloseButton:)] autorelease];
|
||||
item.leftBarButtonItem = closeButton;
|
||||
|
||||
|
||||
[navBar pushNavigationItem:item 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;
|
||||
}
|
||||
|
||||
- (void)onCloseButton:(id)sender
|
||||
{
|
||||
[self dismissModalViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
// Uncomment the following line to preserve selection between presentations.
|
||||
// self.clearsSelectionOnViewWillAppear = NO;
|
||||
|
||||
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
|
||||
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
|
||||
}
|
||||
|
||||
- (void)viewDidUnload
|
||||
{
|
||||
[super viewDidUnload];
|
||||
// Release any retained subviews of the main view.
|
||||
// e.g. self.myOutlet = nil;
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated
|
||||
{
|
||||
[super viewDidAppear:animated];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewWillDisappear:animated];
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewDidDisappear:animated];
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - Table view data source
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
// Return the number of rows in the section.
|
||||
return m_framework->BookmarksCount();
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
SearchCell * cell = (SearchCell *)[tableView dequeueReusableCellWithIdentifier:@"FeatureCell"];
|
||||
if (!cell)
|
||||
cell = [[[SearchCell alloc] initWithReuseIdentifier:@"FeatureCell"] autorelease];
|
||||
|
||||
Bookmark bm;
|
||||
m_framework->GetBookmark(indexPath.row, bm);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (indexPath.row < m_framework->BookmarksCount())
|
||||
{
|
||||
Bookmark bm;
|
||||
m_framework->GetBookmark(indexPath.row, bm);
|
||||
m_framework->ShowRect(bm.GetViewport());
|
||||
|
||||
// Same as "Close".
|
||||
[self dismissModalViewControllerAnimated:YES];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// 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;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Override to support editing the table view.
|
||||
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
||||
// Delete the row from the data source
|
||||
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
}
|
||||
else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
||||
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Override to support rearranging the table view.
|
||||
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Override to support conditional rearranging of the table view.
|
||||
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
// Return NO if you do not want the item to be re-orderable.
|
||||
return YES;
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
5
iphone/Maps/Classes/CustomNavigationView.h
Normal file
5
iphone/Maps/Classes/CustomNavigationView.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface CustomNavigationView : UIView
|
||||
|
||||
@end
|
37
iphone/Maps/Classes/CustomNavigationView.mm
Normal file
37
iphone/Maps/Classes/CustomNavigationView.mm
Normal file
|
@ -0,0 +1,37 @@
|
|||
#import "CustomNavigationView.h"
|
||||
|
||||
@implementation CustomNavigationView
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
// Initialization code
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
UINavigationBar * navBar = (UINavigationBar *)[self.subviews objectAtIndex:0];
|
||||
[navBar sizeToFit];
|
||||
[navBar setNeedsDisplay];
|
||||
|
||||
UIView * table = [self.subviews objectAtIndex:1];
|
||||
CGRect rTable;
|
||||
rTable.origin = CGPointMake(navBar.frame.origin.x, navBar.frame.origin.y + navBar.frame.size.height);
|
||||
rTable.size = self.bounds.size;
|
||||
rTable.size.height -= navBar.bounds.size.height;
|
||||
table.frame = rTable;
|
||||
}
|
||||
|
||||
/*
|
||||
// Only override drawRect: if you perform custom drawing.
|
||||
// An empty implementation adversely affects performance during animation.
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
// Drawing code
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
|
@ -2,6 +2,8 @@
|
|||
#import "CompassView.h"
|
||||
#import "LocationManager.h"
|
||||
#import "SearchCell.h"
|
||||
#import "BookmarksVC.h"
|
||||
#import "CustomNavigationView.h"
|
||||
|
||||
#include "../../geometry/angles.hpp"
|
||||
#include "../../geometry/distance_on_sphere.hpp"
|
||||
|
@ -74,26 +76,6 @@ static void OnSearchResultCallback(search::Results const & res, int queryId)
|
|||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
@interface CustomView : UIView
|
||||
@end
|
||||
@implementation CustomView
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
UINavigationBar * navBar = (UINavigationBar *)[self.subviews objectAtIndex:0];
|
||||
[navBar sizeToFit];
|
||||
[navBar setNeedsDisplay];
|
||||
|
||||
UIView * table = [self.subviews objectAtIndex:1];
|
||||
CGRect rTable;
|
||||
rTable.origin = CGPointMake(navBar.frame.origin.x, navBar.frame.origin.y + navBar.frame.size.height);
|
||||
rTable.size = self.bounds.size;
|
||||
rTable.size.height -= navBar.bounds.size.height;
|
||||
table.frame = rTable;
|
||||
}
|
||||
@end
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
@implementation SearchVC
|
||||
|
||||
|
||||
|
@ -141,7 +123,7 @@ static void OnSearchResultCallback(search::Results const & res, int queryId)
|
|||
{
|
||||
// create user interface
|
||||
// Custom view is used to automatically layout all elements
|
||||
UIView * parentView = [[[CustomView alloc] init] autorelease];
|
||||
UIView * parentView = [[[CustomNavigationView alloc] init] autorelease];
|
||||
parentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
|
||||
|
||||
UINavigationBar * navBar = [[[UINavigationBar alloc] init] autorelease];
|
||||
|
@ -158,7 +140,9 @@ static void OnSearchResultCallback(search::Results const & res, int queryId)
|
|||
m_searchBar.text = g_lastSearchResults.m_searchString;
|
||||
m_searchBar.delegate = self;
|
||||
m_searchBar.placeholder = NSLocalizedString(@"Search map", @"Search box placeholder text");
|
||||
m_searchBar.showsBookmarkButton = YES;
|
||||
item.titleView = m_searchBar;
|
||||
|
||||
// Add search in progress indicator
|
||||
for(UIView * v in m_searchBar.subviews)
|
||||
{
|
||||
|
@ -499,7 +483,9 @@ static void OnSearchResultCallback(search::Results const & res, int queryId)
|
|||
{
|
||||
// Zoom to the feature
|
||||
case search::Result::RESULT_FEATURE:
|
||||
m_framework->AddBookmark(res.GetFeatureCenter(), res.GetString());
|
||||
m_framework->ShowSearchResult(res);
|
||||
|
||||
// Same as "Close" button but do not disable placemark
|
||||
[self dismissModalViewControllerAnimated:YES];
|
||||
break;
|
||||
|
@ -608,4 +594,10 @@ static void OnSearchResultCallback(search::Results const & res, int queryId)
|
|||
[m_table reloadData];
|
||||
}
|
||||
|
||||
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar
|
||||
{
|
||||
BookmarksVC * vc = [[[BookmarksVC alloc] initWithFramework:m_framework] autorelease];
|
||||
[self presentModalViewController:vc animated:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -50,6 +50,10 @@
|
|||
EEFC0BBF12B5656A002914FF /* libfreetype.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EE12020311CD464100ABDD5D /* libfreetype.a */; };
|
||||
EEFE7C1412F8C9E1006AF8C3 /* fonts_blacklist.txt in Resources */ = {isa = PBXBuildFile; fileRef = EEFE7C1212F8C9E1006AF8C3 /* fonts_blacklist.txt */; };
|
||||
EEFE7C1512F8C9E1006AF8C3 /* fonts_whitelist.txt in Resources */ = {isa = PBXBuildFile; fileRef = EEFE7C1312F8C9E1006AF8C3 /* fonts_whitelist.txt */; };
|
||||
F74243241520CAAE004D9D1E /* BookmarksVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = F74243231520CAAE004D9D1E /* BookmarksVC.mm */; };
|
||||
F74243251520CAAE004D9D1E /* BookmarksVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = F74243231520CAAE004D9D1E /* BookmarksVC.mm */; };
|
||||
F7B90CD31521E6D200C054EE /* CustomNavigationView.mm in Sources */ = {isa = PBXBuildFile; fileRef = F7B90CD21521E6D100C054EE /* CustomNavigationView.mm */; };
|
||||
F7B90CD41521E6D200C054EE /* CustomNavigationView.mm in Sources */ = {isa = PBXBuildFile; fileRef = F7B90CD21521E6D100C054EE /* CustomNavigationView.mm */; };
|
||||
F7FDD823147F30CC005900FA /* drules_proto.bin in Resources */ = {isa = PBXBuildFile; fileRef = F7FDD822147F30CC005900FA /* drules_proto.bin */; };
|
||||
FA04373212CAB83F00017494 /* libstorage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FA04373112CAB83F00017494 /* libstorage.a */; };
|
||||
FA065FED128614C400FEA989 /* MainWindow-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = FA065FEC128614C400FEA989 /* MainWindow-iPad.xib */; };
|
||||
|
@ -1291,6 +1295,10 @@
|
|||
EEF5745412DE1AD50082F472 /* libfribidi.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libfribidi.a; sourceTree = SOURCE_ROOT; };
|
||||
EEFE7C1212F8C9E1006AF8C3 /* fonts_blacklist.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = fonts_blacklist.txt; path = ../../data/fonts_blacklist.txt; sourceTree = "<group>"; };
|
||||
EEFE7C1312F8C9E1006AF8C3 /* fonts_whitelist.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = fonts_whitelist.txt; path = ../../data/fonts_whitelist.txt; sourceTree = "<group>"; };
|
||||
F74243221520CAAE004D9D1E /* BookmarksVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BookmarksVC.h; sourceTree = "<group>"; };
|
||||
F74243231520CAAE004D9D1E /* BookmarksVC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BookmarksVC.mm; sourceTree = "<group>"; };
|
||||
F7B90CD11521E6D100C054EE /* CustomNavigationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomNavigationView.h; sourceTree = "<group>"; };
|
||||
F7B90CD21521E6D100C054EE /* CustomNavigationView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomNavigationView.mm; sourceTree = "<group>"; };
|
||||
F7DD848414FE77F8005695E1 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
F7DD848514FE7C7F005695E1 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
F7DD848614FE7FE0005695E1 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
|
@ -1979,6 +1987,10 @@
|
|||
FAEC232A1501299500E024BF /* SearchSuggestionsCell.mm */,
|
||||
FABF223C13FAA97A003D4D49 /* CompassView.h */,
|
||||
FABF223D13FAA97A003D4D49 /* CompassView.mm */,
|
||||
F74243221520CAAE004D9D1E /* BookmarksVC.h */,
|
||||
F74243231520CAAE004D9D1E /* BookmarksVC.mm */,
|
||||
F7B90CD11521E6D100C054EE /* CustomNavigationView.h */,
|
||||
F7B90CD21521E6D100C054EE /* CustomNavigationView.mm */,
|
||||
);
|
||||
path = Classes;
|
||||
sourceTree = "<group>";
|
||||
|
@ -4010,6 +4022,8 @@
|
|||
FA0B7E631487747B00CAB3F2 /* GetActiveConnectionType.mm in Sources */,
|
||||
FA81AE3314D061BF00A0D70D /* SearchCell.mm in Sources */,
|
||||
FAEC232B1501299500E024BF /* SearchSuggestionsCell.mm in Sources */,
|
||||
F74243241520CAAE004D9D1E /* BookmarksVC.mm in Sources */,
|
||||
F7B90CD31521E6D200C054EE /* CustomNavigationView.mm in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -4034,6 +4048,8 @@
|
|||
FAFB08F7151215EE0041901D /* GetActiveConnectionType.mm in Sources */,
|
||||
FAFB08F8151215EE0041901D /* SearchCell.mm in Sources */,
|
||||
FAFB08F9151215EE0041901D /* SearchSuggestionsCell.mm in Sources */,
|
||||
F74243251520CAAE004D9D1E /* BookmarksVC.mm in Sources */,
|
||||
F7B90CD41521E6D200C054EE /* CustomNavigationView.mm in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -11,10 +11,13 @@ class Bookmark
|
|||
string m_name;
|
||||
|
||||
public:
|
||||
Bookmark() {}
|
||||
Bookmark(m2::PointD const & org, string const & name)
|
||||
: m_org(org), m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
m2::PointD GetOrg() const { return m_org; }
|
||||
string const & GetName() const { return m_name; }
|
||||
m2::RectD GetViewport() const { return m2::RectD(m_org, m_org); }
|
||||
};
|
||||
|
|
|
@ -186,6 +186,16 @@ void Framework::AddBookmark(m2::PointD const & pt, string const & name)
|
|||
m_bookmarks.push_back(Bookmark(pt, name));
|
||||
}
|
||||
|
||||
void Framework::GetBookmark(size_t i, Bookmark & bm) const
|
||||
{
|
||||
ASSERT_LESS(i, BookmarksCount(), ());
|
||||
|
||||
list<Bookmark>::const_iterator it = m_bookmarks.begin();
|
||||
advance(it, i); // not so fast ...
|
||||
|
||||
bm = *it;
|
||||
}
|
||||
|
||||
void Framework::ClearBookmarks()
|
||||
{
|
||||
m_bookmarks.clear();
|
||||
|
|
|
@ -125,6 +125,8 @@ public:
|
|||
void RemoveLocalMaps();
|
||||
|
||||
void AddBookmark(m2::PointD const & pt, string const & name);
|
||||
inline size_t BookmarksCount() const { return m_bookmarks.size(); }
|
||||
void GetBookmark(size_t i, Bookmark & bm) const;
|
||||
void ClearBookmarks();
|
||||
|
||||
storage::Storage & Storage() { return m_storage; }
|
||||
|
|
Loading…
Add table
Reference in a new issue