<commit_before>#import "AdmobBanner.h"
#include "reference.h"

@implementation AdmobBanner

- (void)dealloc {
    bannerView.delegate = nil;
    [bannerView release];
    [super dealloc];
}

- (void)initialize:(BOOL)is_real: (int)instance_id {
    isReal = is_real;
    initialized = true;
    instanceId = instance_id;
    rootController = (ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
}

- (void) loadBanner:(NSString*)bannerId: (BOOL)is_on_top {
    NSLog(@"Calling loadBanner");
    
    isOnTop = is_on_top;
    
    if (!initialized) {
        return;
    }
    

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    
    if (bannerView == nil) {
        if (orientation == 0 || orientation == UIInterfaceOrientationPortrait) { //portrait
            bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
        }
        else { //landscape
            bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape];
        }
        
        if(!isReal) {
            bannerView.adUnitID = @"ca-app-pub-3940256099942544/2934735716";
        }
        else {
            bannerView.adUnitID = bannerId;
        }

        bannerView.delegate = self;
        
        bannerView.rootViewController = rootController;
        [rootController.view addSubview:bannerView];
        
    }
    
    GADRequest *request = [GADRequest request];
    [bannerView loadRequest:request];
    
    
    float height = rootController.view.frame.size.height;
    float width = rootController.view.frame.size.width;
    
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { // landscape: swap width/height
        float tmp = height;
        height = width;
        width = tmp;
    }
    
    NSLog(@"height: %f, width: %f", height, width);

    if(!isOnTop) {
        [bannerView setFrame:CGRectMake(0, height-bannerView.bounds.size.height, bannerView.bounds.size.width, bannerView.bounds.size.height)];
    }
}



- (void)showBanner {
    NSLog(@"Calling showBanner");
    
    if (bannerView == nil || !initialized) {
        return;
    }
    
    [bannerView setHidden:NO];
}

- (void) hideBanner {
    NSLog(@"Calling hideBanner");
    if (bannerView == nil || !initialized) {
        return;
    }
    [bannerView setHidden:YES];
}

- (void) resize {<commit_msg>Displays banner inside safe area (iPhone X)<commit_after>#import "AdmobBanner.h"
#include "reference.h"

@implementation AdmobBanner

- (void)dealloc {
    bannerView.delegate = nil;
    [bannerView release];
    [super dealloc];
}

- (void)initialize:(BOOL)is_real: (int)instance_id {
    isReal = is_real;
    initialized = true;
    instanceId = instance_id;
    rootController = (ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
}

- (void) loadBanner:(NSString*)bannerId: (BOOL)is_on_top {
    NSLog(@"Calling loadBanner");
    
    isOnTop = is_on_top;
    
    if (!initialized) {
        return;
    }
    

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    
    if (bannerView == nil) {
        if (orientation == 0 || orientation == UIInterfaceOrientationPortrait) { //portrait
            bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
        }
        else { //landscape
            bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape];
        }
        
        if(!isReal) {
            bannerView.adUnitID = @"ca-app-pub-3940256099942544/2934735716";
        }
        else {
            bannerView.adUnitID = bannerId;
        }

        bannerView.delegate = self;
        bannerView.rootViewController = rootController;
        

        [self addBannerViewToView:bannerView:is_on_top];
    }
    
    GADRequest *request = [GADRequest request];
    [bannerView loadRequest:request];
    
}


- (void)addBannerViewToView:(UIView *_Nonnull)bannerView: (BOOL)is_on_top{
    bannerView.translatesAutoresizingMaskIntoConstraints = NO;
    [rootController.view addSubview:bannerView];
    if (@available(ios 11.0, *)) {
        [self positionBannerViewFullWidthAtSafeArea:bannerView:is_on_top];
    } else {
        [self positionBannerViewFullWidthAtView:bannerView:is_on_top];
    }
}



- (void)positionBannerViewFullWidthAtSafeArea:(UIView *_Nonnull)bannerView: (BOOL)is_on_top  NS_AVAILABLE_IOS(11.0) {
    UILayoutGuide *guide = rootController.view.safeAreaLayoutGuide;
    
    if (is_on_top) {
        [NSLayoutConstraint activateConstraints:@[
            [guide.leftAnchor constraintEqualToAnchor:bannerView.leftAnchor],
            [guide.rightAnchor constraintEqualToAnchor:bannerView.rightAnchor],
            [guide.topAnchor constraintEqualToAnchor:bannerView.topAnchor]
        ]];
    } else {
        [NSLayoutConstraint activateConstraints:@[
            [guide.leftAnchor constraintEqualToAnchor:bannerView.leftAnchor],
            [guide.rightAnchor constraintEqualToAnchor:bannerView.rightAnchor],
            [guide.bottomAnchor constraintEqualToAnchor:bannerView.bottomAnchor]
        ]];
    }
}


- (void)positionBannerViewFullWidthAtView:(UIView *_Nonnull)bannerView: (BOOL)is_on_top {
    
    [rootController.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                                    attribute:NSLayoutAttributeLeading
                                                                    relatedBy:NSLayoutRelationEqual
                                                                       toItem:rootController.view
                                                                    attribute:NSLayoutAttributeLeading
                                                                   multiplier:1
                                                                     constant:0]];
    [rootController.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                                    attribute:NSLayoutAttributeTrailing
                                                                    relatedBy:NSLayoutRelationEqual
                                                                       toItem:rootController.view
                                                                    attribute:NSLayoutAttributeTrailing
                                                                   multiplier:1
                                                                     constant:0]];
    
    if (is_on_top) {
        [rootController.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                                        attribute:NSLayoutAttributeTop
                                                                        relatedBy:NSLayoutRelationEqual
                                                                           toItem:rootController.topLayoutGuide
                                                                        attribute:NSLayoutAttributeTop
                                                                       multiplier:1
                                                                         constant:0]];
        
    } else {
        [rootController.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                              attribute:NSLayoutAttributeBottom
                                                              relatedBy:NSLayoutRelationEqual
                                                                 toItem:rootController.bottomLayoutGuide
                                                              attribute:NSLayoutAttributeTop
                                                             multiplier:1
                                                               constant:0]];
    }
}

- (void)showBanner {
    NSLog(@"Calling showBanner");
    
    if (bannerView == nil || !initialized) {
        return;
    }
    
    [bannerView setHidden:NO];
}

- (void) hideBanner {
    NSLog(@"Calling hideBanner");
    if (bannerView == nil || !initialized) {
        return;
    }
    [bannerView setHidden:YES];
}

- (void) resize {
{'fraction_non_alphanumeric': 0.08373916142059627, 'fraction_numerical': 0.008195747713505166, 'mean_word_length': 1.6645569620253164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 58, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7121608', 'n_tokens_mistral': 2165, 'n_tokens_neox': 2051, 'n_words': 324}