[ios] Added cancel all button.

This commit is contained in:
Ilya Grechuhin 2016-03-18 13:00:51 +03:00 committed by Sergey Yershov
parent 74eaf00cde
commit cbd362c67a
3 changed files with 72 additions and 28 deletions

View file

@ -24,11 +24,16 @@ extern NSString * const kLargeCountryCellIdentifier = @"MWMMapDownloaderLargeCou
namespace
{
NSString * const kDownloadActionTitle = L(@"downloader_download_map");
NSString * const kUpdateActionTitle = L(@"downloader_status_outdated");
NSString * const kDeleteActionTitle = L(@"downloader_delete_map");
NSString * const kShowActionTitle = L(@"zoom_to_country");
NSString * const kAllMapsLabelFormat = @"%@: %@ (%@)";
NSString * const kCancelActionTitle = L(@"cancel");
NSString * const kCancelAllTitle = L(@"downloader_cancel_all");
NSString * const kDeleteActionTitle = L(@"downloader_delete_map");
NSString * const kDownloaAllTitle = L(@"downloader_download_all_button");
NSString * const kDownloadActionTitle = L(@"downloader_download_map");
NSString * const kDownloadingTitle = L(@"downloader_downloading");
NSString * const kMapsTitle = L(@"maps");
NSString * const kShowActionTitle = L(@"zoom_to_country");
NSString * const kUpdateActionTitle = L(@"downloader_status_outdated");
} // namespace
@interface MWMBaseMapDownloaderViewController () <UIActionSheetDelegate, MWMFrameworkStorageObserver>
@ -37,6 +42,7 @@ NSString * const kCancelActionTitle = L(@"cancel");
@property (weak, nonatomic) IBOutlet UIView * allMapsView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * allMapsViewBottomOffset;
@property (weak, nonatomic) IBOutlet UIButton * allMapsButton;
@property (nonatomic) UIImage * navBarBackground;
@property (nonatomic) UIImage * navBarShadow;
@ -307,23 +313,48 @@ using namespace storage;
- (void)configAllMapsView
{
if (self.dataSource.isParentRoot)
return;
self.showAllMapsView = YES;
auto const & s = GetFramework().Storage();
NodeAttrs nodeAttrs;
s.GetNodeAttrs(self.parentCountryId, nodeAttrs);
uint32_t remoteMWMCounter = nodeAttrs.m_mwmCounter - nodeAttrs.m_localMwmCounter;
if (remoteMWMCounter != 0)
TCountriesVec downloadedChildren;
TCountriesVec availableChildren;
s.GetChildrenInGroups(self.parentCountryId, downloadedChildren, availableChildren);
if (availableChildren.empty())
{
self.showAllMapsView = YES;
self.allMapsLabel.text =
[NSString stringWithFormat:@"%@: %@ (%@)", L(@"maps"), @(remoteMWMCounter),
formattedSize(nodeAttrs.m_mwmSize - nodeAttrs.m_localMwmSize)];
TCountriesVec queuedChildren;
s.GetQueuedChildren(self.parentCountryId, queuedChildren);
if (!queuedChildren.empty())
{
size_t queuedSize = 0;
for (TCountryId const & countryId : queuedChildren)
{
NodeAttrs nodeAttrs;
s.GetNodeAttrs(countryId, nodeAttrs);
queuedSize += nodeAttrs.m_mwmSize;
}
self.allMapsLabel.text =
[NSString stringWithFormat:kAllMapsLabelFormat, kDownloadingTitle,
@(queuedChildren.size()), formattedSize(queuedSize)];
[self.allMapsButton setTitle:kCancelAllTitle forState:UIControlStateNormal];
return;
}
}
else
{
self.showAllMapsView = NO;
NodeAttrs nodeAttrs;
s.GetNodeAttrs(self.parentCountryId, nodeAttrs);
uint32_t remoteMWMCounter = nodeAttrs.m_mwmCounter - nodeAttrs.m_localMwmCounter;
if (remoteMWMCounter != 0)
{
self.allMapsLabel.text =
[NSString stringWithFormat:kAllMapsLabelFormat, kMapsTitle, @(remoteMWMCounter),
formattedSize(nodeAttrs.m_mwmSize - nodeAttrs.m_localMwmSize)];
[self.allMapsButton setTitle:kDownloaAllTitle forState:UIControlStateNormal];
return;
}
}
self.showAllMapsView = NO;
}
- (void)refreshAllMapsView
@ -371,16 +402,31 @@ using namespace storage;
}
else
{
[Statistics logEvent:kStatDownloaderMapAction
withParameters:@{
kStatAction : kStatDownload,
kStatIsAuto : kStatNo,
kStatFrom : kStatDownloader,
kStatScenario : kStatDownloadGroup
}];
[MWMStorage downloadNode:self.parentCountryId
alertController:self.alertController
onSuccess:nil];
NSString * allMapsButtonTitle = [self.allMapsButton titleForState:UIControlStateNormal];
if ([allMapsButtonTitle isEqualToString:kDownloaAllTitle])
{
[Statistics logEvent:kStatDownloaderMapAction
withParameters:@{
kStatAction : kStatDownload,
kStatIsAuto : kStatNo,
kStatFrom : kStatDownloader,
kStatScenario : kStatDownloadGroup
}];
[MWMStorage downloadNode:self.parentCountryId
alertController:self.alertController
onSuccess:nil];
}
else if ([allMapsButtonTitle isEqualToString:kCancelAllTitle])
{
[Statistics logEvent:kStatDownloaderMapAction
withParameters:@{
kStatAction : kStatCancel,
kStatIsAuto : kStatNo,
kStatFrom : kStatDownloader,
kStatScenario : kStatDownloadGroup
}];
[MWMStorage cancelDownloadNode:self.parentCountryId];
}
}
self.skipCountryEventProcessing = NO;
[self processCountryEvent:self.parentCountryId];

View file

@ -60,8 +60,6 @@ using namespace storage;
- (void)configAllMapsView
{
[super configAllMapsView];
self.showAllMapsView = NO;
auto const & s = GetFramework().Storage();
Storage::UpdateInfo updateInfo{};

View file

@ -240,7 +240,6 @@
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="textColorName" value="linkBlue"/>
<userDefinedRuntimeAttribute type="string" keyPath="fontName" value="medium17"/>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="downloader_download_all_button"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="allMapsAction" destination="cIk-gU-IeI" eventType="touchUpInside" id="BFl-NK-h9n"/>
@ -314,6 +313,7 @@
</variation>
</view>
<connections>
<outlet property="allMapsButton" destination="X7X-s8-4rf" id="wUG-P2-9cX"/>
<outlet property="allMapsLabel" destination="etq-PP-stT" id="eP2-FS-hQq"/>
<outlet property="allMapsView" destination="Lqq-c4-P1I" id="bG7-3N-pyH"/>
<outlet property="allMapsViewBottomOffset" destination="8rS-RJ-MXs" id="PCw-X2-Tea"/>