From 8d3259c2fc1fd679c54def6d46da96abbbe8c987 Mon Sep 17 00:00:00 2001 From: VladiMihaylenko Date: Thu, 21 Jul 2016 18:08:40 +0300 Subject: [PATCH] [ios] Track warning alert. --- .../AlertController/MWMAlertViewController.h | 1 + .../AlertController/MWMAlertViewController.mm | 5 +++++ .../Classes/CustomAlert/BaseAlert/MWMAlert.h | 1 + .../Classes/CustomAlert/BaseAlert/MWMAlert.mm | 5 +++++ .../DefaultAlert/MWMDefaultAlert.h | 1 + .../DefaultAlert/MWMDefaultAlert.mm | 11 +++++++++++ iphone/Maps/Classes/MapsAppDelegate.mm | 19 +++++++++++++++++++ 7 files changed, 43 insertions(+) diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h index 414aa2b65c..d600e2ae70 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h @@ -46,6 +46,7 @@ - (void)presentEditorViralAlert; - (void)presentOsmAuthAlert; - (void)presentPersonalInfoWarningAlertWithBlock:(nonnull TMWMVoidBlock)block; +- (void)presentTrackWarningAlertWithCancelBlock:(nonnull TMWMVoidBlock)block; - (void)closeAlert; - (nonnull instancetype)init __attribute__((unavailable("call -initWithViewController: instead!"))); diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm index dcc8ed1716..1bacd9a43e 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm @@ -175,6 +175,11 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController [self displayAlert:[MWMAlert personalInfoWarningAlertWithBlock:block]]; } +- (void)presentTrackWarningAlertWithCancelBlock:(nonnull TMWMVoidBlock)block +{ + [self displayAlert:[MWMAlert trackWarningAlertWithCancelBlock:block]]; +} + - (void)presentEditorViralAlert { [self displayAlert:[MWMAlert editorViralAlert]]; } - (void)presentOsmAuthAlert { [self displayAlert:[MWMAlert osmAuthAlert]]; } - (void)displayAlert:(MWMAlert *)alert diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h index b9183a579a..9bd38a5512 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h @@ -44,6 +44,7 @@ using TMWMDownloadBlock = void (^)(storage::TCountriesVec const &, TMWMVoidBlock + (MWMAlert *)editorViralAlert; + (MWMAlert *)osmAuthAlert; + (MWMAlert *)personalInfoWarningAlertWithBlock:(TMWMVoidBlock)block; ++ (MWMAlert *)trackWarningAlertWithCancelBlock:(TMWMVoidBlock)block; - (void)close; - (void)setNeedsCloseAlertAfterEnterBackground; diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm index 71692aa4e3..ab76a37fad 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm @@ -203,6 +203,11 @@ return [MWMDefaultAlert personalInfoWarningAlertWithBlock:block]; } ++ (MWMAlert *)trackWarningAlertWithCancelBlock:(TMWMVoidBlock)block +{ + return [MWMDefaultAlert trackWarningAlertWithCancelBlock:block]; +} + - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { // Should override this method if you want custom relayout after rotation. diff --git a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h index 18e6f23862..4f4d96df6d 100644 --- a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h +++ b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h @@ -32,5 +32,6 @@ + (instancetype)resetChangesAlertWithBlock:(TMWMVoidBlock)block; + (instancetype)deleteFeatureAlertWithBlock:(TMWMVoidBlock)block; + (instancetype)personalInfoWarningAlertWithBlock:(TMWMVoidBlock)block; ++ (instancetype)trackWarningAlertWithCancelBlock:(TMWMVoidBlock)block; @end diff --git a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm index 51f1981b2d..f6b9ee46bf 100644 --- a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm @@ -385,6 +385,17 @@ static NSString * const kDefaultAlertNibName = @"MWMDefaultAlert"; return alert; } ++ (instancetype)trackWarningAlertWithCancelBlock:(TMWMVoidBlock)block +{ + kStatisticsEvent = @"Track warning alert"; + MWMDefaultAlert * alert = [self defaultAlertWithTitle:@"recent_track_background_dialog_title" + message:@"recent_track_background_dialog_message" + rightButtonTitle:@"off_recent_track_background_button" + leftButtonTitle:@"continue_download" + rightButtonAction:block]; + return alert; +} + + (instancetype)defaultAlertWithTitle:(nonnull NSString *)title message:(nullable NSString *)message rightButtonTitle:(nonnull NSString *)rightButtonTitle diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 4b3f540d9d..09a2f6b458 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -58,6 +58,7 @@ static NSString * const kUDLastRateRequestDate = @"LastRateRequestDate"; extern NSString * const kUDAlreadySharedKey = @"UserAlreadyShared"; static NSString * const kUDLastShareRequstDate = @"LastShareRequestDate"; static NSString * const kUDAutoNightModeOff = @"AutoNightModeOff"; +static NSString * const kUDTrackWarningAlertWasShown = @"TrackWarningAlertWasShown"; static NSString * const kPushDeviceTokenLogEvent = @"iOSPushDeviceToken"; static NSString * const kIOSIDFA = @"IFA"; static NSString * const kBundleVersion = @"BundleVersion"; @@ -606,6 +607,24 @@ using namespace osm_auth_ios; { LOG(LINFO, ("applicationWillEnterForeground")); GetFramework().EnterForeground(); + if (!GpsTracker::Instance().IsEnabled()) + return; + + MWMViewController * topVc = static_cast( + self.mapViewController.navigationController.topViewController); + if (![topVc isKindOfClass:[MWMViewController class]]) + return; + + NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; + if ([ud boolForKey:kUDTrackWarningAlertWasShown]) + return; + + [topVc.alertController presentTrackWarningAlertWithCancelBlock:^{ + GpsTracker::Instance().SetEnabled(false); + }]; + + [ud setBool:YES forKey:kUDTrackWarningAlertWasShown]; + [ud synchronize]; } - (void)applicationDidBecomeActive:(UIApplication *)application