[MAPSME-5447] [ios] Added confirmation dialog.

Dialog for cancelling maps auto-update download.
This commit is contained in:
Ilya Grechuhin 2017-08-24 17:47:26 +03:00 committed by Vladimir Byko-Ianko
parent e48e4ff049
commit 88ba4c020b
5 changed files with 43 additions and 18 deletions

View file

@ -24,7 +24,8 @@ using MWMCircularProgressStateVec = vector<MWMCircularProgressState>;
- (void)setSpinnerColoring:(MWMImageColoring)coloring;
- (void)setSpinnerBackgroundColor:(nonnull UIColor *)backgroundColor;
- (void)setImageName:(nonnull NSString *)imageName forStates:(MWMCircularProgressStateVec const &)states;
- (void)setImageName:(nullable NSString *)imageName
forStates:(MWMCircularProgressStateVec const &)states;
- (void)setColor:(nonnull UIColor *)color forStates:(MWMCircularProgressStateVec const &)states;
- (void)setColoring:(MWMButtonColoring)coloring
forStates:(MWMCircularProgressStateVec const &)states;

View file

@ -74,7 +74,8 @@
[self.rootView setSpinnerBackgroundColor:backgroundColor];
}
- (void)setImageName:(nonnull NSString *)imageName forStates:(MWMCircularProgressStateVec const &)states
- (void)setImageName:(nullable NSString *)imageName
forStates:(MWMCircularProgressStateVec const &)states
{
for (auto const & state : states)
[self.rootView setImageName:imageName forState:state];

View file

@ -14,7 +14,7 @@
- (void)setSpinnerColoring:(MWMImageColoring)coloring;
- (void)setSpinnerBackgroundColor:(nonnull UIColor *)backgroundColor;
- (void)setImageName:(nonnull NSString *)imageName forState:(MWMCircularProgressState)state;
- (void)setImageName:(nullable NSString *)imageName forState:(MWMCircularProgressState)state;
- (void)setColor:(nonnull UIColor *)color forState:(MWMCircularProgressState)state;
- (void)setColoring:(MWMButtonColoring)coloring forState:(MWMCircularProgressState)state;

View file

@ -97,7 +97,7 @@ CGFloat angleWithProgress(CGFloat progress) { return 2.0 * M_PI * progress - M_P
}
- (void)setSpinnerColoring:(MWMImageColoring)coloring { self.spinner.mwm_coloring = coloring; }
- (void)setImageName:(nonnull NSString *)imageName forState:(MWMCircularProgressState)state
- (void)setImageName:(nullable NSString *)imageName forState:(MWMCircularProgressState)state
{
m_images[state] = imageName;
[self refreshProgress];
@ -127,10 +127,17 @@ CGFloat angleWithProgress(CGFloat progress) { return 2.0 * M_PI * progress - M_P
self.progressLayer.strokeColor = self.progressLayerColor;
CGRect rect = CGRectInset(self.bounds, kLineWidth, kLineWidth);
self.backgroundLayer.path = [UIBezierPath bezierPathWithOvalInRect:rect].CGPath;
auto imageName = m_images[self.state];
[self.button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
if (UIImage * hl = [UIImage imageNamed:[imageName stringByAppendingString:@"_highlighted"]])
[self.button setImage:hl forState:UIControlStateHighlighted];
if (auto imageName = m_images[self.state])
{
[self.button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
if (auto hl = [UIImage imageNamed:[imageName stringByAppendingString:@"_highlighted"]])
[self.button setImage:hl forState:UIControlStateHighlighted];
}
else
{
[self.button setImage:nil forState:UIControlStateNormal];
[self.button setImage:nil forState:UIControlStateHighlighted];
}
self.button.coloring = m_buttonColoring[self.state];
}

View file

@ -88,6 +88,8 @@ enum class State
self.primaryButton.hidden = YES;
self.spinnerView.hidden = NO;
self.spinner = [MWMCircularProgress downloaderProgressForParentView:self.spinnerView];
[self.spinner setImageName:nil
forStates:{MWMCircularProgressStateProgress, MWMCircularProgressStateSpinner}];
self.spinner.delegate = self.delegate;
[self.spinner setInvertColor:YES];
self.spinner.state = MWMCircularProgressStateSpinner;
@ -175,13 +177,31 @@ std::unordered_set<TCountryId> updatingCountries;
- (IBAction)cancelTap
{
[MWMStorage cancelDownloadNode:RootId()];
[self dismiss];
auto view = static_cast<MWMAutoupdateView *>(self.view);
[Statistics logEvent:view.state == State::Downloading ?
kStatDownloaderOnStartScreenCancelDownload :
kStatDownloaderOnStartScreenSelectLater
withParameters:@{kStatMapDataSize : @(self.sizeInMB)}];
UIAlertController * alertController =
[UIAlertController alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
alertController.popoverPresentationController.sourceView = view.secondaryButton;
alertController.popoverPresentationController.sourceRect = view.secondaryButton.bounds;
auto cancelDownloadAction =
[UIAlertAction actionWithTitle:L(@"cancel_download")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action) {
[MWMStorage cancelDownloadNode:RootId()];
[self dismiss];
[Statistics logEvent:view.state == State::Downloading
? kStatDownloaderOnStartScreenCancelDownload
: kStatDownloaderOnStartScreenSelectLater
withParameters:@{
kStatMapDataSize : @(self.sizeInMB)
}];
}];
[alertController addAction:cancelDownloadAction];
auto cancelAction =
[UIAlertAction actionWithTitle:L(@"cancel") style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)viewWillTransitionToSize:(CGSize)size
@ -196,10 +216,6 @@ std::unordered_set<TCountryId> updatingCountries;
- (void)progressButtonPressed:(MWMCircularProgress *)progress
{
[MWMStorage cancelDownloadNode:RootId()];
[static_cast<MWMAutoupdateView *>(self.view) stateWaiting];
[Statistics logEvent:kStatDownloaderOnStartScreenCancelDownload
withParameters:@{kStatMapDataSize : @(self.sizeInMB)}];
}
#pragma mark - MWMFrameworkStorageObserver