diff options
Diffstat (limited to 'iphone/Maps')
-rw-r--r-- | iphone/Maps/Core/Ads/BannersCache.swift | 30 | ||||
-rw-r--r-- | iphone/Maps/Core/Search/MWMSearch.mm | 12 | ||||
-rw-r--r-- | iphone/Maps/UI/PlacePage/MWMPlacePageData.mm | 5 | ||||
-rw-r--r-- | iphone/Maps/UI/Search/TableView/MWMSearchTableViewController.mm | 1 |
4 files changed, 27 insertions, 21 deletions
diff --git a/iphone/Maps/Core/Ads/BannersCache.swift b/iphone/Maps/Core/Ads/BannersCache.swift index 14fcecb9d1..de12ca0fec 100644 --- a/iphone/Maps/Core/Ads/BannersCache.swift +++ b/iphone/Maps/Core/Ads/BannersCache.swift @@ -22,29 +22,28 @@ final class BannersCache: NSObject { private func onCompletion(isAsync: Bool) { guard let completion = completion else { return } - var bannerType: BannerType? + var banner: Banner? statesLoop: for loadState in loadStates { switch loadState { - case .notLoaded(_): return + case .notLoaded(let type): + banner = cache[type] + break statesLoop case .loaded(let type): - bannerType = type + banner = cache[type] break statesLoop case .error: continue } } - guard bannerType != nil else { return } - guard let banner = cache[bannerType!] else { - assert(false) - return + if let banner = banner { + Statistics.logEvent(kStatPlacePageBannerShow, withParameters: banner.statisticsDescription) + MRMyTracker.trackEvent(withName: kStatPlacePageBannerShow) + completion(banner, isAsync) + banner.isBannerOnScreen = true + self.completion = nil } - Statistics.logEvent(kStatPlacePageBannerShow, withParameters: banner.statisticsDescription) - MRMyTracker.trackEvent(withName: kStatPlacePageBannerShow) - completion(banner, isAsync) - banner.isBannerOnScreen = true - self.completion = nil } - func get(coreBanners: [CoreBanner], completion: @escaping Completion, cacheOnly: Bool) { + func get(coreBanners: [CoreBanner], cacheOnly: Bool, loadNew: Bool = true, completion: @escaping Completion) { self.completion = completion self.cacheOnly = cacheOnly loadStates = coreBanners.map { coreBanner in @@ -52,10 +51,13 @@ final class BannersCache: NSObject { if let banner = cache[bannerType], (!banner.isPossibleToReload || banner.isNeedToRetain) { return .loaded(bannerType) } else { - get(bannerType: bannerType) + if loadNew { + get(bannerType: bannerType) + } return .notLoaded(bannerType) } } + onCompletion(isAsync: false) } diff --git a/iphone/Maps/Core/Search/MWMSearch.mm b/iphone/Maps/Core/Search/MWMSearch.mm index 69e672e89b..1d6952f9d6 100644 --- a/iphone/Maps/Core/Search/MWMSearch.mm +++ b/iphone/Maps/Core/Search/MWMSearch.mm @@ -101,6 +101,7 @@ using TObservers = NSHashTable<__kindof TObserver>; f.SearchInViewport(m_viewportParams); } } + [self updateItemsIndexWithBannerReload:YES]; [self onSearchCompleted]; } else @@ -108,7 +109,7 @@ using TObservers = NSHashTable<__kindof TObserver>; self->m_everywhereResults = results; self->m_isLocalAdsCustomer = isLocalAdsCustomer; self.suggestionsCount = results.GetSuggestsCount(); - [self updateItemsIndex]; + [self updateItemsIndexWithBannerReload:NO]; [self onSearchResultsUpdated]; } }; @@ -258,7 +259,7 @@ using TObservers = NSHashTable<__kindof TObserver>; auto manager = [MWMSearch manager]; manager->m_everywhereResults.Clear(); manager.suggestionsCount = 0; - [manager updateItemsIndex]; + [manager updateItemsIndexWithBannerReload:YES]; [self reset]; } @@ -298,7 +299,7 @@ using TObservers = NSHashTable<__kindof TObserver>; [manager onSearchCompleted]; } -- (void)updateItemsIndex +- (void)updateItemsIndexWithBannerReload:(BOOL)reloadBanner { auto const resultsCount = self->m_everywhereResults.GetCount(); auto const itemsIndex = [[MWMSearchIndex alloc] initWithSuggestionsCount:self.suggestionsCount @@ -313,14 +314,15 @@ using TObservers = NSHashTable<__kindof TObserver>; __weak auto weakSelf = self; [bannersCache getWithCoreBanners:banner_helpers::MatchPriorityBanners(adsEngine.GetSearchBanners()) + cacheOnly:YES + loadNew:reloadBanner completion:^(id<MWMBanner> ad, BOOL isAsync) { __strong auto self = weakSelf; if (!self) return; NSAssert(isAsync == NO, @"Banner is not from cache!"); [self.banners add:ad]; - } - cacheOnly:YES]; + }]; } } else diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm index 4e9ed0cd63..487386bd54 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm @@ -104,6 +104,8 @@ using namespace place_page; __weak auto wSelf = self; [[MWMBannersCache cache] getWithCoreBanners:banner_helpers::MatchPriorityBanners(m_info.GetBanners()) + cacheOnly:NO + loadNew:YES completion:^(id<MWMBanner> ad, BOOL isAsync) { __strong auto self = wSelf; if (!self) @@ -113,8 +115,7 @@ using namespace place_page; self->m_previewRows.push_back(PreviewRows::Banner); if (isAsync) self.bannerIsReadyCallback(); - } - cacheOnly:NO]; + }]; } } diff --git a/iphone/Maps/UI/Search/TableView/MWMSearchTableViewController.mm b/iphone/Maps/UI/Search/TableView/MWMSearchTableViewController.mm index c430d6b766..d0cbb17c51 100644 --- a/iphone/Maps/UI/Search/TableView/MWMSearchTableViewController.mm +++ b/iphone/Maps/UI/Search/TableView/MWMSearchTableViewController.mm @@ -142,6 +142,7 @@ - (void)onSearchCompleted { + [self onSearchResultsUpdated]; BOOL const noResults = [MWMSearch resultsCount] == 0; self.tableView.hidden = noResults; [(MWMSearchTableView *)self.view hideNoResultsView:!noResults]; |