From cea5108b08ba30dcca61afd98d30d71abc311d78 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Mon, 14 Mar 2016 15:58:27 +0300 Subject: [PATCH] [ios] Added filter out downloaded maps from "near me" section. --- .../MWMMapDownloaderExtendedDataSource.mm | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderExtendedDataSource.mm b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderExtendedDataSource.mm index 8ad9858c06..b4e192a835 100644 --- a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderExtendedDataSource.mm +++ b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderExtendedDataSource.mm @@ -9,8 +9,9 @@ using namespace storage; @interface MWMMapDownloaderDefaultDataSource () @property (nonatomic, readonly) NSInteger downloadedCountrySection; +@property (nonatomic, readwrite) BOOL needFullReload; -- (void)reload; +- (void)load; @end @@ -21,29 +22,40 @@ using namespace storage; @property (nonatomic) NSInteger closestCountriesSection; @property (nonatomic, readonly) NSInteger closestCountriesSectionShift; +@property (nonatomic) BOOL needReloadClosestCountriesSection; + @end @implementation MWMMapDownloaderExtendedDataSource -- (instancetype)initForRootCountryId:(storage::TCountryId)countryId delegate:(id)delegate -{ - self = [super initForRootCountryId:countryId delegate:delegate]; - if (self) - [self configNearMeSection]; - return self; -} - - (std::vector)getReloadSections { std::vector sections = [super getReloadSections]; - if (self.haveClosestCountries) - { - for (auto & section : sections) - section += self.closestCountriesSectionShift; - } + if (!self.haveClosestCountries) + return sections; + for (auto & section : sections) + section += self.closestCountriesSectionShift; + if (self.needReloadClosestCountriesSection) + sections.push_back(self.closestCountriesSection); return sections; } +- (void)load +{ + [super load]; + [self configNearMeSection]; +} + +- (void)reload +{ + NSSet * closestCoutryIds = [NSSet setWithArray:self.closestCoutryIds]; + [super reload]; + + self.needReloadClosestCountriesSection = + ![closestCoutryIds isEqualToSet:[NSSet setWithArray:self.closestCoutryIds]]; + self.needFullReload |= self.needReloadClosestCountriesSection && self.closestCoutryIds.count == 0; +} + - (void)configNearMeSection { self.closestCoutryIds = nil; @@ -55,8 +67,14 @@ using namespace storage; TCountriesVec closestCoutryIds; countryInfoGetter.GetRegionsCountryId(lm.lastLocation.mercator, closestCoutryIds); NSMutableArray * nsClosestCoutryIds = [@[] mutableCopy]; + auto const & s = GetFramework().Storage(); for (auto const & countryId : closestCoutryIds) - [nsClosestCoutryIds addObject:@(countryId.c_str())]; + { + NodeStatuses nodeStatuses{}; + s.GetNodeStatuses(countryId, nodeStatuses); + if (nodeStatuses.m_status == NodeStatus::NotDownloaded) + [nsClosestCoutryIds addObject:@(countryId.c_str())]; + } if (nsClosestCoutryIds.count != 0) { self.closestCoutryIds = nsClosestCoutryIds;