diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm index eba597541d..98156cc4f9 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm @@ -314,7 +314,7 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName) [self closePlacePage]; } -- (void)addStop +- (void)routeAddStop { MWMRoutePoint * point = [self routePointWithType:MWMRoutePointTypeIntermediate intermediateIndex:0]; @@ -322,7 +322,7 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName) [self closePlacePage]; } -- (void)removeStop +- (void)routeRemoveStop { auto data = self.data; MWMRoutePoint * point = nil; diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageProtocol.h b/iphone/Maps/UI/PlacePage/MWMPlacePageProtocol.h index 472d8a8d77..a7ec36df3c 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageProtocol.h +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageProtocol.h @@ -7,8 +7,8 @@ - (void)routeFrom; - (void)routeTo; -- (void)addStop; -- (void)removeStop; +- (void)routeAddStop; +- (void)routeRemoveStop; - (void)share; diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h index 1655ddb108..76a17152fc 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.h @@ -1,20 +1,18 @@ enum class EButton // Required button's order { - Api, - Download, Booking, BookingSearch, - Opentable, - Call, Bookmark, - RouteFrom, - RouteTo, - Share, + Call, + Download, More, - AddStop, - RemoveStop, + Opentable, Partner, - Spacer + RouteAddStop, + RouteFrom, + RouteRemoveStop, + RouteTo, + Share }; NSString * titleForButton(EButton type, int partnerIndex, BOOL isSelected); @@ -30,13 +28,10 @@ NSString * titleForButton(EButton type, int partnerIndex, BOOL isSelected); @interface MWMActionBarButton : UIView -- (void)configButtonWithDelegate:(id)delegate type:(EButton)type isSelected:(BOOL)isSelected; - -+ (void)addButtonToSuperview:(UIView *)view - delegate:(id)delegate - buttonType:(EButton)type - partnerIndex:(int)partnerIndex - isSelected:(BOOL)isSelected; ++ (MWMActionBarButton *)buttonWithDelegate:(id)delegate + buttonType:(EButton)type + partnerIndex:(int)partnerIndex + isSelected:(BOOL)isSelected; - (EButton)type; - (MWMCircularProgress *)mapDownloadProgress; diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.mm index a13e4e59ef..98cdd491ea 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.mm @@ -15,35 +15,19 @@ NSString * titleForButton(EButton type, int partnerIndex, BOOL isSelected) { switch (type) { - case EButton::Api: - return L(@"back"); - case EButton::Download: - return L(@"download"); + case EButton::Download: return L(@"download"); case EButton::Booking: - case EButton::Opentable: - return L(@"book_button"); - case EButton::BookingSearch: - return L(@"booking_search"); - case EButton::Call: - return L(@"placepage_call_button"); - case EButton::Bookmark: - return L(isSelected ? @"delete" : @"save"); - case EButton::RouteFrom: - return L(@"p2p_from_here"); - case EButton::RouteTo: - return L(@"p2p_to_here"); - case EButton::Share: - return L(@"share"); - case EButton::More: - return L(@"placepage_more_button"); - case EButton::AddStop: - return L(@"placepage_add_stop"); - case EButton::RemoveStop: - return L(@"placepage_remove_stop"); - case EButton::Partner: - return titleForPartner(partnerIndex); - case EButton::Spacer: - return nil; + case EButton::Opentable: return L(@"book_button"); + case EButton::BookingSearch: return L(@"booking_search"); + case EButton::Call: return L(@"placepage_call_button"); + case EButton::Bookmark: return L(isSelected ? @"delete" : @"save"); + case EButton::RouteFrom: return L(@"p2p_from_here"); + case EButton::RouteTo: return L(@"p2p_to_here"); + case EButton::Share: return L(@"share"); + case EButton::More: return L(@"placepage_more_button"); + case EButton::RouteAddStop: return L(@"placepage_add_stop"); + case EButton::RouteRemoveStop: return L(@"placepage_remove_stop"); + case EButton::Partner: return titleForPartner(partnerIndex); } } @@ -77,136 +61,116 @@ UIColor * backgroundColorForPartner(int partnerIndex) @interface MWMActionBarButton () -@property(weak, nonatomic) IBOutlet MWMButton * button; -@property(weak, nonatomic) IBOutlet UILabel * label; - -@property(weak, nonatomic) id delegate; @property(nonatomic) EButton type; @property(nonatomic) MWMCircularProgress * mapDownloadProgress; @property(nonatomic) int partnerIndex; -@property(nonatomic) UIView * progressWrapper; +@property(weak, nonatomic) IBOutlet MWMButton * button; +@property(weak, nonatomic) IBOutlet UILabel * label; @property(weak, nonatomic) IBOutlet UIView * extraBackground; +@property(weak, nonatomic) id delegate; @end @implementation MWMActionBarButton -- (void)configButtonWithDelegate:(id)delegate type:(EButton)type isSelected:(BOOL)isSelected -{ - self.delegate = delegate; - self.type = type; - [self configButton:isSelected]; -} - - (void)configButton:(BOOL)isSelected { self.label.text = titleForButton(self.type, self.partnerIndex, isSelected); self.extraBackground.hidden = YES; switch (self.type) { - case EButton::Api: - [self.button setImage:[UIImage imageNamed:@"ic_back_api"] forState:UIControlStateNormal]; - break; case EButton::Download: { if (self.mapDownloadProgress) return; - self.progressWrapper = [[UIView alloc] init]; - [self.button addSubview:self.progressWrapper]; - - self.mapDownloadProgress = [MWMCircularProgress downloaderProgressForParentView:self.progressWrapper]; - self.mapDownloadProgress.delegate = self; + self.mapDownloadProgress = [MWMCircularProgress downloaderProgressForParentView:self.button]; + self.mapDownloadProgress.delegate = self; MWMCircularProgressStateVec const affectedStates = {MWMCircularProgressStateNormal, - MWMCircularProgressStateSelected}; + MWMCircularProgressStateSelected}; [self.mapDownloadProgress setImageName:@"ic_download" forStates:affectedStates]; [self.mapDownloadProgress setColoring:MWMButtonColoringBlue forStates:affectedStates]; break; - } - case EButton::Booking: - [self.button setImage:[UIImage imageNamed:@"ic_booking_logo"] forState:UIControlStateNormal]; - self.label.textColor = UIColor.whiteColor; - self.backgroundColor = [UIColor bookingBackground]; - if (!IPAD) - { - self.extraBackground.backgroundColor = [UIColor bookingBackground]; - self.extraBackground.hidden = NO; } - break; - case EButton::BookingSearch: - [self.button setImage:[UIImage imageNamed:@"ic_booking_search"] forState:UIControlStateNormal]; - self.label.textColor = UIColor.whiteColor; - self.backgroundColor = [UIColor bookingBackground]; - if (!IPAD) - { - self.extraBackground.backgroundColor = [UIColor bookingBackground]; - self.extraBackground.hidden = NO; - } - break; - case EButton::Opentable: - [self.button setImage:[UIImage imageNamed:@"ic_opentable"] forState:UIControlStateNormal]; - self.label.textColor = UIColor.whiteColor; - self.backgroundColor = [UIColor opentableBackground]; - if (!IPAD) - { - self.extraBackground.backgroundColor = [UIColor opentableBackground]; - self.extraBackground.hidden = NO; - } - break; - case EButton::Call: - [self.button setImage:[UIImage imageNamed:@"ic_placepage_phone_number"] forState:UIControlStateNormal]; - break; - case EButton::Bookmark: - [self setupBookmarkButton:isSelected]; - break; - case EButton::RouteFrom: - [self.button setImage:[UIImage imageNamed:@"ic_route_from"] forState:UIControlStateNormal]; - break; - case EButton::RouteTo: - [self.button setImage:[UIImage imageNamed:@"ic_route_to"] forState:UIControlStateNormal]; - break; - case EButton::Share: - [self.button setImage:[UIImage imageNamed:@"ic_menu_share"] forState:UIControlStateNormal]; - break; - case EButton::More: - [self.button setImage:[UIImage imageNamed:@"ic_placepage_more"] forState:UIControlStateNormal]; - break; - case EButton::AddStop: - [self.button setImage:[UIImage imageNamed:@"ic_add_route_point"] forState:UIControlStateNormal]; - break; - case EButton::RemoveStop: - [self.button setImage:[UIImage imageNamed:@"ic_remove_route_point"] forState:UIControlStateNormal]; - break; - case EButton::Spacer: - [self.button removeFromSuperview]; - [self.label removeFromSuperview]; - break; - case EButton::Partner: - [self.button setImage:imageForPartner(self.partnerIndex) - forState:UIControlStateNormal]; - self.label.textColor = textColorForPartner(self.partnerIndex); - self.backgroundColor = backgroundColorForPartner(self.partnerIndex); - break; + case EButton::Booking: + [self.button setImage:[UIImage imageNamed:@"ic_booking_logo"] forState:UIControlStateNormal]; + self.label.textColor = UIColor.whiteColor; + self.backgroundColor = [UIColor bookingBackground]; + if (!IPAD) + { + self.extraBackground.backgroundColor = [UIColor bookingBackground]; + self.extraBackground.hidden = NO; + } + break; + case EButton::BookingSearch: + [self.button setImage:[UIImage imageNamed:@"ic_booking_search"] + forState:UIControlStateNormal]; + self.label.textColor = UIColor.whiteColor; + self.backgroundColor = [UIColor bookingBackground]; + if (!IPAD) + { + self.extraBackground.backgroundColor = [UIColor bookingBackground]; + self.extraBackground.hidden = NO; + } + break; + case EButton::Opentable: + [self.button setImage:[UIImage imageNamed:@"ic_opentable"] forState:UIControlStateNormal]; + self.label.textColor = UIColor.whiteColor; + self.backgroundColor = [UIColor opentableBackground]; + if (!IPAD) + { + self.extraBackground.backgroundColor = [UIColor opentableBackground]; + self.extraBackground.hidden = NO; + } + break; + case EButton::Call: + [self.button setImage:[UIImage imageNamed:@"ic_placepage_phone_number"] + forState:UIControlStateNormal]; + break; + case EButton::Bookmark: [self setupBookmarkButton:isSelected]; break; + case EButton::RouteFrom: + [self.button setImage:[UIImage imageNamed:@"ic_route_from"] forState:UIControlStateNormal]; + break; + case EButton::RouteTo: + [self.button setImage:[UIImage imageNamed:@"ic_route_to"] forState:UIControlStateNormal]; + break; + case EButton::Share: + [self.button setImage:[UIImage imageNamed:@"ic_menu_share"] forState:UIControlStateNormal]; + break; + case EButton::More: + [self.button setImage:[UIImage imageNamed:@"ic_placepage_more"] + forState:UIControlStateNormal]; + break; + case EButton::RouteAddStop: + [self.button setImage:[UIImage imageNamed:@"ic_add_route_point"] + forState:UIControlStateNormal]; + break; + case EButton::RouteRemoveStop: + [self.button setImage:[UIImage imageNamed:@"ic_remove_route_point"] + forState:UIControlStateNormal]; + break; + case EButton::Partner: + [self.button setImage:imageForPartner(self.partnerIndex) forState:UIControlStateNormal]; + self.label.textColor = textColorForPartner(self.partnerIndex); + self.backgroundColor = backgroundColorForPartner(self.partnerIndex); + break; } } -+ (void)addButtonToSuperview:(UIView *)view - delegate:(id)delegate - buttonType:(EButton)type - partnerIndex:(int)partnerIndex - isSelected:(BOOL)isSelected ++ (MWMActionBarButton *)buttonWithDelegate:(id)delegate + buttonType:(EButton)type + partnerIndex:(int)partnerIndex + isSelected:(BOOL)isSelected { - if (view.subviews.count) - return; MWMActionBarButton * button = [NSBundle.mainBundle loadNibNamed:[self className] owner:nil options:nil].firstObject; button.delegate = delegate; button.type = type; button.partnerIndex = partnerIndex; - [view addSubview:button]; [button configButton:isSelected]; + return button; } - (void)progressButtonPressed:(MWMCircularProgress *)progress @@ -252,13 +216,4 @@ UIColor * backgroundColorForPartner(int partnerIndex) animationIV.animationRepeatCount = 1; } -- (void)layoutSubviews -{ - [super layoutSubviews]; - self.frame = self.superview.bounds; - CGFloat constexpr designOffset = 4; - self.progressWrapper.size = {self.button.height - designOffset, self.button.height - designOffset}; - self.progressWrapper.center = self.button.center; -} - @end diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.xib b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.xib index c18e29a429..3e2189355b 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.xib +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMActionBarButton.xib @@ -13,7 +13,7 @@ - + diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.h b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.h index 51df3c2cfd..90a74bfb34 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.h +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.h @@ -27,7 +27,6 @@ + (MWMPlacePageActionBar *)actionBarWithDelegate:(id)delegate; - (void)configureWithData:(id)data; -@property(nonatomic) BOOL isBookmark; @property(nonatomic) BOOL isAreaNotDownloaded; - (void)setVisible:(BOOL)visible; diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm index f428f61028..597404748b 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.mm @@ -7,20 +7,16 @@ #import "MWMRouter.h" #import "MapViewController.h" -extern NSString * const kAlohalyticsTapEventKey; - @interface MWMPlacePageActionBar () { vector m_visibleButtons; vector m_additionalButtons; } -@property(copy, nonatomic) IBOutletCollection(UIView) NSArray * buttons; - -@property(weak, nonatomic) id data; -@property(weak, nonatomic) id delegate; - @property(nonatomic) NSLayoutConstraint * visibleConstraint; +@property(weak, nonatomic) IBOutlet UIStackView * barButtons; +@property(weak, nonatomic) id delegate; +@property(weak, nonatomic) id data; @end @@ -38,194 +34,137 @@ extern NSString * const kAlohalyticsTapEventKey; - (void)configureWithData:(id)data { self.data = data; - self.isBookmark = [data isBookmark]; [self configureButtons]; self.autoresizingMask = UIViewAutoresizingNone; [self setNeedsLayout]; } -- (void)configureButtons +- (void)clearButtons { m_visibleButtons.clear(); m_additionalButtons.clear(); - auto data = self.data; + [self.barButtons.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; +} - BOOL const isBooking = [data isBooking]; - BOOL const isOpentable = [data isOpentable]; - BOOL const isBookingSearch = [data isBookingSearch]; - BOOL const isPartner = [data isPartner] && [data sponsoredURL] != nil; - int const partnerIndex = isPartner ? [data partnerIndex] : -1; - BOOL const isSponsored = isBooking || isOpentable || isBookingSearch || isPartner; - BOOL const isPhoneCallAvailable = - [AppInfo sharedInfo].canMakeCalls && [data phoneNumber].length > 0; - BOOL const isApi = [data isApi]; - auto const navigationState = [MWMNavigationDashboardManager manager].state; - BOOL const isNavigationActive = navigationState == MWMNavigationDashboardStateNavigation; - BOOL const isP2P = !isNavigationActive && navigationState != MWMNavigationDashboardStateHidden; - BOOL const isMyPosition = [data isMyPosition]; - BOOL const isRoutePoint = [data isRoutePoint]; - BOOL const isNeedToAddIntermediatePoint = [MWMRouter canAddIntermediatePoint]; +- (void)setFirstButton:(id)data +{ + vector buttons; - EButton sponsoredButton = EButton::BookingSearch; - if (isBooking) - sponsoredButton = EButton::Booking; - else if (isOpentable) - sponsoredButton = EButton::Opentable; - else if (isPartner) - sponsoredButton = EButton::Partner; - BOOL thereAreExtraButtons = true; - - if (isRoutePoint) + if (self.isAreaNotDownloaded) { - thereAreExtraButtons = false; - m_visibleButtons.push_back(EButton::RemoveStop); - } - else if (isNeedToAddIntermediatePoint) - { - thereAreExtraButtons = false; - if (!isNavigationActive) - { - m_visibleButtons.push_back(EButton::RouteFrom); - m_additionalButtons.push_back(EButton::Bookmark); - } - else - { - m_visibleButtons.push_back(EButton::Bookmark); - } - m_visibleButtons.push_back(EButton::RouteTo); - m_visibleButtons.push_back(EButton::AddStop); - m_visibleButtons.push_back(EButton::More); - - if (isSponsored) - m_additionalButtons.push_back(sponsoredButton); - if (isPhoneCallAvailable) - m_additionalButtons.push_back(EButton::Call); - if (isApi) - m_additionalButtons.push_back(EButton::Api); - m_additionalButtons.push_back(EButton::Share); - } - else if (self.isAreaNotDownloaded) - { - thereAreExtraButtons = false; - m_visibleButtons.push_back(EButton::Download); - m_visibleButtons.push_back(EButton::Bookmark); - m_visibleButtons.push_back(EButton::RouteTo); - m_visibleButtons.push_back(EButton::Share); - } - else if (isMyPosition && isP2P) - { - thereAreExtraButtons = false; - m_visibleButtons.push_back(EButton::Bookmark); - m_visibleButtons.push_back(EButton::RouteFrom); - m_visibleButtons.push_back(EButton::RouteTo); - m_visibleButtons.push_back(EButton::More); - m_additionalButtons.push_back(EButton::Share); - } - else if (isMyPosition) - { - thereAreExtraButtons = false; - m_visibleButtons.push_back(EButton::Bookmark); - if (!isNavigationActive) - m_visibleButtons.push_back(EButton::RouteFrom); - m_visibleButtons.push_back(EButton::Share); - } - else if (isApi && isSponsored) - { - m_visibleButtons.push_back(EButton::Api); - m_visibleButtons.push_back(sponsoredButton); - m_additionalButtons.push_back(EButton::Bookmark); - if (!isNavigationActive) - m_additionalButtons.push_back(EButton::RouteFrom); - m_additionalButtons.push_back(EButton::Share); - } - else if (isApi && isPhoneCallAvailable) - { - m_visibleButtons.push_back(EButton::Api); - m_visibleButtons.push_back(EButton::Call); - m_additionalButtons.push_back(EButton::Bookmark); - if (!isNavigationActive) - m_additionalButtons.push_back(EButton::RouteFrom); - m_additionalButtons.push_back(EButton::Share); - } - else if (isApi && isP2P) - { - m_visibleButtons.push_back(EButton::Api); - if (!isNavigationActive) - m_visibleButtons.push_back(EButton::RouteFrom); - m_additionalButtons.push_back(EButton::Bookmark); - m_additionalButtons.push_back(EButton::Share); - } - else if (isApi) - { - m_visibleButtons.push_back(EButton::Api); - m_visibleButtons.push_back(EButton::Bookmark); - if (!isNavigationActive) - m_additionalButtons.push_back(EButton::RouteFrom); - m_additionalButtons.push_back(EButton::Share); - } - else if (isSponsored && isP2P) - { - m_visibleButtons.push_back(EButton::Bookmark); - if (!isNavigationActive) - m_visibleButtons.push_back(EButton::RouteFrom); - m_additionalButtons.push_back(sponsoredButton); - m_additionalButtons.push_back(EButton::Share); - } - else if (isPhoneCallAvailable && isP2P) - { - m_visibleButtons.push_back(EButton::Bookmark); - if (!isNavigationActive) - m_visibleButtons.push_back(EButton::RouteFrom); - m_additionalButtons.push_back(EButton::Call); - m_additionalButtons.push_back(EButton::Share); - } - else if (isSponsored) - { - m_visibleButtons.push_back(sponsoredButton); - m_visibleButtons.push_back(EButton::Bookmark); - if (!isNavigationActive) - m_additionalButtons.push_back(EButton::RouteFrom); - m_additionalButtons.push_back(EButton::Share); - } - else if (isPhoneCallAvailable) - { - m_visibleButtons.push_back(EButton::Call); - m_visibleButtons.push_back(EButton::Bookmark); - if (!isNavigationActive) - m_additionalButtons.push_back(EButton::RouteFrom); - m_additionalButtons.push_back(EButton::Share); + buttons.push_back(EButton::Download); } else { - m_visibleButtons.push_back(EButton::Bookmark); - if (!isNavigationActive) - m_visibleButtons.push_back(EButton::RouteFrom); + BOOL const isRoutePlanning = + [MWMNavigationDashboardManager manager].state != MWMNavigationDashboardStateHidden; + if (isRoutePlanning) + buttons.push_back(EButton::RouteFrom); + + BOOL const isBooking = [data isBooking]; + if (isBooking) + buttons.push_back(EButton::Booking); + BOOL const isOpentable = [data isOpentable]; + if (isOpentable) + buttons.push_back(EButton::Opentable); + BOOL const isPartner = [data isPartner] && [data sponsoredURL] != nil; + if (isPartner) + buttons.push_back(EButton::Partner); + BOOL const isBookingSearch = [data isBookingSearch]; + if (isBookingSearch) + buttons.push_back(EButton::BookingSearch); + + BOOL const isPhoneCallAvailable = + [AppInfo sharedInfo].canMakeCalls && [data phoneNumber].length > 0; + if (isPhoneCallAvailable) + buttons.push_back(EButton::Call); + + if (!isRoutePlanning) + buttons.push_back(EButton::RouteFrom); } + NSAssert(!buttons.empty(), @"Missing first action bar button"); + auto begin = buttons.begin(); + m_visibleButtons.push_back(*begin); + begin++; + std::copy(begin, buttons.end(), std::back_inserter(m_additionalButtons)); +} - if (thereAreExtraButtons) +- (void)setSecondButton:(id)data +{ + vector buttons; + BOOL const isCanAddIntermediatePoint = [MWMRouter canAddIntermediatePoint]; + BOOL const isNavigationReady = + [MWMNavigationDashboardManager manager].state == MWMNavigationDashboardStateReady; + if (isCanAddIntermediatePoint && isNavigationReady) + buttons.push_back(EButton::RouteAddStop); + + buttons.push_back(EButton::Bookmark); + + auto begin = buttons.begin(); + m_visibleButtons.push_back(*begin); + begin++; + std::copy(begin, buttons.end(), std::back_inserter(m_additionalButtons)); +} + +- (void)setThirdButton { m_visibleButtons.push_back(EButton::RouteTo); } + +- (void)setFourthButton +{ + if (m_additionalButtons.empty()) { - m_visibleButtons.push_back(EButton::RouteTo); - m_visibleButtons.push_back(m_additionalButtons.empty() ? EButton::Share : EButton::More); + m_visibleButtons.push_back(EButton::Share); } - - for (UIView * v in self.buttons) + else { - [v.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; - auto const buttonIndex = v.tag - 1; - NSAssert(buttonIndex >= 0, @"Invalid button index."); - if (buttonIndex < 0 || buttonIndex >= m_visibleButtons.size()) - continue; - auto const type = m_visibleButtons[buttonIndex]; - auto const isSelected = (type == EButton::Bookmark ? self.isBookmark : NO); - [MWMActionBarButton addButtonToSuperview:v - delegate:self - buttonType:type - partnerIndex:partnerIndex - isSelected:isSelected]; + m_visibleButtons.push_back(EButton::More); + m_additionalButtons.push_back(EButton::Share); } } +- (void)addButtons2UI:(id)data +{ + BOOL const isPartner = [data isPartner] && [data sponsoredURL] != nil; + int const partnerIndex = isPartner ? [data partnerIndex] : -1; + + for (auto const buttonType : m_visibleButtons) + { + auto const isSelected = (buttonType == EButton::Bookmark ? [data isBookmark] : NO); + auto button = [MWMActionBarButton buttonWithDelegate:self + buttonType:buttonType + partnerIndex:partnerIndex + isSelected:isSelected]; + [self.barButtons addArrangedSubview:button]; + } +} + +- (void)setSingleButton { m_visibleButtons.push_back(EButton::RouteRemoveStop); } + +- (void)setButtons:(id)data +{ + BOOL const isRoutePoint = [data isRoutePoint]; + if (isRoutePoint) + { + [self setSingleButton]; + } + else + { + [self setFirstButton:data]; + [self setSecondButton:data]; + [self setThirdButton]; + [self setFourthButton]; + } +} + +- (void)configureButtons +{ + auto data = self.data; + [self clearButtons]; + + [self setButtons:data]; + [self addButtons2UI:data]; +} + - (void)setDownloadingState:(MWMCircularProgressState)state { self.progressFromActiveButton.state = state; @@ -238,17 +177,13 @@ extern NSString * const kAlohalyticsTapEventKey; - (MWMCircularProgress *)progressFromActiveButton { - if (!self.isAreaNotDownloaded) - return nil; - - for (UIView * view in self.buttons) + if (self.isAreaNotDownloaded) { - MWMActionBarButton * button = view.subviews.firstObject; - NSAssert(button, @"Subviews can't be empty!"); - if (!button || [button type] != EButton::Download) - continue; - - return button.mapDownloadProgress; + for (MWMActionBarButton * button in self.barButtons.subviews) + { + if ([button type] == EButton::Download) + return button.mapDownloadProgress; + } } return nil; } @@ -262,48 +197,35 @@ extern NSString * const kAlohalyticsTapEventKey; [self configureButtons]; } -- (UIView *)shareAnchor -{ - UIView * last = nil; - auto const size = self.buttons.count; - for (UIView * v in self.buttons) - { - if (v.tag == size) - last = v; - } - return last; -} +- (UIView *)shareAnchor { return self.barButtons.subviews.lastObject; } #pragma mark - MWMActionBarButtonDelegate - (void)tapOnButtonWithType:(EButton)type { id delegate = self.delegate; + auto data = self.data; switch (type) { - case EButton::Api: [delegate apiBack]; break; case EButton::Download: [delegate downloadSelectedArea]; break; case EButton::Opentable: case EButton::Booking: [delegate book:NO]; break; case EButton::BookingSearch: [delegate searchBookingHotels]; break; case EButton::Call: [delegate call]; break; case EButton::Bookmark: - if (self.isBookmark) + if ([data isBookmark]) [delegate removeBookmark]; else [delegate addBookmark]; - - self.isBookmark = !self.isBookmark; break; case EButton::RouteFrom: [delegate routeFrom]; break; case EButton::RouteTo: [delegate routeTo]; break; case EButton::Share: [delegate share]; break; case EButton::More: [self showActionSheet]; break; - case EButton::AddStop: [delegate addStop]; break; - case EButton::RemoveStop: [delegate removeStop]; break; + case EButton::RouteAddStop: [delegate routeAddStop]; break; + case EButton::RouteRemoveStop: [delegate routeRemoveStop]; break; case EButton::Partner: [delegate openPartner]; break; - case EButton::Spacer: break; } } @@ -369,17 +291,4 @@ extern NSString * const kAlohalyticsTapEventKey; self.visibleConstraint.active = YES; } -#pragma mark - Layout - -- (void)layoutSubviews -{ - [super layoutSubviews]; - CGFloat const buttonWidth = self.width / m_visibleButtons.size(); - for (UIView * button in self.buttons) - { - button.minX = buttonWidth * (button.tag - 1); - button.width = buttonWidth; - } -} - @end diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.xib b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.xib index dac4d81602..f679e56351 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.xib +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/ActionBar/MWMPlacePageActionBar.xib @@ -6,6 +6,7 @@ + @@ -31,30 +32,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + @@ -64,22 +44,23 @@ + + + + - - - - + diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMiPhonePlacePageLayoutImpl.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMiPhonePlacePageLayoutImpl.mm index 86d0fbfb37..c8b4a2ab98 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMiPhonePlacePageLayoutImpl.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMiPhonePlacePageLayoutImpl.mm @@ -87,13 +87,13 @@ CGFloat const kMinOffset = 1; - (void)onClose { + self.actionBar = nil; place_page_layout::animate(^{ [self setAnimatedContentOffset:0]; },^{ id delegate = self.delegate; // Workaround for preventing a situation when the scroll view destroyed before an animation finished. [delegate onPlacePageTopBoundChanged:0]; - self.actionBar = nil; self.scrollView = nil; [delegate destroyLayout]; }); @@ -233,9 +233,6 @@ CGFloat const kMinOffset = 1; else if (actualOffset < self.bottomContentOffset) { (*targetContentOffset).y = 0; - place_page_layout::animate(^{ - self.actionBar.minY = self.ownerView.height; - }); } else {