diff options
8 files changed, 64 insertions, 11 deletions
diff --git a/configure.sh b/configure.sh index c1a202309e..365158e3cc 100755 --- a/configure.sh +++ b/configure.sh @@ -39,6 +39,8 @@ else #define RESOURCES_METASERVER_URL "" #define METASERVER_URL "" #define DEFAULT_URLS_JSON "" +#define AD_PERMISION_SERVER_URL "" +#define AD_PERMISION_CHECK_DURATION 2 * 60 * 60 ' > "$PRIVATE_HEADER" echo ' ext { diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuView.h b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuView.h index 459da8ffec..5e001b0ac4 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuView.h +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuView.h @@ -20,4 +20,6 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuState) @property(nonatomic) BOOL searchIsActive; +- (void)refreshLayout; + @end diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuView.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuView.mm index aa2b19872b..89f1c583bf 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuView.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuView.mm @@ -290,6 +290,12 @@ self.leftBound = 0.0; } +- (void)refreshLayout +{ + self.layoutDuration = kDefaultAnimationDuration; + [self setNeedsLayout]; +} + #pragma mark - Properties - (void)setFrame:(CGRect)frame @@ -303,7 +309,7 @@ { if (_state == state) return; - self.layoutDuration = kDefaultAnimationDuration; + [self refreshLayout]; switch (state) { case MWMBottomMenuStateHidden: @@ -351,7 +357,6 @@ break; } _state = state; - [self setNeedsLayout]; } - (void)setLeftBound:(CGFloat)leftBound diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm index a36fc99f27..01314ff151 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm @@ -21,8 +21,6 @@ extern NSString * const kAlohalyticsTapEventKey; extern NSString * const kSearchStateWillChangeNotification; extern NSString * const kSearchStateKey; -extern char const * kAdForbiddenSettingsKey; - static NSString * const kCollectionCellPortrait = @"MWMBottomMenuCollectionViewPortraitCell"; static NSString * const kCollectionCelllandscape = @"MWMBottomMenuCollectionViewLandscapeCell"; @@ -130,6 +128,7 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) (MWMBottomMenuLayout *)self.buttonsCollectionView.collectionViewLayout; cvLayout.buttonsCount = [self additionalButtonsCount]; [self.additionalButtons reloadData]; + [(MWMBottomMenuView *)self.view refreshLayout]; } #pragma mark - Layout diff --git a/iphone/Maps/Classes/MapViewController.h b/iphone/Maps/Classes/MapViewController.h index 7dc96da2d5..460435e256 100644 --- a/iphone/Maps/Classes/MapViewController.h +++ b/iphone/Maps/Classes/MapViewController.h @@ -46,6 +46,7 @@ namespace search { struct AddressInfo; } - (void)openBookmarks; +- (void)refreshAd; @property (nonatomic) MTRGNativeAppwallAd * appWallAd; @property (nonatomic, readonly) BOOL isAppWallAdActive; diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index fc96a8c87b..defb854f82 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -36,6 +36,7 @@ extern NSString * const kAlohalyticsTapEventKey = @"$onClick"; static NSString * const kUDWhatsNewWasShown = @"WhatsNewWithTTSAndP2PWasShown"; extern char const * kAdForbiddenSettingsKey; +extern char const * kAdServerForbiddenKey; typedef NS_ENUM(NSUInteger, ForceRoutingStateChange) { @@ -543,7 +544,7 @@ typedef NS_ENUM(NSUInteger, UserTouchesAction) self.controlsManager.menuState = self.menuRestoreState; - [self setupMyTarget]; + [self refreshAd]; } - (void)viewDidLoad @@ -789,13 +790,13 @@ typedef NS_ENUM(NSUInteger, UserTouchesAction) #pragma mark - myTarget -- (void)setupMyTarget +- (void)refreshAd { - if (isIOSVersionLessThan(8)) - return; + bool adServerForbidden = false; + (void)Settings::Get(kAdServerForbiddenKey, adServerForbidden); bool adForbidden = false; (void)Settings::Get(kAdForbiddenSettingsKey, adForbidden); - if (adForbidden) + if (isIOSVersionLessThan(8) || adServerForbidden || adForbidden) { self.appWallAd = nil; return; @@ -819,7 +820,6 @@ typedef NS_ENUM(NSUInteger, UserTouchesAction) - (void)onNoAdWithReason:(NSString *)reason appwallAd:(MTRGNativeAppwallAd *)appwallAd { self.appWallAd = nil; - [self.controlsManager refreshLayout]; } #pragma mark - API bar @@ -960,6 +960,12 @@ NSInteger compareAddress(id l, id r, void * context) #pragma mark - Properties +- (void)setAppWallAd:(MTRGNativeAppwallAd *)appWallAd +{ + _appWallAd = appWallAd; + [self.controlsManager refreshLayout]; +} + - (MWMMapViewControlsManager *)controlsManager { if (!_controlsManager) diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 6d230125e1..1aea424489 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -53,6 +53,8 @@ extern string const kLanguageKey; extern NSString * const kUserDefaultsTTSLanguage; extern NSString * const kUserDafaultsNeedToEnableTTS; +extern char const * kAdServerForbiddenKey; + /// Adds needed localized strings to C++ code /// @TODO Refactor localization mechanism to make it simpler void InitLocalizedStrings() @@ -84,6 +86,8 @@ void InitLocalizedStrings() @property (nonatomic) NSInteger standbyCounter; +@property (weak, nonatomic) NSTimer * checkAdServerForbiddenTimer; + @end @implementation MapsAppDelegate @@ -208,6 +212,8 @@ void InitLocalizedStrings() [self showAlertIfRequired]; } + [self startAdServerForbiddenCheckTimer]; + Framework & f = GetFramework(); application.applicationIconBadgeNumber = f.GetCountryTree().GetActiveMapLayout().GetOutOfDateCount(); f.GetLocationState()->InvalidatePosition(); @@ -733,4 +739,33 @@ void InitLocalizedStrings() return difference.day; } +#pragma mark - Showcase + +- (void)checkAdServerForbidden +{ + NSURLSession * session = [NSURLSession sharedSession]; + NSURL * url = [NSURL URLWithString:@(AD_PERMISION_SERVER_URL)]; + NSURLSessionDataTask * task = [session dataTaskWithURL:url + completionHandler:^(NSData * data, NSURLResponse * response, + NSError * error) + { + bool adServerForbidden = (error || [(NSHTTPURLResponse *)response statusCode] != 200); + Settings::Set(kAdServerForbiddenKey, adServerForbidden); + dispatch_async(dispatch_get_main_queue(), ^{ [self.mapViewController refreshAd]; }); + }]; + [task resume]; +} + +- (void)startAdServerForbiddenCheckTimer +{ + [self checkAdServerForbidden]; + [self.checkAdServerForbiddenTimer invalidate]; + self.checkAdServerForbiddenTimer = + [NSTimer scheduledTimerWithTimeInterval:AD_PERMISION_CHECK_DURATION + target:self + selector:@selector(checkAdServerForbidden) + userInfo:nil + repeats:YES]; +} + @end diff --git a/iphone/Maps/Settings/SettingsViewController.mm b/iphone/Maps/Settings/SettingsViewController.mm index d81b7e7c71..7195f90460 100644 --- a/iphone/Maps/Settings/SettingsViewController.mm +++ b/iphone/Maps/Settings/SettingsViewController.mm @@ -18,6 +18,7 @@ extern char const * kStatisticsEnabledSettingsKey; char const * kAdForbiddenSettingsKey = "AdForbidden"; +char const * kAdServerForbiddenKey = "AdServerForbidden"; extern NSString * const kTTSStatusWasChangedNotification = @"TTFStatusWasChangedFromSettingsNotification"; typedef NS_ENUM(NSUInteger, Section) @@ -45,7 +46,9 @@ typedef NS_ENUM(NSUInteger, Section) self.title = L(@"settings"); self.tableView.backgroundView = nil; self.tableView.backgroundColor = [UIColor applicationBackgroundColor]; - if (isIOSVersionLessThan(8)) + bool adServerForbidden = false; + (void)Settings::Get(kAdServerForbiddenKey, adServerForbidden); + if (isIOSVersionLessThan(8) || adServerForbidden) sections = {SectionMetrics, SectionZoomButtons, SectionRouting, SectionCalibration, SectionStatistics}; else sections = {SectionMetrics, SectionZoomButtons, SectionRouting, SectionCalibration, SectionAd, SectionStatistics}; |