diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h index dbad78c787..2d65aa6a92 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h @@ -1,13 +1,11 @@ -#import "SwiftBridge.h" - #include "local_ads/event.hpp" +#include "partners_api/booking_api.hpp" + #include "map/place_page_info.hpp" #include "std/vector.hpp" -#include "partners_api/booking_api.hpp" - @class MWMPlacePageData; namespace place_page @@ -16,12 +14,13 @@ enum class Sections { Preview, Bookmark, - Metainfo, - Buttons, HotelPhotos, HotelDescription, HotelFacilities, - HotelReviews + HotelReviews, + Metainfo, + Ad, + Buttons }; enum class PreviewRows @@ -72,6 +71,12 @@ enum class MetainfoRows Operator, Internet, Coordinate, + LocalAdsCandidate, + LocalAdsCustomer +}; + +enum class AdRows +{ Taxi }; @@ -81,11 +86,7 @@ enum class ButtonsRows EditPlace, AddPlace, HotelDescription, - BookingShowMoreFacilities, - BookingShowMoreOnSite, - BookingShowMoreReviews, - LocalAdsCandidate, - LocalAdsCustomer + Other }; enum class OpeningHours @@ -103,6 +104,7 @@ using BannerIsReady = void (^)(); @class MWMGalleryItemModel; +@protocol MWMBanner; /// ViewModel for place page. @interface MWMPlacePageData : NSObject @@ -168,6 +170,7 @@ using BannerIsReady = void (^)(); - (vector const &)hotelFacilitiesRows; - (vector const &)hotelReviewsRows; - (vector const &)metainfoRows; +- (vector const &)adRows; - (vector const &)buttonsRows; // Table view metainfo rows diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm index 67c78722c3..2c644d29b2 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm @@ -40,6 +40,7 @@ using namespace place_page; vector m_sections; vector m_previewRows; vector m_metainfoRows; + vector m_adRows; vector m_buttonsRows; vector m_hotelPhotosRows; vector m_hotelDescriptionRows; @@ -63,6 +64,7 @@ using namespace place_page; m_sections.clear(); m_previewRows.clear(); m_metainfoRows.clear(); + m_adRows.clear(); m_buttonsRows.clear(); m_hotelPhotosRows.clear(); m_hotelDescriptionRows.clear(); @@ -80,6 +82,12 @@ using namespace place_page; m_sections.push_back(Sections::Metainfo); [self fillMetaInfoSection]; + if (m_info.IsReachableByTaxi()) + { + m_sections.push_back(Sections::Ad); + m_adRows.push_back(AdRows::Taxi); + } + // There is at least one of these buttons. if (m_info.ShouldShowAddPlace() || m_info.ShouldShowEditPlace() || m_info.ShouldShowAddBusiness() || m_info.IsSponsored()) @@ -155,8 +163,18 @@ using namespace place_page; m_metainfoRows.push_back(MetainfoRows::Address); m_metainfoRows.push_back(MetainfoRows::Coordinate); - if (m_info.IsReachableByTaxi()) - m_metainfoRows.push_back(MetainfoRows::Taxi); + + switch (m_info.GetLocalAdsStatus()) + { + case place_page::LocalAdsStatus::NotAvailable: break; + case place_page::LocalAdsStatus::Candidate: + m_metainfoRows.push_back(MetainfoRows::LocalAdsCandidate); + break; + case place_page::LocalAdsStatus::Customer: + m_metainfoRows.push_back(MetainfoRows::LocalAdsCustomer); + [self logLocalAdsEvent:local_ads::EventType::OpenInfo]; + break; + } } - (void)fillButtonsSection @@ -176,18 +194,6 @@ using namespace place_page; if (m_info.ShouldShowAddBusiness()) m_buttonsRows.push_back(ButtonsRows::AddBusiness); - - switch (m_info.GetLocalAdsStatus()) - { - case place_page::LocalAdsStatus::NotAvailable: break; - case place_page::LocalAdsStatus::Candidate: - m_buttonsRows.push_back(ButtonsRows::LocalAdsCandidate); - break; - case place_page::LocalAdsStatus::Customer: - m_buttonsRows.push_back(ButtonsRows::LocalAdsCustomer); - [self logLocalAdsEvent:local_ads::EventType::OpenInfo]; - break; - } } - (void)fillOnlineBookingSections @@ -521,6 +527,7 @@ using namespace place_page; - (vector const &)previewRows { return m_previewRows; } - (vector const &)metainfoRows { return m_metainfoRows; } - (vector &)mutableMetainfoRows { return m_metainfoRows; } +- (vector const &)adRows { return m_adRows; } - (vector const &)buttonsRows { return m_buttonsRows; } - (vector const &)photosRows { return m_hotelPhotosRows; } - (vector const &)descriptionRows { return m_hotelDescriptionRows; } @@ -530,7 +537,7 @@ using namespace place_page; { switch (row) { - case MetainfoRows::Taxi: + case MetainfoRows::ExtendedOpeningHours: return nil; case MetainfoRows::OpeningHours: return @(m_info.GetOpeningHours().c_str()); case MetainfoRows::Phone: return @(m_info.GetPhone().c_str()); @@ -541,6 +548,8 @@ using namespace place_page; return @(strings::JoinStrings(m_info.GetLocalizedCuisines(), Info::kSubtitleSeparator).c_str()); case MetainfoRows::Operator: return @(m_info.GetOperator().c_str()); case MetainfoRows::Internet: return L(@"WiFi_available"); + case MetainfoRows::LocalAdsCandidate: return L(@"create_campaign_button"); + case MetainfoRows::LocalAdsCustomer: return L(@"view_campaign_button"); case MetainfoRows::Coordinate: return @(m_info .GetFormattedCoordinate( diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/ButtonCell/MWMPlacePageButtonCell.h b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/ButtonCell/MWMPlacePageButtonCell.h index 52a94b01b1..1fab5e205f 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/ButtonCell/MWMPlacePageButtonCell.h +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/ButtonCell/MWMPlacePageButtonCell.h @@ -1,12 +1,17 @@ #import "MWMPlacePageData.h" #import "MWMTableViewCell.h" +#import "MWMTypes.h" @protocol MWMPlacePageButtonsProtocol; @interface MWMPlacePageButtonCell : MWMTableViewCell +- (void)configWithTitle:(NSString *)title + action:(MWMVoidBlock)action + isInsetButton:(BOOL)isInsetButton; + - (void)configForRow:(place_page::ButtonsRows)row - withDelegate:(id)delegate; + withAction:(MWMVoidBlock)action; - (void)setEnabled:(BOOL)enabled; - (BOOL)isEnabled; diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/ButtonCell/MWMPlacePageButtonCell.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/ButtonCell/MWMPlacePageButtonCell.mm index f535b6e8a6..457f234cf8 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/ButtonCell/MWMPlacePageButtonCell.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/ButtonCell/MWMPlacePageButtonCell.mm @@ -7,8 +7,8 @@ @property(weak, nonatomic) IBOutlet MWMBorderedButton * titleButton; -@property(weak, nonatomic) id delegate; @property(nonatomic) place_page::ButtonsRows rowType; +@property(copy, nonatomic) MWMVoidBlock action; @property(weak, nonatomic) IBOutlet NSLayoutConstraint * buttonTop; @property(weak, nonatomic) IBOutlet NSLayoutConstraint * buttonTrailing; @@ -31,13 +31,24 @@ - (void)setEnabled:(BOOL)enabled { self.titleButton.enabled = enabled; } - (BOOL)isEnabled { return self.titleButton.isEnabled; } + +- (void)configWithTitle:(NSString *)title + action:(MWMVoidBlock)action + isInsetButton:(BOOL)isInsetButton +{ + self.rowType = place_page::ButtonsRows::Other; + self.action = action; + self.isInsetButton = isInsetButton; + [self.titleButton setTitle:title forState:UIControlStateNormal]; +} + - (void)configForRow:(place_page::ButtonsRows)row - withDelegate:(id)delegate + withAction:(MWMVoidBlock)action { using place_page::ButtonsRows; - self.delegate = delegate; self.rowType = row; + self.action = action; NSString * title = nil; BOOL isInsetButton = NO; switch (row) @@ -56,23 +67,9 @@ break; case ButtonsRows::HotelDescription: title = L(@"details_on_bookingcom"); - break; - case ButtonsRows::BookingShowMoreFacilities: - title = L(@"booking_show_more"); - break; - case ButtonsRows::BookingShowMoreReviews: - title = L(@"reviews_on_bookingcom"); - break; - case ButtonsRows::BookingShowMoreOnSite: - title = L(@"more_on_bookingcom"); - break; - case ButtonsRows::LocalAdsCandidate: - title = L(@"create_campaign_button"); isInsetButton = YES; break; - case ButtonsRows::LocalAdsCustomer: - title = L(@"view_campaign_button"); - isInsetButton = YES; + case ButtonsRows::Other: break; } @@ -82,21 +79,8 @@ - (IBAction)buttonTap { - using place_page::ButtonsRows; - - auto d = self.delegate; - switch (self.rowType) - { - case ButtonsRows::AddPlace: [d addPlace]; break; - case ButtonsRows::EditPlace: [d editPlace]; break; - case ButtonsRows::AddBusiness: [d addBusiness]; break; - case ButtonsRows::BookingShowMoreOnSite: - case ButtonsRows::HotelDescription: [d book:YES]; break; - case ButtonsRows::BookingShowMoreFacilities: [d showAllFacilities]; break; - case ButtonsRows::BookingShowMoreReviews: [d showAllReviews]; break; - case ButtonsRows::LocalAdsCandidate: - case ButtonsRows::LocalAdsCustomer: [d openLocalAdsURL]; break; - } + if (self.action) + self.action(); } #pragma mark - Properties diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/RegularCell/MWMPlacePageRegularCell.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/RegularCell/MWMPlacePageRegularCell.mm index 4a85895d2a..b398ca3940 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/RegularCell/MWMPlacePageRegularCell.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Content/RegularCell/MWMPlacePageRegularCell.mm @@ -77,8 +77,7 @@ name = @"coordinate"; break; case MetainfoRows::ExtendedOpeningHours: - case MetainfoRows::OpeningHours: - case MetainfoRows::Taxi: NSAssert(false, @"Incorrect cell type!"); break; + case MetainfoRows::OpeningHours: break; } [self configWithIconName:name data:[data stringForRow:row]]; } @@ -154,8 +153,7 @@ case MetainfoRows::Operator: case MetainfoRows::OpeningHours: case MetainfoRows::Address: - case MetainfoRows::Internet: - case MetainfoRows::Taxi: break; + case MetainfoRows::Internet: break; } } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm index ccbf046062..cb94adf0c2 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm @@ -31,8 +31,7 @@ map const kMetaInfoCells = { {MetainfoRows::Cuisine, [MWMPlacePageInfoCell class]}, {MetainfoRows::Operator, [MWMPlacePageInfoCell class]}, {MetainfoRows::Coordinate, [MWMPlacePageInfoCell class]}, - {MetainfoRows::Internet, [MWMPlacePageInfoCell class]}, - {MetainfoRows::Taxi, [MWMPlacePageTaxiCell class]}}; + {MetainfoRows::Internet, [MWMPlacePageInfoCell class]}}; } // namespace @interface MWMPlacePageLayout () const kMetaInfoCells = { [tv registerWithCellClass:[MWMPPReviewHeaderCell class]]; [tv registerWithCellClass:[MWMPPReviewCell class]]; [tv registerWithCellClass:[MWMPPFacilityCell class]]; + [tv registerWithCellClass:[MWMPlacePageTaxiCell class]]; // Register all meta info cells. for (auto const & pair : kMetaInfoCells) @@ -316,6 +316,7 @@ map const kMetaInfoCells = { case Sections::Bookmark: return 1; case Sections::Preview: return data.previewRows.size(); case Sections::Metainfo: return data.metainfoRows.size(); + case Sections::Ad: return data.adRows.size(); case Sections::Buttons: return data.buttonsRows.size(); case Sections::HotelPhotos: return data.photosRows.size(); case Sections::HotelDescription: return data.descriptionRows.size(); @@ -373,24 +374,43 @@ map const kMetaInfoCells = { [c configWithRow:row data:data]; return c; } - case MetainfoRows::Taxi: + case MetainfoRows::LocalAdsCustomer: + case MetainfoRows::LocalAdsCandidate: { - Class cls = kMetaInfoCells.at(row); - auto c = static_cast( - [tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]); - c.delegate = delegate; + Class cls = [MWMPlacePageButtonCell class]; + auto c = static_cast([tableView dequeueReusableCellWithCellClass:cls + indexPath:indexPath]); + [c configWithTitle:[data stringForRow:row] action:^{ [delegate openLocalAdsURL]; } isInsetButton:NO]; return c; } } } + case Sections::Ad: + { + Class cls = [MWMPlacePageTaxiCell class]; + auto c = static_cast( + [tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]); + c.delegate = delegate; + return c; + } case Sections::Buttons: { Class cls = [MWMPlacePageButtonCell class]; auto c = static_cast( [tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]); auto const row = data.buttonsRows[indexPath.row]; - [c configForRow:row withDelegate:delegate]; + [c configForRow:row withAction:^{ + switch (row) + { + case ButtonsRows::AddPlace: [delegate addPlace]; break; + case ButtonsRows::EditPlace: [delegate editPlace]; break; + case ButtonsRows::AddBusiness: [delegate addBusiness]; break; + case ButtonsRows::HotelDescription: [delegate book:YES]; break; + case ButtonsRows::Other: NSAssert(false, @"Incorrect row"); + } + }]; + if (row != ButtonsRows::HotelDescription) [c setEnabled:self.isPlacePageButtonsEnabled]; else @@ -420,7 +440,7 @@ map const kMetaInfoCells = { case HotelFacilitiesRow::ShowMore: Class cls = [MWMPlacePageButtonCell class]; auto c = static_cast([tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]); - [c configForRow:ButtonsRows::BookingShowMoreFacilities withDelegate:delegate]; + [c configWithTitle:L(@"booking_show_more") action:^{ [delegate showAllFacilities]; } isInsetButton:NO]; return c; } } @@ -447,7 +467,8 @@ map const kMetaInfoCells = { { Class cls = [MWMPlacePageButtonCell class]; auto c = static_cast([tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]); - [c configForRow:ButtonsRows::BookingShowMoreReviews withDelegate:delegate]; + + [c configWithTitle:L(@"reviews_on_bookingcom") action:^{ [delegate showAllReviews]; } isInsetButton:NO]; return c; } } @@ -469,7 +490,7 @@ map const kMetaInfoCells = { { Class cls = [MWMPlacePageButtonCell class]; auto c = static_cast([tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]); - [c configForRow:ButtonsRows::BookingShowMoreOnSite withDelegate:delegate]; + [c configWithTitle:L(@"more_on_bookingcom") action:^{ [delegate book:YES];; } isInsetButton:NO]; return c; } }