forked from organicmaps/organicmaps
[ios] Downloader fixes
This commit is contained in:
parent
018b5b66dd
commit
91a42c80d5
7 changed files with 93 additions and 98 deletions
|
@ -95,6 +95,19 @@
|
|||
self.selectedGroup = [self groupWithSection:indexPath.section];
|
||||
}
|
||||
|
||||
- (void)configureSizeLabelOfMapCell:(MapCell *)cell position:(int)position group:(ActiveMapsLayout::TGroup const &)group status:(TStatus const &)status options:(TMapOptions const &)options
|
||||
{
|
||||
if (status == TStatus::ENotDownloaded)
|
||||
{
|
||||
LocalAndRemoteSizeT const size = self.mapsLayout.GetRemoteCountrySizes(group, position);
|
||||
cell.sizeLabel.text = [NSString stringWithFormat:@"%@ / %@", [self formattedMapSize:size.first], [self formattedMapSize:size.second]];
|
||||
}
|
||||
else if (status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate)
|
||||
cell.sizeLabel.text = [self formattedMapSize:self.mapsLayout.GetCountrySize(group, position, options).second];
|
||||
else if (status == TStatus::EOutOfMemFailed || status == TStatus::EDownloadFailed || status == TStatus::EDownloading || status == TStatus::EInQueue)
|
||||
cell.sizeLabel.text = [self formattedMapSize:self.mapsLayout.GetDownloadableCountrySize(group, position).second];
|
||||
}
|
||||
|
||||
#pragma mark - DownloaderParentVC virtual methods implementation
|
||||
|
||||
- (NSString *)parentTitle
|
||||
|
@ -245,25 +258,12 @@
|
|||
cell.delegate = self;
|
||||
cell.badgeView.value = 0;
|
||||
|
||||
NSString * sizeString;
|
||||
if (status == TStatus::ENotDownloaded)
|
||||
if (status == TStatus::EOutOfMemFailed || status == TStatus::EDownloadFailed || status == TStatus::EDownloading || status == TStatus::EInQueue)
|
||||
{
|
||||
LocalAndRemoteSizeT const size = self.mapsLayout.GetRemoteCountrySizes(position);
|
||||
sizeString = [NSString stringWithFormat:@"%@ / %@", [self formattedMapSize:size.first], [self formattedMapSize:size.second]];
|
||||
}
|
||||
else if (status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate)
|
||||
{
|
||||
size_t const size = self.mapsLayout.GetCountrySize(position, options).second;
|
||||
sizeString = [self formattedMapSize:size];
|
||||
}
|
||||
else if (status == TStatus::EOutOfMemFailed || status == TStatus::EDownloadFailed || status == TStatus::EDownloading || status == TStatus::EInQueue)
|
||||
{
|
||||
LocalAndRemoteSizeT const size = self.mapsLayout.GetDownloadableCountrySize(position);
|
||||
sizeString = [self formattedMapSize:size.second];
|
||||
LocalAndRemoteSizeT const size = self.mapsLayout.GetDownloadableCountrySize(group, position);
|
||||
cell.downloadProgress = (double)size.first / size.second;
|
||||
}
|
||||
|
||||
cell.sizeLabel.text = sizeString;
|
||||
[self configureSizeLabelOfMapCell:cell position:position group:group status:status options:options];
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
@ -279,11 +279,9 @@
|
|||
if (editingStyle == UITableViewCellEditingStyleDelete)
|
||||
{
|
||||
int const position = indexPath.row;
|
||||
ActiveMapsLayout::TGroup const group = [self groupWithSection:position];
|
||||
ActiveMapsLayout::TGroup const group = [self groupWithSection:indexPath.section];
|
||||
TMapOptions const options = self.mapsLayout.GetCountryOptions(group, position);
|
||||
|
||||
self.mapsLayout.DeleteMap(group, position, options);
|
||||
|
||||
[tableView setEditing:NO animated:YES];
|
||||
}
|
||||
}
|
||||
|
@ -321,7 +319,7 @@
|
|||
self.selectedPosition = indexPath.row;
|
||||
self.selectedGroup = [self groupWithSection:indexPath.section];
|
||||
|
||||
[[self actionSheetToDeleteSelectedMap] showFromRect:cell.frame inView:cell.superview animated:YES];
|
||||
[[self actionSheetToCancelDownloadingSelectedMap] showFromRect:cell.frame inView:cell.superview animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - ActiveMaps core callbacks
|
||||
|
@ -331,6 +329,10 @@
|
|||
[self refreshTopRightButton];
|
||||
|
||||
MapCell * cell = [self cellAtPosition:position inGroup:group];
|
||||
|
||||
TStatus const status = self.mapsLayout.GetCountryStatus(group, position);
|
||||
TMapOptions const options = self.mapsLayout.GetCountryOptions(group, position);
|
||||
[self configureSizeLabelOfMapCell:cell position:position group:group status:status options:options];
|
||||
[cell setStatus:self.mapsLayout.GetCountryStatus(group, position) options:self.mapsLayout.GetCountryOptions(group, position) animated:YES];
|
||||
|
||||
self.outOfDateBadge.value = self.mapsLayout.GetCountInGroup(ActiveMapsLayout::TGroup::EOutOfDate);
|
||||
|
@ -339,6 +341,10 @@
|
|||
- (void)countryOptionsChangedAtPosition:(int)position inGroup:(ActiveMapsLayout::TGroup const &)group
|
||||
{
|
||||
MapCell * cell = [self cellAtPosition:position inGroup:group];
|
||||
|
||||
TStatus const status = self.mapsLayout.GetCountryStatus(group, position);
|
||||
TMapOptions const options = self.mapsLayout.GetCountryOptions(group, position);
|
||||
[self configureSizeLabelOfMapCell:cell position:position group:group status:status options:options];
|
||||
[cell setStatus:self.mapsLayout.GetCountryStatus(group, position) options:self.mapsLayout.GetCountryOptions(group, position) animated:YES];
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
@property (nonatomic) UILabel * statusLabel;
|
||||
@property (nonatomic) UILabel * sizeLabel;
|
||||
@property (nonatomic) ProgressView * progressView;
|
||||
@property (nonatomic) UIView * rightTapZone;
|
||||
@property (nonatomic) UIImageView * arrowView;
|
||||
@property (nonatomic) BadgeView * badgeView;
|
||||
@property (nonatomic) UIImageView * routingImageView;
|
||||
|
@ -37,7 +36,6 @@
|
|||
self.status = status;
|
||||
self.options = options;
|
||||
|
||||
self.rightTapZone.userInteractionEnabled = NO;
|
||||
self.progressView.failedMode = NO;
|
||||
|
||||
if (options == TMapOptions::EMapOnly)
|
||||
|
@ -55,21 +53,15 @@
|
|||
self.statusLabel.text = L(@"downloader_status_outdated").uppercaseString;
|
||||
|
||||
self.statusLabel.textColor = [UIColor colorWithColorCode:@"179E4D"];
|
||||
self.rightTapZone.userInteractionEnabled = YES;
|
||||
[self setProgressMode:NO withAnimatedLayout:animated];
|
||||
break;
|
||||
|
||||
case TStatus::EInQueue:
|
||||
self.statusLabel.text = L(@"downloader_queued").uppercaseString;
|
||||
self.statusLabel.textColor = [UIColor colorWithColorCode:@"999999"];
|
||||
[self.progressView setProgress:0 animated:animated];
|
||||
[self setProgressMode:YES withAnimatedLayout:animated];
|
||||
break;
|
||||
|
||||
case TStatus::EDownloading:
|
||||
self.statusLabel.textColor = [UIColor colorWithColorCode:@"999999"];
|
||||
[self.progressView setProgress:self.downloadProgress animated:animated];
|
||||
[self setProgressMode:YES withAnimatedLayout:animated];
|
||||
[self setDownloadProgress:self.downloadProgress animated:animated];
|
||||
if (status == TStatus::EInQueue)
|
||||
self.statusLabel.text = L(@"downloader_queued").uppercaseString;
|
||||
break;
|
||||
|
||||
case TStatus::EOnDisk:
|
||||
|
@ -95,7 +87,6 @@
|
|||
self.progressView.failedMode = YES;
|
||||
self.statusLabel.text = L(@"downloader_retry").uppercaseString;
|
||||
self.statusLabel.textColor = [UIColor colorWithColorCode:@"FF4436"];
|
||||
self.rightTapZone.userInteractionEnabled = YES;
|
||||
[self setProgressMode:YES withAnimatedLayout:animated];
|
||||
break;
|
||||
|
||||
|
@ -116,6 +107,8 @@
|
|||
- (void)setProgressMode:(BOOL)progressMode withAnimatedLayout:(BOOL)withLayout
|
||||
{
|
||||
_progressMode = progressMode;
|
||||
|
||||
self.progressView.progress = self.downloadProgress;
|
||||
if (withLayout)
|
||||
{
|
||||
if (progressMode)
|
||||
|
@ -130,6 +123,7 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
[self alignProgressView];
|
||||
[self alignSubviews];
|
||||
}
|
||||
}
|
||||
|
@ -165,25 +159,18 @@
|
|||
self.subtitleLabel.frame = CGRectMake([self leftOffset], self.titleLabel.maxY + 1, leftLabelsWith, 18);
|
||||
self.subtitleLabel.hidden = self.subtitleLabel.text == nil;
|
||||
|
||||
CGFloat const rightTapWidth = rightLabelsMaxWidth + [self rightOffset] + [self betweenSpace];
|
||||
self.rightTapZone.frame = CGRectMake(self.width - rightTapWidth, 0, rightTapWidth - [self rightOffset] + 4, self.height);
|
||||
if (self.parentMode)
|
||||
self.rightTapZone.userInteractionEnabled = NO;
|
||||
|
||||
self.routingImageView.center = CGPointMake(self.width - 25, self.height / 2 - 1);
|
||||
self.routingImageView.alpha = [self shouldShowRoutingView];
|
||||
}
|
||||
|
||||
- (BOOL)shouldShowRoutingView
|
||||
{
|
||||
return !self.progressMode && !self.parentMode && self.status != TStatus::ENotDownloaded;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[self alignProgressView];
|
||||
[self setStatus:self.status options:self.options animated:NO];
|
||||
|
||||
[self alignSubviews];
|
||||
if (!self.parentMode)
|
||||
{
|
||||
[self alignProgressView];
|
||||
[self setStatus:self.status options:self.options animated:NO];
|
||||
}
|
||||
self.badgeView.minX = self.titleLabel.maxX + 4;
|
||||
self.badgeView.minY = self.titleLabel.minY - 5;
|
||||
|
||||
|
@ -192,6 +179,12 @@
|
|||
self.separator.maxY = self.height + 0.5;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)shouldShowRoutingView
|
||||
{
|
||||
return !self.progressMode && !self.parentMode && self.status != TStatus::ENotDownloaded;
|
||||
}
|
||||
|
||||
- (CGFloat)leftOffset
|
||||
{
|
||||
return 12;
|
||||
|
@ -297,17 +290,6 @@
|
|||
return _sizeLabel;
|
||||
}
|
||||
|
||||
- (UIView *)rightTapZone
|
||||
{
|
||||
if (!_rightTapZone)
|
||||
{
|
||||
_rightTapZone = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightTap:)];
|
||||
[_rightTapZone addGestureRecognizer:tap];
|
||||
}
|
||||
return _rightTapZone;
|
||||
}
|
||||
|
||||
- (UIImageView *)routingImageView
|
||||
{
|
||||
if (!_routingImageView)
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
|
@ -66,7 +65,7 @@
|
|||
- (void)outOfDateCountriesCountChanged:(NSNotification *)notification
|
||||
{
|
||||
NSInteger const count = [[notification userInfo][@"OutOfDate"] integerValue];
|
||||
if ([self isRootScreen])
|
||||
if ([self activeMapsRowIsVisible])
|
||||
{
|
||||
MapCell * cell = (MapCell *)[self.tableView cellForRowAtIndexPath:[self downloadedCountriesIndexPath]];
|
||||
cell.badgeView.value = count;
|
||||
|
@ -75,11 +74,6 @@
|
|||
|
||||
#pragma mark - Helpers
|
||||
|
||||
- (BOOL)isRootScreen
|
||||
{
|
||||
return !self.tree.HasParent();
|
||||
}
|
||||
|
||||
- (CountryTree &)tree
|
||||
{
|
||||
return GetFramework().GetCountryTree();
|
||||
|
@ -87,13 +81,34 @@
|
|||
|
||||
- (MapCell *)cellAtPositionInNode:(int)position
|
||||
{
|
||||
NSInteger const section = [self isRootScreen] ? [self downloadedCountriesIndexPath].section + 1 : 0;
|
||||
NSInteger const section = [self activeMapsRowIsVisible] ? [self downloadedCountriesIndexPath].section + 1 : 0;
|
||||
return (MapCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:position inSection:section]];
|
||||
}
|
||||
|
||||
- (BOOL)activeMapsRowIsVisible
|
||||
{
|
||||
return !self.tree.GetActiveMapLayout().IsEmpty() && !self.tree.HasParent();
|
||||
}
|
||||
|
||||
- (BOOL)isActiveMapsIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return [self isRootScreen] && [indexPath isEqual:[self downloadedCountriesIndexPath]];
|
||||
return [self activeMapsRowIsVisible] && [indexPath isEqual:[self downloadedCountriesIndexPath]];
|
||||
}
|
||||
|
||||
- (void)configureSizeLabelOfMapCell:(MapCell *)cell position:(int)position status:(TStatus const &)status options:(TMapOptions const &)options
|
||||
{
|
||||
if (self.tree.IsLeaf(position))
|
||||
{
|
||||
if (status == TStatus::ENotDownloaded)
|
||||
{
|
||||
LocalAndRemoteSizeT const size = self.tree.GetRemoteLeafSizes(position);
|
||||
cell.sizeLabel.text = [NSString stringWithFormat:@"%@ / %@", [self formattedMapSize:size.first], [self formattedMapSize:size.second]];
|
||||
}
|
||||
else if (status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate)
|
||||
cell.sizeLabel.text = [self formattedMapSize:self.tree.GetLeafSize(position, options).second];
|
||||
else if (status == TStatus::EOutOfMemFailed || status == TStatus::EDownloadFailed || status == TStatus::EDownloading || status == TStatus::EInQueue)
|
||||
cell.sizeLabel.text = [self formattedMapSize:self.tree.GetDownloadableLeafSize(position).second];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - DownloaderParentVC virtual methods implementation
|
||||
|
@ -183,12 +198,12 @@
|
|||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||
{
|
||||
return [self isRootScreen] ? 1 + TOP_ROWS_COUNT : 1;
|
||||
return [self activeMapsRowIsVisible] ? 1 + TOP_ROWS_COUNT : 1;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
if ([self isRootScreen] && section == [self downloadedCountriesIndexPath].section)
|
||||
if ([self activeMapsRowIsVisible] && section == [self downloadedCountriesIndexPath].section)
|
||||
return TOP_ROWS_COUNT;
|
||||
else
|
||||
return self.tree.GetChildCount();
|
||||
|
@ -221,28 +236,14 @@
|
|||
{
|
||||
TMapOptions const options = self.tree.GetLeafOptions(position);
|
||||
TStatus const status = self.tree.GetLeafStatus(position);
|
||||
|
||||
NSString * sizeString;
|
||||
if (status == TStatus::ENotDownloaded)
|
||||
{
|
||||
LocalAndRemoteSizeT const size = self.tree.GetRemoteLeafSizes(position);
|
||||
sizeString = [NSString stringWithFormat:@"%@ / %@", [self formattedMapSize:size.first], [self formattedMapSize:size.second]];
|
||||
}
|
||||
else if (status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate)
|
||||
{
|
||||
size_t const size = self.tree.GetLeafSize(position, options).second;
|
||||
sizeString = [self formattedMapSize:size];
|
||||
}
|
||||
else if (status == TStatus::EOutOfMemFailed || status == TStatus::EDownloadFailed || status == TStatus::EDownloading || status == TStatus::EInQueue)
|
||||
if (status == TStatus::EOutOfMemFailed || status == TStatus::EDownloadFailed || status == TStatus::EDownloading || status == TStatus::EInQueue)
|
||||
{
|
||||
LocalAndRemoteSizeT const size = self.tree.GetDownloadableLeafSize(position);
|
||||
sizeString = [self formattedMapSize:size.second];
|
||||
cell.downloadProgress = (double)size.first / size.second;
|
||||
}
|
||||
|
||||
cell.sizeLabel.text = sizeString;
|
||||
cell.status = status;
|
||||
cell.options = options;
|
||||
[self configureSizeLabelOfMapCell:cell position:position status:status options:options];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,15 +252,21 @@
|
|||
|
||||
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TStatus const status = self.tree.GetLeafStatus(indexPath.row);
|
||||
return status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate;
|
||||
int const position = indexPath.row;
|
||||
if (self.tree.IsLeaf(position))
|
||||
{
|
||||
TStatus const status = self.tree.GetLeafStatus(position);
|
||||
return status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (editingStyle == UITableViewCellEditingStyleDelete)
|
||||
{
|
||||
self.tree.DeleteCountry(indexPath.row, TMapOptions::EMapWithCarRouting);
|
||||
int const position = indexPath.row;
|
||||
self.tree.DeleteCountry(position, self.tree.GetLeafOptions(position));
|
||||
[tableView setEditing:NO animated:YES];
|
||||
}
|
||||
}
|
||||
|
@ -309,7 +316,7 @@
|
|||
- (void)mapCellDidCancelDownloading:(MapCell *)cell
|
||||
{
|
||||
self.selectedPosition = [self.tableView indexPathForCell:cell].row;
|
||||
[[self actionSheetToDeleteSelectedMap] showFromRect:cell.frame inView:cell.superview animated:YES];
|
||||
[[self actionSheetToCancelDownloadingSelectedMap] showFromRect:cell.frame inView:cell.superview animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - CountryTree core callbacks
|
||||
|
@ -317,7 +324,10 @@
|
|||
- (void)countryStatusChangedAtPositionInNode:(int)position
|
||||
{
|
||||
MapCell * cell = [self cellAtPositionInNode:position];
|
||||
[cell setStatus:self.tree.GetLeafStatus(position) options:self.tree.GetLeafOptions(position) animated:YES];
|
||||
TStatus const status = self.tree.GetLeafStatus(position);
|
||||
TMapOptions const options = self.tree.GetLeafOptions(position);
|
||||
[self configureSizeLabelOfMapCell:cell position:position status:status options:options];
|
||||
[cell setStatus:self.tree.GetLeafStatus(position) options:options animated:YES];
|
||||
}
|
||||
|
||||
- (void)countryDownloadingProgressChanged:(LocalAndRemoteSizeT const &)progress atPositionInNode:(int)position
|
||||
|
|
|
@ -29,7 +29,6 @@ using namespace storage;
|
|||
- (void)openGuideWithInfo:(guides::GuideInfo const &)info;
|
||||
|
||||
- (BOOL)canDownloadSelectedMap;
|
||||
- (UIActionSheet *)actionSheetToDeleteSelectedMap;
|
||||
- (UIActionSheet *)actionSheetToCancelDownloadingSelectedMap;
|
||||
- (UIActionSheet *)actionSheetToPerformActionOnSelectedMap;
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@
|
|||
actionSheet.destructiveButtonIndex = actionSheet.numberOfButtons - 1;
|
||||
}
|
||||
|
||||
if (status == TStatus::EDownloading)
|
||||
if (status == TStatus::EDownloading || status == TStatus::EInQueue)
|
||||
{
|
||||
[self addButtonWithTitle:L(@"cancel_download") action:DownloaderActionCancelDownloading toActionSheet:actionSheet];
|
||||
actionSheet.destructiveButtonIndex = actionSheet.numberOfButtons - 1;
|
||||
|
@ -203,14 +203,6 @@
|
|||
return actionSheet;
|
||||
}
|
||||
|
||||
- (UIActionSheet *)actionSheetToDeleteSelectedMap
|
||||
{
|
||||
[self.actionSheetActions removeAllObjects];
|
||||
self.actionSheetActions[@0] = @(DownloaderActionDeleteAll);
|
||||
|
||||
return [[UIActionSheet alloc] initWithTitle:[self actionSheetTitle] delegate:self cancelButtonTitle:L(@"cancel") destructiveButtonTitle:L(@"downloader_delete_map") otherButtonTitles:nil];
|
||||
}
|
||||
|
||||
- (UIActionSheet *)actionSheetToCancelDownloadingSelectedMap
|
||||
{
|
||||
[self.actionSheetActions removeAllObjects];
|
||||
|
|
|
@ -154,6 +154,11 @@ int ActiveMapsLayout::GetCountInGroup(TGroup const & group) const
|
|||
return result;
|
||||
}
|
||||
|
||||
bool ActiveMapsLayout::IsEmpty() const
|
||||
{
|
||||
return GetCountInGroup(TGroup::ENewMap) == 0 && GetCountInGroup(TGroup::EOutOfDate) == 0 && GetCountInGroup(TGroup::EUpToDate) == 0;
|
||||
}
|
||||
|
||||
string const & ActiveMapsLayout::GetCountryName(TGroup const & group, int position) const
|
||||
{
|
||||
return GetCountryName(GetItemInGroup(group, position).m_index);
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
void CancelAll();
|
||||
|
||||
int GetCountInGroup(TGroup const & group) const;
|
||||
bool IsEmpty() const;
|
||||
string const & GetCountryName(TGroup const & group, int position) const;
|
||||
string const & GetCountryName(storage::TIndex const & index) const;
|
||||
TStatus GetCountryStatus(TGroup const & group, int position) const;
|
||||
|
|
Loading…
Add table
Reference in a new issue