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