[ios] unification of search category banner

This commit is contained in:
Arsentiy Milchakov 2020-10-23 15:55:48 +03:00 committed by Alexander Boriskov
parent d0b533cd4e
commit 284f16d734
5 changed files with 65 additions and 39 deletions

View file

@ -1,5 +1,7 @@
#import <Foundation/Foundation.h>
@protocol MWMBanner;
NS_ASSUME_NONNULL_BEGIN
@interface MWMSearchFrameworkHelper : NSObject
@ -7,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN
- (NSArray<NSString *> *)searchCategories;
- (BOOL)hasMegafonCategoryBanner;
- (NSURL *)megafonBannerUrl;
- (nullable NSURL *)citymobilBannerUrl;
- (nullable id<MWMBanner>)searchCategoryBanner;
- (BOOL)isSearchHistoryEmpty;
- (NSArray<NSString *> *)lastSearchQueries;

View file

@ -1,4 +1,5 @@
#import "MWMSearchFrameworkHelper.h"
#import "CoreBanner+Core.h"
#include "partners_api/ads/ads_engine.hpp"
#include "partners_api/megafon_countries.hpp"
@ -45,16 +46,16 @@
return [NSURL URLWithString:@(urlStr.c_str())];
}
- (NSURL *)citymobilBannerUrl
- (id<MWMBanner>)searchCategoryBanner
{
auto const & f = GetFramework();
auto const pos = f.GetCurrentPosition();
auto const banners = f.GetAdsEngine().GetSearchCategoryBanners(pos);
if (banners.empty() || banners.front().m_type != ads::Banner::Type::Citymobil)
if (banners.empty())
return nil;
return [NSURL URLWithString:@(banners.front().m_value.c_str())];
return [[CoreBanner alloc] initWithAdBanner:banners.front()];
}
- (BOOL)isSearchHistoryEmpty

View file

@ -4,12 +4,17 @@ protocol SearchBannerCellDelegate: AnyObject {
}
class SearchBannerCell: MWMTableViewCell {
@IBOutlet var taxiImageView: UIImageView!
weak var delegate: SearchBannerCellDelegate?
override func awakeFromNib() {
super.awakeFromNib()
taxiImageView.mwm_name = "ic_taxi_logo_citymobil"
@IBOutlet var iconView: UIImageView!
@IBOutlet weak var labelView: UILabel!
@IBOutlet weak var buttonView: UIButton!
private weak var delegate: SearchBannerCellDelegate?
func configure(icon: String, label: String, buttonText: String, delegate: SearchBannerCellDelegate?) {
iconView.mwm_name = icon
labelView.text = label
buttonView.localizedText = buttonText
self.delegate = delegate
}
@IBAction private func onInstall(_ sender: UIButton) {

View file

@ -17,37 +17,35 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" verticalCompressionResistancePriority="751" image="ic_taxi_logo_citymobil_light" translatesAutoresizingMaskIntoConstraints="NO" id="a9s-eh-L10" userLabel="Icon">
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" verticalCompressionResistancePriority="751" translatesAutoresizingMaskIntoConstraints="NO" id="a9s-eh-L10" userLabel="Icon">
<rect key="frame" x="16" y="8" width="28" height="28"/>
<constraints>
<constraint firstAttribute="width" constant="28" id="UkL-Ob-9dH"/>
<constraint firstAttribute="height" constant="28" id="hQ1-JP-hkI"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="Taxi" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6Wf-Ru-5dt" userLabel="Category label">
<rect key="frame" x="60" y="12" width="172" height="20"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6Wf-Ru-5dt" userLabel="Category label">
<rect key="frame" x="60" y="22" width="212" height="0.0"/>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="17"/>
<color key="textColor" red="0.12941176469999999" green="0.12941176469999999" blue="0.12941176469999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="regular17:blackPrimaryText"/>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="taxi"/>
</userDefinedRuntimeAttributes>
</label>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" verticalCompressionResistancePriority="751" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="M1X-p4-OlN">
<rect key="frame" x="240" y="10" width="56" height="24"/>
<rect key="frame" x="280" y="10" width="16" height="24"/>
<color key="backgroundColor" red="0.81568627449999997" green="0.82745098039999998" blue="0.82745098039999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="24" id="mma-Ly-hLb"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="14"/>
<inset key="contentEdgeInsets" minX="8" minY="0.0" maxX="8" maxY="0.0"/>
<state key="normal" title="Install">
<state key="normal">
<color key="titleColor" red="0.57254901960000004" green="0.58431372550000005" blue="0.64705882349999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="SearchInstallButton"/>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="taxi_category_order"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="onInstall:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="0o7-8I-f79"/>
@ -105,13 +103,14 @@
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
<connections>
<outlet property="taxiImageView" destination="a9s-eh-L10" id="aS5-nJ-ZZW"/>
<outlet property="buttonView" destination="M1X-p4-OlN" id="dGP-aq-Yky"/>
<outlet property="iconView" destination="a9s-eh-L10" id="aS5-nJ-ZZW"/>
<outlet property="labelView" destination="6Wf-Ru-5dt" id="1DI-gN-fDf"/>
</connections>
<point key="canvasLocation" x="52.799999999999997" y="48.575712143928037"/>
</tableViewCell>
</objects>
<resources>
<image name="ic_ad_close" width="8" height="8"/>
<image name="ic_taxi_logo_citymobil_light" width="24" height="24"/>
</resources>
</document>

View file

@ -6,16 +6,14 @@ protocol SearchCategoriesViewControllerDelegate: AnyObject {
final class SearchCategoriesViewController: MWMTableViewController {
private weak var delegate: SearchCategoriesViewControllerDelegate?
private let categories: [String]
private let showCitymobilBanner: Bool
private let bannerUrl: URL?
private let banner: MWMBanner?
private var bannerShown = false
private static let citymobilIndex = 6
private static let bannerIndex = 6
init(frameworkHelper: MWMSearchFrameworkHelper, delegate: SearchCategoriesViewControllerDelegate?) {
self.delegate = delegate
categories = frameworkHelper.searchCategories()
bannerUrl = frameworkHelper.citymobilBannerUrl()
showCitymobilBanner = bannerUrl != nil
banner = frameworkHelper.searchCategoryBanner()
super.init(nibName: nil, bundle: nil)
}
@ -33,18 +31,12 @@ final class SearchCategoriesViewController: MWMTableViewController {
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return categories.count + (showCitymobilBanner ? 1 : 0)
return categories.count + (banner != nil ? 1 : 0)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if showCitymobilBanner && (indexPath.row == SearchCategoriesViewController.citymobilIndex) {
let cell = tableView.dequeueReusableCell(cell: SearchBannerCell.self, indexPath: indexPath)
cell.delegate = self
if (!bannerShown) {
bannerShown = true;
Statistics.logEvent(kStatSearchSponsoredShow);
}
return cell
if banner != nil && (indexPath.row == SearchCategoriesViewController.bannerIndex) {
return createBanner(indexPath)
}
let cell = tableView.dequeueReusableCell(cell: SearchCategoryCell.self, indexPath: indexPath)
@ -53,7 +45,7 @@ final class SearchCategoriesViewController: MWMTableViewController {
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if showCitymobilBanner && (indexPath.row == SearchCategoriesViewController.citymobilIndex) {
if banner != nil && (indexPath.row == SearchCategoriesViewController.bannerIndex) {
openBanner()
return
}
@ -66,16 +58,43 @@ final class SearchCategoriesViewController: MWMTableViewController {
func category(at indexPath: IndexPath) -> String {
let index = indexPath.row
if showCitymobilBanner && (index > SearchCategoriesViewController.citymobilIndex) {
if banner != nil && (index > SearchCategoriesViewController.bannerIndex) {
return categories[index - 1]
} else {
return categories[index]
}
}
func openBanner() {
UIApplication.shared.open(bannerUrl!)
Statistics.logEvent(kStatSearchSponsoredSelect);
private func bannerStatProvider() -> String {
switch banner!.mwmType {
case .citymobil: return kStatCitymobil
default: return ""
}
}
private func createBanner(_ indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(cell: SearchBannerCell.self, indexPath: indexPath)
switch self.banner!.mwmType {
case .citymobil:
cell.configure(icon: "ic_taxi_logo_citymobil",
label: L("taxi"),
buttonText: L("taxi_category_order"),
delegate: self)
default: fatalError("Unexpected banner type")
}
if (!bannerShown) {
bannerShown = true;
Statistics.logEvent(kStatSearchSponsoredShow, withParameters: [kStatProvider: bannerStatProvider()]);
}
return cell
}
private func openBanner() {
if let url = URL(string: banner!.bannerID) {
UIApplication.shared.open(url)
}
Statistics.logEvent(kStatSearchSponsoredSelect, withParameters: [kStatProvider: bannerStatProvider()]);
}
}