diff --git a/iphone/Maps/Categories/UIColor+MapsMeColor.h b/iphone/Maps/Categories/UIColor+MapsMeColor.h index c95ee9366b..c185ff608a 100644 --- a/iphone/Maps/Categories/UIColor+MapsMeColor.h +++ b/iphone/Maps/Categories/UIColor+MapsMeColor.h @@ -50,6 +50,7 @@ + (UIColor *)border; + (UIColor *)colorWithName:(NSString *)colorName; ++ (UIColor *)colorFromHexString:(NSString *)hexString; + (void)setNightMode:(BOOL)mode; + (BOOL)isNightMode; diff --git a/iphone/Maps/Categories/UIColor+MapsMeColor.mm b/iphone/Maps/Categories/UIColor+MapsMeColor.mm index db8868fd8f..41fdc37e91 100644 --- a/iphone/Maps/Categories/UIColor+MapsMeColor.mm +++ b/iphone/Maps/Categories/UIColor+MapsMeColor.mm @@ -113,6 +113,16 @@ UIColor * color(SEL cmd) @implementation UIColor (MapsMeColor) +// hex string without # ++ (UIColor *)colorFromHexString:(NSString *)hexString +{ + unsigned rgbValue = 0; + NSScanner *scanner = [NSScanner scannerWithString:hexString]; + [scanner setScanLocation:0]; + [scanner scanHexInt:&rgbValue]; + return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0]; +} + + (void)setNightMode:(BOOL)mode { isNightMode = mode; diff --git a/iphone/Maps/Categories/UIKitCategories.h b/iphone/Maps/Categories/UIKitCategories.h index 7a311e7d8b..b842f83649 100644 --- a/iphone/Maps/Categories/UIKitCategories.h +++ b/iphone/Maps/Categories/UIKitCategories.h @@ -25,15 +25,6 @@ static inline CGFloat LengthCGPoint(CGPoint point) @end -@interface UIColor (HexColor) - -+ (UIColor *)colorWithColorCode:(NSString *)colorCode; -+ (UIColor *)applicationBackgroundColor; -+ (UIColor *)applicationColor; -+ (UIColor *)navigationBarColor; - -@end - @interface UIView (Coordinates) @property (nonatomic) CGFloat minX; diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 8d1328a0a4..3b6b88d387 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -568,6 +568,7 @@ BB8123CF212C264700ADE512 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB8123CD212C264700ADE512 /* Metal.framework */; }; BB8123D0212C264700ADE512 /* MetalKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB8123CE212C264700ADE512 /* MetalKit.framework */; }; BB8123D62130427E00ADE512 /* MetalContextFactory.mm in Sources */ = {isa = PBXBuildFile; fileRef = BB8123D52130427E00ADE512 /* MetalContextFactory.mm */; }; + CD08887422B7ABB400C1368D /* MWMDiscoveryCollectionView.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD08887322B7ABB400C1368D /* MWMDiscoveryCollectionView.mm */; }; CD96C70C22A681C400DB7CFE /* DiscoveryGuideCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD96C70A22A681C400DB7CFE /* DiscoveryGuideCell.swift */; }; CD96C70D22A681C400DB7CFE /* DiscoveryGuideCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = CD96C70B22A681C400DB7CFE /* DiscoveryGuideCell.xib */; }; CD96C71122A6820800DB7CFE /* DiscoveryGuideCollectionHolderCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = CD96C70F22A6820800DB7CFE /* DiscoveryGuideCollectionHolderCell.xib */; }; @@ -1604,6 +1605,8 @@ BB8123CE212C264700ADE512 /* MetalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MetalKit.framework; path = System/Library/Frameworks/MetalKit.framework; sourceTree = SDKROOT; }; BB8123D42130427E00ADE512 /* MetalContextFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MetalContextFactory.h; sourceTree = ""; }; BB8123D52130427E00ADE512 /* MetalContextFactory.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MetalContextFactory.mm; sourceTree = ""; }; + CD08887222B7ABB400C1368D /* MWMDiscoveryCollectionView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMDiscoveryCollectionView.h; sourceTree = ""; }; + CD08887322B7ABB400C1368D /* MWMDiscoveryCollectionView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMDiscoveryCollectionView.mm; sourceTree = ""; }; CD96C70A22A681C400DB7CFE /* DiscoveryGuideCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoveryGuideCell.swift; sourceTree = ""; }; CD96C70B22A681C400DB7CFE /* DiscoveryGuideCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DiscoveryGuideCell.xib; sourceTree = ""; }; CD96C70F22A6820800DB7CFE /* DiscoveryGuideCollectionHolderCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DiscoveryGuideCollectionHolderCell.xib; sourceTree = ""; }; @@ -4395,6 +4398,8 @@ CDB92CED229E9CF900EC757C /* MWMDiscoveryMapObjects.mm */, CD96C71522A7B5DE00DB7CFE /* MWMDiscoveryCityGalleryObjects.h */, CD96C71622A7B5DE00DB7CFE /* MWMDiscoveryCityGalleryObjects.mm */, + CD08887222B7ABB400C1368D /* MWMDiscoveryCollectionView.h */, + CD08887322B7ABB400C1368D /* MWMDiscoveryCollectionView.mm */, ); path = Discovery; sourceTree = ""; @@ -5385,6 +5390,7 @@ 6741AA291BF340DE002C974C /* ColorPickerView.mm in Sources */, 6741AA2B1BF340DE002C974C /* CircleView.mm in Sources */, F6E2FEEB1E097BA00083EBEC /* MWMSearchTextField.mm in Sources */, + CD08887422B7ABB400C1368D /* MWMDiscoveryCollectionView.mm in Sources */, 4788739220EE326500F6826B /* VerticallyAlignedButton.swift in Sources */, 3444DFDE1F18A5AF00E73099 /* SideButtonsArea.swift in Sources */, 3451F4EE1F026DAF00A981F2 /* PlacePageTaxiCell.swift in Sources */, diff --git a/iphone/Maps/UI/Discovery/Collection Cells/DiscoveryGuideCell.swift b/iphone/Maps/UI/Discovery/Collection Cells/DiscoveryGuideCell.swift index 2f0170b7b6..1184d9e29e 100644 --- a/iphone/Maps/UI/Discovery/Collection Cells/DiscoveryGuideCell.swift +++ b/iphone/Maps/UI/Discovery/Collection Cells/DiscoveryGuideCell.swift @@ -26,11 +26,7 @@ final class DiscoveryGuideCell: UICollectionViewCell { } } - @IBOutlet var proContainer: UIView! { - didSet { - proLabel.backgroundColor = UIColor.ratingRed() - } - } + @IBOutlet var proContainer: UIView! @IBOutlet var detailsButton: UIButton! { didSet { @@ -81,6 +77,7 @@ final class DiscoveryGuideCell: UICollectionViewCell { title: String, subtitle: String, label: String?, + labelHexColor: String?, onDetails: @escaping OnDetails) { setAvatar(avatarURL) titleLabel.text = title @@ -91,6 +88,11 @@ final class DiscoveryGuideCell: UICollectionViewCell { return } proLabel.text = label + if let labelHexColor = labelHexColor, labelHexColor.count == 6 { + proContainer.backgroundColor = UIColor(fromHexString: labelHexColor) ?? UIColor.ratingRed() + } else { + proContainer.backgroundColor = UIColor.ratingRed() + } proContainer.isHidden = false } diff --git a/iphone/Maps/UI/Discovery/Collection Cells/DiscoveryGuideCell.xib b/iphone/Maps/UI/Discovery/Collection Cells/DiscoveryGuideCell.xib index f2d7fa3aff..949c94b145 100644 --- a/iphone/Maps/UI/Discovery/Collection Cells/DiscoveryGuideCell.xib +++ b/iphone/Maps/UI/Discovery/Collection Cells/DiscoveryGuideCell.xib @@ -19,7 +19,7 @@ - + @@ -36,6 +36,9 @@ + + + - + @@ -45,12 +47,12 @@ - - - + + + @@ -65,7 +67,7 @@ - + diff --git a/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoveryCollectionHolderCell.swift b/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoveryCollectionHolderCell.swift index 3aeaa17a36..f3d5d38366 100644 --- a/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoveryCollectionHolderCell.swift +++ b/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoveryCollectionHolderCell.swift @@ -32,7 +32,7 @@ final class DiscoveryBookingCollectionHolderCell: DiscoveryCollectionHolder { @objc(MWMDiscoveryGuideCollectionHolderCell) final class DiscoveryGuideCollectionHolderCell: DiscoveryCollectionHolder { @objc func config() { - header.text = L("discovery_button_subtitle_guides").uppercased() + header.text = L("gallery_pp_download_guides_title").uppercased() collectionView.register(cellClass: DiscoveryGuideCell.self) collectionView.register(cellClass: DiscoveryMoreCell.self) } diff --git a/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoveryGuideCollectionHolderCell.xib b/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoveryGuideCollectionHolderCell.xib index 832998d35f..4ebee5d6a5 100644 --- a/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoveryGuideCollectionHolderCell.xib +++ b/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoveryGuideCollectionHolderCell.xib @@ -12,15 +12,18 @@ - - + + - - + + - + - + @@ -45,9 +48,9 @@ - - + + diff --git a/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoverySearchCollectionHolderCell.xib b/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoverySearchCollectionHolderCell.xib index 125797a567..d3a6d914f6 100644 --- a/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoverySearchCollectionHolderCell.xib +++ b/iphone/Maps/UI/Discovery/Table Cells/Holders/DiscoverySearchCollectionHolderCell.xib @@ -1,12 +1,11 @@ - + - - + @@ -15,12 +14,15 @@ - + - + @@ -45,13 +47,13 @@ - - - + + + - + diff --git a/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryControllerViewModel.mm b/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryControllerViewModel.mm index 4975debcdd..e1906e1bb2 100644 --- a/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryControllerViewModel.mm +++ b/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryControllerViewModel.mm @@ -159,6 +159,7 @@ using namespace discovery; return [[MWMDiscoveryGuideViewModel alloc] initWithTitle:@(item.m_name.c_str()) subtitle:@(item.m_author.m_name.c_str()) label:@(item.m_luxCategory.m_name.c_str()) + labelHexColor:@(item.m_luxCategory.m_color.c_str()) imageURL:@(item.m_imageUrl.c_str())]; } diff --git a/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryGuideViewModel.h b/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryGuideViewModel.h index cb5be67618..0148c0e654 100644 --- a/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryGuideViewModel.h +++ b/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryGuideViewModel.h @@ -5,11 +5,13 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, readonly) NSString *title; @property(nonatomic, readonly) NSString *subtitle; @property(nonatomic, nullable, readonly) NSString *label; +@property(nonatomic, nullable, readonly) NSString *labelHexColor; @property(nonatomic, nullable, readonly) NSString *imagePath; - (instancetype)initWithTitle:(NSString *)title subtitle:(NSString *)subtitle label:(nullable NSString *)label + labelHexColor:(nullable NSString *)labelHexColor imageURL:(nullable NSString *) imagePath; @end diff --git a/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryGuideViewModel.m b/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryGuideViewModel.m index 18cd51683d..a4ecacd4e3 100644 --- a/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryGuideViewModel.m +++ b/iphone/Maps/UI/Discovery/View Models/MWMDiscoveryGuideViewModel.m @@ -5,6 +5,7 @@ @property(nonatomic, readwrite) NSString *title; @property(nonatomic, readwrite) NSString *subtitle; @property(nonatomic, readwrite) NSString *label; +@property(nonatomic, readwrite) NSString *labelHexColor; @property(nonatomic, readwrite) NSString *imagePath; @end @@ -14,12 +15,14 @@ - (instancetype)initWithTitle:(NSString *)title subtitle:(NSString *)subtitle label:(NSString *)label + labelHexColor:(NSString *)labelHexColor imageURL:(NSString *) imagePath { self = [super init]; if (self) { self.title = title; self.subtitle = subtitle; self.label = label; + self.labelHexColor = labelHexColor; self.imagePath = imagePath; } return self; diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageButtonsProtocol.h b/iphone/Maps/UI/PlacePage/MWMPlacePageButtonsProtocol.h index 610967743b..ef340a9370 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageButtonsProtocol.h +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageButtonsProtocol.h @@ -34,4 +34,6 @@ typedef UIView * _Nullable (^MWMPlacePageButtonsDismissBlock)(NSInteger); - (void)showPlaceDescription:(NSString * _Nonnull)htmlString; +- (void)openCatalogForURL:(NSURL * _Nullable)url; + @end diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h index 1a0e1f2155..559d716439 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h @@ -51,7 +51,8 @@ enum class Sections Buttons, UGCRating, UGCAddReview, - UGCReviews + UGCReviews, + PromoCatalog }; enum class PreviewRows @@ -128,6 +129,13 @@ enum class OpeningHours Closed, Unknown }; + +enum class PromoCatalogRow +{ + Guides, + GuidesNoInternetError, + GuidesRequestError +}; using NewSectionsAreReady = void (^)(NSRange const & range, MWMPlacePageData * data, BOOL isSection); } // namespace place_page @@ -136,6 +144,8 @@ using NewSectionsAreReady = void (^)(NSRange const & range, MWMPlacePageData * d @class MWMUGCViewModel; @class MWMUGCReviewModel; @class MWMUGCRatingValueType; +@class MWMDiscoveryCityGalleryObjects; +@class MWMDiscoveryGuideViewModel; @protocol MWMBanner; /// ViewModel for place page. @@ -145,7 +155,9 @@ using NewSectionsAreReady = void (^)(NSRange const & range, MWMPlacePageData * d @property(copy, nonatomic) place_page::NewSectionsAreReady sectionsAreReadyCallback; @property(copy, nonatomic) MWMVoidBlock bannerIsReadyCallback; @property(copy, nonatomic) MWMVoidBlock bookingDataUpdatedCallback; +@property(copy, nonatomic) MWMVoidBlock refreshPromoCallback; @property(nonatomic, readonly) MWMUGCViewModel * ugc; +@property(nonatomic, readonly) MWMDiscoveryCityGalleryObjects *promoGallery; @property(nonatomic, readonly) NSInteger bookingDiscount; @property(nonatomic, readonly) BOOL isSmartDeal; @property(nonatomic, readonly) BOOL isPopular; @@ -228,6 +240,10 @@ using NewSectionsAreReady = void (^)(NSRange const & range, MWMPlacePageData * d - (NSString *)localAdsURL; - (void)logLocalAdsEvent:(local_ads::EventType)type; +// Promo Catalog +- (void)fillPromoCatalogSection; +- (MWMDiscoveryGuideViewModel *)guideAtIndex:(NSUInteger)index; + // Table view's data - (std::vector const &)sections; - (std::vector const &)previewRows; @@ -238,6 +254,7 @@ using NewSectionsAreReady = void (^)(NSRange const & range, MWMPlacePageData * d - (std::vector const &)metainfoRows; - (std::vector const &)adRows; - (std::vector const &)buttonsRows; +- (std::vector const &)promoCatalogRows; // Table view metainfo rows - (NSString *)stringForRow:(place_page::MetainfoRows)row; @@ -250,6 +267,7 @@ using NewSectionsAreReady = void (^)(NSRange const & range, MWMPlacePageData * d - (BOOL)isOpentable; - (BOOL)isPartner; - (BOOL)isHolidayObject; +- (BOOL)isPromoCatalog; - (BOOL)isBookingSearch; - (BOOL)isHTMLDescription; - (BOOL)isMyPosition; diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm index 28a12abf8f..3d6c4502e9 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm @@ -1,6 +1,8 @@ #import "MWMPlacePageData.h" #import "AppInfo.h" #import "LocaleTranslator.h" +#import "MWMDiscoveryCityGalleryObjects.h" +#import "MWMDiscoveryGuideViewModel.h" #import "MWMBannerHelpers.h" #import "MWMBookmarksManager.h" #import "MWMNetworkPolicy.h" @@ -18,6 +20,7 @@ #include "partners_api/booking_api.hpp" #include "partners_api/booking_block_params.hpp" +#include "partners_api/promo_api.hpp" #include "3party/opening_hours/opening_hours.hpp" @@ -38,6 +41,7 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; @property(copy, nonatomic) NSArray * photos; @property(nonatomic) NSNumberFormatter * currencyFormatter; @property(nonatomic, readwrite) MWMUGCViewModel * ugc; +@property(nonatomic, readwrite) MWMDiscoveryCityGalleryObjects *promoGallery; @property(nonatomic) NSInteger bookingDiscount; @property(nonatomic) BOOL isSmartDeal; @@ -56,6 +60,7 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; std::vector m_hotelDescriptionRows; std::vector m_hotelFacilitiesRows; std::vector m_hotelReviewsRows; + std::vector m_promoCatalogRows; booking::HotelInfo m_hotelInfo; } @@ -87,6 +92,10 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; m_sections.push_back(Sections::Preview); [self fillPreviewSection]; + + if (self.isPromoCatalog) { + m_sections.push_back(Sections::PromoCatalog); + } if ([[self placeDescription] length] && ![[self bookmarkDescription] length]) m_sections.push_back(Sections::Description); @@ -798,6 +807,7 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; .c_str()); } } +- (std::vector const &)promoCatalogRows { return m_promoCatalogRows; } #pragma mark - Helpers @@ -808,6 +818,7 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; - (BOOL)isOpentable { return m_info.GetSponsoredType() == SponsoredType::Opentable; } - (BOOL)isPartner { return m_info.GetSponsoredType() == SponsoredType::Partner; } - (BOOL)isHolidayObject { return m_info.GetSponsoredType() == SponsoredType::Holiday; } +- (BOOL)isPromoCatalog { return m_info.GetSponsoredType() == SponsoredType::PromoCatalog; } - (BOOL)isBookingSearch { return !m_info.GetBookingSearchUrl().empty(); } - (BOOL)isMyPosition { return m_info.IsMyPosition(); } - (BOOL)isHTMLDescription { return strings::IsHTML(GetPreferredBookmarkStr(m_info.GetBookmarkData().m_description)); } @@ -854,4 +865,44 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; return [result componentsJoinedByString:@", "]; } +#pragma mark - Promo Gallery + +- (void)fillPromoCatalogSection { + if (!self.isPromoCatalog) { + return; + } + network_policy::CallPartnersApi([self](auto const & canUseNetwork) { + auto const api = GetFramework().GetPromoApi(canUseNetwork); + if (!api) + return; + auto const row = canUseNetwork.CanUse() ? PromoCatalogRow::GuidesRequestError : PromoCatalogRow::GuidesNoInternetError; + auto const resultHandler = [self](promo::CityGallery const & cityGallery) { + self.promoGallery = [[MWMDiscoveryCityGalleryObjects alloc] initWithGalleryResults:cityGallery]; + m_promoCatalogRows.push_back(PromoCatalogRow::Guides); + if (self.refreshPromoCallback) { + self.refreshPromoCallback(); + } + }; + + auto const errorHandler = [self, row]() { + m_promoCatalogRows.push_back(row); + if (self.refreshPromoCallback) { + self.refreshPromoCallback(); + } + }; + auto appInfo = AppInfo.sharedInfo; + auto locale = appInfo.twoLetterLanguageId.UTF8String; + api->GetCityGallery("", locale, resultHandler, errorHandler); + }); +} + +- (MWMDiscoveryGuideViewModel *)guideAtIndex:(NSUInteger)index { + promo::CityGallery::Item const &item = [self.promoGallery galleryItemAtIndex:index]; + return [[MWMDiscoveryGuideViewModel alloc] initWithTitle:@(item.m_name.c_str()) + subtitle:@(item.m_author.m_name.c_str()) + label:@(item.m_luxCategory.m_name.c_str()) + labelHexColor:@(item.m_luxCategory.m_color.c_str()) + imageURL:@(item.m_imageUrl.c_str())]; +} + @end diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm index 5eb1f70afe..92733a1043 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm @@ -768,4 +768,15 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type, place_page: [data setUGCUpdateFrom:model resultHandler:resultHandler]; } +#pragma mark - MWMPlacePagePromoProtocol + +- (void)openCatalogForURL:(NSURL *)url { + auto bookmarks = [[MWMBookmarksTabViewController alloc] init]; + bookmarks.activeTab = ActiveTabCatalog; + MWMCatalogWebViewController *catalog = [[MWMCatalogWebViewController alloc] init:url]; + NSMutableArray * controllers = [self.ownerViewController.navigationController.viewControllers mutableCopy]; + [controllers addObjectsFromArray:@[bookmarks, catalog]]; + [self.ownerViewController.navigationController setViewControllers:controllers animated:YES]; +} + @end diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm index e4556372fc..54db2670ec 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/MWMPlacePageLayout.mm @@ -1,5 +1,8 @@ #import "MWMPlacePageLayout.h" #import "MWMBookmarkCell.h" +#import "MWMDiscoveryCityGalleryObjects.h" +#import "MWMDiscoveryCollectionView.h" +#import "MWMDiscoveryGuideViewModel.h" #import "MWMPlaceDescriptionCell.h" #import "MWMOpeningHoursLayoutHelper.h" #import "MWMPPPreviewLayoutHelper.h" @@ -35,7 +38,10 @@ map const kMetaInfoCells = { {MetainfoRows::Internet, [MWMPlacePageInfoCell class]}}; } // namespace -@interface MWMPlacePageLayout () @property(weak, nonatomic) MWMPlacePageData * data; @@ -102,6 +108,8 @@ map const kMetaInfoCells = { [tv registerWithCellClass:[MWMUGCAddReviewCell class]]; [tv registerWithCellClass:[MWMUGCYourReviewCell class]]; [tv registerWithCellClass:[MWMUGCReviewCell class]]; + [tv registerWithCellClass:[MWMDiscoveryOnlineTemplateCell class]]; + [tv registerWithCellClass:[MWMDiscoveryGuideCollectionHolderCell class]]; // Register all meta info cells. for (auto const & pair : kMetaInfoCells) @@ -118,6 +126,7 @@ map const kMetaInfoCells = { dispatch_async(dispatch_get_main_queue(), ^{ [data fillOnlineBookingSections]; + [data fillPromoCatalogSection]; }); } @@ -297,6 +306,7 @@ map const kMetaInfoCells = { case Sections::UGCRating: return data.ugc.ratingCellsCount; case Sections::UGCAddReview: return data.ugc.addReviewCellsCount; case Sections::UGCReviews: return data.ugc.reviewRows.size(); + case Sections::PromoCatalog: return 1; } } @@ -593,6 +603,34 @@ map const kMetaInfoCells = { } } } + case Sections::PromoCatalog: + { + auto rows = self.data.promoCatalogRows; + if (rows.empty() || rows[indexPath.row] != PromoCatalogRow::Guides) { + Class cls = [MWMDiscoveryOnlineTemplateCell class]; + MWMDiscoveryOnlineTemplateCell * cell = (MWMDiscoveryOnlineTemplateCell *)[tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]; + __weak __typeof__(self) weakSelf = self; + [cell configWithType:MWMDiscoveryOnlineTemplateTypePromo + needSpinner:rows.empty() + canUseNetwork: rows.empty() || rows[indexPath.row] == PromoCatalogRow::GuidesRequestError + tap:^{ + __strong __typeof__(weakSelf) strongSelf = weakSelf; + if (!strongSelf) { return; } + NSURL *url = [strongSelf.data.promoGallery moreURL]; + [strongSelf.delegate openCatalogForURL:url]; + }]; + return cell; + } + Class cls = [MWMDiscoveryGuideCollectionHolderCell class]; + MWMDiscoveryGuideCollectionHolderCell *cell = (MWMDiscoveryGuideCollectionHolderCell *) + [tableView dequeueReusableCellWithCellClass:cls indexPath:indexPath]; + MWMDiscoveryCollectionView *collection = (MWMDiscoveryCollectionView *)cell.collectionView; + [cell config]; + collection.delegate = self; + collection.dataSource = self; + collection.itemType = discovery::ItemType::Promo; + return cell; + } } } @@ -735,6 +773,12 @@ map const kMetaInfoCells = { data.bannerIsReadyCallback = ^{ [self.previewLayoutHelper insertRowAtTheEnd]; }; + + data.refreshPromoCallback = ^{ + auto tv = self.placePageView.tableView; + [tv reloadSections:[NSIndexSet indexSetWithIndex:1] + withRowAnimation:UITableViewRowAnimationFade]; + }; [self.actionBar configureWithData:data]; [self.previewLayoutHelper configWithData:data]; @@ -749,4 +793,59 @@ map const kMetaInfoCells = { self.buttonsSectionEnabled = YES; } +#pragma mark - UICollectionViewDataSource + +- (NSInteger)collectionView:(MWMDiscoveryCollectionView *)collectionView + numberOfItemsInSection:(NSInteger)section +{ + NSInteger count = self.data.promoGallery.count; + return count > 0 ? count + 1 : 0; +} + +- (UICollectionViewCell *)collectionView:(MWMDiscoveryCollectionView *)collectionView + cellForItemAtIndexPath:(NSIndexPath *)indexPath { + auto data = self.data; + if (!data) { + return [[UICollectionViewCell alloc] init]; + } + + if (indexPath.row == self.data.promoGallery.count) { + Class cls = [MWMDiscoveryMoreCell class]; + MWMDiscoveryMoreCell *cell = (MWMDiscoveryMoreCell *)[collectionView + dequeueReusableCellWithCellClass:cls + indexPath:indexPath]; + return cell; + } + + Class cls = [MWMDiscoveryGuideCell class]; + MWMDiscoveryGuideCell *cell = (MWMDiscoveryGuideCell *) + [collectionView dequeueReusableCellWithCellClass:cls indexPath:indexPath]; + MWMDiscoveryGuideViewModel *objectVM = [self.data guideAtIndex:indexPath.item]; + __weak __typeof__(self) weakSelf = self; + [cell configWithAvatarURL:objectVM.imagePath + title:objectVM.title + subtitle:objectVM.subtitle + label:objectVM.label + labelHexColor:objectVM.labelHexColor + onDetails:^{ + __strong __typeof__(weakSelf) strongSelf = weakSelf; + if (!strongSelf) { return; } + promo::CityGallery::Item const &item = [strongSelf.data.promoGallery galleryItemAtIndex:indexPath.row]; + NSString *itemPath = @(item.m_url.c_str()); + if (!itemPath || itemPath.length == 0) { + return; + } + NSURL *url = [NSURL URLWithString:itemPath]; + [strongSelf.delegate openCatalogForURL:url]; + }]; + return cell; +} + +#pragma mark - UICollectionViewDelegate + +- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { + NSURL *url = [self.data.promoGallery moreURL]; + [self.delegate openCatalogForURL:url]; +} + @end