From 5bcc41bf6ff502ed62aec6c3e61d742bdbcd57d9 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Mon, 28 Nov 2016 14:55:19 +0300 Subject: [PATCH 1/4] [MAPSME-2994] [ios] Added networking policy. --- .../NetworkingPolicy/MWMNetworkingPolicy.h | 18 +++++ .../NetworkingPolicy/MWMNetworkingPolicy.mm | 65 +++++++++++++++++++ iphone/Maps/Maps.xcodeproj/project.pbxproj | 16 +++++ 3 files changed, 99 insertions(+) create mode 100644 iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h create mode 100644 iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm diff --git a/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h b/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h new file mode 100644 index 0000000000..07957f3b72 --- /dev/null +++ b/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h @@ -0,0 +1,18 @@ +#include "std/function.hpp" + +namespace networking_policy +{ +using MWMNetworkingPolicyFn = function; + +void callPartnersApiWithNetworkingPolicy(MWMNetworkingPolicyFn const & fn); + +enum class NetworkingPolicyState +{ + Always, + Session, + Never +}; + +void SetNetworkingPolicyState(NetworkingPolicyState state); +NetworkingPolicyState GetNetworkingPolicyState(); +} // namespace networking_policy diff --git a/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm b/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm new file mode 100644 index 0000000000..5bde8750fe --- /dev/null +++ b/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm @@ -0,0 +1,65 @@ +#import "MWMNetworkingPolicy.h" +#import "MWMAlertViewController.h" + +namespace +{ +NSString * const kNetworkingPolicyTimeStamp = @"NetworkingPolicyTimeStamp"; +NSTimeInterval const kSessionDurationSeconds = 24 * 60 * 60; +} // namespace + +namespace networking_policy +{ +void callPartnersApiWithNetworkingPolicy(MWMNetworkingPolicyFn const & fn) +{ + auto checkAndApply = ^BOOL { + NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; + NSDate * policyDate = [ud objectForKey:kNetworkingPolicyTimeStamp]; + if ([policyDate compare:[NSDate date]] == NSOrderedDescending) + { + fn(YES); + return YES; + } + if ([policyDate isEqualToDate:NSDate.distantPast]) + { + fn(NO); + return YES; + } + return NO; + }; + + if (checkAndApply()) + return; + + MWMAlertViewController * alertController = [MWMAlertViewController activeAlertController]; + [alertController presentMobileInternetAlertWithBlock:^{ + if (!checkAndApply()) + fn(NO); + }]; +} + +void SetNetworkingPolicyState(NetworkingPolicyState state) +{ + NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; + NSDate * policyDate = nil; + switch (state) + { + case NetworkingPolicyState::Always: policyDate = NSDate.distantFuture; break; + case NetworkingPolicyState::Session: + policyDate = [NSDate dateWithTimeIntervalSinceNow:kSessionDurationSeconds]; + break; + case NetworkingPolicyState::Never: policyDate = NSDate.distantPast; break; + } + [ud setObject:policyDate forKey:kNetworkingPolicyTimeStamp]; +} + +NetworkingPolicyState GetNetworkingPolicyState() +{ + NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; + NSDate * policyDate = [ud objectForKey:kNetworkingPolicyTimeStamp]; + if ([policyDate isEqualToDate:NSDate.distantFuture]) + return NetworkingPolicyState::Always; + if ([policyDate isEqualToDate:NSDate.distantPast]) + return NetworkingPolicyState::Never; + return NetworkingPolicyState::Session; +} +} // namespace networking_policy diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index cdebe62766..aae006ecc7 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -233,6 +233,8 @@ 349A13831DEC138C00C7DB60 /* MWMMobileInternetAlert.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A13801DEC138C00C7DB60 /* MWMMobileInternetAlert.mm */; }; 349A13841DEC138C00C7DB60 /* MWMMobileInternetAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A13811DEC138C00C7DB60 /* MWMMobileInternetAlert.xib */; }; 349A13851DEC138C00C7DB60 /* MWMMobileInternetAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A13811DEC138C00C7DB60 /* MWMMobileInternetAlert.xib */; }; + 349A13891DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */; }; + 349A138A1DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */; }; 349A357A1B53D4C9009677EE /* MWMCircularProgress.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A35761B53D4C9009677EE /* MWMCircularProgress.mm */; }; 349A357B1B53D4C9009677EE /* MWMCircularProgress.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A35771B53D4C9009677EE /* MWMCircularProgress.xib */; }; 349A357C1B53D4C9009677EE /* MWMCircularProgressView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A35791B53D4C9009677EE /* MWMCircularProgressView.mm */; }; @@ -1194,6 +1196,8 @@ 349A137F1DEC138C00C7DB60 /* MWMMobileInternetAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMMobileInternetAlert.h; sourceTree = ""; }; 349A13801DEC138C00C7DB60 /* MWMMobileInternetAlert.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMMobileInternetAlert.mm; sourceTree = ""; }; 349A13811DEC138C00C7DB60 /* MWMMobileInternetAlert.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMMobileInternetAlert.xib; sourceTree = ""; }; + 349A13871DEC44C600C7DB60 /* MWMNetworkingPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMNetworkingPolicy.h; sourceTree = ""; }; + 349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMNetworkingPolicy.mm; sourceTree = ""; }; 349A35751B53D4C9009677EE /* MWMCircularProgress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMCircularProgress.h; sourceTree = ""; }; 349A35761B53D4C9009677EE /* MWMCircularProgress.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMCircularProgress.mm; sourceTree = ""; }; 349A35771B53D4C9009677EE /* MWMCircularProgress.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMCircularProgress.xib; sourceTree = ""; }; @@ -1884,6 +1888,7 @@ 080E96DDFE201D6D7F000001 /* Classes */ = { isa = PBXGroup; children = ( + 349A13861DEC448500C7DB60 /* NetworkingPolicy */, 348868F01D87DF8C0069BBA3 /* Keyboard */, 3436FE7F1D366CA0005CD87B /* Search */, 344D77B11D1BD79700DBED70 /* Location */, @@ -2411,6 +2416,15 @@ path = MobileInternetAlert; sourceTree = ""; }; + 349A13861DEC448500C7DB60 /* NetworkingPolicy */ = { + isa = PBXGroup; + children = ( + 349A13871DEC44C600C7DB60 /* MWMNetworkingPolicy.h */, + 349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */, + ); + path = NetworkingPolicy; + sourceTree = ""; + }; 349A35741B53D4C9009677EE /* CircularProgress */ = { isa = PBXGroup; children = ( @@ -4042,6 +4056,7 @@ 3418CEAE1CBF9E3300641B25 /* MWMNoMapsViewController.mm in Sources */, 3401CD7D1C3CF1BE0028C6F8 /* MWMEditorSwitchTableViewCell.mm in Sources */, 34B82AD61B84746E00180497 /* MWMSearchSuggestionCell.mm in Sources */, + 349A13891DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */, F6C641B01C15BBE6008FCAF3 /* MWMRecentTrackSettingsController.mm in Sources */, 341F99F11C6B4288001C67B8 /* MWMMapDownloaderSearchDataSource.mm in Sources */, 34A759D81DC795D10078C3AE /* MWMWhatsNewUberController.mm in Sources */, @@ -4293,6 +4308,7 @@ 34EC270B1CB2A7120084FA36 /* fabric_logging_ios.mm in Sources */, 6741A9FA1BF340DE002C974C /* MWMBookmarkColorViewController.mm in Sources */, 3418CEAF1CBF9E3300641B25 /* MWMNoMapsViewController.mm in Sources */, + 349A138A1DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */, 3401CD7E1C3CF1BE0028C6F8 /* MWMEditorSwitchTableViewCell.mm in Sources */, 34EB84591C073DF70004689F /* MWMOpeningHoursEditorViewController.mm in Sources */, 341F99F21C6B4288001C67B8 /* MWMMapDownloaderSearchDataSource.mm in Sources */, From fa1f7a6bd1400774f4f8d246dc8c751d5c9f1db9 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Mon, 28 Nov 2016 14:56:16 +0300 Subject: [PATCH 2/4] [MAPSME-2994] [ios] Updated UI to support networking policy. --- .../AlertController/MWMAlertViewController.h | 2 +- .../AlertController/MWMAlertViewController.mm | 5 ++++- .../MWMMobileInternetAlert.h | 2 +- .../MWMMobileInternetAlert.mm | 21 +++++++++++++++---- .../Maps/MWMMobileInternetViewController.mm | 17 +++++++++++++-- .../Settings/MWMSettingsViewController.mm | 10 ++++++++- 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h index 8caaf4649d..5dcd096de9 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h @@ -50,7 +50,7 @@ - (void)presentPersonalInfoWarningAlertWithBlock:(nonnull TMWMVoidBlock)block; - (void)presentTrackWarningAlertWithCancelBlock:(nonnull TMWMVoidBlock)block; - (void)presentSearchNoResultsAlert; -- (void)presentMobileInternetAlert; +- (void)presentMobileInternetAlertWithBlock:(nonnull TMWMVoidBlock)block; - (void)closeAlert:(nullable TMWMVoidBlock)completion; - (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 9f9f115f39..f1b35fcd4c 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm @@ -206,7 +206,10 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController [alert update]; } -- (void)presentMobileInternetAlert { [self displayAlert:[MWMMobileInternetAlert alert]]; } +- (void)presentMobileInternetAlertWithBlock:(nonnull TMWMVoidBlock)block +{ + [self displayAlert:[MWMMobileInternetAlert alertWithBlock:block]]; +} - (void)presentEditorViralAlert { [self displayAlert:[MWMAlert editorViralAlert]]; } - (void)presentOsmAuthAlert { [self displayAlert:[MWMAlert osmAuthAlert]]; } - (void)displayAlert:(MWMAlert *)alert diff --git a/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.h b/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.h index 1e059d7aff..a9d3ce6353 100644 --- a/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.h +++ b/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.h @@ -2,6 +2,6 @@ @interface MWMMobileInternetAlert : MWMAlert -+ (instancetype)alert; ++ (instancetype)alertWithBlock:(nonnull TMWMVoidBlock)block; @end diff --git a/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm b/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm index c12a0f8651..76de22362e 100644 --- a/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm @@ -1,38 +1,51 @@ #import "MWMMobileInternetAlert.h" +#import "MWMNetworkingPolicy.h" #import "Statistics.h" +using namespace networking_policy; + namespace { NSString * const kStatisticsEvent = @"Mobile Internet Settings Alert"; } +@interface MWMMobileInternetAlert () + +@property(copy, nonatomic) TMWMVoidBlock completionBlock; + +@end + @implementation MWMMobileInternetAlert -+ (instancetype)alert ++ (instancetype)alertWithBlock:(nonnull TMWMVoidBlock)block { [Statistics logEvent:kStatisticsEvent withParameters:@{kStatAction : kStatOpen}]; MWMMobileInternetAlert * alert = [[[NSBundle mainBundle] loadNibNamed:[MWMMobileInternetAlert className] owner:nil options:nil] firstObject]; + alert.completionBlock = block; return alert; } - (IBAction)alwaysTap { [Statistics logEvent:kStatMobileInternet withParameters:@{kStatValue : kStatAlways}]; - [self close:nil]; + SetNetworkingPolicyState(NetworkingPolicyState::Always); + [self close:self.completionBlock]; } - (IBAction)askTap { [Statistics logEvent:kStatMobileInternet withParameters:@{kStatValue : kStatAsk}]; - [self close:nil]; + SetNetworkingPolicyState(NetworkingPolicyState::Session); + [self close:self.completionBlock]; } - (IBAction)neverTap { [Statistics logEvent:kStatisticsEvent withParameters:@{kStatAction : kStatNever}]; - [self close:nil]; + SetNetworkingPolicyState(NetworkingPolicyState::Never); + [self close:self.completionBlock]; } @end diff --git a/iphone/Maps/MWMMobileInternetViewController.mm b/iphone/Maps/MWMMobileInternetViewController.mm index 11f3aa03ea..9f4e3afc84 100644 --- a/iphone/Maps/MWMMobileInternetViewController.mm +++ b/iphone/Maps/MWMMobileInternetViewController.mm @@ -1,7 +1,10 @@ #import "MWMMobileInternetViewController.h" +#import "MWMNetworkingPolicy.h" #import "SelectableCell.h" #import "Statistics.h" +using namespace networking_policy; + @interface MWMMobileInternetViewController () @property(weak, nonatomic) IBOutlet SelectableCell * always; @@ -18,8 +21,15 @@ [super viewDidLoad]; self.title = L(@"pref_mobile_internet"); - self.never.accessoryType = UITableViewCellAccessoryCheckmark; - _selected = self.never; + SelectableCell * selected; + switch (GetNetworkingPolicyState()) + { + case NetworkingPolicyState::Always: selected = self.always; break; + case NetworkingPolicyState::Session: selected = self.ask; break; + case NetworkingPolicyState::Never: selected = self.never; break; + } + selected.accessoryType = UITableViewCellAccessoryCheckmark; + self.selected = selected; } - (void)setSelected:(SelectableCell *)selected @@ -32,14 +42,17 @@ if ([selected isEqual:self.always]) { statValue = kStatAlways; + SetNetworkingPolicyState(NetworkingPolicyState::Always); } else if ([selected isEqual:self.ask]) { statValue = kStatAsk; + SetNetworkingPolicyState(NetworkingPolicyState::Session); } else if ([selected isEqual:self.never]) { statValue = kStatNever; + SetNetworkingPolicyState(NetworkingPolicyState::Never); } [Statistics logEvent:kStatMobileInternet withParameters:@{kStatValue : statValue}]; diff --git a/iphone/Maps/Settings/MWMSettingsViewController.mm b/iphone/Maps/Settings/MWMSettingsViewController.mm index 4ebed5de25..f21b314e04 100644 --- a/iphone/Maps/Settings/MWMSettingsViewController.mm +++ b/iphone/Maps/Settings/MWMSettingsViewController.mm @@ -2,6 +2,7 @@ #import "LinkCell.h" #import "LocaleTranslator.h" #import "MWMAuthorizationCommon.h" +#import "MWMNetworkingPolicy.h" #import "MWMSettings.h" #import "MWMTextToSpeech.h" #import "Statistics.h" @@ -85,7 +86,14 @@ extern NSString * const kAlohalyticsTapEventKey; self.autoDownloadCell.switchButton.on = [MWMSettings autoDownloadEnabled]; self.autoDownloadCell.delegate = self; - self.mobileInternetCell.infoLabel.text = L(@"pref_ask"); + NSString * internetLabel = nil; + switch (networking_policy::GetNetworkingPolicyState()) + { + case networking_policy::NetworkingPolicyState::Always: internetLabel = L(@"pref_always"); break; + case networking_policy::NetworkingPolicyState::Session: internetLabel = L(@"pref_ask"); break; + case networking_policy::NetworkingPolicyState::Never: internetLabel = L(@"pref_never"); break; + } + self.mobileInternetCell.infoLabel.text = internetLabel; if (!GpsTracker::Instance().IsEnabled()) { From eef657c692328af61a33124f306e7290de345d4e Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Mon, 28 Nov 2016 15:06:10 +0300 Subject: [PATCH 3/4] [MAPSME-2994] Review fixes. --- .../MWMMobileInternetAlert.mm | 6 ++--- .../NetworkingPolicy/MWMNetworkingPolicy.h | 10 +++---- .../NetworkingPolicy/MWMNetworkingPolicy.mm | 26 +++++++++---------- .../Maps/MWMMobileInternetViewController.mm | 14 +++++----- .../Settings/MWMSettingsViewController.mm | 8 +++--- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm b/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm index 76de22362e..f1f6b5b62b 100644 --- a/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm @@ -30,21 +30,21 @@ NSString * const kStatisticsEvent = @"Mobile Internet Settings Alert"; - (IBAction)alwaysTap { [Statistics logEvent:kStatMobileInternet withParameters:@{kStatValue : kStatAlways}]; - SetNetworkingPolicyState(NetworkingPolicyState::Always); + SetStage(Stage::Always); [self close:self.completionBlock]; } - (IBAction)askTap { [Statistics logEvent:kStatMobileInternet withParameters:@{kStatValue : kStatAsk}]; - SetNetworkingPolicyState(NetworkingPolicyState::Session); + SetStage(Stage::Session); [self close:self.completionBlock]; } - (IBAction)neverTap { [Statistics logEvent:kStatisticsEvent withParameters:@{kStatAction : kStatNever}]; - SetNetworkingPolicyState(NetworkingPolicyState::Never); + SetStage(Stage::Never); [self close:self.completionBlock]; } diff --git a/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h b/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h index 07957f3b72..5196bc60e7 100644 --- a/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h +++ b/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h @@ -2,17 +2,17 @@ namespace networking_policy { -using MWMNetworkingPolicyFn = function; +using MWMPartnersApiFn = function; -void callPartnersApiWithNetworkingPolicy(MWMNetworkingPolicyFn const & fn); +void CallPartnersApi(MWMPartnersApiFn const & fn); -enum class NetworkingPolicyState +enum class Stage { Always, Session, Never }; -void SetNetworkingPolicyState(NetworkingPolicyState state); -NetworkingPolicyState GetNetworkingPolicyState(); +void SetStage(Stage state); +Stage GetStage(); } // namespace networking_policy diff --git a/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm b/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm index 5bde8750fe..315c36f4e5 100644 --- a/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm +++ b/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm @@ -9,22 +9,22 @@ NSTimeInterval const kSessionDurationSeconds = 24 * 60 * 60; namespace networking_policy { -void callPartnersApiWithNetworkingPolicy(MWMNetworkingPolicyFn const & fn) +void CallPartnersApi(MWMPartnersApiFn const & fn) { - auto checkAndApply = ^BOOL { + auto checkAndApply = ^bool { NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; NSDate * policyDate = [ud objectForKey:kNetworkingPolicyTimeStamp]; if ([policyDate compare:[NSDate date]] == NSOrderedDescending) { fn(YES); - return YES; + return true; } if ([policyDate isEqualToDate:NSDate.distantPast]) { fn(NO); - return YES; + return true; } - return NO; + return false; }; if (checkAndApply()) @@ -37,29 +37,29 @@ void callPartnersApiWithNetworkingPolicy(MWMNetworkingPolicyFn const & fn) }]; } -void SetNetworkingPolicyState(NetworkingPolicyState state) +void SetStage(Stage state) { NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; NSDate * policyDate = nil; switch (state) { - case NetworkingPolicyState::Always: policyDate = NSDate.distantFuture; break; - case NetworkingPolicyState::Session: + case Stage::Always: policyDate = NSDate.distantFuture; break; + case Stage::Session: policyDate = [NSDate dateWithTimeIntervalSinceNow:kSessionDurationSeconds]; break; - case NetworkingPolicyState::Never: policyDate = NSDate.distantPast; break; + case Stage::Never: policyDate = NSDate.distantPast; break; } [ud setObject:policyDate forKey:kNetworkingPolicyTimeStamp]; } -NetworkingPolicyState GetNetworkingPolicyState() +Stage GetStage() { NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; NSDate * policyDate = [ud objectForKey:kNetworkingPolicyTimeStamp]; if ([policyDate isEqualToDate:NSDate.distantFuture]) - return NetworkingPolicyState::Always; + return Stage::Always; if ([policyDate isEqualToDate:NSDate.distantPast]) - return NetworkingPolicyState::Never; - return NetworkingPolicyState::Session; + return Stage::Never; + return Stage::Session; } } // namespace networking_policy diff --git a/iphone/Maps/MWMMobileInternetViewController.mm b/iphone/Maps/MWMMobileInternetViewController.mm index 9f4e3afc84..2ecbe25bfd 100644 --- a/iphone/Maps/MWMMobileInternetViewController.mm +++ b/iphone/Maps/MWMMobileInternetViewController.mm @@ -22,11 +22,11 @@ using namespace networking_policy; self.title = L(@"pref_mobile_internet"); SelectableCell * selected; - switch (GetNetworkingPolicyState()) + switch (GetStage()) { - case NetworkingPolicyState::Always: selected = self.always; break; - case NetworkingPolicyState::Session: selected = self.ask; break; - case NetworkingPolicyState::Never: selected = self.never; break; + case Stage::Always: selected = self.always; break; + case Stage::Session: selected = self.ask; break; + case Stage::Never: selected = self.never; break; } selected.accessoryType = UITableViewCellAccessoryCheckmark; self.selected = selected; @@ -42,17 +42,17 @@ using namespace networking_policy; if ([selected isEqual:self.always]) { statValue = kStatAlways; - SetNetworkingPolicyState(NetworkingPolicyState::Always); + SetStage(Stage::Always); } else if ([selected isEqual:self.ask]) { statValue = kStatAsk; - SetNetworkingPolicyState(NetworkingPolicyState::Session); + SetStage(Stage::Session); } else if ([selected isEqual:self.never]) { statValue = kStatNever; - SetNetworkingPolicyState(NetworkingPolicyState::Never); + SetStage(Stage::Never); } [Statistics logEvent:kStatMobileInternet withParameters:@{kStatValue : statValue}]; diff --git a/iphone/Maps/Settings/MWMSettingsViewController.mm b/iphone/Maps/Settings/MWMSettingsViewController.mm index f21b314e04..b8f4828bc5 100644 --- a/iphone/Maps/Settings/MWMSettingsViewController.mm +++ b/iphone/Maps/Settings/MWMSettingsViewController.mm @@ -87,11 +87,11 @@ extern NSString * const kAlohalyticsTapEventKey; self.autoDownloadCell.delegate = self; NSString * internetLabel = nil; - switch (networking_policy::GetNetworkingPolicyState()) + switch (networking_policy::GetStage()) { - case networking_policy::NetworkingPolicyState::Always: internetLabel = L(@"pref_always"); break; - case networking_policy::NetworkingPolicyState::Session: internetLabel = L(@"pref_ask"); break; - case networking_policy::NetworkingPolicyState::Never: internetLabel = L(@"pref_never"); break; + case networking_policy::Stage::Always: internetLabel = L(@"pref_always"); break; + case networking_policy::Stage::Session: internetLabel = L(@"pref_ask"); break; + case networking_policy::Stage::Never: internetLabel = L(@"pref_never"); break; } self.mobileInternetCell.infoLabel.text = internetLabel; From db4a6592645a100568f819ea69069f8dd6e4e7eb Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Mon, 28 Nov 2016 17:35:08 +0300 Subject: [PATCH 4/4] [MAPSME-2994] [ios] Adopted Network Policy. --- .../MWMMobileInternetAlert.mm | 11 +-- .../RoutePreview/MWMTaxiPreviewDataSource.mm | 81 ++++++++++--------- iphone/Maps/Classes/MWMPlacePageData.mm | 13 +-- iphone/Maps/Classes/MWMPlacePageEntity.mm | 62 +++++++------- .../Classes/NetworkPolicy/MWMNetworkPolicy.h | 11 +++ .../MWMNetworkPolicy.mm} | 38 +++++---- .../NetworkingPolicy/MWMNetworkingPolicy.h | 18 ----- .../Maps/MWMMobileInternetViewController.mm | 17 ++-- iphone/Maps/Maps.xcodeproj/project.pbxproj | 32 ++++---- .../Settings/MWMSettingsViewController.mm | 11 +-- platform/network_policy.hpp | 31 +++++-- 11 files changed, 178 insertions(+), 147 deletions(-) create mode 100644 iphone/Maps/Classes/NetworkPolicy/MWMNetworkPolicy.h rename iphone/Maps/Classes/{NetworkingPolicy/MWMNetworkingPolicy.mm => NetworkPolicy/MWMNetworkPolicy.mm} (69%) delete mode 100644 iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h diff --git a/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm b/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm index f1f6b5b62b..7b9c73448b 100644 --- a/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm @@ -1,8 +1,9 @@ #import "MWMMobileInternetAlert.h" -#import "MWMNetworkingPolicy.h" +#import "MWMNetworkPolicy.h" #import "Statistics.h" -using namespace networking_policy; +using namespace network_policy; +using np = platform::NetworkPolicy; namespace { @@ -30,21 +31,21 @@ NSString * const kStatisticsEvent = @"Mobile Internet Settings Alert"; - (IBAction)alwaysTap { [Statistics logEvent:kStatMobileInternet withParameters:@{kStatValue : kStatAlways}]; - SetStage(Stage::Always); + SetStage(np::Stage::Always); [self close:self.completionBlock]; } - (IBAction)askTap { [Statistics logEvent:kStatMobileInternet withParameters:@{kStatValue : kStatAsk}]; - SetStage(Stage::Session); + SetStage(np::Stage::Session); [self close:self.completionBlock]; } - (IBAction)neverTap { [Statistics logEvent:kStatisticsEvent withParameters:@{kStatAction : kStatNever}]; - SetStage(Stage::Never); + SetStage(np::Stage::Never); [self close:self.completionBlock]; } diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/MWMTaxiPreviewDataSource.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/MWMTaxiPreviewDataSource.mm index 0e9383eb90..04bc7f33d5 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/MWMTaxiPreviewDataSource.mm +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/MWMTaxiPreviewDataSource.mm @@ -1,6 +1,10 @@ +#import "MWMTaxiPreviewDataSource.h" +#import "Common.h" +#import "MWMNetworkPolicy.h" #import "MWMRoutePoint.h" #import "MWMTaxiPreviewCell.h" -#import "MWMTaxiPreviewDataSource.h" + +#include "Framework.h" #include "geometry/mercator.hpp" @@ -56,7 +60,6 @@ using namespace uber; @interface MWMTaxiPreviewDataSource() { - Api m_api; vector m_products; ms::LatLon m_from; ms::LatLon m_to; @@ -107,43 +110,47 @@ using namespace uber; cv.hidden = YES; cv.pageControl.hidden = YES; - m_requestId = m_api.GetAvailableProducts(m_from, m_to, [self, completion](vector const & products, - uint64_t const requestId) - { - dispatch_async(dispatch_get_main_queue(), [products, requestId, self, completion] - { - if (self->m_requestId != requestId) - return; + network_policy::CallPartnersApi( + [self, completion, failure](platform::NetworkPolicy const & canUseNetwork) { + auto const api = GetFramework().GetUberApi(canUseNetwork); + if (!api) + { + failure(L(@"dialog_taxi_error")); + return; + } - self->m_products = products; - auto cv = self.collectionView; - cv.hidden = NO; - cv.pageControl.hidden = NO; - cv.numberOfPages = self->m_products.size(); - [cv reloadData]; - cv.contentOffset = {}; - cv.currentPage = 0; - completion(); - }); - }, - [self, failure](uber::ErrorCode const code, uint64_t const requestId) - { - dispatch_async(dispatch_get_main_queue(), ^ - { - if (self->m_requestId != requestId) - return; + auto success = [self, completion](vector const & products, + uint64_t const requestId) { + if (self->m_requestId != requestId) + return; + runAsyncOnMainQueue([self, completion, products] { - switch (code) - { - case uber::ErrorCode::NoProducts: - failure(L(@"taxi_not_found")); - break; - case uber::ErrorCode::RemoteError: - failure(L(@"dialog_taxi_error")); - break; - } - }); - }); + self->m_products = products; + auto cv = self.collectionView; + cv.hidden = NO; + cv.pageControl.hidden = NO; + cv.numberOfPages = self->m_products.size(); + [cv reloadData]; + cv.contentOffset = {}; + cv.currentPage = 0; + completion(); + }); + + }; + auto error = [self, failure](uber::ErrorCode const code, uint64_t const requestId) { + if (self->m_requestId != requestId) + return; + runAsyncOnMainQueue(^{ + switch (code) + { + case uber::ErrorCode::NoProducts: failure(L(@"taxi_not_found")); break; + case uber::ErrorCode::RemoteError: failure(L(@"dialog_taxi_error")); break; + } + }); + }; + m_requestId = api->GetAvailableProducts(m_from, m_to, success, error); + }, + true /* force */); } - (BOOL)isTaxiInstalled diff --git a/iphone/Maps/Classes/MWMPlacePageData.mm b/iphone/Maps/Classes/MWMPlacePageData.mm index bd9de153fd..28d73cf56f 100644 --- a/iphone/Maps/Classes/MWMPlacePageData.mm +++ b/iphone/Maps/Classes/MWMPlacePageData.mm @@ -1,9 +1,8 @@ #import "MWMPlacePageData.h" +#import "MWMNetworkPolicy.h" #include "Framework.h" -#include "platform/network_policy.hpp" - #include "base/string_utils.hpp" #include "3party/opening_hours/opening_hours.hpp" @@ -15,7 +14,6 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; } // namespace using namespace place_page; -using platform::MakeNetworkPolicyIos; @implementation MWMPlacePageData { @@ -260,7 +258,6 @@ using platform::MakeNetworkPolicyIos; currencyFormatter.maximumFractionDigits = 0; string const currency = currencyFormatter.currencyCode.UTF8String; - auto const api = GetFramework().GetBookingApi(MakeNetworkPolicyIos(true)); auto const func = [self, label, currency, currencyFormatter](string const & minPrice, string const & priceCurrency) { @@ -287,8 +284,12 @@ using platform::MakeNetworkPolicyIos; }); }; - if (api) - api->GetMinPrice(self.sponsoredId.UTF8String, currency, func); + network_policy::CallPartnersApi( + [self, currency, func](platform::NetworkPolicy const & canUseNetwork) { + auto const api = GetFramework().GetBookingApi(canUseNetwork); + if (api) + api->GetMinPrice(self.sponsoredId.UTF8String, currency, func); + }); } - (NSString *)address { return @(m_info.GetAddress().c_str()); } diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.mm b/iphone/Maps/Classes/MWMPlacePageEntity.mm index d3c099f052..7a442101f6 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.mm +++ b/iphone/Maps/Classes/MWMPlacePageEntity.mm @@ -1,5 +1,6 @@ #import "MWMPlacePageEntity.h" #import "MWMMapViewControlsManager.h" +#import "MWMNetworkPolicy.h" #import "MapViewController.h" #import "MapsAppDelegate.h" @@ -9,11 +10,9 @@ #include "platform/measurement_utils.hpp" #include "platform/mwm_version.hpp" -#include "platform/network_policy.hpp" #include "platform/platform.hpp" using feature::Metadata; -using platform::MakeNetworkPolicyIos; static NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; @@ -133,33 +132,38 @@ void initFieldsMap() currencyFormatter.numberStyle = NSNumberFormatterCurrencyStyle; currencyFormatter.maximumFractionDigits = 0; string const currency = currencyFormatter.currencyCode.UTF8String; - auto const api = GetFramework().GetBookingApi(MakeNetworkPolicyIos(true)); - if (api) - api->GetMinPrice( - m_info.GetMetadata().Get(Metadata::FMD_SPONSORED_ID), currency, - [self, completion, failure, currency, currencyFormatter](string const & minPrice, - string const & priceCurrency) { - if (currency != priceCurrency) - { - failure(); - return; - } - NSNumberFormatter * decimalFormatter = [[NSNumberFormatter alloc] init]; - decimalFormatter.numberStyle = NSNumberFormatterDecimalStyle; - NSString * currencyString = [currencyFormatter - stringFromNumber: - [decimalFormatter - numberFromString: - [@(minPrice.c_str()) - stringByReplacingOccurrencesOfString:@"." - withString:decimalFormatter - .decimalSeparator]]]; - NSString * currencyPattern = - [L(@"place_page_starting_from") stringByReplacingOccurrencesOfString:@"%s" - withString:@"%@"]; - self.bookingOnlinePrice = [NSString stringWithFormat:currencyPattern, currencyString]; - completion(); - }); + network_policy::CallPartnersApi([self, completion, failure, currency, currencyFormatter]( + platform::NetworkPolicy const & canUseNetwork) { + auto const api = GetFramework().GetBookingApi(canUseNetwork); + if (!api) + { + failure(); + return; + } + auto success = [self, completion, failure, currency, currencyFormatter]( + string const & minPrice, string const & priceCurrency) { + if (currency != priceCurrency) + { + failure(); + return; + } + NSNumberFormatter * decimalFormatter = [[NSNumberFormatter alloc] init]; + decimalFormatter.numberStyle = NSNumberFormatterDecimalStyle; + NSString * currencyString = [currencyFormatter + stringFromNumber: + [decimalFormatter + numberFromString: + [@(minPrice.c_str()) + stringByReplacingOccurrencesOfString:@"." + withString:decimalFormatter.decimalSeparator]]]; + NSString * currencyPattern = + [L(@"place_page_starting_from") stringByReplacingOccurrencesOfString:@"%s" + withString:@"%@"]; + self.bookingOnlinePrice = [NSString stringWithFormat:currencyPattern, currencyString]; + completion(); + }; + api->GetMinPrice(m_info.GetMetadata().Get(Metadata::FMD_SPONSORED_ID), currency, success); + }); } - (void)configureBookmark diff --git a/iphone/Maps/Classes/NetworkPolicy/MWMNetworkPolicy.h b/iphone/Maps/Classes/NetworkPolicy/MWMNetworkPolicy.h new file mode 100644 index 0000000000..f8944d478d --- /dev/null +++ b/iphone/Maps/Classes/NetworkPolicy/MWMNetworkPolicy.h @@ -0,0 +1,11 @@ +#pragma once + +#include "platform/network_policy.hpp" + +namespace network_policy +{ +void CallPartnersApi(platform::PartnersApiFn fn, bool force = false); + +void SetStage(platform::NetworkPolicy::Stage state); +platform::NetworkPolicy::Stage GetStage(); +} // namespace network_policy diff --git a/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm b/iphone/Maps/Classes/NetworkPolicy/MWMNetworkPolicy.mm similarity index 69% rename from iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm rename to iphone/Maps/Classes/NetworkPolicy/MWMNetworkPolicy.mm index 315c36f4e5..ab0826c89f 100644 --- a/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm +++ b/iphone/Maps/Classes/NetworkPolicy/MWMNetworkPolicy.mm @@ -1,27 +1,35 @@ -#import "MWMNetworkingPolicy.h" +#import "MWMNetworkPolicy.h" #import "MWMAlertViewController.h" +using np = platform::NetworkPolicy; + namespace { NSString * const kNetworkingPolicyTimeStamp = @"NetworkingPolicyTimeStamp"; NSTimeInterval const kSessionDurationSeconds = 24 * 60 * 60; } // namespace -namespace networking_policy +namespace network_policy { -void CallPartnersApi(MWMPartnersApiFn const & fn) +void CallPartnersApi(platform::PartnersApiFn fn, bool force) { + if (force) + { + fn(true); + return; + } + auto checkAndApply = ^bool { NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; NSDate * policyDate = [ud objectForKey:kNetworkingPolicyTimeStamp]; if ([policyDate compare:[NSDate date]] == NSOrderedDescending) { - fn(YES); + fn(true); return true; } if ([policyDate isEqualToDate:NSDate.distantPast]) { - fn(NO); + fn(false); return true; } return false; @@ -33,33 +41,33 @@ void CallPartnersApi(MWMPartnersApiFn const & fn) MWMAlertViewController * alertController = [MWMAlertViewController activeAlertController]; [alertController presentMobileInternetAlertWithBlock:^{ if (!checkAndApply()) - fn(NO); + fn(false); }]; } -void SetStage(Stage state) +void SetStage(np::Stage state) { NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; NSDate * policyDate = nil; switch (state) { - case Stage::Always: policyDate = NSDate.distantFuture; break; - case Stage::Session: + case np::Stage::Always: policyDate = NSDate.distantFuture; break; + case np::Stage::Session: policyDate = [NSDate dateWithTimeIntervalSinceNow:kSessionDurationSeconds]; break; - case Stage::Never: policyDate = NSDate.distantPast; break; + case np::Stage::Never: policyDate = NSDate.distantPast; break; } [ud setObject:policyDate forKey:kNetworkingPolicyTimeStamp]; } -Stage GetStage() +np::Stage GetStage() { NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; NSDate * policyDate = [ud objectForKey:kNetworkingPolicyTimeStamp]; if ([policyDate isEqualToDate:NSDate.distantFuture]) - return Stage::Always; + return np::Stage::Always; if ([policyDate isEqualToDate:NSDate.distantPast]) - return Stage::Never; - return Stage::Session; + return np::Stage::Never; + return np::Stage::Session; } -} // namespace networking_policy +} // namespace network_policy diff --git a/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h b/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h deleted file mode 100644 index 5196bc60e7..0000000000 --- a/iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h +++ /dev/null @@ -1,18 +0,0 @@ -#include "std/function.hpp" - -namespace networking_policy -{ -using MWMPartnersApiFn = function; - -void CallPartnersApi(MWMPartnersApiFn const & fn); - -enum class Stage -{ - Always, - Session, - Never -}; - -void SetStage(Stage state); -Stage GetStage(); -} // namespace networking_policy diff --git a/iphone/Maps/MWMMobileInternetViewController.mm b/iphone/Maps/MWMMobileInternetViewController.mm index 2ecbe25bfd..48733ed74c 100644 --- a/iphone/Maps/MWMMobileInternetViewController.mm +++ b/iphone/Maps/MWMMobileInternetViewController.mm @@ -1,9 +1,10 @@ #import "MWMMobileInternetViewController.h" -#import "MWMNetworkingPolicy.h" +#import "MWMNetworkPolicy.h" #import "SelectableCell.h" #import "Statistics.h" -using namespace networking_policy; +using namespace network_policy; +using np = platform::NetworkPolicy; @interface MWMMobileInternetViewController () @@ -24,9 +25,9 @@ using namespace networking_policy; SelectableCell * selected; switch (GetStage()) { - case Stage::Always: selected = self.always; break; - case Stage::Session: selected = self.ask; break; - case Stage::Never: selected = self.never; break; + case np::Stage::Always: selected = self.always; break; + case np::Stage::Session: selected = self.ask; break; + case np::Stage::Never: selected = self.never; break; } selected.accessoryType = UITableViewCellAccessoryCheckmark; self.selected = selected; @@ -42,17 +43,17 @@ using namespace networking_policy; if ([selected isEqual:self.always]) { statValue = kStatAlways; - SetStage(Stage::Always); + SetStage(np::Stage::Always); } else if ([selected isEqual:self.ask]) { statValue = kStatAsk; - SetStage(Stage::Session); + SetStage(np::Stage::Session); } else if ([selected isEqual:self.never]) { statValue = kStatNever; - SetStage(Stage::Never); + SetStage(np::Stage::Never); } [Statistics logEvent:kStatMobileInternet withParameters:@{kStatValue : statValue}]; diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index aae006ecc7..9c82dc98b0 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -233,8 +233,6 @@ 349A13831DEC138C00C7DB60 /* MWMMobileInternetAlert.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A13801DEC138C00C7DB60 /* MWMMobileInternetAlert.mm */; }; 349A13841DEC138C00C7DB60 /* MWMMobileInternetAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A13811DEC138C00C7DB60 /* MWMMobileInternetAlert.xib */; }; 349A13851DEC138C00C7DB60 /* MWMMobileInternetAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A13811DEC138C00C7DB60 /* MWMMobileInternetAlert.xib */; }; - 349A13891DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */; }; - 349A138A1DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */; }; 349A357A1B53D4C9009677EE /* MWMCircularProgress.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A35761B53D4C9009677EE /* MWMCircularProgress.mm */; }; 349A357B1B53D4C9009677EE /* MWMCircularProgress.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A35771B53D4C9009677EE /* MWMCircularProgress.xib */; }; 349A357C1B53D4C9009677EE /* MWMCircularProgressView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A35791B53D4C9009677EE /* MWMCircularProgressView.mm */; }; @@ -388,6 +386,8 @@ 34E273221C737A4100463965 /* MWMMigrationViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34E273201C737A4100463965 /* MWMMigrationViewController.mm */; }; 34E273251C73876500463965 /* MWMMigrationView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34E273241C73876500463965 /* MWMMigrationView.mm */; }; 34E273261C73876500463965 /* MWMMigrationView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34E273241C73876500463965 /* MWMMigrationView.mm */; }; + 34EA976C1DEC779D00616B11 /* MWMNetworkPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34EA976B1DEC779D00616B11 /* MWMNetworkPolicy.mm */; }; + 34EA976D1DEC779D00616B11 /* MWMNetworkPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34EA976B1DEC779D00616B11 /* MWMNetworkPolicy.mm */; }; 34EB5E7D1C900145002C4D37 /* QuickLook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 845C89341C8983F300940D7F /* QuickLook.framework */; }; 34EB5E7E1C900159002C4D37 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 845C89301C89837900940D7F /* AssetsLibrary.framework */; }; 34EB84581C073DF70004689F /* MWMOpeningHoursEditorViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34EB84571C073DF70004689F /* MWMOpeningHoursEditorViewController.mm */; }; @@ -1196,8 +1196,6 @@ 349A137F1DEC138C00C7DB60 /* MWMMobileInternetAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMMobileInternetAlert.h; sourceTree = ""; }; 349A13801DEC138C00C7DB60 /* MWMMobileInternetAlert.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMMobileInternetAlert.mm; sourceTree = ""; }; 349A13811DEC138C00C7DB60 /* MWMMobileInternetAlert.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMMobileInternetAlert.xib; sourceTree = ""; }; - 349A13871DEC44C600C7DB60 /* MWMNetworkingPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMNetworkingPolicy.h; sourceTree = ""; }; - 349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMNetworkingPolicy.mm; sourceTree = ""; }; 349A35751B53D4C9009677EE /* MWMCircularProgress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMCircularProgress.h; sourceTree = ""; }; 349A35761B53D4C9009677EE /* MWMCircularProgress.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMCircularProgress.mm; sourceTree = ""; }; 349A35771B53D4C9009677EE /* MWMCircularProgress.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMCircularProgress.xib; sourceTree = ""; }; @@ -1361,6 +1359,8 @@ 34E273201C737A4100463965 /* MWMMigrationViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMMigrationViewController.mm; sourceTree = ""; }; 34E273231C73876500463965 /* MWMMigrationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMMigrationView.h; sourceTree = ""; }; 34E273241C73876500463965 /* MWMMigrationView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMMigrationView.mm; sourceTree = ""; }; + 34EA976A1DEC779D00616B11 /* MWMNetworkPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMNetworkPolicy.h; sourceTree = ""; }; + 34EA976B1DEC779D00616B11 /* MWMNetworkPolicy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMNetworkPolicy.mm; sourceTree = ""; }; 34EB84561C073DF70004689F /* MWMOpeningHoursEditorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMOpeningHoursEditorViewController.h; sourceTree = ""; }; 34EB84571C073DF70004689F /* MWMOpeningHoursEditorViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMOpeningHoursEditorViewController.mm; sourceTree = ""; }; 34EC27081CB2A7120084FA36 /* fabric_logging_ios.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = fabric_logging_ios.mm; sourceTree = ""; }; @@ -1888,7 +1888,7 @@ 080E96DDFE201D6D7F000001 /* Classes */ = { isa = PBXGroup; children = ( - 349A13861DEC448500C7DB60 /* NetworkingPolicy */, + 34EA97691DEC779D00616B11 /* NetworkPolicy */, 348868F01D87DF8C0069BBA3 /* Keyboard */, 3436FE7F1D366CA0005CD87B /* Search */, 344D77B11D1BD79700DBED70 /* Location */, @@ -2416,15 +2416,6 @@ path = MobileInternetAlert; sourceTree = ""; }; - 349A13861DEC448500C7DB60 /* NetworkingPolicy */ = { - isa = PBXGroup; - children = ( - 349A13871DEC44C600C7DB60 /* MWMNetworkingPolicy.h */, - 349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */, - ); - path = NetworkingPolicy; - sourceTree = ""; - }; 349A35741B53D4C9009677EE /* CircularProgress */ = { isa = PBXGroup; children = ( @@ -2715,6 +2706,15 @@ path = Migration; sourceTree = ""; }; + 34EA97691DEC779D00616B11 /* NetworkPolicy */ = { + isa = PBXGroup; + children = ( + 34EA976A1DEC779D00616B11 /* MWMNetworkPolicy.h */, + 34EA976B1DEC779D00616B11 /* MWMNetworkPolicy.mm */, + ); + path = NetworkPolicy; + sourceTree = ""; + }; 34EB84501C0738D30004689F /* Editor */ = { isa = PBXGroup; children = ( @@ -4056,7 +4056,6 @@ 3418CEAE1CBF9E3300641B25 /* MWMNoMapsViewController.mm in Sources */, 3401CD7D1C3CF1BE0028C6F8 /* MWMEditorSwitchTableViewCell.mm in Sources */, 34B82AD61B84746E00180497 /* MWMSearchSuggestionCell.mm in Sources */, - 349A13891DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */, F6C641B01C15BBE6008FCAF3 /* MWMRecentTrackSettingsController.mm in Sources */, 341F99F11C6B4288001C67B8 /* MWMMapDownloaderSearchDataSource.mm in Sources */, 34A759D81DC795D10078C3AE /* MWMWhatsNewUberController.mm in Sources */, @@ -4107,6 +4106,7 @@ 978F9242183B660F000D6C7C /* SelectableCell.mm in Sources */, 34ABA6241C2D551900FE1BEC /* MWMInputValidatorFactory.mm in Sources */, 34257D1B1DC9FD9400DC5BB9 /* MWMSearchChangeModeView.mm in Sources */, + 34EA976C1DEC779D00616B11 /* MWMNetworkPolicy.mm in Sources */, 34B82AE21B84AC5E00180497 /* MWMSearchCategoriesManager.mm in Sources */, 34CE8A671C7740E100F4351A /* MWMStorage.mm in Sources */, F6F7787A1DABC6D800B603E7 /* MWMTaxiCollectionLayout.mm in Sources */, @@ -4308,7 +4308,6 @@ 34EC270B1CB2A7120084FA36 /* fabric_logging_ios.mm in Sources */, 6741A9FA1BF340DE002C974C /* MWMBookmarkColorViewController.mm in Sources */, 3418CEAF1CBF9E3300641B25 /* MWMNoMapsViewController.mm in Sources */, - 349A138A1DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */, 3401CD7E1C3CF1BE0028C6F8 /* MWMEditorSwitchTableViewCell.mm in Sources */, 34EB84591C073DF70004689F /* MWMOpeningHoursEditorViewController.mm in Sources */, 341F99F21C6B4288001C67B8 /* MWMMapDownloaderSearchDataSource.mm in Sources */, @@ -4359,6 +4358,7 @@ 34ABA6251C2D551900FE1BEC /* MWMInputValidatorFactory.mm in Sources */, 348868F41D87DFB70069BBA3 /* MWMKeyboard.mm in Sources */, 34257D1C1DC9FD9400DC5BB9 /* MWMSearchChangeModeView.mm in Sources */, + 34EA976D1DEC779D00616B11 /* MWMNetworkPolicy.mm in Sources */, F639883C1CF70FE500226B6B /* MWMActionBarButton.mm in Sources */, 34CE8A681C7740E100F4351A /* MWMStorage.mm in Sources */, 6741AA141BF340DE002C974C /* MWMMultilineLabel.mm in Sources */, diff --git a/iphone/Maps/Settings/MWMSettingsViewController.mm b/iphone/Maps/Settings/MWMSettingsViewController.mm index b8f4828bc5..b2ff33e347 100644 --- a/iphone/Maps/Settings/MWMSettingsViewController.mm +++ b/iphone/Maps/Settings/MWMSettingsViewController.mm @@ -2,7 +2,7 @@ #import "LinkCell.h" #import "LocaleTranslator.h" #import "MWMAuthorizationCommon.h" -#import "MWMNetworkingPolicy.h" +#import "MWMNetworkPolicy.h" #import "MWMSettings.h" #import "MWMTextToSpeech.h" #import "Statistics.h" @@ -87,11 +87,12 @@ extern NSString * const kAlohalyticsTapEventKey; self.autoDownloadCell.delegate = self; NSString * internetLabel = nil; - switch (networking_policy::GetStage()) + using np = platform::NetworkPolicy; + switch (network_policy::GetStage()) { - case networking_policy::Stage::Always: internetLabel = L(@"pref_always"); break; - case networking_policy::Stage::Session: internetLabel = L(@"pref_ask"); break; - case networking_policy::Stage::Never: internetLabel = L(@"pref_never"); break; + case np::Stage::Always: internetLabel = L(@"pref_always"); break; + case np::Stage::Session: internetLabel = L(@"pref_ask"); break; + case np::Stage::Never: internetLabel = L(@"pref_never"); break; } self.mobileInternetCell.infoLabel.text = internetLabel; diff --git a/platform/network_policy.hpp b/platform/network_policy.hpp index a1e64112a2..da732e35b4 100644 --- a/platform/network_policy.hpp +++ b/platform/network_policy.hpp @@ -1,8 +1,21 @@ #pragma once +#include "std/function.hpp" + class _jobject; typedef _jobject * jobject; +namespace platform +{ +class NetworkPolicy; +using PartnersApiFn = function; +} + +namespace network_policy +{ +void CallPartnersApi(platform::PartnersApiFn fn, bool force); +} + namespace platform { /// Class that is used to allow or disallow remote calls. @@ -10,11 +23,18 @@ class NetworkPolicy { // Maker for android. friend NetworkPolicy ToNativeNetworkPolicy(jobject obj); - // Maker for ios. - // Dummy, real signature should be chosen by ios developer. - friend NetworkPolicy MakeNetworkPolicyIos(bool canUseNetwork); + + // iOS + friend void network_policy::CallPartnersApi(PartnersApiFn fn, bool force); public: + enum class Stage + { + Always, + Session, + Never + }; + bool CanUse() const { return m_canUse; } private: @@ -22,9 +42,4 @@ private: bool m_canUse = false; }; -// Dummy, real signature, implementation and location should be chosen by ios developer. -inline NetworkPolicy MakeNetworkPolicyIos(bool canUseNetwork) -{ - return NetworkPolicy(canUseNetwork); -} } // namespace platform