diff --git a/iphone/Maps/Core/Search/MWMSearch.h b/iphone/Maps/Core/Search/MWMSearch.h index d2c7323ee3..dd86c0f700 100644 --- a/iphone/Maps/Core/Search/MWMSearch.h +++ b/iphone/Maps/Core/Search/MWMSearch.h @@ -1,12 +1,11 @@ -#import #import +#import #import "MWMHotelParams.h" #import "MWMSearchItemType.h" #import "MWMSearchObserver.h" -namespace search -{ +namespace search { class Result; struct ProductInfo; } // namespace search @@ -48,8 +47,7 @@ struct ProductInfo; - (instancetype)init __attribute__((unavailable("call +manager instead"))); - (instancetype)copy __attribute__((unavailable("call +manager instead"))); - (instancetype)copyWithZone:(NSZone *)zone __attribute__((unavailable("call +manager instead"))); -+ (instancetype)allocWithZone:(struct _NSZone *)zone -__attribute__((unavailable("call +manager instead"))); -+ (instancetype) new __attribute__((unavailable("call +manager instead"))); ++ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable("call +manager instead"))); ++ (instancetype)new __attribute__((unavailable("call +manager instead"))); @end diff --git a/iphone/Maps/Core/Search/MWMSearch.mm b/iphone/Maps/Core/Search/MWMSearch.mm index 27e5284135..891974b174 100644 --- a/iphone/Maps/Core/Search/MWMSearch.mm +++ b/iphone/Maps/Core/Search/MWMSearch.mm @@ -9,67 +9,61 @@ #include "partners_api/ads/ads_engine.hpp" #include "platform/network_policy.hpp" -namespace -{ +namespace { using Observer = id; using Observers = NSHashTable; -booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availabilityParams) -{ +booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params &&availabilityParams) { booking::filter::Tasks tasks; - if (availabilityParams.IsEmpty()) - { + if (availabilityParams.IsEmpty()) { if (!platform::GetCurrentNetworkPolicy().CanUse()) return {}; - + auto params = GetFramework().GetLastBookingAvailabilityParams(); if (params.IsEmpty()) params = booking::AvailabilityParams::MakeDefault(); params.m_dealsOnly = true; - + booking::filter::Params dp(std::make_shared(params), {}); tasks.EmplaceBack(booking::filter::Type::Deals, move(dp)); - } - else - { + } else { booking::AvailabilityParams dp; dp.Set(*(availabilityParams.m_apiParams)); dp.m_dealsOnly = true; booking::filter::Params dealsParams(std::make_shared(dp), {}); - + tasks.EmplaceBack(booking::filter::Type::Availability, std::move(availabilityParams)); tasks.EmplaceBack(booking::filter::Type::Deals, std::move(dealsParams)); } - + return tasks; } } // namespace -@interface MWMSearch () +@interface MWMSearch () @property(nonatomic) NSUInteger suggestionsCount; @property(nonatomic) BOOL searchOnMap; @property(nonatomic) BOOL textChanged; -@property(nonatomic) Observers * observers; +@property(nonatomic) Observers *observers; @property(nonatomic) NSUInteger lastSearchTimestamp; -@property(nonatomic) MWMHotelParams * filter; +@property(nonatomic) MWMHotelParams *filter; -@property(nonatomic) MWMSearchIndex * itemsIndex; +@property(nonatomic) MWMSearchIndex *itemsIndex; -@property(nonatomic) MWMSearchBanners * banners; +@property(nonatomic) MWMSearchBanners *banners; @property(nonatomic) NSInteger searchCount; -@property(copy, nonatomic) NSString * lastQuery; +@property(copy, nonatomic) NSString *lastQuery; @end -@implementation MWMSearch -{ +@implementation MWMSearch { search::EverywhereSearchParams m_everywhereParams; search::ViewportSearchParams m_viewportParams; search::Results m_everywhereResults; @@ -80,9 +74,8 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab #pragma mark - Instance -+ (MWMSearch *)manager -{ - static MWMSearch * manager; ++ (MWMSearch *)manager { + static MWMSearch *manager; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ manager = [[self alloc] initManager]; @@ -90,11 +83,9 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab return manager; } -- (instancetype)initManager -{ +- (instancetype)initManager { self = [super init]; - if (self) - { + if (self) { _observers = [Observers weakObjectsHashTable]; [MWMFrameworkListener addObserver:self]; } @@ -102,21 +93,19 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab } - (void)enableCallbackFor:(booking::filter::Type const)filterType { - auto & tasks = self->m_everywhereParams.m_bookingFilterTasks; + auto &tasks = self->m_everywhereParams.m_bookingFilterTasks; auto availabilityTaskIt = tasks.Find(filterType); - if (availabilityTaskIt != tasks.end()) - { - availabilityTaskIt->m_filterParams.m_callback = - [self, filterType](std::shared_ptr const & apiParams, - std::vector const & sortedFeatures) - { - auto & t = self->m_everywhereParams.m_bookingFilterTasks; + if (availabilityTaskIt != tasks.end()) { + availabilityTaskIt->m_filterParams.m_callback = [self, filterType]( + std::shared_ptr const &apiParams, + std::vector const &sortedFeatures) { + auto &t = self->m_everywhereParams.m_bookingFilterTasks; auto const it = t.Find(filterType); if (it == t.end()) return; - auto const & p = it->m_filterParams.m_apiParams; + auto const &p = it->m_filterParams.m_apiParams; if (p->IsEmpty() || !p->Equals(*apiParams)) return; @@ -126,16 +115,12 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab } } -- (void)searchEverywhere -{ +- (void)searchEverywhere { self.lastSearchTimestamp += 1; NSUInteger const timestamp = self.lastSearchTimestamp; - m_everywhereParams.m_onResults = [self, timestamp]( - search::Results const & results, - std::vector const & productInfo) { - - if (timestamp == self.lastSearchTimestamp) - { + m_everywhereParams.m_onResults = [self, timestamp](search::Results const &results, + std::vector const &productInfo) { + if (timestamp == self.lastSearchTimestamp) { self->m_everywhereResults = results; self->m_productInfo = productInfo; self.suggestionsCount = results.GetSuggestsCount(); @@ -154,10 +139,9 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab self.searchCount += 1; } -- (void)searchInViewport -{ +- (void)searchInViewport { m_viewportParams.m_onStarted = [self] { self.searchCount += 1; }; - m_viewportParams.m_onCompleted = [self](search::Results const & results) { + m_viewportParams.m_onCompleted = [self](search::Results const &results) { if (!results.IsEndMarker()) return; self->m_viewportResults = results; @@ -167,14 +151,12 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab GetFramework().GetSearchAPI().SearchInViewport(m_viewportParams); } -- (void)updateFilters -{ +- (void)updateFilters { std::shared_ptr const hotelsRules = self.filter ? [self.filter rules] : nullptr; m_viewportParams.m_hotelsFilter = hotelsRules; m_everywhereParams.m_hotelsFilter = hotelsRules; - - auto availabilityParams = - self.filter ? [self.filter availabilityParams] : booking::filter::Params(); + + auto availabilityParams = self.filter ? [self.filter availabilityParams] : booking::filter::Params(); auto const tasks = MakeBookingFilterTasks(std::move(availabilityParams)); @@ -182,20 +164,16 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab m_everywhereParams.m_bookingFilterTasks = tasks; } -- (void)update -{ +- (void)update { [self reset]; if (m_everywhereParams.m_query.empty()) return; [self updateFilters]; - if (IPAD) - { + if (IPAD) { [self searchInViewport]; [self searchEverywhere]; - } - else - { + } else { if (self.searchOnMap) [self searchInViewport]; else @@ -205,38 +183,33 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab #pragma mark - Add/Remove Observers -+ (void)addObserver:(id)observer -{ ++ (void)addObserver:(id)observer { [[MWMSearch manager].observers addObject:observer]; } -+ (void)removeObserver:(id)observer -{ ++ (void)removeObserver:(id)observer { [[MWMSearch manager].observers removeObject:observer]; } #pragma mark - Methods -+ (void)saveQuery:(NSString *)query forInputLocale:(NSString *)inputLocale -{ ++ (void)saveQuery:(NSString *)query forInputLocale:(NSString *)inputLocale { if (!query || query.length == 0) return; std::string const locale = (!inputLocale || inputLocale.length == 0) - ? [MWMSearch manager]->m_everywhereParams.m_inputLocale - : inputLocale.UTF8String; + ? [MWMSearch manager]->m_everywhereParams.m_inputLocale + : inputLocale.UTF8String; std::string const text = query.precomposedStringWithCompatibilityMapping.UTF8String; GetFramework().GetSearchAPI().SaveSearchQuery(make_pair(locale, text)); } -+ (void)searchQuery:(NSString *)query forInputLocale:(NSString *)inputLocale -{ ++ (void)searchQuery:(NSString *)query forInputLocale:(NSString *)inputLocale { if (!query) return; - MWMSearch * manager = [MWMSearch manager]; - if (inputLocale.length != 0) - { + MWMSearch *manager = [MWMSearch manager]; + if (inputLocale.length != 0) { std::string const locale = inputLocale.UTF8String; manager->m_everywhereParams.m_inputLocale = locale; manager->m_viewportParams.m_inputLocale = locale; @@ -246,9 +219,9 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab manager->m_everywhereParams.m_query = text; manager->m_viewportParams.m_query = text; manager.textChanged = YES; - auto const & adsEngine = GetFramework().GetAdsEngine(); + auto const &adsEngine = GetFramework().GetAdsEngine(); auto const banners = adsEngine.GetSearchBanners(); - + if (!banners.empty()) { auto coreBanners = banner_helpers::MatchPriorityBanners(banners, manager.lastQuery); [[MWMBannersCache cache] refreshWithCoreBanners:coreBanners]; @@ -256,61 +229,53 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab [manager update]; } -+ (void)showResult:(search::Result const &)result { GetFramework().ShowSearchResult(result); } -+ (search::Result const &)resultWithContainerIndex:(NSUInteger)index -{ ++ (void)showResult:(search::Result const &)result { + GetFramework().ShowSearchResult(result); +} ++ (search::Result const &)resultWithContainerIndex:(NSUInteger)index { return [MWMSearch manager]->m_everywhereResults[index]; } -+ (search::ProductInfo const &)productInfoWithContainerIndex:(NSUInteger)index -{ ++ (search::ProductInfo const &)productInfoWithContainerIndex:(NSUInteger)index { return [MWMSearch manager]->m_productInfo[index]; } -+ (id)adWithContainerIndex:(NSUInteger)index -{ ++ (id)adWithContainerIndex:(NSUInteger)index { return [[MWMSearch manager].banners bannerAtIndex:index]; } -+ (BOOL)isFeatureAt:(NSUInteger)index in:(std::vector const &)array -{ - auto const & result = [self resultWithContainerIndex:index]; ++ (BOOL)isFeatureAt:(NSUInteger)index in:(std::vector const &)array { + auto const &result = [self resultWithContainerIndex:index]; if (result.GetResultType() != search::Result::Type::Feature) return NO; - auto const & resultFeatureID = result.GetFeatureID(); + auto const &resultFeatureID = result.GetFeatureID(); return std::binary_search(array.begin(), array.end(), resultFeatureID); } -+ (BOOL)isBookingAvailableWithContainerIndex:(NSUInteger)index -{ ++ (BOOL)isBookingAvailableWithContainerIndex:(NSUInteger)index { return [self isFeatureAt:index in:[MWMSearch manager]->m_filterResults[booking::filter::Type::Availability]]; } -+ (BOOL)isDealAvailableWithContainerIndex:(NSUInteger)index -{ ++ (BOOL)isDealAvailableWithContainerIndex:(NSUInteger)index { return [self isFeatureAt:index in:[MWMSearch manager]->m_filterResults[booking::filter::Type::Deals]]; } -+ (MWMSearchItemType)resultTypeWithRow:(NSUInteger)row -{ ++ (MWMSearchItemType)resultTypeWithRow:(NSUInteger)row { auto itemsIndex = [MWMSearch manager].itemsIndex; return [itemsIndex resultTypeWithRow:row]; } -+ (NSUInteger)containerIndexWithRow:(NSUInteger)row -{ ++ (NSUInteger)containerIndexWithRow:(NSUInteger)row { auto itemsIndex = [MWMSearch manager].itemsIndex; return [itemsIndex resultContainerIndexWithRow:row]; } -+ (void)updateHotelFilterWithParams:(MWMHotelParams *)params -{ ++ (void)updateHotelFilterWithParams:(MWMHotelParams *)params { [MWMSearch manager].filter = params; [[MWMSearch manager] update]; } -- (void)reset -{ +- (void)reset { self.lastSearchTimestamp += 1; GetFramework().GetSearchAPI().CancelAllSearches(); @@ -324,8 +289,7 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab [self onSearchResultsUpdated]; } -+ (void)clear -{ ++ (void)clear { auto manager = [MWMSearch manager]; manager->m_everywhereParams.m_query.clear(); manager->m_viewportParams.m_query.clear(); @@ -334,11 +298,10 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab [manager reset]; } -+ (void)setSearchOnMap:(BOOL)searchOnMap -{ ++ (void)setSearchOnMap:(BOOL)searchOnMap { if (IPAD) return; - MWMSearch * manager = [MWMSearch manager]; + MWMSearch *manager = [MWMSearch manager]; if (manager.searchOnMap == searchOnMap) return; manager.searchOnMap = searchOnMap; @@ -347,14 +310,19 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab [manager update]; } -+ (NSUInteger)suggestionsCount { return [MWMSearch manager].suggestionsCount; } -+ (NSUInteger)resultsCount { return [MWMSearch manager].itemsIndex.count; } -+ (BOOL)isHotelResults { return [[MWMSearch manager] isHotelResults]; } ++ (NSUInteger)suggestionsCount { + return [MWMSearch manager].suggestionsCount; +} ++ (NSUInteger)resultsCount { + return [MWMSearch manager].itemsIndex.count; +} ++ (BOOL)isHotelResults { + return [[MWMSearch manager] isHotelResults]; +} #pragma mark - Filters -+ (BOOL)hasFilter -{ ++ (BOOL)hasFilter { auto filter = [MWMSearch manager].filter; if (!filter) return NO; @@ -375,27 +343,23 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab return 0; } -+ (MWMHotelParams *)getFilter -{ - MWMSearch * manager = [MWMSearch manager]; ++ (MWMHotelParams *)getFilter { + MWMSearch *manager = [MWMSearch manager]; return manager.filter; } -+ (void)clearFilter -{ - MWMSearch * manager = [MWMSearch manager]; ++ (void)clearFilter { + MWMSearch *manager = [MWMSearch manager]; manager.filter = nil; [manager update]; } -- (void)updateItemsIndexWithBannerReload:(BOOL)reloadBanner -{ +- (void)updateItemsIndexWithBannerReload:(BOOL)reloadBanner { auto const resultsCount = self->m_everywhereResults.GetCount(); auto const itemsIndex = [[MWMSearchIndex alloc] initWithSuggestionsCount:self.suggestionsCount resultsCount:resultsCount]; - if (resultsCount > 0) - { - auto const & adsEngine = GetFramework().GetAdsEngine(); + if (resultsCount > 0) { + auto const &adsEngine = GetFramework().GetAdsEngine(); auto const banners = adsEngine.GetSearchBanners(); if (!banners.empty()) { @@ -412,9 +376,7 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab [self.banners add:ad]; }]; } - } - else - { + } else { self.banners = nil; } [itemsIndex build]; @@ -423,30 +385,24 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab #pragma mark - Notifications -- (void)onSearchStarted -{ - for (Observer observer in self.observers) - { +- (void)onSearchStarted { + for (Observer observer in self.observers) { if ([observer respondsToSelector:@selector(onSearchStarted)]) [observer onSearchStarted]; } } -- (void)onSearchCompleted -{ +- (void)onSearchCompleted { [self updateItemsIndexWithBannerReload:YES]; - for (Observer observer in self.observers) - { + for (Observer observer in self.observers) { if ([observer respondsToSelector:@selector(onSearchCompleted)]) [observer onSearchCompleted]; } } -- (void)onSearchResultsUpdated -{ +- (void)onSearchResultsUpdated { [self updateItemsIndexWithBannerReload:NO]; - for (Observer observer in self.observers) - { + for (Observer observer in self.observers) { if ([observer respondsToSelector:@selector(onSearchResultsUpdated)]) [observer onSearchResultsUpdated]; } @@ -454,8 +410,7 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab #pragma mark - MWMFrameworkDrapeObserver -- (void)processViewportChangedEvent -{ +- (void)processViewportChangedEvent { if (!GetFramework().GetSearchAPI().IsViewportSearchActive()) return; if (IPAD) @@ -464,10 +419,8 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab #pragma mark - Properties -- (void)setSearchCount:(NSInteger)searchCount -{ - NSAssert((searchCount >= 0) && - ((_searchCount == searchCount - 1) || (_searchCount == searchCount + 1)), +- (void)setSearchCount:(NSInteger)searchCount { + NSAssert((searchCount >= 0) && ((_searchCount == searchCount - 1) || (_searchCount == searchCount + 1)), @"Invalid search count update"); if (_searchCount == 0) [self onSearchStarted]; @@ -476,8 +429,7 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab _searchCount = searchCount; } -- (BOOL)isHotelResults -{ +- (BOOL)isHotelResults { return m_everywhereResults.GetType() == search::Results::Type::Hotels || m_viewportResults.GetType() == search::Results::Type::Hotels; } diff --git a/iphone/Maps/Core/Theme/SearchStyleSheet.swift b/iphone/Maps/Core/Theme/SearchStyleSheet.swift index 40faf76bd2..5f52422eb3 100644 --- a/iphone/Maps/Core/Theme/SearchStyleSheet.swift +++ b/iphone/Maps/Core/Theme/SearchStyleSheet.swift @@ -1,6 +1,6 @@ class SearchStyleSheet: IStyleSheet { static func register(theme: Theme, colors: IColors, fonts: IFonts) { - theme.add(styleName: "SearchInstallButton") { (s) -> (Void) in + theme.add(styleName: "SearchInstallButton") { (s) -> Void in s.cornerRadius = 10 s.clip = true s.font = fonts.medium12 @@ -8,28 +8,28 @@ class SearchStyleSheet: IStyleSheet { s.backgroundColor = colors.searchPromoBackground } - theme.add(styleName: "SearchBanner") { (s) -> (Void) in + theme.add(styleName: "SearchBanner") { (s) -> Void in s.backgroundColor = colors.searchPromoBackground } - theme.add(styleName: "SearchClosedBackground") { (s) -> (Void) in + theme.add(styleName: "SearchClosedBackground") { (s) -> Void in s.cornerRadius = 4 s.backgroundColor = colors.blackHintText } - theme.add(styleName: "SearchPopularView") { (s) -> (Void) in + theme.add(styleName: "SearchPopularView") { (s) -> Void in s.cornerRadius = 10 s.backgroundColor = colors.linkBlueHighlighted } - theme.add(styleName: "SearchSideAvaliableMarker") { (s) -> (Void) in + theme.add(styleName: "SearchSideAvaliableMarker") { (s) -> Void in s.backgroundColor = colors.ratingGreen } - theme.add(styleName: "SearchBarView") { (s) -> (Void) in + theme.add(styleName: "SearchBarView") { (s) -> Void in s.backgroundColor = colors.primary s.shadowRadius = 2 - s.shadowColor = UIColor(0,0,0, alpha26) + s.shadowColor = UIColor(0, 0, 0, alpha26) s.shadowOpacity = 1 s.shadowOffset = CGSize.zero } @@ -38,7 +38,7 @@ class SearchStyleSheet: IStyleSheet { s.backgroundColor = colors.linkBlue s.cornerRadius = 20 s.shadowRadius = 1 - s.shadowColor = UIColor(0, 0, 0, 0.24); + s.shadowColor = UIColor(0, 0, 0, 0.24) s.shadowOffset = CGSize(width: 0, height: 2) s.shadowOpacity = 1 } @@ -50,43 +50,43 @@ class SearchStyleSheet: IStyleSheet { s.coloring = .whiteText } - theme.add(styleName: "SearchFilterAppliedIndicator") { (s) -> (Void) in + theme.add(styleName: "SearchFilterAppliedIndicator") { (s) -> Void in s.round = true s.clip = true } - theme.add(styleName: "SearchSearchTextField") { (s) -> (Void) in + theme.add(styleName: "SearchSearchTextField") { (s) -> Void in s.fontColor = colors.blackSecondaryText s.backgroundColor = colors.white s.tintColor = colors.blackSecondaryText } - theme.add(styleName: "SearchSearchTextFieldIcon") { (s) -> (Void) in + theme.add(styleName: "SearchSearchTextFieldIcon") { (s) -> Void in s.tintColor = colors.blackSecondaryText s.coloring = MWMButtonColoring.black s.color = colors.blackSecondaryText } - theme.add(styleName: "SearchDatePickerField") { (s) -> (Void) in + theme.add(styleName: "SearchDatePickerField") { (s) -> Void in s.backgroundColor = colors.white s.cornerRadius = 4 s.borderColor = colors.solidDividers s.borderWidth = 1 } - theme.add(styleName: "FilterRatingButton") { (s) -> (Void) in + theme.add(styleName: "FilterRatingButton") { (s) -> Void in s.cornerRadius = 4 s.borderWidth = 1 s.borderColor = colors.blackDividers } - theme.add(styleName: "SearchFilterTypeCell") { (s) -> (Void) in + theme.add(styleName: "SearchFilterTypeCell") { (s) -> Void in s.cornerRadius = 16 s.borderColor = colors.blackDividers s.borderWidth = 1 } - theme.add(styleName: "FilterCheckButton") { (s) -> (Void) in + theme.add(styleName: "FilterCheckButton") { (s) -> Void in s.fontColor = colors.blackPrimaryText s.fontColorDisabled = colors.blackDividers s.backgroundColor = colors.white @@ -97,11 +97,11 @@ class SearchStyleSheet: IStyleSheet { s.textAlignment = .natural } - theme.add(styleName: "SearchCellAds", from: "TableCell") { (s) -> (Void) in + theme.add(styleName: "SearchCellAds", from: "TableCell") { (s) -> Void in s.backgroundColor = colors.searchPromoBackground } - theme.add(styleName: "SearchCellAvaliable", from: "TableCell") { (s) -> (Void) in + theme.add(styleName: "SearchCellAvaliable", from: "TableCell") { (s) -> Void in s.backgroundColor = colors.transparentGreen } diff --git a/iphone/Maps/UI/Search/Filters/MWMHotelParams.h b/iphone/Maps/UI/Search/Filters/MWMHotelParams.h index af2fbd1adf..de56e6c0f8 100644 --- a/iphone/Maps/UI/Search/Filters/MWMHotelParams.h +++ b/iphone/Maps/UI/Search/Filters/MWMHotelParams.h @@ -1,5 +1,5 @@ -#include "map/place_page_info.hpp" #include "map/booking_filter_params.hpp" +#include "map/place_page_info.hpp" #include "search/hotels_filter.hpp" @@ -16,13 +16,13 @@ enum class Price { @class PlacePageData; -@interface MWMHotelParams : NSObject +@interface MWMHotelParams : NSObject -@property (nonatomic) std::unordered_set price; -@property (nonatomic) std::unordered_set types; -@property (nonatomic) place_page::rating::FilterRating rating; -@property (nonatomic) NSDate * checkInDate; -@property (nonatomic) NSDate * checkOutDate; +@property(nonatomic) std::unordered_set price; +@property(nonatomic) std::unordered_set types; +@property(nonatomic) place_page::rating::FilterRating rating; +@property(nonatomic) NSDate *checkInDate; +@property(nonatomic) NSDate *checkOutDate; - (instancetype)initWithPlacePageData:(PlacePageData *)data; - (std::shared_ptr)rules; diff --git a/iphone/Maps/UI/Search/Filters/MWMHotelParams.mm b/iphone/Maps/UI/Search/Filters/MWMHotelParams.mm index c33aab66d5..023a2f6d74 100644 --- a/iphone/Maps/UI/Search/Filters/MWMHotelParams.mm +++ b/iphone/Maps/UI/Search/Filters/MWMHotelParams.mm @@ -1,53 +1,54 @@ #import "MWMHotelParams.h" #include +#include #include #include -#include static uint8_t kAdultsCount = 2; static int8_t kAgeOfChild = 5; @implementation MWMHotelParams -- (instancetype)initWithPlacePageData:(PlacePageData *)data -{ +- (instancetype)initWithPlacePageData:(PlacePageData *)data { self = [super init]; - if (self) - { + if (self) { _types.insert(ftypes::IsHotelChecker::Type::Hotel); PlacePagePreviewData *previewData = data.previewData; CHECK(previewData.hotelType != PlacePageDataHotelTypeNone, ("Incorrect hotel type at coordinate:", data.locationCoordinate.latitude, data.locationCoordinate.longitude)); - - if (data.sponsoredType == PlacePageSponsoredTypeBooking) - { - if (auto const price = [previewData.rawPricing intValue]) - { + + if (data.sponsoredType == PlacePageSponsoredTypeBooking) { + if (auto const price = [previewData.rawPricing intValue]) { CHECK_LESS_OR_EQUAL(price, base::Underlying(Price::Three), ()); _price.insert(static_cast(price)); } - + self.rating = place_page::rating::GetFilterRating(previewData.rawRating); } } - + return self; } -- (std::shared_ptr)rules -{ +- (std::shared_ptr)rules { using namespace search::hotels_filter; using namespace place_page::rating; - + std::shared_ptr ratingRule; - switch (self.rating) - { - case FilterRating::Any: break; - case FilterRating::Good: ratingRule = Ge(7.0); break; - case FilterRating::VeryGood: ratingRule = Ge(8.0); break; - case FilterRating::Excellent: ratingRule = Ge(9.0); break; + switch (self.rating) { + case FilterRating::Any: + break; + case FilterRating::Good: + ratingRule = Ge(7.0); + break; + case FilterRating::VeryGood: + ratingRule = Ge(8.0); + break; + case FilterRating::Excellent: + ratingRule = Ge(9.0); + break; } std::shared_ptr priceRule; @@ -55,14 +56,14 @@ static int8_t kAgeOfChild = 5; if (filter != Price::Any) priceRule = Or(priceRule, Eq(static_cast(filter))); } - + std::shared_ptr typeRule; if (!self.types.empty()) typeRule = OneOf(makeMask(self.types)); - + if (!ratingRule && !priceRule && !typeRule) return nullptr; - + return And(And(ratingRule, priceRule), typeRule); } @@ -87,26 +88,23 @@ static int8_t kAgeOfChild = 5; return result; } -unsigned makeMask(std::unordered_set const & items) -{ +unsigned makeMask(std::unordered_set const &items) { unsigned mask = 0; for (auto const i : items) mask = mask | 1U << static_cast(i); - + return mask; } -- (booking::filter::Params)availabilityParams -{ +- (booking::filter::Params)availabilityParams { using Clock = booking::AvailabilityParams::Clock; booking::AvailabilityParams params; params.m_rooms = {{kAdultsCount, {kAgeOfChild}}}; - if (Platform::IsConnected()) - { + if (Platform::IsConnected()) { params.m_checkin = Clock::from_time_t(self.checkInDate.timeIntervalSince1970); params.m_checkout = Clock::from_time_t(self.checkOutDate.timeIntervalSince1970); } - return { std::make_shared(params), {} }; + return {std::make_shared(params), {}}; } @end diff --git a/iphone/Maps/UI/Search/MWMSearchManager+Layout.m b/iphone/Maps/UI/Search/MWMSearchManager+Layout.m index d7fdb63747..30178d215a 100644 --- a/iphone/Maps/UI/Search/MWMSearchManager+Layout.m +++ b/iphone/Maps/UI/Search/MWMSearchManager+Layout.m @@ -1,6 +1,6 @@ +#import #import "MWMSearchManager+Layout.h" #import "MapViewController.h" -#import static CGFloat const kWidthForiPad = 320.0; static CGFloat const changeModeViewOffsetNormal = -24; @@ -8,35 +8,34 @@ static CGFloat const changeModeViewOffsetKeyboard = -12; @interface MWMSearchManager () -@property(nonatomic) IBOutlet UIView * searchBarView; -@property(nonatomic) IBOutlet UIView * actionBarView; -@property(nonatomic) IBOutlet UIView * contentView; +@property(nonatomic) IBOutlet UIView *searchBarView; +@property(nonatomic) IBOutlet UIView *actionBarView; +@property(nonatomic) IBOutlet UIView *contentView; -@property(nonatomic) NSLayoutConstraint * contentViewTopHidden; -@property(nonatomic) NSLayoutConstraint * actionBarViewBottomKeyboard; -@property(nonatomic) NSLayoutConstraint * actionBarViewBottomNormal; +@property(nonatomic) NSLayoutConstraint *contentViewTopHidden; +@property(nonatomic) NSLayoutConstraint *actionBarViewBottomKeyboard; +@property(nonatomic) NSLayoutConstraint *actionBarViewBottomNormal; -@property(weak, nonatomic, readonly) UIView * searchViewContainer; +@property(weak, nonatomic, readonly) UIView *searchViewContainer; @end @implementation MWMSearchManager (Layout) -- (void)layoutTopViews -{ - UIView * searchBarView = self.searchBarView; - UIView * changeModeView = self.actionBarView; - UIView * contentView = self.contentView; - UIView * parentView = self.searchViewContainer; +- (void)layoutTopViews { + UIView *searchBarView = self.searchBarView; + UIView *changeModeView = self.actionBarView; + UIView *contentView = self.contentView; + UIView *parentView = self.searchViewContainer; searchBarView.translatesAutoresizingMaskIntoConstraints = NO; changeModeView.translatesAutoresizingMaskIntoConstraints = NO; contentView.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutXAxisAnchor * leadingAnchor = parentView.leadingAnchor; - NSLayoutXAxisAnchor * trailingAnchor = parentView.trailingAnchor; - NSLayoutYAxisAnchor * topAnchor = parentView.safeAreaLayoutGuide.topAnchor; - NSLayoutYAxisAnchor * bottomAnchor = parentView.safeAreaLayoutGuide.bottomAnchor; + NSLayoutXAxisAnchor *leadingAnchor = parentView.leadingAnchor; + NSLayoutXAxisAnchor *trailingAnchor = parentView.trailingAnchor; + NSLayoutYAxisAnchor *topAnchor = parentView.safeAreaLayoutGuide.topAnchor; + NSLayoutYAxisAnchor *bottomAnchor = parentView.safeAreaLayoutGuide.bottomAnchor; [searchBarView.topAnchor constraintEqualToAnchor:topAnchor].active = YES; [searchBarView.leadingAnchor constraintEqualToAnchor:leadingAnchor].active = YES; @@ -46,21 +45,21 @@ static CGFloat const changeModeViewOffsetKeyboard = -12; [searchBarView.trailingAnchor constraintEqualToAnchor:trailingAnchor].active = YES; [changeModeView.centerXAnchor constraintEqualToAnchor:parentView.centerXAnchor].active = YES; - self.actionBarViewBottomNormal = [changeModeView.bottomAnchor constraintEqualToAnchor:bottomAnchor constant:changeModeViewOffsetNormal]; + self.actionBarViewBottomNormal = [changeModeView.bottomAnchor constraintEqualToAnchor:bottomAnchor + constant:changeModeViewOffsetNormal]; self.actionBarViewBottomNormal.priority = UILayoutPriorityDefaultLow + 10; self.actionBarViewBottomNormal.active = YES; - self.actionBarViewBottomKeyboard = [changeModeView.bottomAnchor constraintEqualToAnchor:parentView.bottomAnchor constant:changeModeViewOffsetKeyboard]; + self.actionBarViewBottomKeyboard = [changeModeView.bottomAnchor constraintEqualToAnchor:parentView.bottomAnchor + constant:changeModeViewOffsetKeyboard]; self.actionBarViewBottomKeyboard.priority = UILayoutPriorityDefaultLow; self.actionBarViewBottomKeyboard.active = YES; - NSLayoutConstraint * contentViewTop = - [contentView.topAnchor constraintEqualToAnchor:searchBarView.bottomAnchor]; - contentViewTop.priority = UILayoutPriorityDefaultLow+10; + NSLayoutConstraint *contentViewTop = [contentView.topAnchor constraintEqualToAnchor:searchBarView.bottomAnchor]; + contentViewTop.priority = UILayoutPriorityDefaultLow + 10; contentViewTop.active = YES; - NSLayoutConstraint * contentViewBottom = - [contentView.bottomAnchor constraintEqualToAnchor:parentView.bottomAnchor]; + NSLayoutConstraint *contentViewBottom = [contentView.bottomAnchor constraintEqualToAnchor:parentView.bottomAnchor]; contentViewBottom.priority = UILayoutPriorityDefaultLow + 10; contentViewBottom.active = YES; @@ -71,36 +70,42 @@ static CGFloat const changeModeViewOffsetKeyboard = -12; [contentView.leadingAnchor constraintEqualToAnchor:searchBarView.leadingAnchor].active = YES; [contentView.trailingAnchor constraintEqualToAnchor:searchBarView.trailingAnchor].active = YES; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillShow:) + name:UIKeyboardWillShowNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillHide:) + name:UIKeyboardWillHideNotification + object:nil]; } #pragma mark - keyboard movements -- (void)keyboardWillShow:(NSNotification *)notification -{ +- (void)keyboardWillShow:(NSNotification *)notification { CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; CGFloat offset = IPAD ? changeModeViewOffsetNormal : changeModeViewOffsetKeyboard; if (self.actionBarView.isHidden) { - self.actionBarViewBottomKeyboard.constant = -keyboardSize.height+offset; + self.actionBarViewBottomKeyboard.constant = -keyboardSize.height + offset; self.actionBarViewBottomKeyboard.priority = UILayoutPriorityDefaultHigh; } else { - [UIView animateWithDuration:kDefaultAnimationDuration animations:^{ - self.actionBarViewBottomKeyboard.constant = -keyboardSize.height+offset; - self.actionBarViewBottomKeyboard.priority = UILayoutPriorityDefaultHigh; - [self.actionBarView.superview layoutIfNeeded]; - }]; + [UIView animateWithDuration:kDefaultAnimationDuration + animations:^{ + self.actionBarViewBottomKeyboard.constant = -keyboardSize.height + offset; + self.actionBarViewBottomKeyboard.priority = UILayoutPriorityDefaultHigh; + [self.actionBarView.superview layoutIfNeeded]; + }]; } } --(void)keyboardWillHide:(NSNotification *)notification -{ +- (void)keyboardWillHide:(NSNotification *)notification { if (self.actionBarView.isHidden) { self.actionBarViewBottomKeyboard.priority = UILayoutPriorityDefaultLow; } else { - [UIView animateWithDuration:kDefaultAnimationDuration animations:^{ - self.actionBarViewBottomKeyboard.priority = UILayoutPriorityDefaultLow; - [self.actionBarView.superview layoutIfNeeded]; - }]; + [UIView animateWithDuration:kDefaultAnimationDuration + animations:^{ + self.actionBarViewBottomKeyboard.priority = UILayoutPriorityDefaultLow; + [self.actionBarView.superview layoutIfNeeded]; + }]; } } diff --git a/iphone/Maps/UI/Search/MWMSearchManager.mm b/iphone/Maps/UI/Search/MWMSearchManager.mm index 134650c549..79396e8ff4 100644 --- a/iphone/Maps/UI/Search/MWMSearchManager.mm +++ b/iphone/Maps/UI/Search/MWMSearchManager.mm @@ -4,9 +4,9 @@ #import "MWMNoMapsViewController.h" #import "MWMRoutePoint+CPP.h" #import "MWMRouter.h" -#import "MWMSearchTableViewController.h" #import "MWMSearchManager+Filter.h" #import "MWMSearchManager+Layout.h" +#import "MWMSearchTableViewController.h" #import "MapViewController.h" #import "Statistics.h" #import "SwiftBridge.h" @@ -41,13 +41,13 @@ using Observers = NSHashTable; @property(weak, nonatomic, readonly) MWMMapViewControlsManager *controlsManager; @property(nonatomic) IBOutlet SearchBar *searchBarView; -@property(weak, nonatomic) IBOutlet SearchActionBarView* actionBarView; +@property(weak, nonatomic) IBOutlet SearchActionBarView *actionBarView; @property(nonatomic) IBOutlet UIView *contentView; -@property (strong, nonatomic) IBOutlet UIView *tableViewContainer; +@property(strong, nonatomic) IBOutlet UIView *tableViewContainer; -@property(nonatomic) NSLayoutConstraint * contentViewTopHidden; -@property(nonatomic) NSLayoutConstraint * actionBarViewBottomKeyboard; -@property(nonatomic) NSLayoutConstraint * actionBarViewBottomNormal; +@property(nonatomic) NSLayoutConstraint *contentViewTopHidden; +@property(nonatomic) NSLayoutConstraint *actionBarViewBottomKeyboard; +@property(nonatomic) NSLayoutConstraint *actionBarViewBottomNormal; @property(nonatomic) UINavigationController *navigationController; @property(nonatomic) MWMSearchTableViewController *tableViewController; @@ -117,7 +117,8 @@ using Observers = NSHashTable; statFrom = kStatSearchMapSearch; } if (GetFramework().HasPlacePageInfo()) { - [Statistics logEvent:kStatBackClick withParameters:@{kStatFrom: statFrom, kStatTo: kStatSearchResults, kStatPlacePage: kStatPreview}]; + [Statistics logEvent:kStatBackClick + withParameters:@{kStatFrom: statFrom, kStatTo: kStatSearchResults, kStatPlacePage: kStatPreview}]; } else { [Statistics logEvent:kStatBackClick withParameters:@{kStatFrom: statFrom, kStatTo: kStatSearchResults}]; } @@ -220,13 +221,13 @@ using Observers = NSHashTable; self.routingTooltipSearch = MWMSearchManagerRoutingTooltipSearchNone; [self endSearch]; - MWMMapViewControlsManager* controlsManager = self.controlsManager; + MWMMapViewControlsManager *controlsManager = self.controlsManager; controlsManager.menuState = controlsManager.menuRestoreState; [self viewHidden:YES]; } - (void)changeToDefaultState { - MWMMapViewControlsManager* controlsManager = self.controlsManager; + MWMMapViewControlsManager *controlsManager = self.controlsManager; [self.navigationController popToRootViewControllerAnimated:NO]; @@ -244,7 +245,7 @@ using Observers = NSHashTable; } - (void)changeToTableSearchState { - MWMMapViewControlsManager* controlsManager = self.controlsManager; + MWMMapViewControlsManager *controlsManager = self.controlsManager; [self.navigationController popToRootViewControllerAnimated:NO]; @@ -326,7 +327,7 @@ using Observers = NSHashTable; self.searchBarView.isBookingSearchViewHidden = !([MWMSearch isHotelResults] || [MWMSearch hasAvailability]); [self.actionBarView updateFilterButtonWithShowFilter:[MWMSearch isHotelResults] || [MWMSearch hasFilter] - filterCount:[MWMSearch filterCount]]; + filterCount:[MWMSearch filterCount]]; if (self.state != MWMSearchManagerStateTableSearch) return; [self.tableViewController onSearchCompleted]; @@ -337,7 +338,7 @@ using Observers = NSHashTable; self.searchBarView.state = SearchBarStateSearching; self.searchBarView.isBookingSearchViewHidden = !([MWMSearch isHotelResults] || [MWMSearch hasAvailability]); [self.actionBarView updateFilterButtonWithShowFilter:[MWMSearch isHotelResults] || [MWMSearch hasFilter] - filterCount:[MWMSearch filterCount]]; + filterCount:[MWMSearch filterCount]]; if (self.state != MWMSearchManagerStateTableSearch) return; self.actionBarState = MWMSearchManagerActionBarStateModeFilter; @@ -551,7 +552,7 @@ didSelectStartDate:(NSDate *)startDate return [MapViewController sharedController].controlsView; } --(MWMMapViewControlsManager *)controlsManager { +- (MWMMapViewControlsManager *)controlsManager { return [MWMMapViewControlsManager manager]; } @end diff --git a/iphone/Maps/UI/Search/SearchActionBarView.swift b/iphone/Maps/UI/Search/SearchActionBarView.swift index c26e4e436b..56326484de 100644 --- a/iphone/Maps/UI/Search/SearchActionBarView.swift +++ b/iphone/Maps/UI/Search/SearchActionBarView.swift @@ -36,7 +36,7 @@ } } - @objc func updateFilterButton(showFilter:Bool, filterCount: Int){ + @objc func updateFilterButton(showFilter: Bool, filterCount: Int) { filterAppliedLabel.text = "\(filterCount)" if showFilter { hideView(filterButton, isHidden: filterCount > 0, animated: true) @@ -52,14 +52,14 @@ private func hideView(_ view: UIView, isHidden: Bool, animated: Bool) { view.isHidden = isHidden if animated { - UIView.animate(withDuration: kDefaultAnimationDuration/2, + UIView.animate(withDuration: kDefaultAnimationDuration / 2, delay: 0, options: [.beginFromCurrentState], animations: { self.layoutIfNeeded() - }, completion: {complete in + }, completion: { complete in if complete { - UIView.animate(withDuration: kDefaultAnimationDuration/2, + UIView.animate(withDuration: kDefaultAnimationDuration / 2, delay: 0, options: [.beginFromCurrentState], animations: { view.alpha = isHidden ? 0 : 1 diff --git a/iphone/Maps/UI/Search/TableView/MWMSearchTableViewController.mm b/iphone/Maps/UI/Search/TableView/MWMSearchTableViewController.mm index 75cda46468..0df5154f9b 100644 --- a/iphone/Maps/UI/Search/TableView/MWMSearchTableViewController.mm +++ b/iphone/Maps/UI/Search/TableView/MWMSearchTableViewController.mm @@ -7,10 +7,8 @@ #include "platform/localization.hpp" -namespace -{ -NSString * GetLocalizedTypeName(search::Result const & result) -{ +namespace { +NSString *GetLocalizedTypeName(search::Result const &result) { if (result.GetResultType() != search::Result::Type::Feature) return @""; @@ -20,9 +18,9 @@ NSString * GetLocalizedTypeName(search::Result const & result) } } -@interface MWMSearchTableViewController () +@interface MWMSearchTableViewController () -@property(weak, nonatomic) IBOutlet UITableView * tableView; +@property(weak, nonatomic) IBOutlet UITableView *tableView; @property(weak, nonatomic) id delegate; @@ -30,22 +28,19 @@ NSString * GetLocalizedTypeName(search::Result const & result) @implementation MWMSearchTableViewController -- (nonnull instancetype)initWithDelegate:(id)delegate -{ +- (nonnull instancetype)initWithDelegate:(id)delegate { self = [super init]; if (self) _delegate = delegate; return self; } -- (void)viewDidLoad -{ +- (void)viewDidLoad { [super viewDidLoad]; [self setupTableView]; } -- (void)viewWillAppear:(BOOL)animated -{ +- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.tableView.hidden = NO; self.tableView.insetsContentViewsToSafeArea = YES; @@ -53,9 +48,8 @@ NSString * GetLocalizedTypeName(search::Result const & result) [self reloadData]; } -- (void)setupTableView -{ - UITableView * tableView = self.tableView; +- (void)setupTableView { + UITableView *tableView = self.tableView; tableView.estimatedRowHeight = 80.; tableView.rowHeight = UITableViewAutomaticDimension; [tableView registerNibWithCellClass:[MWMSearchSuggestionCell class]]; @@ -63,113 +57,105 @@ NSString * GetLocalizedTypeName(search::Result const & result) [tableView registerClassWithCellClass:[MWMAdBannerCell class]]; } -- (void)reloadData { [self.tableView reloadData]; } +- (void)reloadData { + [self.tableView reloadData]; +} #pragma mark - Layout - (void)viewWillTransitionToSize:(CGSize)size - withTransitionCoordinator:(id)coordinator -{ + withTransitionCoordinator:(id)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [coordinator - animateAlongsideTransition:^(id context) { - [self reloadData]; - } - completion:nil]; + animateAlongsideTransition:^(id context) { + [self reloadData]; + } + completion:nil]; } #pragma mark - UITableViewDataSource -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [MWMSearch resultsCount]; } -- (UITableViewCell *)tableView:(UITableView *)tableView - cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - if ([MWMSearch resultsCount] == 0) - { +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + if ([MWMSearch resultsCount] == 0) { NSAssert(false, @"Invalid reload with outdated SearchIndex"); return [tableView dequeueReusableCellWithCellClass:[MWMSearchCommonCell class] indexPath:indexPath]; } auto const row = indexPath.row; auto const containerIndex = [MWMSearch containerIndexWithRow:row]; - switch ([MWMSearch resultTypeWithRow:row]) - { - case MWMSearchItemTypeRegular: - { - auto cell = static_cast([tableView - dequeueReusableCellWithCellClass:[MWMSearchCommonCell class] - indexPath:indexPath]); - auto const & result = [MWMSearch resultWithContainerIndex:containerIndex]; - auto const isBookingAvailable = [MWMSearch isBookingAvailableWithContainerIndex:containerIndex]; - auto const isDealAvailable = [MWMSearch isDealAvailableWithContainerIndex:containerIndex]; - auto const & productInfo = [MWMSearch productInfoWithContainerIndex:containerIndex]; - auto const typeName = GetLocalizedTypeName(result); - [cell config:result isAvailable:isBookingAvailable isHotOffer:isDealAvailable productInfo:productInfo + switch ([MWMSearch resultTypeWithRow:row]) { + case MWMSearchItemTypeRegular: { + auto cell = + static_cast([tableView dequeueReusableCellWithCellClass:[MWMSearchCommonCell class] + indexPath:indexPath]); + auto const &result = [MWMSearch resultWithContainerIndex:containerIndex]; + auto const isBookingAvailable = [MWMSearch isBookingAvailableWithContainerIndex:containerIndex]; + auto const isDealAvailable = [MWMSearch isDealAvailableWithContainerIndex:containerIndex]; + auto const &productInfo = [MWMSearch productInfoWithContainerIndex:containerIndex]; + auto const typeName = GetLocalizedTypeName(result); + [cell config:result + isAvailable:isBookingAvailable + isHotOffer:isDealAvailable + productInfo:productInfo localizedTypeName:typeName]; - return cell; - } - case MWMSearchItemTypeMopub: - case MWMSearchItemTypeFacebook: - { - auto cell = static_cast([tableView dequeueReusableCellWithCellClass:[MWMAdBannerCell class] indexPath:indexPath]); - auto ad = [MWMSearch adWithContainerIndex:containerIndex]; - [cell configWithAd:ad - containerType:MWMAdBannerContainerTypeSearch - canRemoveAds:[SubscriptionManager canMakePayments] - onRemoveAds: ^{ - [[MapViewController sharedController] showRemoveAds]; - }]; - return cell; - } - case MWMSearchItemTypeSuggestion: - { - auto cell = static_cast([tableView - dequeueReusableCellWithCellClass:[MWMSearchSuggestionCell class] - indexPath:indexPath]); - auto const & suggestion = [MWMSearch resultWithContainerIndex:containerIndex]; - [cell config:suggestion localizedTypeName:@""]; - cell.isLastCell = row == [MWMSearch suggestionsCount] - 1; - return cell; - } + return cell; + } + case MWMSearchItemTypeMopub: + case MWMSearchItemTypeFacebook: { + auto cell = static_cast([tableView dequeueReusableCellWithCellClass:[MWMAdBannerCell class] + indexPath:indexPath]); + auto ad = [MWMSearch adWithContainerIndex:containerIndex]; + [cell configWithAd:ad + containerType:MWMAdBannerContainerTypeSearch + canRemoveAds:[SubscriptionManager canMakePayments] + onRemoveAds:^{ + [[MapViewController sharedController] showRemoveAds]; + }]; + return cell; + } + case MWMSearchItemTypeSuggestion: { + auto cell = static_cast( + [tableView dequeueReusableCellWithCellClass:[MWMSearchSuggestionCell class] indexPath:indexPath]); + auto const &suggestion = [MWMSearch resultWithContainerIndex:containerIndex]; + [cell config:suggestion localizedTypeName:@""]; + cell.isLastCell = row == [MWMSearch suggestionsCount] - 1; + return cell; + } } } #pragma mark - UITableViewDelegate -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { id delegate = self.delegate; auto const row = indexPath.row; auto const containerIndex = [MWMSearch containerIndexWithRow:row]; - switch ([MWMSearch resultTypeWithRow:row]) - { - case MWMSearchItemTypeRegular: - { - MWMSearchTextField * textField = delegate.searchTextField; - [MWMSearch saveQuery:textField.text forInputLocale:textField.textInputMode.primaryLanguage]; - auto const & result = [MWMSearch resultWithContainerIndex:containerIndex]; - [delegate processSearchWithResult:result]; - break; - } - case MWMSearchItemTypeMopub: - case MWMSearchItemTypeFacebook: break; - case MWMSearchItemTypeSuggestion: - { - auto const & suggestion = [MWMSearch resultWithContainerIndex:containerIndex]; - NSString * suggestionString = @(suggestion.GetSuggestionString().c_str()); - [Statistics logEvent:kStatEventName(kStatSearch, kStatSelectResult) - withParameters:@{kStatValue : suggestionString, kStatScreen : kStatSearch}]; - [delegate searchText:suggestionString forInputLocale:nil]; - } + switch ([MWMSearch resultTypeWithRow:row]) { + case MWMSearchItemTypeRegular: { + MWMSearchTextField *textField = delegate.searchTextField; + [MWMSearch saveQuery:textField.text forInputLocale:textField.textInputMode.primaryLanguage]; + auto const &result = [MWMSearch resultWithContainerIndex:containerIndex]; + [delegate processSearchWithResult:result]; + break; + } + case MWMSearchItemTypeMopub: + case MWMSearchItemTypeFacebook: + break; + case MWMSearchItemTypeSuggestion: { + auto const &suggestion = [MWMSearch resultWithContainerIndex:containerIndex]; + NSString *suggestionString = @(suggestion.GetSuggestionString().c_str()); + [Statistics logEvent:kStatEventName(kStatSearch, kStatSelectResult) + withParameters:@{kStatValue: suggestionString, kStatScreen: kStatSearch}]; + [delegate searchText:suggestionString forInputLocale:nil]; + } } } #pragma mark - MWMSearchObserver -- (void)onSearchCompleted -{ +- (void)onSearchCompleted { [self reloadData]; BOOL const noResults = [MWMSearch resultsCount] == 0; self.tableView.hidden = noResults;