[ios] Added PlacePageView

This commit is contained in:
Igor Khmurets 2014-03-10 19:12:31 +03:00 committed by Alex Zolotarev
parent 66e0575086
commit 5f2284c113
11 changed files with 1248 additions and 85 deletions

View file

@ -7,7 +7,6 @@
#include "../../platform/platform.hpp"
#define TEXTFIELD_TAG 999
@implementation BookmarksRootVC
@ -223,6 +222,7 @@
{
Framework & f = GetFramework();
f.DeleteBmCategory(indexPath.row);
[[NSNotificationCenter defaultCenter] postNotificationName:BOOKMARK_CATEGORY_DELETED_NOTIFICATION object:@(indexPath.row)];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
// Disable edit mode if no categories are left
if (!f.GetBmCategoriesCount())

View file

@ -300,9 +300,16 @@
if (editingStyle == UITableViewCellEditingStyleDelete)
{
if (indexPath.section == m_trackSection)
{
cat->DeleteTrack(indexPath.row);
}
else
{
cat->DeleteBookmark(indexPath.row);
BookmarkAndCategory bookmarkAndCategory = BookmarkAndCategory(m_categoryIndex, indexPath.row);
NSValue * value = [NSValue valueWithBytes:&bookmarkAndCategory objCType:@encode(BookmarkAndCategory)];
[[NSNotificationCenter defaultCenter] postNotificationName:BOOKMARK_DELETED_NOTIFICATION object:value];
}
}
cat->SaveToKMLFile();
size_t previousNumberOfSections = m_numberOfSections;

View file

@ -4,6 +4,17 @@
#import "ColorPickerView.h"
#import "../../../map/bookmark.hpp"
typedef NS_ENUM(NSUInteger, PlacePageVCMode) {
PlacePageVCModeEditing,
PlacePageVCModeSaved,
};
@class PlacePageVC;
@protocol PlacePageVCDelegate <NSObject>
- (void)placePageVC:(PlacePageVC *)placePageVC didUpdateBookmarkAndCategory:(BookmarkAndCategory const &)bookmarkAndCategory;
@end
namespace search { struct AddressInfo; }
namespace url_scheme { struct ApiPoint; }
@ -15,4 +26,7 @@ namespace url_scheme { struct ApiPoint; }
- (id)initWithBookmark:(BookmarkAndCategory)bmAndCat;
- (id)initWithName:(NSString *)name andGlobalPoint:(CGPoint)point;
@property (nonatomic, weak) id <PlacePageVCDelegate> delegate;
@property (nonatomic) PlacePageVCMode mode;
@end

View file

@ -24,12 +24,9 @@
#define COORDINATECOLOR 51.0/255.0
#define BUTTONDIAMETER 18
typedef enum {Editing, Saved} Mode;
@interface PlacePageVC() <UIWebViewDelegate>
{
int m_selectedRow;
Mode m_mode;
size_t m_categoryIndex;
//statistics purpose
@ -67,7 +64,7 @@ typedef enum {Editing, Saved} Mode;
notes:@""
color:@""
category:MakeEmptyBookmarkAndCategory() point:point];
m_mode = Editing;
self.mode = PlacePageVCModeEditing;
}
return self;
}
@ -77,7 +74,7 @@ typedef enum {Editing, Saved} Mode;
self = [super initWithStyle:UITableViewStyleGrouped];
if (self)
{
m_mode = Editing;
self.mode = PlacePageVCModeEditing;
[self initializeProperties:[NSString stringWithUTF8String:apiPoint.m_name.c_str()]
notes:@""
color:@""
@ -108,7 +105,7 @@ typedef enum {Editing, Saved} Mode;
category:bmAndCat
point:CGPointMake(pt.x, pt.y)];
m_mode = Saved;
self.mode = PlacePageVCModeSaved;
}
return self;
}
@ -118,7 +115,7 @@ typedef enum {Editing, Saved} Mode;
self = [super initWithStyle:UITableViewStyleGrouped];
if (self)
{
m_mode = Editing;
self.mode = PlacePageVCModeEditing;
[self initializeProperties:name
notes:@""
color:@""
@ -155,7 +152,7 @@ typedef enum {Editing, Saved} Mode;
{
[super viewDidLoad];
self.title = NSLocalizedString(@"info", nil);
if (m_mode == Editing)
if (self.mode == PlacePageVCModeEditing)
[self addRightNavigationItemWithAction:@selector(save)];
else
[self addRightNavigationItemWithAction:@selector(edit)];
@ -176,7 +173,7 @@ typedef enum {Editing, Saved} Mode;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (m_mode == Editing)
if (self.mode == PlacePageVCModeEditing)
switch (section)
{
//name
@ -202,7 +199,7 @@ typedef enum {Editing, Saved} Mode;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 3 && m_mode == Editing)
if (indexPath.section == 3 && self.mode == PlacePageVCModeEditing)
return DESCRIPTIONHEIGHT;
return CELLHEIGHT;
}
@ -228,25 +225,25 @@ typedef enum {Editing, Saved} Mode;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0 && m_mode == Saved)
if (section == 0 && self.mode == PlacePageVCModeSaved)
return [self getCompassView].frame.size.height;
if (section == 1 && m_mode == Saved)
if (section == 1 && self.mode == PlacePageVCModeSaved)
return TWOBUTTONSHEIGHT;
return [self.tableView sectionHeaderHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == 1 && [self.pinNotes length] && m_mode == Saved)
if (section == 1 && [self.pinNotes length] && self.mode == PlacePageVCModeSaved)
return webView.scrollView.contentSize.height + 10;
return [self.tableView sectionFooterHeight];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 0 && m_mode == Saved)
if (section == 0 && self.mode == PlacePageVCModeSaved)
return [self getCompassView];
if (section == 1 && m_mode == Saved)
if (section == 1 && self.mode == PlacePageVCModeSaved)
return [[TwoButtonsView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, TWOBUTTONSHEIGHT)
leftButtonSelector:@selector(share)
rightButtonSelector:@selector(remove)
@ -258,7 +255,7 @@ typedef enum {Editing, Saved} Mode;
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (m_mode == Saved && section == 1 && [self.pinNotes length])
if (self.mode == PlacePageVCModeSaved && section == 1 && [self.pinNotes length])
{
UIView * contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.width, 20)];
if (!webView)
@ -283,7 +280,7 @@ typedef enum {Editing, Saved} Mode;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = nil;
if (m_mode == Editing)
if (self.mode == PlacePageVCModeEditing)
cell = [self cellForEditingModeWithTable:tableView cellForRowAtIndexPath:indexPath];
else
cell = [self cellForSaveModeWithTable:tableView cellForRowAtIndexPath:indexPath];
@ -293,7 +290,7 @@ typedef enum {Editing, Saved} Mode;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
if (m_mode == Editing)
if (self.mode == PlacePageVCModeEditing)
{
if (indexPath.section == 1)
{
@ -355,7 +352,7 @@ typedef enum {Editing, Saved} Mode;
- (void)addRightNavigationItemWithAction:(SEL)selector
{
UIBarButtonItem * but;
if (m_mode == Saved)
if (self.mode == PlacePageVCModeSaved)
but = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:selector];
else
but = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:selector];
@ -372,7 +369,7 @@ typedef enum {Editing, Saved} Mode;
- (void)edit
{
m_mode = Editing;
self.mode = PlacePageVCModeEditing;
[self.tableView reloadData];
[self addRightNavigationItemWithAction:@selector(save)];
}
@ -383,14 +380,19 @@ typedef enum {Editing, Saved} Mode;
{
BookmarkCategory * cat = GetFramework().GetBmCategory(_pinEditedBookmark.first);
if (cat->GetBookmarksCount() > _pinEditedBookmark.second)
{
cat->DeleteBookmark(_pinEditedBookmark.second);
cat->SaveToKMLFile();
}
[self deleteBookmarkInCategory:cat];
}
[self goToTheMap];
}
- (void)deleteBookmarkInCategory:(BookmarkCategory *)category
{
category->DeleteBookmark(_pinEditedBookmark.second);
category->SaveToKMLFile();
NSValue * value = [NSValue valueWithBytes:&_pinEditedBookmark objCType:@encode(BookmarkAndCategory)];
[[NSNotificationCenter defaultCenter] postNotificationName:BOOKMARK_DELETED_NOTIFICATION object:value];
}
- (void)share
{
ShareInfo * info = [[ShareInfo alloc] initWithText:self.pinTitle gX:_pinGlobalPosition.x gY:_pinGlobalPosition.y myPosition:NO];
@ -441,8 +443,7 @@ typedef enum {Editing, Saved} Mode;
if (_pinEditedBookmark.first != m_categoryIndex)
{
[[Statistics instance] logEvent:@"Bookmark Category" withParameters:@{@"Changed" : @"YES"}];
cat->DeleteBookmark(_pinEditedBookmark.second);
cat->SaveToKMLFile();
[self deleteBookmarkInCategory:cat];
[self addBookmarkToCategory:m_categoryIndex];
}
else
@ -453,6 +454,7 @@ typedef enum {Editing, Saved} Mode;
newBm.SetDescription([self.pinNotes UTF8String]);
f.ReplaceBookmark(_pinEditedBookmark.first, _pinEditedBookmark.second, newBm);
}
[self.delegate placePageVC:self didUpdateBookmarkAndCategory:_pinEditedBookmark];
}
}
@ -462,6 +464,7 @@ typedef enum {Editing, Saved} Mode;
bm.SetDescription([self.pinNotes UTF8String]);
_pinEditedBookmark = pair<int, int>(index, GetFramework().AddBookmark(index, bm));
[self.delegate placePageVC:self didUpdateBookmarkAndCategory:_pinEditedBookmark];
}
- (void)initializeProperties:(NSString *)name notes:(NSString *)notes color:(NSString *)color category:(BookmarkAndCategory) bmAndCat point:(CGPoint)point
@ -596,7 +599,7 @@ typedef enum {Editing, Saved} Mode;
- (void)orientationChanged
{
if (m_mode == Saved)
if (self.mode == PlacePageVCModeSaved)
{
[self.placeAndCompass drawView];
[self.tableView reloadData];

View file

@ -0,0 +1,21 @@
#import <Foundation/Foundation.h>
#include "../../geometry/point2d.hpp"
@interface LocationImageView : UIImageView
@property (nonatomic) UILabel * longitudeValueLabel;
@property (nonatomic) UILabel * latitudeValueLabel;
@property (nonatomic) UILabel * coordinatesLabel;
@property (nonatomic) UILabel * distanceLabel;
@property (nonatomic) UILabel * distanceValueLabel;
@property (nonatomic) m2::PointD pinPoint;
@property (nonatomic) CLLocation * userLocation;
@end
@interface CopyLabel : UILabel
@end

View file

@ -0,0 +1,224 @@
#import "ContextViews.h"
#import "UIKitCategories.h"
#import "LocationManager.h"
#import "MapsAppDelegate.h"
#import "Framework.h"
@implementation LocationImageView
- (instancetype)initWithImage:(UIImage *)image
{
self = [super initWithImage:image];
self.userInteractionEnabled = YES;
self.distanceLabel.hidden = YES;
self.distanceValueLabel.hidden = YES;
return self;
}
- (NSString *)distanceTitle
{
if (self.userLocation)
{
double userLatitude = self.userLocation.coordinate.latitude;
double userLongitude = self.userLocation.coordinate.longitude;
double azimut = -1;
double north = -1;
[[MapsAppDelegate theApp].m_locationManager getNorthRad:north];
string distance;
GetFramework().GetDistanceAndAzimut(self.pinPoint, userLatitude, userLongitude, north, distance, azimut);
return [NSString stringWithUTF8String:distance.c_str()];
}
return nil;
}
- (void)setUserLocation:(CLLocation *)userLocation
{
if (userLocation)
{
_userLocation = userLocation;
self.distanceValueLabel.text = [self distanceTitle];
if (self.distanceLabel.hidden)
[self layoutSubviews];
}
}
- (void)setPinPoint:(m2::PointD)pinPoint
{
_pinPoint = pinPoint;
double const longitude = MercatorBounds::XToLon(self.pinPoint.x);
self.longitudeValueLabel.text = [self coordinateString:longitude digitsCount:4];
[self.longitudeValueLabel sizeToFit];
double const latitude = MercatorBounds::YToLat(self.pinPoint.y);
self.latitudeValueLabel.text = [self coordinateString:latitude digitsCount:4];
[self.latitudeValueLabel sizeToFit];
[self layoutSubviews];
}
- (void)layoutSubviews
{
CGFloat const deltaY = 29;
CGFloat const xShift = 14;
CGFloat const yShift = 11;
CGFloat height = yShift;
NSString * distanceTitle = [self distanceTitle];
if (distanceTitle)
{
self.distanceLabel.hidden = NO;
self.distanceValueLabel.hidden = NO;
self.distanceValueLabel.text = distanceTitle;
self.distanceLabel.origin = CGPointMake(xShift, height);
self.distanceValueLabel.maxX = self.width - xShift;
self.distanceValueLabel.midY = self.distanceLabel.midY;
height += deltaY;
}
else
{
self.distanceLabel.hidden = YES;
self.distanceValueLabel.hidden = YES;
}
self.coordinatesLabel.origin = CGPointMake(xShift, height);
self.latitudeValueLabel.maxX = self.width - xShift;
self.latitudeValueLabel.midY = self.coordinatesLabel.midY;
self.longitudeValueLabel.maxX = self.latitudeValueLabel.minX - 12;
self.longitudeValueLabel.midY = self.coordinatesLabel.midY;
self.height = height + deltaY + 1;
}
- (NSString *)coordinateString:(double)coordinate digitsCount:(NSInteger)digitsCount
{
NSNumberFormatter * numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setMaximumFractionDigits:digitsCount];
[numberFormatter setMinimumFractionDigits:digitsCount];
return [numberFormatter stringFromNumber:@(coordinate)];
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
return action == @selector(copyDegreesLocation:) || action == @selector(copyDecimalLocation:);
}
- (void)copyDecimalLocation:(id)sender
{
double const longitude = MercatorBounds::XToLon(self.pinPoint.x);
double const latitude = MercatorBounds::YToLat(self.pinPoint.y);
NSString * coordinates = [NSString stringWithFormat:@"%@ %@", [self coordinateString:longitude digitsCount:7], [self coordinateString:latitude digitsCount:7]];
[UIPasteboard generalPasteboard].string = coordinates;
}
- (void)copyDegreesLocation:(id)sender
{
[self copyDecimalLocation:nil];
}
- (UILabel *)longitudeValueLabel
{
if (!_longitudeValueLabel)
_longitudeValueLabel = [self rightLabel];
return _longitudeValueLabel;
}
- (UILabel *)latitudeValueLabel
{
if (!_latitudeValueLabel)
_latitudeValueLabel = [self rightLabel];
return _latitudeValueLabel;
}
- (UILabel *)distanceValueLabel
{
if (!_distanceValueLabel)
_distanceValueLabel = [self rightLabel];
return _distanceValueLabel;
}
- (UILabel *)coordinatesLabel
{
if (!_coordinatesLabel)
_coordinatesLabel = [self leftLabelWithTitle:NSLocalizedString(@"placepage_coordinates", nil)];
return _coordinatesLabel;
}
- (UILabel *)distanceLabel
{
if (!_distanceLabel)
_distanceLabel = [self leftLabelWithTitle:NSLocalizedString(@"placepage_distance", nil)];
return _distanceLabel;
}
- (UILabel *)rightLabel
{
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 74, 18)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:@"HelveticaNeue" size:15];
label.textAlignment = NSTextAlignmentRight;
label.textColor = [UIColor colorWithColorCode:@"4cd964"];
label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[self addSubview:label];
return label;
}
- (UILabel *)leftLabelWithTitle:(NSString *)title
{
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 18)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
label.textColor = [UIColor colorWithColorCode:@"333333"];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
label.text = title;
[self addSubview:label];
return label;
}
@end
@implementation CopyLabel
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
self.userInteractionEnabled = YES;
return self;
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
return action == @selector(copy:);
}
- (void)copy:(id)sender
{
[UIPasteboard generalPasteboard].string = self.text;
}
@end

View file

@ -38,17 +38,10 @@ namespace search { struct AddressInfo; }
- (IBAction)onMyPositionClicked:(id)sender;
- (void)showSearchResultAsBookmarkAtMercatorPoint:(m2::PointD const &)pt withInfo:(search::AddressInfo const &)info;
- (void)showBalloonWithCategoryIndex:(int)cat andBookmarkIndex:(int)bm;
- (void)prepareForApi;
- (void)clearApiMode;
- (BOOL)shouldShowNavBar;
- (void)dismissPopover;
@property (nonatomic) BOOL isApiMode;
@property (weak, nonatomic) IBOutlet UIView * zoomButtonsView;
@property (nonatomic) SideToolbar * sideToolbar;
@property (nonatomic, strong) UIPopoverController * popoverVC;

View file

@ -150,23 +150,19 @@ const long long LITE_IDL = 431183278L;
[self pushViewController:preview];
}
- (void)poiBalloonClicked:(m2::PointD const &)pt info:(search::AddressInfo const &)info
- (void)additionalLayer:(size_t)index
{
PlacePreviewViewController * preview = [[PlacePreviewViewController alloc] initWith:info point:CGPointMake(pt.x, pt.y)];
m_popoverPos = CGPointMake(pt.x, pt.y);
[self pushViewController:preview];
Framework & framework = GetFramework();
Bookmark const * bookmark = framework.AdditionalPoiLayerGetBookmark(index);
[self.placePageView showBookmark:*bookmark];
[self.placePageView setState:PlacePageStateBitShown animated:YES];
}
- (void)apiBalloonClicked:(url_scheme::ApiPoint const &)apiPoint
{
if (GetFramework().GoBackOnBalloonClick() && [MWMApi canOpenApiUrl:apiPoint])
{
[MWMApi openAppWithPoint:apiPoint];
return;
}
PlacePreviewViewController * apiPreview = [[PlacePreviewViewController alloc] initWithApiPoint:apiPoint];
m_popoverPos = CGPointMake(MercatorBounds::LonToX(apiPoint.m_lon), MercatorBounds::LatToY(apiPoint.m_lat));
[self pushViewController:apiPreview];
[self.placePageView showApiPoint:apiPoint];
[self.placePageView setState:PlacePageStateBitShown animated:YES];
}
- (void)bookmarkBalloonClicked:(BookmarkAndCategory const &)bmAndCat
@ -703,8 +699,6 @@ const long long LITE_IDL = 431183278L;
if (!f.LoadState())
f.SetMaxWorldRect();
_isApiMode = NO;
f.Invalidate();
f.LoadBookmarks();
}
@ -715,6 +709,32 @@ const long long LITE_IDL = 431183278L;
#pragma mark - Getters
- (PlacePageView *)placePageView
{
if (!_placePageView)
{
_placePageView = [[PlacePageView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 0)];
_placePageView.minY = self.view.height;
_placePageView.delegate = self;
_placePageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[_placePageView addObserver:self forKeyPath:@"state" options:NSKeyValueObservingOptionNew context:nil];
}
return _placePageView;
}
- (SearchView *)searchView
{
if (!_searchView)
{
_searchView = [[SearchView alloc] initWithFrame:self.view.bounds];
_searchView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[_searchView addObserver:self forKeyPath:@"active" options:NSKeyValueObservingOptionNew context:nil];
}
return _searchView;
}
#define LOCATION_BUTTON_MID_Y (self.view.height - 28)
- (LocationButton *)locationButton
{
if (!_locationButton)
@ -789,12 +809,15 @@ const long long LITE_IDL = 431183278L;
_sideToolbar.slideView = toolbarButton;
[_sideToolbar addObserver:self forKeyPath:@"isMenuHidden" options:NSKeyValueObservingOptionNew context:nil];
}
return _sideToolbar;
- (void)placePageView:(PlacePageView *)placePage willEditBookmarkAndCategory:(BookmarkAndCategory const &)bookmarkAndCategory
{
PlacePageVC * vc = [[PlacePageVC alloc] initWithBookmark:bookmarkAndCategory];
vc.delegate = self;
vc.mode = PlacePageVCModeEditing;
[self pushViewController:vc];
}
- (UINavigationBar *)apiNavigationBar
- (void)placePageView:(PlacePageView *)placePage willEditBookmarkWithInfo:(search::AddressInfo const &)addressInfo point:(m2::PointD const &)point
{
if (!_apiNavigationBar)
{
@ -809,6 +832,19 @@ const long long LITE_IDL = 431183278L;
return _apiNavigationBar;
}
- (void)placePageView:(PlacePageView *)placePage willShareInfo:(search::AddressInfo const &)addressInfo point:(m2::PointD const &)point
{
NSString * text = [NSString stringWithUTF8String:addressInfo.GetPinName().c_str()];
ShareInfo * info = [[ShareInfo alloc] initWithText:text gX:point.x gY:point.y myPosition:NO];
self.shareActionSheet = [[ShareActionSheet alloc] initWithInfo:info viewController:self];
[self.shareActionSheet show];
}
- (void)placePageVC:(PlacePageVC *)placePageVC didUpdateBookmarkAndCategory:(BookmarkAndCategory const &)bookmarkAndCategory
{
[self.placePageView showBookmarkAndCategory:bookmarkAndCategory];
}
#pragma mark - SideToolbarDelegate
- (void)sideToolbar:(SideToolbar *)toolbar didPressButtonAtIndex:(NSInteger)buttonIndex
@ -929,33 +965,39 @@ const long long LITE_IDL = 431183278L;
darkTail.alpha = self.sideToolbar.isMenuHidden ? 0 : 1;
}];
}
else if (object == self.placePageView && [keyPath isEqualToString:@"state"])
{
[UIView animateWithDuration:0.5 delay:0 damping:0.8 initialVelocity:0 options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction) animations:^{
switch (self.placePageView.state)
{
case PlacePageStateHidden:
self.sideToolbar.slideView.midY = SLIDE_VIEW_MID_Y;
self.locationButton.midY = LOCATION_BUTTON_MID_Y;
GetFramework().GetBalloonManager().RemovePin();
break;
case PlacePageStateBitShown:
self.sideToolbar.slideView.midY = SLIDE_VIEW_MID_Y - (self.view.height - self.placePageView.minY);
self.locationButton.midY = LOCATION_BUTTON_MID_Y - (self.view.height - self.placePageView.minY);
break;
case PlacePageStateOpened:
Framework & f = GetFramework();
CGFloat x = self.view.width / 2;
CGFloat y = (self.searchView.searchBar.maxY + self.placePageView.minY) / 2;
CGPoint const center = [(EAGLView *)self.view viewPoint2GlobalPoint:CGPointMake(x, y)];
m2::PointD const offsetV = self.placePageView.pinPoint - m2::PointD(center.x, center.y);
f.SetViewportCenterAnimated(f.GetViewportCenter() + offsetV);
break;
}
} completion:nil];
}
}
#pragma mark - Public methods
- (void)prepareForApi
{
_isApiMode = YES;
if ([self shouldShowNavBar])
{
self.apiNavigationBar.topItem.title = [NSString stringWithUTF8String:GetFramework().GetMapApiAppTitle().c_str()];
[UIView animateWithDuration:0.3 animations:^{
self.apiNavigationBar.alpha = 1;
}];
[self dismissPopover];
}
}
- (void)clearApiMode
{
_isApiMode = NO;
[self invalidate];
[UIView animateWithDuration:0.3 animations:^{
self.apiNavigationBar.alpha = 0;
}];
Framework & f = GetFramework();
f.ClearMapApiPoints();
f.GetBalloonManager().Hide();
[self dismissPopover];
self.searchView.searchBar.apiText = [NSString stringWithUTF8String:GetFramework().GetMapApiAppTitle().c_str()];
}
+ (NSURL *)getBackUrl
@ -963,17 +1005,6 @@ const long long LITE_IDL = 431183278L;
return [NSURL URLWithString:[NSString stringWithUTF8String:GetFramework().GetMapApiBackUrl().c_str()]];
}
- (void)returnToApiApp
{
[APP openURL:[MapViewController getBackUrl]];
[self clearApiMode];
}
- (BOOL)shouldShowNavBar
{
return (_isApiMode && [APP canOpenURL:[MapViewController getBackUrl]]);
}
- (void)setupMeasurementSystem
{
GetFramework().SetupMeasurementSystem();

View file

@ -0,0 +1,37 @@
#import <UIKit/UIKit.h>
#include "../../map/bookmark.hpp"
#include "../../geometry/point2d.hpp"
namespace search { struct AddressInfo; }
namespace url_scheme { struct ApiPoint; }
typedef NS_ENUM(NSUInteger, PlacePageState) {
PlacePageStateHidden,
PlacePageStateBitShown,
PlacePageStateOpened,
};
@class PlacePageView;
@protocol PlacePageViewDelegate <NSObject>
- (void)placePageView:(PlacePageView *)placePage willEditBookmarkWithInfo:(search::AddressInfo const &)addressInfo point:(const m2::PointD &)point;
- (void)placePageView:(PlacePageView *)placePage willEditBookmarkAndCategory:(BookmarkAndCategory const &)bookmarkAndCategory;
- (void)placePageView:(PlacePageView *)placePage willShareInfo:(search::AddressInfo const &)addressInfo point:(const m2::PointD &)point;
@end
@interface PlacePageView : UIView
- (void)showPoint:(m2::PointD const &)point addressInfo:(search::AddressInfo const &)addressInfo;
- (void)showBookmarkAndCategory:(BookmarkAndCategory const &)bookmarkAndCategory;
- (void)showBookmark:(Bookmark const &)bookmark;
- (void)showApiPoint:(url_scheme::ApiPoint const &)point;
- (void)setState:(PlacePageState)state animated:(BOOL)animated;
@property (nonatomic, readonly) PlacePageState state;
@property (nonatomic, weak) id <PlacePageViewDelegate> delegate;
@property (nonatomic, readonly) m2::PointD pinPoint;
@end

View file

@ -0,0 +1,820 @@
#import "PlacePageView.h"
#import "UIKitCategories.h"
#import "LocationManager.h"
#import "MapsAppDelegate.h"
#import "MapViewController.h"
#import "BookmarksRootVC.h"
#import "Framework.h"
#import "ContextViews.h"
#include "../../search/result.hpp"
@interface PlacePageView () <LocationObserver, UIGestureRecognizerDelegate>
@property (nonatomic) CopyLabel * titleLabel;
@property (nonatomic) UIButton * bookmarkButton;
@property (nonatomic) UILabel * typeLabel;
@property (nonatomic) UIView * lineView;
@property (nonatomic) CopyLabel * addressLabel;
@property (nonatomic) LocationImageView * locationView;
@property (nonatomic) UIButton * shareButton;
@property (nonatomic) UIButton * editButton;
@property (nonatomic) UIButton * largeShareButton;
@property (nonatomic) UIScrollView * scrollView;
@property (nonatomic) UIButton * guideButton;
@property (nonatomic) UIImageView * guideImageView;
@property (nonatomic) UILabel * guideLeftLabel;
@property (nonatomic) UILabel * guideRightLabel;
@property (nonatomic) CGFloat pageShift;
@property (nonatomic) CGFloat maximumPageShift;
@property (nonatomic) CGFloat startPageShift;
@property (nonatomic) BOOL empty;
@property (nonatomic) BOOL isBookmark;
@property (nonatomic) BOOL loadedAsBookmark;
@property (nonatomic) BOOL isApiPoint;
@property (nonatomic) search::AddressInfo addressInfo;
@property (nonatomic) BookmarkAndCategory bookmarkAndCategory;
@property (nonatomic) m2::PointD pinPoint;
@property (nonatomic) Bookmark bookmark;
@end
@implementation PlacePageView
{
CGFloat locationMidY;
CGFloat addressMidY;
CGFloat shareMidY;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
self.backgroundColor = [UIColor applicationBackgroundColor];
self.clipsToBounds = YES;
self.empty = YES;
UIView * tapView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 56)];
tapView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self addSubview:tapView];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[tapView addGestureRecognizer:tap];
UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self addGestureRecognizer:pan];
UISwipeGestureRecognizer * swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
[self addGestureRecognizer:swipeDown];
[self addSubview:self.titleLabel];
[self addSubview:self.typeLabel];
[self addSubview:self.bookmarkButton];
[self addSubview:self.lineView];
[self addSubview:self.scrollView];
[self.scrollView addSubview:self.addressLabel];
[self.scrollView addSubview:self.locationView];
[self.scrollView addSubview:self.shareButton];
[self.scrollView addSubview:self.guideButton];
[self.scrollView addSubview:self.editButton];
[self.scrollView addSubview:self.largeShareButton];
[self layoutShareAndEditButtons];
[self setState:PlacePageStateHidden animated:NO];
UILongPressGestureRecognizer * locationPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(locationPress:)];
[self.locationView addGestureRecognizer:locationPress];
UILongPressGestureRecognizer * titlePress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(labelPress:)];
[self.titleLabel addGestureRecognizer:titlePress];
UITapGestureRecognizer * titleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[self.titleLabel addGestureRecognizer:titleTap];
UILongPressGestureRecognizer * addressPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(labelPress:)];
[self.addressLabel addGestureRecognizer:addressPress];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bookmarkDeletedNotification:) name:BOOKMARK_DELETED_NOTIFICATION object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bookmarkCategoryDeletedNotification:) name:BOOKMARK_CATEGORY_DELETED_NOTIFICATION object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(metricsChangedNotification:) name:METRICS_CHANGED_NOTIFICATION object:nil];
return self;
}
- (void)layoutShareAndEditButtons
{
CGFloat const borderOffset = 21;
CGFloat const betweenOffset = 4;
CGFloat width = (self.width - 2 * borderOffset - betweenOffset) / 2;
self.shareButton.width = width;
self.shareButton.minX = borderOffset;
self.editButton.width = width;
self.editButton.minX = self.shareButton.maxX + betweenOffset;
self.largeShareButton.width = self.width - 2 * borderOffset;
self.largeShareButton.midX = self.width / 2;
}
- (void)metricsChangedNotification:(NSNotification *)notification
{
self.locationView.pinPoint = self.pinPoint;
}
- (void)bookmarkCategoryDeletedNotification:(NSNotification *)notification
{
if (self.bookmarkAndCategory.first == [[notification object] integerValue])
{
[self deleteBookmark];
[self updateBookmarkStateAnimated:NO];
}
}
- (void)bookmarkDeletedNotification:(NSNotification *)notification
{
BookmarkAndCategory bookmarkAndCategory;
[[notification object] getValue:&bookmarkAndCategory];
if (bookmarkAndCategory == self.bookmarkAndCategory)
{
[self deleteBookmark];
[self updateBookmarkStateAnimated:NO];
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {}
- (void)setState:(PlacePageState)state animated:(BOOL)animated
{
[self setState:state duration:(animated ? 0.5 : 0)];
}
- (void)setState:(PlacePageState)state duration:(NSTimeInterval)duration
{
[UIView animateWithDuration:duration delay:0 damping:0.75 initialVelocity:0 options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction) animations:^{
if (state == PlacePageStateHidden)
self.pageShift = 0;
else if (state == PlacePageStateBitShown)
self.pageShift = self.lineView.minY;
else if (state == PlacePageStateOpened)
self.pageShift = self.maximumPageShift;
} completion:nil];
[UIView animateWithDuration:(duration + 0.15) delay:0 damping:0.8 initialVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
if (state == PlacePageStateBitShown)
{
self.locationView.midY = locationMidY + 40;
self.addressLabel.midY = addressMidY + 32;
self.shareButton.midY = shareMidY + 26;
self.editButton.midY = self.shareButton.midY;
self.largeShareButton.midY = self.shareButton.midY;
}
else if (state == PlacePageStateOpened)
{
self.locationView.midY = locationMidY;
self.addressLabel.midY = addressMidY;
self.shareButton.midY = shareMidY;
self.editButton.midY = self.shareButton.midY;
self.largeShareButton.midY = self.shareButton.midY;
}
} completion:nil];
[self willChangeValueForKey:@"state"];
_state = state;
[self didChangeValueForKey:@"state"];
}
- (void)setPageShift:(CGFloat)pageShift
{
CGFloat delta = pageShift - self.maximumPageShift;
if (delta > 0)
{
delta = MIN(50, powf(delta, 0.65));
pageShift = self.maximumPageShift + delta;
}
pageShift = MAX(0, pageShift);
self.minY = self.superview.height - pageShift;
_pageShift = pageShift;
}
- (void)swipe:(UISwipeGestureRecognizer *)sender
{
if (sender.direction == UISwipeGestureRecognizerDirectionDown && self.state == PlacePageStateBitShown)
[self setState:PlacePageStateHidden animated:YES];
}
- (void)labelPress:(UILongPressGestureRecognizer *)sender
{
UIMenuController * menuController = [UIMenuController sharedMenuController];
if (!menuController.isMenuVisible)
{
CGPoint tapPoint = [sender locationInView:sender.view.superview];
[menuController setTargetRect:CGRectMake(tapPoint.x, sender.view.minY, 0, 0) inView:sender.view.superview];
[menuController setMenuVisible:YES animated:YES];
[sender.view becomeFirstResponder];
[menuController update];
}
}
- (void)locationPress:(UILongPressGestureRecognizer *)sender
{
UIMenuController * menuController = [UIMenuController sharedMenuController];
if (!menuController.isMenuVisible)
{
UIMenuItem * item1 = [[UIMenuItem alloc] initWithTitle:@"Copy degrees" action:@selector(copyDegreesLocation:)];
UIMenuItem * item2 = [[UIMenuItem alloc] initWithTitle:@"Copy decimal" action:@selector(copyDecimalLocation:)];
menuController.menuItems = @[item1, item2];
CGPoint tapPoint = [sender locationInView:sender.view.superview];
[menuController setTargetRect:CGRectMake(tapPoint.x, sender.view.minY, 0, 0) inView:sender.view.superview];
[menuController setMenuVisible:YES animated:YES];
[sender.view becomeFirstResponder];
[menuController update];
}
}
- (void)tap:(UITapGestureRecognizer *)sender
{
if (self.state == PlacePageStateBitShown)
[self setState:PlacePageStateOpened animated:YES];
else if (self.state == PlacePageStateOpened)
[self setState:PlacePageStateBitShown animated:YES];
}
- (void)pan:(UIPanGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateBegan)
{
self.startPageShift = self.pageShift;
self.locationView.midY = locationMidY;
self.addressLabel.midY = addressMidY;
self.shareButton.midY = shareMidY;
self.editButton.midY = self.shareButton.midY;
self.largeShareButton.midY = self.shareButton.midY;
}
self.pageShift = self.startPageShift - [sender translationInView:self.superview].y;
if (sender.state == UIGestureRecognizerStateCancelled || sender.state == UIGestureRecognizerStateEnded)
{
CGFloat velocity = [sender velocityInView:self.superview].y;
CGFloat const minV = 1000;
CGFloat const maxV = 5000;
BOOL isPositive = velocity > 0;
CGFloat absV = ABS(velocity);
absV = MIN(maxV, MAX(minV, absV));
PlacePageState state;
if (isPositive)
state = self.pageShift < (self.lineView.midY - 1) ? PlacePageStateHidden : PlacePageStateBitShown;
else
state = PlacePageStateOpened;
NSTimeInterval duration = 500 / absV;
[self setState:state duration:duration];
}
}
- (void)layoutSubviews
{
[self updateHeight];
if (self.state == PlacePageStateOpened)
self.pageShift = self.maximumPageShift;
}
- (void)updateHeight
{
if (self.empty)
{
self.height = 0;
return;
}
if (!self.titleLabel.hidden)
{
[self.titleLabel sizeToFit];
self.titleLabel.size = CGSizeMake(MIN(self.titleLabel.width, self.width - 70), 22);
self.titleLabel.origin = CGPointMake(23, 9);
}
if (!self.typeLabel.hidden)
{
[self.typeLabel sizeToFit];
self.typeLabel.width += 4;
self.typeLabel.height += 2;
self.typeLabel.origin = CGPointMake(self.titleLabel.minX + 1, self.titleLabel.maxY + 1);
}
self.bookmarkButton.hidden = NO;
self.bookmarkButton.center = CGPointMake(self.width - 32, 28);
CGFloat lineOffsetX = 10;
self.lineView.size = CGSizeMake(self.width - 2 * lineOffsetX, 0.5);
self.lineView.origin = CGPointMake(lineOffsetX, 56);
self.lineView.hidden = NO;
CGFloat shift = 12;
if (!self.addressLabel.hidden)
{
CGFloat const offsetX = 22;
self.addressLabel.width = self.width - 2 * offsetX;
[self.addressLabel sizeToFit];
self.addressLabel.origin = CGPointMake(offsetX, shift);
shift = self.addressLabel.maxY;
addressMidY = self.addressLabel.midY;
}
if (!self.locationView.hidden)
{
self.locationView.midX = self.width / 2;
self.locationView.minY = shift + 15;
shift = self.locationView.maxY;
locationMidY = self.locationView.midY;
}
if (self.isApiPoint)
{
self.guideButton.hidden = NO;
self.guideButton.midX = self.width / 2;
self.guideButton.minY = shift + 9;
shift = self.guideButton.maxY;
}
self.editButton.hidden = NO;
self.shareButton.hidden = NO;
self.largeShareButton.hidden = NO;
self.shareButton.minY = shift + 9;
self.largeShareButton.minY = self.shareButton.minY;
self.editButton.minY = self.shareButton.minY;
shareMidY = self.shareButton.midY;
shift = self.shareButton.maxY + 14;
CGFloat maxHeight = self.superview.height - 68;
self.maximumPageShift = MIN(shift + self.lineView.maxY, maxHeight);
self.height = self.maximumPageShift + 50;
self.scrollView.frame = CGRectMake(0, self.lineView.maxY, self.width, self.height - self.lineView.maxY);
self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, self.height - self.maximumPageShift, 0);
self.scrollView.contentSize = CGSizeMake(self.scrollView.width, shift);
}
- (void)hideAll
{
self.typeLabel.hidden = YES;
[self.scrollView.subviews makeObjectsPerformSelector:@selector(setHidden:) withObject:@YES];
}
- (void)editButtonPressed:(id)sender
{
if (self.isBookmark)
[self.delegate placePageView:self willEditBookmarkAndCategory:self.bookmarkAndCategory];
else
[self.delegate placePageView:self willEditBookmarkWithInfo:self.addressInfo point:self.pinPoint];
}
- (void)shareButtonPressed:(id)sender
{
[self.delegate placePageView:self willShareInfo:self.addressInfo point:self.pinPoint];
}
- (void)bookmarkButtonPressed:(UIButton *)sender
{
if (self.isBookmark)
[self deleteBookmark];
else
[self addBookmark];
[self updateBookmarkStateAnimated:YES];
}
- (void)guideButtonPressed:(id)sender
{
NSString * urlString = [NSString stringWithUTF8String:GetFramework().GetMapApiBackUrl().c_str()];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
- (void)showPoint:(m2::PointD const &)point addressInfo:(search::AddressInfo const &)addressInfo
{
self.isApiPoint = NO;
[self processPoint:point addressInfo:addressInfo];
}
- (void)showApiPoint:(url_scheme::ApiPoint const &)apiPoint
{
Framework & framework = GetFramework();
m2::PointD point;
point.x = MercatorBounds::LonToX(apiPoint.m_lon);
point.y = MercatorBounds::LatToY(apiPoint.m_lat);
search::AddressInfo addressInfo;
framework.GetAddressInfoForGlobalPoint(point, addressInfo);
self.isApiPoint = YES;
NSString * appTitle = [NSString stringWithUTF8String:framework.GetMapApiAppTitle().c_str()];
if ([appTitle isEqualToString:@"GuideWithMe"])
{
NSString * urlString = [NSString stringWithUTF8String:framework.GetMapApiBackUrl().c_str()];
NSString * lastComponent = [urlString componentsSeparatedByString:@"-"][1];
NSString * imageName = [[lastComponent substringWithRange:NSMakeRange(0, [lastComponent length] - 3)] capitalizedString];
self.guideLeftLabel.text = NSLocalizedString(@"more_info", nil);
[self.guideLeftLabel sizeToFit];
self.guideRightLabel.text = appTitle;
[self.guideRightLabel sizeToFit];
self.guideImageView.image = [self iconImageWithImage:[UIImage imageNamed:imageName]];
CGFloat const betweenSpace = 4;
CGFloat const width = self.guideLeftLabel.width + self.guideImageView.width + self.guideRightLabel.width + 2 * betweenSpace;
UIView * contentView = self.guideImageView.superview;
CGFloat const startX = (contentView.width - width) / 2;
self.guideLeftLabel.minX = startX;
self.guideImageView.minX = self.guideLeftLabel.maxX + betweenSpace;
self.guideRightLabel.minX = self.guideImageView.maxX + betweenSpace;
self.guideLeftLabel.midY = contentView.height / 2;
self.guideImageView.midY = contentView.height / 2;
self.guideRightLabel.midY = contentView.height / 2;
[self.guideButton setTitle:nil forState:UIControlStateNormal];
}
else
{
self.guideLeftLabel.text = nil;
self.guideRightLabel.text = nil;
self.guideImageView.image = nil;
[self.guideButton setTitle:appTitle forState:UIControlStateNormal];
}
self.titleLabel.text = [NSString stringWithUTF8String:apiPoint.m_name.c_str()];
[self processPoint:point addressInfo:addressInfo];
}
- (void)processPoint:(m2::PointD const &)point addressInfo:(search::AddressInfo const &)addressInfo
{
[[MapsAppDelegate theApp].m_locationManager start:self];
self.loadedAsBookmark = NO;
self.addressInfo = addressInfo;
self.pinPoint = point;
self.empty = NO;
[self hideAll];
if (!self.isApiPoint)
self.titleLabel.text = addressInfo.GetPinName().empty() ? NSLocalizedString(@"dropped_pin", nil) : [NSString stringWithUTF8String:addressInfo.GetPinName().c_str()];
self.titleLabel.hidden = NO;
if (!addressInfo.GetPinType().empty())
{
self.typeLabel.text = [NSString stringWithUTF8String:addressInfo.GetPinType().c_str()];
self.typeLabel.hidden = NO;
}
self.addressLabel.text = [NSString stringWithUTF8String:addressInfo.FormatAddress().c_str()];
self.addressLabel.hidden = ![self.addressLabel.text length];
self.locationView.hidden = NO;
self.locationView.pinPoint = self.pinPoint;
self.isBookmark = NO;
[self updateHeight];
[self updateBookmarkStateAnimated:NO];
}
- (void)showBookmark:(Bookmark const &)bookmark
{
Framework & framework = GetFramework();
[[MapsAppDelegate theApp].m_locationManager start:self];
self.loadedAsBookmark = NO;
self.isApiPoint = NO;
self.pinPoint = bookmark.GetOrg();
search::AddressInfo addressInfo;
framework.GetAddressInfoForGlobalPoint(self.pinPoint, addressInfo);
addressInfo.m_name = bookmark.GetName();
self.addressInfo = addressInfo;
self.empty = NO;
[self hideAll];
self.titleLabel.text = addressInfo.GetPinName().empty() ? NSLocalizedString(@"dropped_pin", nil) : [NSString stringWithUTF8String:addressInfo.GetPinName().c_str()];
self.titleLabel.hidden = NO;
if (!addressInfo.GetPinType().empty())
{
self.typeLabel.text = [NSString stringWithUTF8String:addressInfo.GetPinType().c_str()];
self.typeLabel.hidden = NO;
}
self.addressLabel.text = [NSString stringWithUTF8String:addressInfo.FormatAddress().c_str()];
self.addressLabel.hidden = ![self.addressLabel.text length];
self.locationView.hidden = NO;
self.locationView.pinPoint = self.pinPoint;
self.isBookmark = NO;
[self updateHeight];
[self updateBookmarkStateAnimated:NO];
}
- (void)showBookmarkAndCategory:(BookmarkAndCategory const &)bookmarkAndCategory
{
Framework & framework = GetFramework();
[[MapsAppDelegate theApp].m_locationManager start:self];
self.bookmarkAndCategory = bookmarkAndCategory;
self.loadedAsBookmark = YES;
self.isApiPoint = NO;
BookmarkCategory const * category = framework.GetBmCategory(bookmarkAndCategory.first);
self.bookmark = *(category->GetBookmark(bookmarkAndCategory.second));
self.pinPoint = self.bookmark.GetOrg();
self.empty = NO;
[self hideAll];
self.titleLabel.text = self.bookmark.GetName().empty() ? NSLocalizedString(@"dropped_pin", nil) : [NSString stringWithUTF8String:self.bookmark.GetName().c_str()];
self.titleLabel.hidden = NO;
if (!self.bookmark.GetType().empty())
{
self.typeLabel.text = [NSString stringWithUTF8String:self.bookmark.GetType().c_str()];
self.typeLabel.hidden = NO;
}
search::AddressInfo addressInfo;
framework.GetAddressInfoForGlobalPoint(self.pinPoint, addressInfo);
self.addressInfo = addressInfo;
self.addressLabel.text = [NSString stringWithUTF8String:addressInfo.FormatAddress().c_str()];
self.addressLabel.hidden = ![self.addressLabel.text length];
self.locationView.hidden = NO;
self.locationView.pinPoint = self.pinPoint;
self.isBookmark = YES;
[self updateHeight];
[self updateBookmarkStateAnimated:NO];
}
- (UIImage *)iconImageWithImage:(UIImage *)image
{
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale);
[[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:5.5] addClip];
[image drawInRect:rect];
UIImage * iconImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return iconImage;
}
- (void)deleteBookmark
{
BookmarkCategory * category = GetFramework().GetBmCategory(self.bookmarkAndCategory.first);
if (category)
category->DeleteBookmark(self.bookmarkAndCategory.second);
self.isBookmark = NO;
}
- (void)addBookmark
{
Framework & framework = GetFramework();
if (self.loadedAsBookmark)
{
size_t categoryIndex = self.bookmarkAndCategory.first;
BookmarkCategory const * category = framework.GetBmCategory(categoryIndex);
if (!category)
categoryIndex = framework.LastEditedBMCategory();
Bookmark bookmark(self.bookmark.GetOrg(), self.bookmark.GetName(), self.bookmark.GetType());
bookmark.SetDescription(self.bookmark.GetDescription());
bookmark.SetTimeStamp(self.bookmark.GetTimeStamp());
bookmark.SetScale(self.bookmark.GetScale());
framework.AddBookmark(categoryIndex, bookmark);
}
else
{
size_t categoryIndex = framework.LastEditedBMCategory();
std::string const & name = self.addressInfo.GetPinName().empty() ? [NSLocalizedString(@"dropped_pin", nil) UTF8String] : self.addressInfo.GetPinName().c_str();
Bookmark bookmark(self.pinPoint, name, "placemark-red");
self.bookmarkAndCategory = BookmarkAndCategory(categoryIndex, framework.AddBookmark(categoryIndex, bookmark));
}
self.isBookmark = YES;
}
- (void)updateBookmarkStateAnimated:(BOOL)animated
{
self.bookmarkButton.selected = self.isBookmark;
[UIView animateWithDuration:0.25 animations:^{
self.largeShareButton.alpha = self.isBookmark ? 0 : 1;
}];
}
- (void)onLocationError:(location::TLocationError)errorCode
{
NSLog(@"Location error in PlacePageView");
}
- (void)onLocationUpdate:(location::GpsInfo const &)info
{
CGFloat oldHeight = self.locationView.height;
self.locationView.userLocation = [MapsAppDelegate theApp].m_locationManager.lastLocation;
if (oldHeight != self.locationView.height)
{
[self updateHeight];
[self setState:self.state animated:YES];
}
}
- (CopyLabel *)titleLabel
{
if (!_titleLabel)
{
_titleLabel = [[CopyLabel alloc] initWithFrame:CGRectZero];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:17.5];
_titleLabel.textColor = [UIColor colorWithColorCode:@"333333"];
_titleLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
}
return _titleLabel;
}
- (UILabel *)typeLabel
{
if (!_typeLabel)
{
_typeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_typeLabel.backgroundColor = [UIColor colorWithColorCode:@"33cc66"];
_typeLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:10];
_typeLabel.textAlignment = NSTextAlignmentCenter;
_typeLabel.textColor = [UIColor whiteColor];
_typeLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
}
return _typeLabel;
}
- (UIView *)lineView
{
if (!_lineView)
{
_lineView = [[UIView alloc] initWithFrame:CGRectZero];
_lineView.backgroundColor = [UIColor colorWithColorCode:@"cccccc"];
_lineView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
}
return _lineView;
}
- (CopyLabel *)addressLabel
{
if (!_addressLabel)
{
_addressLabel = [[CopyLabel alloc] initWithFrame:CGRectZero];
_addressLabel.backgroundColor = [UIColor clearColor];
_addressLabel.numberOfLines = 0;
_addressLabel.lineBreakMode = NSLineBreakByWordWrapping;
_addressLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
_addressLabel.textColor = [UIColor colorWithColorCode:@"333333"];
_addressLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
}
return _addressLabel;
}
- (UIButton *)bookmarkButton
{
if (!_bookmarkButton)
{
_bookmarkButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 64, 44)];
_bookmarkButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[_bookmarkButton setImage:[UIImage imageNamed:@"PlacePageBookmarkButton"] forState:UIControlStateNormal];
[_bookmarkButton setImage:[UIImage imageNamed:@"PlacePageBookmarkButtonSelected"] forState:UIControlStateSelected];
[_bookmarkButton addTarget:self action:@selector(bookmarkButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
}
return _bookmarkButton;
}
- (LocationImageView *)locationView
{
if (!_locationView)
{
UIImage * image = [[UIImage imageNamed:@"PlacePageLocationBackground"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
_locationView = [[LocationImageView alloc] initWithImage:image];
_locationView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
}
return _locationView;
}
- (UIButton *)guideButton
{
if (!_guideButton)
{
UIImage * image = [[UIImage imageNamed:@"PlacePageGuideButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
_guideButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
_guideButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15];
_guideButton.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[_guideButton setBackgroundImage:image forState:UIControlStateNormal];
[_guideButton addTarget:self action:@selector(guideButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[_guideButton setTitleColor:[UIColor colorWithColorCode:@"33cc66"] forState:UIControlStateNormal];
UIView * contentView = [[UIView alloc] initWithFrame:_guideButton.bounds];
contentView.userInteractionEnabled = NO;
contentView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[_guideButton addSubview:contentView];
UIImageView * guideImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 17, 17)];
guideImageView.origin = CGPointMake(104, 10);
[contentView addSubview:guideImageView];
self.guideImageView = guideImageView;
UILabel * leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, image.size.height)];
leftLabel.backgroundColor = [UIColor clearColor];
leftLabel.textAlignment = NSTextAlignmentRight;
leftLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15];
leftLabel.textColor = [UIColor colorWithColorCode:@"33cc66"];
[contentView addSubview:leftLabel];
self.guideLeftLabel = leftLabel;
UILabel * rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(125, 0, 150, image.size.height)];
rightLabel.backgroundColor = [UIColor clearColor];
rightLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15];
rightLabel.textColor = [UIColor colorWithColorCode:@"33cc66"];
[contentView addSubview:rightLabel];
self.guideRightLabel = rightLabel;
}
return _guideButton;
}
- (UIButton *)editButton
{
if (!_editButton)
{
UIImage * image = [[UIImage imageNamed:@"PlacePageButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
_editButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
_editButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
_editButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth;
[_editButton setBackgroundImage:image forState:UIControlStateNormal];
[_editButton addTarget:self action:@selector(editButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[_editButton setTitle:NSLocalizedString(@"edit", nil) forState:UIControlStateNormal];
[_editButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
return _editButton;
}
- (UIButton *)largeShareButton
{
if (!_largeShareButton)
{
UIImage * image = [[UIImage imageNamed:@"PlacePageButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
_largeShareButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
_largeShareButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
_largeShareButton.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[_largeShareButton setBackgroundImage:image forState:UIControlStateNormal];
[_largeShareButton addTarget:self action:@selector(shareButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[_largeShareButton setTitle:NSLocalizedString(@"share", nil) forState:UIControlStateNormal];
[_largeShareButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
return _largeShareButton;
}
- (UIButton *)shareButton
{
if (!_shareButton)
{
UIImage * image = [[UIImage imageNamed:@"PlacePageButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
_shareButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
_shareButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
_shareButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
[_shareButton setBackgroundImage:image forState:UIControlStateNormal];
[_shareButton addTarget:self action:@selector(shareButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[_shareButton setTitle:NSLocalizedString(@"share", nil) forState:UIControlStateNormal];
[_shareButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
return _shareButton;
}
- (UIScrollView *)scrollView
{
if (!_scrollView)
{
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.width, 0)];
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
}
return _scrollView;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[MapsAppDelegate theApp].m_locationManager stop:self];
}
@end

View file

@ -170,6 +170,8 @@
97DD585918A8EB060079837E /* MobileAppTracker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97DD585718A8EB060079837E /* MobileAppTracker.framework */; };
97DD585C18A8EB130079837E /* libFlurry_4.3.2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 97DD585A18A8EB120079837E /* libFlurry_4.3.2.a */; };
97DD585D18A8EB130079837E /* libFlurry_4.3.2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 97DD585A18A8EB120079837E /* libFlurry_4.3.2.a */; };
97DEA09618D75BB000C5F963 /* ContextViews.mm in Sources */ = {isa = PBXBuildFile; fileRef = 97DEA09518D75BB000C5F963 /* ContextViews.mm */; };
97DEA09718D75BB000C5F963 /* ContextViews.mm in Sources */ = {isa = PBXBuildFile; fileRef = 97DEA09518D75BB000C5F963 /* ContextViews.mm */; };
97ECD871183620CE00F77A46 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97ECD870183620CE00F77A46 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
97ECD872183625F900F77A46 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97ECD870183620CE00F77A46 /* AdSupport.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
97ECD87818362B3D00F77A46 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97ECD87718362B3D00F77A46 /* CoreTelephony.framework */; };
@ -1668,6 +1670,9 @@
97DD585718A8EB060079837E /* MobileAppTracker.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = MobileAppTracker.framework; sourceTree = "<group>"; };
97DD585A18A8EB120079837E /* libFlurry_4.3.2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libFlurry_4.3.2.a; sourceTree = "<group>"; };
97DD585B18A8EB120079837E /* Flurry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Flurry.h; sourceTree = "<group>"; };
97DEA09018D706C300C5F963 /* Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Common.h; sourceTree = "<group>"; };
97DEA09418D75BB000C5F963 /* ContextViews.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContextViews.h; sourceTree = "<group>"; };
97DEA09518D75BB000C5F963 /* ContextViews.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextViews.mm; sourceTree = "<group>"; };
97ECD870183620CE00F77A46 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
97ECD87718362B3D00F77A46 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; };
97ECD87918362B5400F77A46 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
@ -2658,6 +2663,10 @@
isa = PBXGroup;
children = (
9747277618328E65006B7CB7 /* SideToolbar */,
97ABBA4318C8DF620079333C /* PlacePageView.h */,
97ABBA4418C8DF620079333C /* PlacePageView.mm */,
97DEA09418D75BB000C5F963 /* ContextViews.h */,
97DEA09518D75BB000C5F963 /* ContextViews.mm */,
ED48BBB317C267F5003E7E92 /* ColorPickerView.h */,
ED48BBB417C267F5003E7E92 /* ColorPickerView.mm */,
ED48BBB817C2B1E2003E7E92 /* CircleView.h */,
@ -5047,6 +5056,7 @@
FA29FDAA141E77F8004ADF66 /* Preferences.mm in Sources */,
FAA5C2A2144F135F005337F6 /* LocationManager.mm in Sources */,
FA81AE3314D061BF00A0D70D /* SearchCell.mm in Sources */,
97DEA09618D75BB000C5F963 /* ContextViews.mm in Sources */,
978F9240183B660F000D6C7C /* SettingsViewController.mm in Sources */,
97D807BC18A933FB00D416E0 /* MoreAppsCell.m in Sources */,
F7B90CD31521E6D200C054EE /* CustomNavigationView.mm in Sources */,
@ -5065,6 +5075,7 @@
9747277D18328E65006B7CB7 /* SideToolbarCell.m in Sources */,
978F9244183B660F000D6C7C /* SwitchCell.m in Sources */,
EDB811A3175E1A9C00E36BF2 /* TwoButtonsView.m in Sources */,
97ABBA4518C8DF620079333C /* PlacePageView.mm in Sources */,
9747277B18328E65006B7CB7 /* SideToolbar.mm in Sources */,
97F61794183E7445009919E2 /* LinkCell.m in Sources */,
EDCB4E8E175E67120005AA35 /* PlacePreviewViewController.mm in Sources */,
@ -5099,8 +5110,10 @@
97C9863A186C487900AF7E9E /* MPLogging.m in Sources */,
FAFB08EE151215EE0041901D /* SettingsManager.mm in Sources */,
FAFB08EF151215EE0041901D /* RenderBuffer.mm in Sources */,
97DEA09718D75BB000C5F963 /* ContextViews.mm in Sources */,
978F9254183BD530000D6C7C /* NavigationController.mm in Sources */,
97C9851F186AE3C500AF7E9E /* Reachability.m in Sources */,
97ABBA4618C8DF620079333C /* PlacePageView.mm in Sources */,
9789DB5B188D94F9007C6FAE /* InterstitialView.mm in Sources */,
FAFB08F0151215EE0041901D /* RenderContext.mm in Sources */,
97C985FD186C487900AF7E9E /* CDataScanner.m in Sources */,