From 3354e07b939e1911ed2862a486cbfc179082dac3 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Wed, 23 Mar 2016 12:00:03 +0300 Subject: [PATCH] [ios] Refactored downloader. --- .../Cells/MWMMapDownloaderTableViewCell.h | 2 +- .../Cells/MWMMapDownloaderTableViewCell.mm | 6 ++-- .../DataSources/MWMMapDownloaderDataSource.h | 6 ++-- .../DataSources/MWMMapDownloaderDataSource.mm | 28 ++++++++------- .../MWMMapDownloaderDefaultDataSource.h | 2 +- .../MWMMapDownloaderDefaultDataSource.mm | 18 +++++----- .../MWMMapDownloaderExtendedDataSource.mm | 4 +-- .../MWMMapDownloaderSearchDataSource.mm | 16 ++++----- .../MWMBaseMapDownloaderViewController.h | 2 +- .../MWMBaseMapDownloaderViewController.mm | 35 +++++++++++-------- .../MWMMapDownloaderViewController.mm | 2 +- iphone/Maps/Classes/MapViewController.mm | 2 +- .../Migration/MWMMigrationViewController.mm | 2 +- 13 files changed, 67 insertions(+), 58 deletions(-) diff --git a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.h b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.h index bf6e7897bb..6cf4ab1ead 100644 --- a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.h +++ b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.h @@ -16,6 +16,6 @@ @property (weak, nonatomic) id delegate; - (void)config:(storage::NodeAttrs const &)nodeAttrs; -- (void)setCountryId:(storage::TCountryId const &)countryId; +- (void)setCountryId:(NSString *)countryId; @end diff --git a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm index 9e90182636..0782dcb7d1 100644 --- a/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm +++ b/iphone/Maps/Classes/MapDownloader/Cells/MWMMapDownloaderTableViewCell.mm @@ -144,11 +144,11 @@ #pragma mark - Properties -- (void)setCountryId:(storage::TCountryId const &)countryId +- (void)setCountryId:(NSString *)countryId { - if (m_countryId == countryId) + if (m_countryId == countryId.UTF8String) return; - m_countryId = countryId; + m_countryId = countryId.UTF8String; storage::NodeAttrs nodeAttrs; GetFramework().Storage().GetNodeAttrs(m_countryId, nodeAttrs); [self config:nodeAttrs]; diff --git a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.h b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.h index 8f927e9e2b..5468e7c0b9 100644 --- a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.h +++ b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.h @@ -10,11 +10,11 @@ @property (nonatomic, readonly) NSMutableIndexSet * reloadSections; - (instancetype)initWithDelegate:(id)delegate; -- (storage::TCountryId)parentCountryId; -- (storage::TCountryId)countryIdForIndexPath:(NSIndexPath *)indexPath; +- (NSString *)parentCountryId; +- (NSString *)countryIdForIndexPath:(NSIndexPath *)indexPath; - (NSString *)cellIdentifierForIndexPath:(NSIndexPath *)indexPath; - (void)fillCell:(MWMMapDownloaderTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath; -- (NSString *)searchMatchedResultForCountryId:(storage::TCountryId)countryId; +- (NSString *)searchMatchedResultForCountryId:(NSString *)countryId; @end diff --git a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm index d0282cb43c..26c29ef230 100644 --- a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm +++ b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm @@ -33,16 +33,20 @@ using namespace storage; - (void)fillCell:(MWMMapDownloaderTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { - TCountryId const countryId = [self countryIdForIndexPath:indexPath]; + NSString * countryId = [self countryIdForIndexPath:indexPath]; + [cell setCountryId:countryId]; if ([cell isKindOfClass:[MWMMapDownloaderPlaceTableViewCell class]]) - static_cast(cell).needDisplayArea = self.isParentRoot; + { + MWMMapDownloaderPlaceTableViewCell * placeCell = static_cast(cell); + placeCell.needDisplayArea = self.isParentRoot; + } if ([cell isKindOfClass:[MWMMapDownloaderSubplaceTableViewCell class]]) - [static_cast(cell) - setSubplaceText:[self searchMatchedResultForCountryId:countryId]]; - - [cell setCountryId:countryId]; + { + MWMMapDownloaderSubplaceTableViewCell * subplaceCell = static_cast(cell); + [subplaceCell setSubplaceText:[self searchMatchedResultForCountryId:countryId]]; + } } #pragma mark - UITableViewDataSource @@ -69,7 +73,7 @@ using namespace storage; - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) - [self.delegate deleteNode:[self countryIdForIndexPath:indexPath]]; + [self.delegate deleteNode:[self countryIdForIndexPath:indexPath].UTF8String]; } #pragma mark - MWMMapDownloaderDataSource @@ -79,14 +83,14 @@ using namespace storage; return YES; } -- (TCountryId)parentCountryId +- (NSString *)parentCountryId { - return kInvalidCountryId; + return @(kInvalidCountryId.c_str()); } -- (TCountryId)countryIdForIndexPath:(NSIndexPath *)indexPath +- (NSString *)countryIdForIndexPath:(NSIndexPath *)indexPath { - return kInvalidCountryId; + return @(kInvalidCountryId.c_str()); } - (NSString *)cellIdentifierForIndexPath:(NSIndexPath *)indexPath @@ -94,7 +98,7 @@ using namespace storage; return nil; } -- (NSString *)searchMatchedResultForCountryId:(storage::TCountryId)countryId +- (NSString *)searchMatchedResultForCountryId:(NSString *)countryId { return nil; } diff --git a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.h b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.h index a0cef19a72..bcc58b03b5 100644 --- a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.h +++ b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.h @@ -2,7 +2,7 @@ @interface MWMMapDownloaderDefaultDataSource : MWMMapDownloaderDataSource -- (instancetype)initForRootCountryId:(storage::TCountryId)countryId delegate:(id)delegate; +- (instancetype)initForRootCountryId:(NSString *)countryId delegate:(id)delegate; - (void)reload; @end diff --git a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.mm b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.mm index abcd30d92d..ef873cd1db 100644 --- a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.mm +++ b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.mm @@ -49,12 +49,12 @@ using namespace storage; @synthesize isParentRoot = _isParentRoot; -- (instancetype)initForRootCountryId:(storage::TCountryId)countryId delegate:(id)delegate +- (instancetype)initForRootCountryId:(NSString *)countryId delegate:(id)delegate { self = [super initWithDelegate:delegate]; if (self) { - m_parentId = countryId; + m_parentId = countryId.UTF8String; _isParentRoot = (m_parentId == GetFramework().Storage().GetRootId()); [self load]; } @@ -188,35 +188,35 @@ using namespace storage; - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { NodeAttrs nodeAttrs; - GetFramework().Storage().GetNodeAttrs([self countryIdForIndexPath:indexPath], nodeAttrs); + GetFramework().Storage().GetNodeAttrs([self countryIdForIndexPath:indexPath].UTF8String, nodeAttrs); NodeStatus const status = nodeAttrs.m_status; return (status == NodeStatus::OnDisk || status == NodeStatus::OnDiskOutOfDate || nodeAttrs.m_localMwmCounter != 0); } #pragma mark - MWMMapDownloaderDataSource -- (TCountryId)parentCountryId +- (NSString *)parentCountryId { - return m_parentId; + return @(m_parentId.c_str()); } -- (TCountryId)countryIdForIndexPath:(NSIndexPath *)indexPath +- (NSString *)countryIdForIndexPath:(NSIndexPath *)indexPath { NSInteger const section = indexPath.section; NSInteger const row = indexPath.row; if (section == self.downloadedSection) - return self.downloadedCountries[row].UTF8String; + return self.downloadedCountries[row]; NSString * index = self.indexes[section - self.downloadedSectionShift]; NSArray * availableCountries = self.availableCountries[index]; NSString * nsCountryId = availableCountries[indexPath.row]; - return nsCountryId.UTF8String; + return nsCountryId; } - (NSString *)cellIdentifierForIndexPath:(NSIndexPath *)indexPath { auto const & s = GetFramework().Storage(); TCountriesVec children; - s.GetChildren([self countryIdForIndexPath:indexPath], children); + s.GetChildren([self countryIdForIndexPath:indexPath].UTF8String, children); BOOL const haveChildren = !children.empty(); if (haveChildren) return kLargeCountryCellIdentifier; diff --git a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderExtendedDataSource.mm b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderExtendedDataSource.mm index 93063a1212..84fe3208e9 100644 --- a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderExtendedDataSource.mm +++ b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderExtendedDataSource.mm @@ -98,12 +98,12 @@ using namespace storage; #pragma mark - MWMMapDownloaderDataSource -- (TCountryId)countryIdForIndexPath:(NSIndexPath *)indexPath +- (NSString *)countryIdForIndexPath:(NSIndexPath *)indexPath { NSInteger const row = indexPath.row; NSInteger const section = indexPath.section; if (section == self.nearmeSection) - return self.nearmeCountries[row].UTF8String; + return self.nearmeCountries[row]; return [super countryIdForIndexPath:[NSIndexPath indexPathForRow:row inSection:section - self.nearmeSectionShift]]; } diff --git a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderSearchDataSource.mm b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderSearchDataSource.mm index fa3b36f318..daa21ea288 100644 --- a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderSearchDataSource.mm +++ b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderSearchDataSource.mm @@ -51,22 +51,22 @@ extern NSString * const kPlaceCellIdentifier; #pragma mark - MWMMapDownloaderDataSource -- (TCountryId)parentCountryId +- (NSString *)parentCountryId { - return GetFramework().Storage().GetRootId(); + return @(GetFramework().Storage().GetRootId().c_str()); } -- (TCountryId)countryIdForIndexPath:(NSIndexPath *)indexPath +- (NSString *)countryIdForIndexPath:(NSIndexPath *)indexPath { - return self.searchCountryIds[indexPath.row].UTF8String; + return self.searchCountryIds[indexPath.row]; } - (NSString *)cellIdentifierForIndexPath:(NSIndexPath *)indexPath { auto const & s = GetFramework().Storage(); NodeAttrs nodeAttrs; - TCountryId const countryId = [self countryIdForIndexPath:indexPath]; - s.GetNodeAttrs(countryId, nodeAttrs); + NSString * countryId = [self countryIdForIndexPath:indexPath]; + s.GetNodeAttrs(countryId.UTF8String, nodeAttrs); NSString * nodeLocalName = @(nodeAttrs.m_nodeLocalName.c_str()); NSString * matchedResult = [self searchMatchedResultForCountryId:countryId]; if (![nodeLocalName isEqualToString:matchedResult]) @@ -76,9 +76,9 @@ extern NSString * const kPlaceCellIdentifier; return kPlaceCellIdentifier; } -- (NSString *)searchMatchedResultForCountryId:(storage::TCountryId)countryId +- (NSString *)searchMatchedResultForCountryId:(NSString *)countryId { - return self.searchMatchedResults[@(countryId.c_str())]; + return self.searchMatchedResults[countryId]; } - (BOOL)needFullReload diff --git a/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.h b/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.h index ee2ab16b80..f7cd2cad0c 100644 --- a/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.h +++ b/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.h @@ -8,7 +8,7 @@ @property (nonatomic) BOOL showAllMapsView; -@property (nonatomic) storage::TCountryId parentCountryId; +@property (nonatomic) NSString * parentCountryId; - (void)configTable; - (void)configAllMapsView; diff --git a/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm b/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm index 4e2d66f69f..ee7c34d77a 100644 --- a/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm +++ b/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm @@ -107,7 +107,7 @@ using namespace storage; else { NodeAttrs nodeAttrs; - GetFramework().Storage().GetNodeAttrs(self.parentCountryId, nodeAttrs); + GetFramework().Storage().GetNodeAttrs(self.parentCountryId.UTF8String, nodeAttrs); self.title = @(nodeAttrs.m_nodeLocalName.c_str()); } } @@ -125,7 +125,10 @@ using namespace storage; return; MWMViewController * parentVC = viewControllers.lastObject; if ([parentVC isKindOfClass:[MWMBaseMapDownloaderViewController class]]) - [static_cast(parentVC) processCountryEvent:self.parentCountryId]; + { + MWMBaseMapDownloaderViewController * downloaderVC = static_cast(parentVC); + [downloaderVC processCountryEvent:self.parentCountryId.UTF8String]; + } } #pragma mark - MWMFrameworkStorageObserver @@ -144,14 +147,14 @@ using namespace storage; [self reloadData]; }; - if (countryId == self.parentCountryId) + if (countryId == self.parentCountryId.UTF8String) { process(); } else { TCountriesVec childrenId; - GetFramework().Storage().GetChildren(self.parentCountryId, childrenId); + GetFramework().Storage().GetChildren(self.parentCountryId.UTF8String, childrenId); if (find(childrenId.cbegin(), childrenId.cend(), countryId) != childrenId.cend()) process(); } @@ -188,7 +191,7 @@ using namespace storage; { auto const & s = GetFramework().Storage(); NodeAttrs nodeAttrs; - m_actionSheetId = [self.dataSource countryIdForIndexPath:indexPath]; + m_actionSheetId = [self.dataSource countryIdForIndexPath:indexPath].UTF8String; s.GetNodeAttrs(m_actionSheetId, nodeAttrs); BOOL const needsUpdate = (nodeAttrs.m_status == NodeStatus::OnDiskOutOfDate); BOOL const isDownloaded = (needsUpdate || nodeAttrs.m_status == NodeStatus::OnDisk); @@ -318,12 +321,13 @@ using namespace storage; auto const & s = GetFramework().Storage(); TCountriesVec downloadedChildren; TCountriesVec availableChildren; - s.GetChildrenInGroups(self.parentCountryId, downloadedChildren, availableChildren); + TCountryId const parentCountryId = self.parentCountryId.UTF8String; + s.GetChildrenInGroups(parentCountryId, downloadedChildren, availableChildren); if (availableChildren.empty()) { TCountriesVec queuedChildren; - s.GetQueuedChildren(self.parentCountryId, queuedChildren); + s.GetQueuedChildren(parentCountryId, queuedChildren); if (!queuedChildren.empty()) { size_t queuedSize = 0; @@ -343,7 +347,7 @@ using namespace storage; else { NodeAttrs nodeAttrs; - s.GetNodeAttrs(self.parentCountryId, nodeAttrs); + s.GetNodeAttrs(parentCountryId, nodeAttrs); uint32_t remoteMWMCounter = nodeAttrs.m_mwmCounter - nodeAttrs.m_localMwmCounter; if (remoteMWMCounter != 0) { @@ -390,7 +394,8 @@ using namespace storage; - (IBAction)allMapsAction { self.skipCountryEventProcessing = YES; - if (self.parentCountryId == GetFramework().Storage().GetRootId()) + TCountryId const parentCountryId = self.parentCountryId.UTF8String; + if (parentCountryId == GetFramework().Storage().GetRootId()) { [Statistics logEvent:kStatDownloaderMapAction withParameters:@{ @@ -399,7 +404,7 @@ using namespace storage; kStatFrom : kStatDownloader, kStatScenario : kStatUpdateAll }]; - [MWMStorage updateNode:self.parentCountryId alertController:self.alertController]; + [MWMStorage updateNode:parentCountryId alertController:self.alertController]; } else { @@ -413,7 +418,7 @@ using namespace storage; kStatFrom : kStatDownloader, kStatScenario : kStatDownloadGroup }]; - [MWMStorage downloadNode:self.parentCountryId + [MWMStorage downloadNode:parentCountryId alertController:self.alertController onSuccess:nil]; } @@ -426,11 +431,11 @@ using namespace storage; kStatFrom : kStatDownloader, kStatScenario : kStatDownloadGroup }]; - [MWMStorage cancelDownloadNode:self.parentCountryId]; + [MWMStorage cancelDownloadNode:parentCountryId]; } } self.skipCountryEventProcessing = NO; - [self processCountryEvent:self.parentCountryId]; + [self processCountryEvent:parentCountryId]; } #pragma mark - UITableViewDelegate @@ -605,12 +610,12 @@ using namespace storage; self.allMapsView.hidden = !showAllMapsView; } -- (TCountryId)parentCountryId +- (NSString *)parentCountryId { return [self.dataSource parentCountryId]; } -- (void)setParentCountryId:(TCountryId)parentId +- (void)setParentCountryId:(NSString *)parentId { self.defaultDataSource = [[MWMMapDownloaderDefaultDataSource alloc] initForRootCountryId:parentId delegate:self]; } diff --git a/iphone/Maps/Classes/MapDownloader/MWMMapDownloaderViewController.mm b/iphone/Maps/Classes/MapDownloader/MWMMapDownloaderViewController.mm index 656e649b15..e0090042ad 100644 --- a/iphone/Maps/Classes/MapDownloader/MWMMapDownloaderViewController.mm +++ b/iphone/Maps/Classes/MapDownloader/MWMMapDownloaderViewController.mm @@ -146,7 +146,7 @@ using namespace storage; #pragma mark - Properties -- (void)setParentCountryId:(TCountryId)parentId +- (void)setParentCountryId:(NSString *)parentId { self.defaultDataSource = [[MWMMapDownloaderExtendedDataSource alloc] initForRootCountryId:parentId delegate:self]; } diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 81c28d084a..f98c82f85b 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -834,7 +834,7 @@ NSString * const kReportSegue = @"Map2ReportSegue"; else if ([segue.identifier isEqualToString:kDownloaderSegue]) { MWMMapDownloaderViewController * dvc = segue.destinationViewController; - dvc.parentCountryId = GetFramework().Storage().GetRootId(); + dvc.parentCountryId = @(GetFramework().Storage().GetRootId().c_str()); } else if ([segue.identifier isEqualToString:kReportSegue]) { diff --git a/iphone/Maps/Classes/Migration/MWMMigrationViewController.mm b/iphone/Maps/Classes/Migration/MWMMigrationViewController.mm index cb63071a47..d79438cfaa 100644 --- a/iphone/Maps/Classes/Migration/MWMMigrationViewController.mm +++ b/iphone/Maps/Classes/Migration/MWMMigrationViewController.mm @@ -158,7 +158,7 @@ using namespace storage; if ([segue.identifier isEqualToString:kDownloaderSegue]) { MWMMapDownloaderViewController * dvc = segue.destinationViewController; - dvc.parentCountryId = GetFramework().Storage().GetRootId(); + dvc.parentCountryId = @(GetFramework().Storage().GetRootId().c_str()); } }