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..7b9c73448b 100644 --- a/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.mm @@ -1,38 +1,52 @@ #import "MWMMobileInternetAlert.h" +#import "MWMNetworkPolicy.h" #import "Statistics.h" +using namespace network_policy; +using np = platform::NetworkPolicy; + 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]; + SetStage(np::Stage::Always); + [self close:self.completionBlock]; } - (IBAction)askTap { [Statistics logEvent:kStatMobileInternet withParameters:@{kStatValue : kStatAsk}]; - [self close:nil]; + SetStage(np::Stage::Session); + [self close:self.completionBlock]; } - (IBAction)neverTap { [Statistics logEvent:kStatisticsEvent withParameters:@{kStatAction : kStatNever}]; - [self close:nil]; + SetStage(np::Stage::Never); + [self close:self.completionBlock]; } @end 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/NetworkPolicy/MWMNetworkPolicy.mm b/iphone/Maps/Classes/NetworkPolicy/MWMNetworkPolicy.mm new file mode 100644 index 0000000000..ab0826c89f --- /dev/null +++ b/iphone/Maps/Classes/NetworkPolicy/MWMNetworkPolicy.mm @@ -0,0 +1,73 @@ +#import "MWMNetworkPolicy.h" +#import "MWMAlertViewController.h" + +using np = platform::NetworkPolicy; + +namespace +{ +NSString * const kNetworkingPolicyTimeStamp = @"NetworkingPolicyTimeStamp"; +NSTimeInterval const kSessionDurationSeconds = 24 * 60 * 60; +} // namespace + +namespace network_policy +{ +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(true); + return true; + } + if ([policyDate isEqualToDate:NSDate.distantPast]) + { + fn(false); + return true; + } + return false; + }; + + if (checkAndApply()) + return; + + MWMAlertViewController * alertController = [MWMAlertViewController activeAlertController]; + [alertController presentMobileInternetAlertWithBlock:^{ + if (!checkAndApply()) + fn(false); + }]; +} + +void SetStage(np::Stage state) +{ + NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; + NSDate * policyDate = nil; + switch (state) + { + case np::Stage::Always: policyDate = NSDate.distantFuture; break; + case np::Stage::Session: + policyDate = [NSDate dateWithTimeIntervalSinceNow:kSessionDurationSeconds]; + break; + case np::Stage::Never: policyDate = NSDate.distantPast; break; + } + [ud setObject:policyDate forKey:kNetworkingPolicyTimeStamp]; +} + +np::Stage GetStage() +{ + NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; + NSDate * policyDate = [ud objectForKey:kNetworkingPolicyTimeStamp]; + if ([policyDate isEqualToDate:NSDate.distantFuture]) + return np::Stage::Always; + if ([policyDate isEqualToDate:NSDate.distantPast]) + return np::Stage::Never; + return np::Stage::Session; +} +} // namespace network_policy diff --git a/iphone/Maps/MWMMobileInternetViewController.mm b/iphone/Maps/MWMMobileInternetViewController.mm index 11f3aa03ea..48733ed74c 100644 --- a/iphone/Maps/MWMMobileInternetViewController.mm +++ b/iphone/Maps/MWMMobileInternetViewController.mm @@ -1,7 +1,11 @@ #import "MWMMobileInternetViewController.h" +#import "MWMNetworkPolicy.h" #import "SelectableCell.h" #import "Statistics.h" +using namespace network_policy; +using np = platform::NetworkPolicy; + @interface MWMMobileInternetViewController () @property(weak, nonatomic) IBOutlet SelectableCell * always; @@ -18,8 +22,15 @@ [super viewDidLoad]; self.title = L(@"pref_mobile_internet"); - self.never.accessoryType = UITableViewCellAccessoryCheckmark; - _selected = self.never; + SelectableCell * selected; + switch (GetStage()) + { + 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; } - (void)setSelected:(SelectableCell *)selected @@ -32,14 +43,17 @@ if ([selected isEqual:self.always]) { statValue = kStatAlways; + SetStage(np::Stage::Always); } else if ([selected isEqual:self.ask]) { statValue = kStatAsk; + SetStage(np::Stage::Session); } else if ([selected isEqual:self.never]) { statValue = kStatNever; + 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 300e97f959..4bb8837e34 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -386,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 */; }; @@ -1804,6 +1806,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 = ""; }; @@ -2378,6 +2382,7 @@ 080E96DDFE201D6D7F000001 /* Classes */ = { isa = PBXGroup; children = ( + 34EA97691DEC779D00616B11 /* NetworkPolicy */, 348868F01D87DF8C0069BBA3 /* Keyboard */, 3436FE7F1D366CA0005CD87B /* Search */, 344D77B11D1BD79700DBED70 /* Location */, @@ -3196,6 +3201,15 @@ path = Migration; sourceTree = ""; }; + 34EA97691DEC779D00616B11 /* NetworkPolicy */ = { + isa = PBXGroup; + children = ( + 34EA976A1DEC779D00616B11 /* MWMNetworkPolicy.h */, + 34EA976B1DEC779D00616B11 /* MWMNetworkPolicy.mm */, + ); + path = NetworkPolicy; + sourceTree = ""; + }; 34EB84501C0738D30004689F /* Editor */ = { isa = PBXGroup; children = ( @@ -4800,6 +4814,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 */, @@ -5051,6 +5066,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 4ebed5de25..b2ff33e347 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 "MWMNetworkPolicy.h" #import "MWMSettings.h" #import "MWMTextToSpeech.h" #import "Statistics.h" @@ -85,7 +86,15 @@ extern NSString * const kAlohalyticsTapEventKey; self.autoDownloadCell.switchButton.on = [MWMSettings autoDownloadEnabled]; self.autoDownloadCell.delegate = self; - self.mobileInternetCell.infoLabel.text = L(@"pref_ask"); + NSString * internetLabel = nil; + using np = platform::NetworkPolicy; + switch (network_policy::GetStage()) + { + 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; if (!GpsTracker::Instance().IsEnabled()) { 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