From 2aa6cae74efb0ab7a5aaace2c696de6100ecefda Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Fri, 10 Feb 2017 10:58:57 +0300 Subject: [PATCH] [MAPSME-3810] [ios] Added Facebook ads banner. --- iphone/Maps/Bridging-Header.h | 1 + iphone/Maps/Categories/UIColor+MapsMeColor.h | 1 + iphone/Maps/Categories/UIColor+MapsMeColor.mm | 13 +- .../MWMMapViewControlsManager.mm | 25 ++-- iphone/Maps/Common/MWMCommon.h | 13 +- iphone/Maps/Common/MWMConsts.h | 11 ++ iphone/Maps/Maps.xcodeproj/project.pbxproj | 26 ++++ iphone/Maps/UI/Ads/FBAdsBanner.swift | 83 ++++++++++++ iphone/Maps/UI/Ads/FBAdsBanner.xib | 127 ++++++++++++++++++ iphone/Maps/UI/PlacePage/MWMPlacePageData.h | 1 + iphone/Maps/UI/PlacePage/MWMPlacePageData.mm | 9 +- .../PlacePageView/MWMPPView.xib | 12 +- .../Preview/MWMPPPreviewLayoutHelper.mm | 21 ++- 13 files changed, 314 insertions(+), 29 deletions(-) create mode 100644 iphone/Maps/Common/MWMConsts.h create mode 100644 iphone/Maps/UI/Ads/FBAdsBanner.swift create mode 100644 iphone/Maps/UI/Ads/FBAdsBanner.xib diff --git a/iphone/Maps/Bridging-Header.h b/iphone/Maps/Bridging-Header.h index 1dbbdd6d97..5dada36761 100644 --- a/iphone/Maps/Bridging-Header.h +++ b/iphone/Maps/Bridging-Header.h @@ -8,6 +8,7 @@ #import "AppInfo.h" #import "MWMController.h" +#import "MWMConsts.h" #import "MWMFrameworkHelper.h" #import "MWMKeyboard.h" #import "MWMLocationManager.h" diff --git a/iphone/Maps/Categories/UIColor+MapsMeColor.h b/iphone/Maps/Categories/UIColor+MapsMeColor.h index 7621fb3dc1..9787eb0448 100644 --- a/iphone/Maps/Categories/UIColor+MapsMeColor.h +++ b/iphone/Maps/Categories/UIColor+MapsMeColor.h @@ -35,6 +35,7 @@ + (UIColor *)bookingBackground; + (UIColor *)opentableBackground; + (UIColor *)bannerBackground; ++ (UIColor *)bannerButtonBackground; + (UIColor *)toastBackground; + (UIColor *)statusBarBackground; diff --git a/iphone/Maps/Categories/UIColor+MapsMeColor.mm b/iphone/Maps/Categories/UIColor+MapsMeColor.mm index ca8ed8d282..ade842d1f1 100644 --- a/iphone/Maps/Categories/UIColor+MapsMeColor.mm +++ b/iphone/Maps/Categories/UIColor+MapsMeColor.mm @@ -65,7 +65,9 @@ NSDictionary * night = @{ [UIColor colorWithRed:scaled(60.) green:scaled(64.) blue:scaled(68.) alpha:alpha90], @"blackOpaque" : [UIColor colorWithWhite:1. alpha:alpha04], @"bannerBackground" : - [UIColor colorWithRed:scaled(85.) green:scaled(90.) blue:scaled(90.) alpha:alpha100], + [UIColor colorWithRed:scaled(71.) green:scaled(75.) blue:scaled(80.) alpha:alpha100], + @"bannerButtonBackground" : + [UIColor colorWithRed:scaled(45.) green:scaled(48.) blue:scaled(50.) alpha:alpha100], @"toastBackground" : [UIColor colorWithWhite:0. alpha:alpha87], @"statusBarBackground" : [UIColor colorWithWhite:0. alpha:alpha32] }; @@ -113,7 +115,9 @@ NSDictionary * day = @{ @"alertBackground" : [UIColor colorWithWhite:1. alpha:alpha90], @"blackOpaque" : [UIColor colorWithWhite:0. alpha:alpha04], @"bannerBackground" : - [UIColor colorWithRed:scaled(255.) green:scaled(248.) blue:scaled(225.) alpha:alpha100], + [UIColor colorWithRed:scaled(252.) green:scaled(247.) blue:scaled(237.) alpha:alpha100], + @"bannerButtonBackground" : + [UIColor colorWithRed:scaled(242.) green:scaled(234.) blue:scaled(218.) alpha:alpha100], @"toastBackground" : [UIColor colorWithWhite:1. alpha:alpha87], @"statusBarBackground" : [UIColor colorWithWhite:1. alpha:alpha36] }; @@ -314,6 +318,11 @@ UIColor * color(SEL cmd) { return color(_cmd); } + ++ (UIColor *)bannerButtonBackground +{ + return color(_cmd); +} + (UIColor *)toastBackground { return color(_cmd); } + (UIColor *)statusBarBackground { return color(_cmd); } + (UIColor *)colorWithName:(NSString *)colorName diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm index 6dbb605784..83d96a2dcf 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm @@ -22,6 +22,7 @@ #import "MapsAppDelegate.h" #import "Statistics.h" #import "SwiftBridge.h" +#import "MWMNetworkPolicy.h" #import "3party/Alohalytics/src/alohalytics_objc.h" @@ -143,14 +144,22 @@ extern NSString * const kAlohalyticsTapEventKey; - (void)showPlacePage:(place_page::Info const &)info { - self.trafficButtonHidden = YES; - [self.placePageManager show:info]; - if (IPAD) - { - auto ownerView = self.ownerController.view; - [ownerView bringSubviewToFront:self.menuController.view]; - [ownerView bringSubviewToFront:self.navigationManager.routePreview]; - } + auto show = ^{ + self.trafficButtonHidden = YES; + [self.placePageManager show:info]; + if (IPAD) + { + auto ownerView = self.ownerController.view; + [ownerView bringSubviewToFront:self.menuController.view]; + [ownerView bringSubviewToFront:self.navigationManager.routePreview]; + } + }; + + using namespace network_policy; + if (!CanUseNetwork() && GetStage() == platform::NetworkPolicy::Stage::Session) + [[MWMAlertViewController activeAlertController] presentMobileInternetAlertWithBlock:show]; + else + show(); } - (void)searchViewDidEnterState:(MWMSearchManagerState)state diff --git a/iphone/Maps/Common/MWMCommon.h b/iphone/Maps/Common/MWMCommon.h index 39f3d77523..b83e8477d1 100644 --- a/iphone/Maps/Common/MWMCommon.h +++ b/iphone/Maps/Common/MWMCommon.h @@ -1,14 +1,6 @@ #import #import - -static NSString * const BOOKMARK_CATEGORY_DELETED_NOTIFICATION = - @"BookmarkCategoryDeletedNotification"; - -static NSString * const BOOKMARK_DELETED_NOTIFICATION = @"BookmarkDeletedNotification"; - -static NSString * const kMapsmeErrorDomain = @"com.mapsme.error"; - -static CGFloat const kDefaultAnimationDuration = .2; +#import "MWMConsts.h" static inline BOOL firstVersionIsLessThanSecond(NSString * first, NSString * second) { @@ -46,9 +38,6 @@ static inline BOOL isInterfaceRightToLeft() UIUserInterfaceLayoutDirectionRightToLeft; } -static uint64_t const KB = 1024; -static uint64_t const MB = 1024 * 1024; - static inline NSString * formattedSize(uint64_t size) { return diff --git a/iphone/Maps/Common/MWMConsts.h b/iphone/Maps/Common/MWMConsts.h new file mode 100644 index 0000000000..dd54977480 --- /dev/null +++ b/iphone/Maps/Common/MWMConsts.h @@ -0,0 +1,11 @@ +static NSString * const BOOKMARK_CATEGORY_DELETED_NOTIFICATION = +@"BookmarkCategoryDeletedNotification"; + +static NSString * const BOOKMARK_DELETED_NOTIFICATION = @"BookmarkDeletedNotification"; + +static NSString * const kMapsmeErrorDomain = @"com.mapsme.error"; + +static NSTimeInterval const kDefaultAnimationDuration = .2; + +static uint64_t const KB = 1024; +static uint64_t const MB = 1024 * 1024; diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 81d0817431..38e4cd5e8c 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -134,6 +134,12 @@ 3432E1781E49B3A2008477E9 /* Bolts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3432E1771E49B3A2008477E9 /* Bolts.framework */; }; 3432E1791E49B3A2008477E9 /* Bolts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3432E1771E49B3A2008477E9 /* Bolts.framework */; }; 3432E17A1E49B3A2008477E9 /* Bolts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3432E1771E49B3A2008477E9 /* Bolts.framework */; }; + 3432E1811E49BF09008477E9 /* FBAdsBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3432E1801E49BF09008477E9 /* FBAdsBanner.swift */; }; + 3432E1821E49BF09008477E9 /* FBAdsBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3432E1801E49BF09008477E9 /* FBAdsBanner.swift */; }; + 3432E1831E49BF09008477E9 /* FBAdsBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3432E1801E49BF09008477E9 /* FBAdsBanner.swift */; }; + 3432E1851E49BF5C008477E9 /* FBAdsBanner.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3432E1841E49BF5C008477E9 /* FBAdsBanner.xib */; }; + 3432E1861E49BF5C008477E9 /* FBAdsBanner.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3432E1841E49BF5C008477E9 /* FBAdsBanner.xib */; }; + 3432E1871E49BF5C008477E9 /* FBAdsBanner.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3432E1841E49BF5C008477E9 /* FBAdsBanner.xib */; }; 3446C6771DDCA9A200146687 /* libtraffic.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3446C6761DDCA9A200146687 /* libtraffic.a */; }; 3454D7B81E07F045004AF2AD /* CALayer+RuntimeAttributes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3454D79A1E07F045004AF2AD /* CALayer+RuntimeAttributes.mm */; }; 3454D7B91E07F045004AF2AD /* CALayer+RuntimeAttributes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3454D79A1E07F045004AF2AD /* CALayer+RuntimeAttributes.mm */; }; @@ -1413,11 +1419,14 @@ 341C2A5A1B720B8A00AD41A1 /* MWMAPIBarView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMAPIBarView.xib; sourceTree = ""; }; 341F09831C20138100F18AC5 /* libpugixml.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpugixml.a; path = "../../../omim-xcode-build/Debug/libpugixml.a"; sourceTree = ""; }; 34201E0B1DC0E33100D24118 /* libtracking.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtracking.a; path = "../../../omim-xcode-build/Debug/libtracking.a"; sourceTree = ""; }; + 3427AF0B1E49E3A500D466DB /* MWMConsts.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMConsts.h; sourceTree = ""; }; 342CC5EF1C2D7730005F3FE5 /* MWMAuthorizationLoginViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMAuthorizationLoginViewController.h; sourceTree = ""; }; 342CC5F01C2D7730005F3FE5 /* MWMAuthorizationLoginViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMAuthorizationLoginViewController.mm; sourceTree = ""; }; 342EE40F1C43DAA7009F6A49 /* MWMAuthorizationWebViewLoginViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMAuthorizationWebViewLoginViewController.h; sourceTree = ""; }; 342EE4101C43DAA7009F6A49 /* MWMAuthorizationWebViewLoginViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMAuthorizationWebViewLoginViewController.mm; sourceTree = ""; }; 3432E1771E49B3A2008477E9 /* Bolts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Bolts.framework; sourceTree = ""; }; + 3432E1801E49BF09008477E9 /* FBAdsBanner.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FBAdsBanner.swift; sourceTree = ""; }; + 3432E1841E49BF5C008477E9 /* FBAdsBanner.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FBAdsBanner.xib; sourceTree = ""; }; 3446C6761DDCA9A200146687 /* libtraffic.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtraffic.a; path = "../../../omim-build/xcode/Debug/libtraffic.a"; sourceTree = ""; }; 345050211E028B8000A8DC59 /* Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = ""; }; 3454D7991E07F045004AF2AD /* CALayer+RuntimeAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CALayer+RuntimeAttributes.h"; sourceTree = ""; }; @@ -2392,6 +2401,7 @@ 34F5E0D61E3F334700B1C415 /* Types.swift */, 340475261E081A4600C92850 /* WebViewController.h */, 340475271E081A4600C92850 /* WebViewController.mm */, + 3427AF0B1E49E3A500D466DB /* MWMConsts.h */, ); path = Common; sourceTree = ""; @@ -2541,6 +2551,15 @@ path = Storyboard; sourceTree = ""; }; + 3432E17F1E49BEFA008477E9 /* Ads */ = { + isa = PBXGroup; + children = ( + 3432E1801E49BF09008477E9 /* FBAdsBanner.swift */, + 3432E1841E49BF5C008477E9 /* FBAdsBanner.xib */, + ); + path = Ads; + sourceTree = ""; + }; 3454D7981E07F045004AF2AD /* Categories */ = { isa = PBXGroup; children = ( @@ -3149,6 +3168,7 @@ F6E2FBFB1E097B9F0083EBEC /* UI */ = { isa = PBXGroup; children = ( + 3432E17F1E49BEFA008477E9 /* Ads */, 34574A601E3B5B2A0061E839 /* Appearance */, 349D1AC21E2E325B004A2006 /* BottomMenu */, F6E2FBFC1E097B9F0083EBEC /* Downloader */, @@ -4074,6 +4094,7 @@ F623DA6B1C9C2731006A3436 /* opening_hours_how_to_edit.html in Resources */, F6E2FF291E097BA00083EBEC /* MWMSearchTabButtonsView.xib in Resources */, F6E2FDCA1E097BA00083EBEC /* MWMEditorNotesFooter.xib in Resources */, + 3432E1851E49BF5C008477E9 /* FBAdsBanner.xib in Resources */, 34D3B0231E389D05004100F9 /* MWMEditorAddAdditionalNameTableViewCell.xib in Resources */, 341C2A5B1B720B8A00AD41A1 /* MWMAPIBarView.xib in Resources */, F653CE181C71F62400A453F1 /* MWMAddPlaceNavigationBar.xib in Resources */, @@ -4228,6 +4249,7 @@ 6741A9811BF340DE002C974C /* MWMRateAlert.xib in Resources */, 6741A9871BF340DE002C974C /* drules_proto_clear.bin in Resources */, F6E2FDEF1E097BA00083EBEC /* MWMOpeningHoursAddClosedTableViewCell.xib in Resources */, + 3432E1861E49BF5C008477E9 /* FBAdsBanner.xib in Resources */, 34D3B0241E389D05004100F9 /* MWMEditorAddAdditionalNameTableViewCell.xib in Resources */, F6E2FE851E097BA00083EBEC /* MWMPlacePageOpeningHoursWeekDayView.xib in Resources */, F6E2FEB51E097BA00083EBEC /* _MWMPPPSpace.xib in Resources */, @@ -4345,6 +4367,7 @@ 349B92721DF0526D007779DD /* MWMToast.xib in Resources */, 849CF6251DE842290024A8A5 /* cuisine-strings in Resources */, F6E2FEE91E097BA00083EBEC /* MWMSearchNoResults.xib in Resources */, + 3432E1871E49BF5C008477E9 /* FBAdsBanner.xib in Resources */, 849CF6281DE842290024A8A5 /* tts-how-to-set-up-voice.html in Resources */, 849CF6291DE842290024A8A5 /* faq.html in Resources */, 849CF62F1DE842290024A8A5 /* MWMDownloadTransitMapAlert.xib in Resources */, @@ -4574,6 +4597,7 @@ 34C9BD091C6DBCDA000DC38D /* MWMNavigationController.mm in Sources */, 34D3B0171E389D05004100F9 /* EditorAdditionalNamePlaceholderTableViewCell.swift in Sources */, 3406FA151C6E0C3300E9FAD2 /* MWMMapDownloadDialog.mm in Sources */, + 3432E1811E49BF09008477E9 /* FBAdsBanner.swift in Sources */, F6E2FECC1E097BA00083EBEC /* MWMSearchFilterTransitioningManager.mm in Sources */, F6E2FF111E097BA00083EBEC /* MWMSearchHistoryRequestCell.mm in Sources */, 34C9BD021C6DB693000DC38D /* MWMTableViewController.mm in Sources */, @@ -4833,6 +4857,7 @@ F6E2FECD1E097BA00083EBEC /* MWMSearchFilterTransitioningManager.mm in Sources */, 34D3B0181E389D05004100F9 /* EditorAdditionalNamePlaceholderTableViewCell.swift in Sources */, F6E2FF121E097BA00083EBEC /* MWMSearchHistoryRequestCell.mm in Sources */, + 3432E1821E49BF09008477E9 /* FBAdsBanner.swift in Sources */, F6FE3C391CC50FFD00A73196 /* MWMPlaceDoesntExistAlert.mm in Sources */, F6E2FDFE1E097BA00083EBEC /* MWMOpeningHoursClosedSpanTableViewCell.mm in Sources */, F6E2FEDC1E097BA00083EBEC /* MWMSearchManager+Filter.mm in Sources */, @@ -5092,6 +5117,7 @@ 849CF6CF1DE842290024A8A5 /* MWMAlertViewController.mm in Sources */, 34D3B0191E389D05004100F9 /* EditorAdditionalNamePlaceholderTableViewCell.swift in Sources */, 340475781E081A4600C92850 /* MWMTrafficManager.mm in Sources */, + 3432E1831E49BF09008477E9 /* FBAdsBanner.swift in Sources */, F6E2FECE1E097BA00083EBEC /* MWMSearchFilterTransitioningManager.mm in Sources */, F6E2FF131E097BA00083EBEC /* MWMSearchHistoryRequestCell.mm in Sources */, 849CF6D21DE842290024A8A5 /* MWMNavigationController.mm in Sources */, diff --git a/iphone/Maps/UI/Ads/FBAdsBanner.swift b/iphone/Maps/UI/Ads/FBAdsBanner.swift new file mode 100644 index 0000000000..990dc2bd34 --- /dev/null +++ b/iphone/Maps/UI/Ads/FBAdsBanner.swift @@ -0,0 +1,83 @@ +import FBAudienceNetwork + +@objc(MWMFBAdsBannerState) +enum FBAdsBannerState: Int { + case compact + case detailed +} + +@objc(MWMFBAdsBanner) +final class FBAdsBanner: UITableViewCell { + @IBOutlet private var detailedModeConstraints: [NSLayoutConstraint]! + @IBOutlet fileprivate weak var adIconImageView: UIImageView! + @IBOutlet fileprivate weak var adTitleLabel: UILabel! + @IBOutlet fileprivate weak var adBodyLabel: UILabel! + @IBOutlet fileprivate var adCallToActionButtonCompact: UIButton! + @IBOutlet fileprivate var adCallToActionButtonDetailed: UIButton! + + var state = FBAdsBannerState.compact { + didSet { + let priority: UILayoutPriority + let numberOfLines: Int + switch state { + case .compact: (priority, numberOfLines) = (UILayoutPriorityDefaultLow, 2) + case .detailed: (priority, numberOfLines) = (UILayoutPriorityDefaultHigh, 0) + } + layoutIfNeeded() + adBodyLabel.numberOfLines = numberOfLines + detailedModeConstraints.forEach { $0.priority = priority } + UIView.animate(withDuration: kDefaultAnimationDuration) { self.layoutIfNeeded() } + } + } + + fileprivate var nativeAd: FBNativeAd? + + func config(placementID: String) { + style() + contentView.alpha = 0 + state = .compact + let nativeAd = FBNativeAd(placementID: placementID) + nativeAd.delegate = self + nativeAd.mediaCachePolicy = .all + nativeAd.load() + } + + private func style() { + adTitleLabel.font = UIFont.bold12() + adBodyLabel.font = UIFont.regular12() + adCallToActionButtonCompact.titleLabel?.font = UIFont.regular12() + adCallToActionButtonDetailed.titleLabel?.font = UIFont.regular15() + + backgroundColor = UIColor.bannerBackground() + let color = UIColor.blackSecondaryText()! + adTitleLabel.textColor = color + adBodyLabel.textColor = color + adCallToActionButtonCompact.setTitleColor(color, for: .normal) + adCallToActionButtonDetailed.setTitleColor(color, for: .normal) + adCallToActionButtonDetailed.backgroundColor = UIColor.bannerButtonBackground() + + let layer = adCallToActionButtonCompact.layer + layer.borderColor = color.cgColor + layer.borderWidth = 1 + layer.cornerRadius = 4 + } +} + +extension FBAdsBanner: FBNativeAdDelegate { + func nativeAdDidLoad(_ nativeAd: FBNativeAd) { + if let sNativeAd = self.nativeAd { + sNativeAd.unregisterView() + } + self.nativeAd = nativeAd + let adCallToActionButtons = [adCallToActionButtonCompact!, adCallToActionButtonDetailed!] + nativeAd.registerView(forInteraction: self, with: nil, withClickableViews: adCallToActionButtons) + + nativeAd.icon?.loadAsync { [weak self] image in + self?.adIconImageView.image = image + } + adTitleLabel.text = nativeAd.title + adBodyLabel.text = nativeAd.body + adCallToActionButtons.forEach { $0.setTitle(nativeAd.callToAction, for: .normal) } + UIView.animate(withDuration: kDefaultAnimationDuration) { self.contentView.alpha = 1 } + } +} diff --git a/iphone/Maps/UI/Ads/FBAdsBanner.xib b/iphone/Maps/UI/Ads/FBAdsBanner.xib new file mode 100644 index 0000000000..d17326e06e --- /dev/null +++ b/iphone/Maps/UI/Ads/FBAdsBanner.xib @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h index f3d3cc099a..ccd6bf4c4b 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h @@ -81,6 +81,7 @@ enum class OpeningHours - (NSURL *)sponsoredURL; - (NSURL *)sponsoredDescriptionURL; - (NSString *)sponsoredId; +- (banners::Banner)banner; - (void)assignOnlinePriceToLabel:(UILabel *)label; // API diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm index f34058bac3..600857c219 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm @@ -1,8 +1,11 @@ #import "MWMPlacePageData.h" #import "MWMNetworkPolicy.h" +#import "MWMSettings.h" #include "Framework.h" +#include "indexer/banners.hpp" + #include "base/string_utils.hpp" #include "3party/opening_hours/opening_hours.hpp" @@ -75,7 +78,9 @@ using namespace place_page; NSAssert(!m_previewRows.empty(), @"Preview row's can't be empty!"); m_previewRows.push_back(PreviewRows::Space); - if (m_info.HasBanner()) m_previewRows.push_back(PreviewRows::Banner); + BOOL const hasBanner = m_info.GetBanner().m_type != banners::Banner::Type::None; + if (hasBanner && network_policy::CanUseNetwork() && ![MWMSettings adForbidden]) + m_previewRows.push_back(PreviewRows::Banner); } - (void)fillMetaInfoSection @@ -228,7 +233,9 @@ using namespace place_page; : nil; } +- (banners::Banner)banner { + return m_info.GetBanner(); } - (void)assignOnlinePriceToLabel:(UILabel *)label diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/PlacePageView/MWMPPView.xib b/iphone/Maps/UI/PlacePage/PlacePageLayout/PlacePageView/MWMPPView.xib index 944b455060..d03ea05315 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/PlacePageView/MWMPPView.xib +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/PlacePageView/MWMPPView.xib @@ -1,8 +1,11 @@ - + + + + - + @@ -17,8 +20,10 @@ + + @@ -39,7 +44,8 @@ - + + diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/MWMPPPreviewLayoutHelper.mm b/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/MWMPPPreviewLayoutHelper.mm index 35faf0b5c1..715217f3ee 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/MWMPPPreviewLayoutHelper.mm +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Preview/MWMPPPreviewLayoutHelper.mm @@ -124,7 +124,7 @@ namespace array const kPreviewCells = {{[_MWMPPPTitle class], [_MWMPPPExternalTitle class], [_MWMPPPSubtitle class], [_MWMPPPSchedule class], [_MWMPPPBooking class], [_MWMPPPAddress class], - [_MWMPPPSpace class], [MWMPPPreviewBannerCell class]}}; + [_MWMPPPSpace class], [MWMFBAdsBanner class]}}; } // namespace @interface MWMPPPreviewLayoutHelper () @@ -142,6 +142,7 @@ array const kPreviewCells = {{[_MWMPPPTitle class], [_MWMPPPExternalTi @property(nonatomic) BOOL lastCellIsBanner; @property(nonatomic) NSUInteger distanceRow; +@property(weak, nonatomic) MWMFBAdsBanner * cachedBannerCell; @end @@ -229,8 +230,20 @@ array const kPreviewCells = {{[_MWMPPPTitle class], [_MWMPPPExternalTi case PreviewRows::Space: return c; case PreviewRows::Banner: + auto banner = [data banner]; + NSString * bannerId = @(banner.m_bannerId.c_str()); [Statistics logEvent:kStatPlacePageBannerShow withParameters:@{kStatTags : data.statisticsTags, + kStatBanner : bannerId, kStatState : IPAD ? @1 : @0}]; + auto bannerCell = static_cast(c); + using namespace banners; + switch (banner.m_type) + { + case Banner::Type::None: NSAssert(false, @"Invalid banner type"); break; + case Banner::Type::Facebook: + [bannerCell configWithPlacementID:bannerId]; + break; + } self.cachedBannerCell = bannerCell; return bannerCell; } @@ -289,15 +302,17 @@ array const kPreviewCells = {{[_MWMPPPTitle class], [_MWMPPPExternalTi - (CGFloat)height { - CGFloat constexpr bannerDefaultHeight = 45; auto const rect = [self.tableView rectForRowAtIndexPath:self.lastCellIndexPath]; - return rect.origin.y + (self.lastCellIsBanner ? bannerDefaultHeight : rect.size.height); + return rect.origin.y + rect.size.height + (self.lastCellIsBanner ? 4 : 0); } - (void)layoutInOpenState:(BOOL)isOpen { if (IPAD) return; + [self.tableView update:^{ + self.cachedBannerCell.state = isOpen ? MWMFBAdsBannerStateDetailed : MWMFBAdsBannerStateCompact; + }]; } - (MWMDirectionView *)directionView