WLNativeAdsTableMode.m 27.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
//
//  WLNativeAds.m
//  DemoApp
//
//  Created by Nick Xirotyris on 14/10/15.
//  Copyright © 2015 YC. All rights reserved.
//

#import "WLNativeAdsTableMode.h"
#import "Warply.h"
#import "WLAnalyticsManager.h"
#import <UIKit/UIKit.h>
#import "WLNativeAdTableViewCell.h"
#import <AVFoundation/AVFoundation.h>



@interface WLNativeAdsTableMode ()

@property (nonatomic, strong) id<UITableViewDelegate> originalDelegate;
@property (nonatomic, weak) id<UITableViewDataSource> originalDataSource;
@property (nonatomic, weak) UITableView *nativeTableView;
@property (nonatomic, weak) WLCustomNativeAdTableViewCell *customCell;
@property (nonatomic, strong) NSString *customCellIdentifier;
@property (nonatomic, strong) NSString *customCellNibName;

@property(nonatomic, weak) UIViewController <UITableViewDataSource,UITableViewDelegate> *originalVC;
@end

@implementation WLNativeAdsTableMode {
    NSArray *offersArray;
    CGFloat nativeAdHeight;
    NSInteger startAd;
    NSInteger frequencyAd;
    NSInteger totalOriginalRows;
    NSInteger totalExtraRows;
    NSInteger currentRows;
    NSInteger originalNumberOfsections;
    NSMutableArray *originalRowsPerSection;
    NSMutableArray *indexArrayOfAds;
    NSString *display_type;
    
    BOOL repeatableAds;
}



-(id)initWithViewController:(UIViewController <UITableViewDataSource,UITableViewDelegate> *)viewController Tableview:(UITableView *)tableView withStartPosition:(NSInteger)startPosition Frequency:(NSInteger)frequency Height:(CGFloat)adHeight andDisplayType:(NSString *)displayType{
    NSLog(@"%@", displayType);
    self = [super init];
    if (self) {
        
        [self.nativeTableView registerNib:[UINib nibWithNibName:@"WLNativeAdTableViewCell" bundle:nil] forCellReuseIdentifier:@"nativeCell"];
        [tableView registerNib:[UINib nibWithNibName:@"WLNativeAdTableViewCell" bundle:nil] forCellReuseIdentifier:@"nativeCell"];
        
        self.originalDataSource = tableView.dataSource;
        self.originalDelegate = tableView.delegate;
        self.nativeTableView = tableView;
        self.originalVC = viewController;
        
        if ([self.originalDataSource respondsToSelector:@selector(numberOfSectionsInTableView:)]) {
            originalNumberOfsections = [self.originalDataSource numberOfSectionsInTableView:tableView];
        } else {
            originalNumberOfsections = 1;
        }
        
        currentRows = 0;
        totalExtraRows = 0;
        startAd = startPosition;
        frequencyAd = frequency;
        nativeAdHeight = adHeight;
        display_type = displayType;
        repeatableAds = NO;
        
        [self getInbox];
        
//        tableView.dataSource = self.nativeTableView.dataSource;
//        tableView.delegate = self.nativeTableView.delegate;
        
    }
    
    return self;
}


- (void)refreshAdsForTableView:(UITableView *)tableView {
    self.originalDataSource = nil;
    self.originalDelegate = nil;
    self.nativeTableView = nil;
    tableView.dataSource = nil;
    tableView.delegate = nil;
    tableView.dataSource = self.originalVC;
    tableView.delegate = self.originalVC;
    
    self.originalDataSource = tableView.dataSource;
    self.originalDelegate = tableView.delegate;
    self.nativeTableView = tableView;
    
    if ([tableView.dataSource respondsToSelector:@selector(numberOfSectionsInTableView:)]) {
        originalNumberOfsections = [tableView.dataSource numberOfSectionsInTableView:tableView];
    } else {
        originalNumberOfsections = 1;
    }
    
    currentRows = 0;
    totalExtraRows = 0;
    
    [self getInbox];
}


-(void)setCustomCellForNativeAd:(WLCustomNativeAdTableViewCell *)cell withIdentifier:(NSString *)cellIdentifier andNibName:(NSString *)nibName {
    self.customCell = cell;
    self.customCellIdentifier = cellIdentifier;
    self.customCellNibName = nibName;
}


-(void)setRepeatable:(BOOL)repeatable {
    
    repeatableAds = repeatable;
    
    if (!repeatable) {
        int counter = 0;
        
        for (int i = 0; i < originalNumberOfsections; i++) {

            for (int j = 0; j < [[indexArrayOfAds objectAtIndex:i] count]; j++) {
                if ([[[indexArrayOfAds objectAtIndex:i] objectAtIndex:j] isEqual:@(YES)]) {
                    counter++;
                    if (counter > offersArray.count) {
                        [[indexArrayOfAds objectAtIndex:i] removeObjectAtIndex:j];
                    }
                }
                
            }
        }
        
        [self.nativeTableView reloadData];
        
    } else {
        NSLog(@"Nothing to remove");
    }
}


-(void)getInbox {

    [[Warply sharedService] getInboxWithSuccessBlock:^(NSArray *list) {

        NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"(display_type == '%@')", display_type]];
        offersArray = [list filteredArrayUsingPredicate:predicate];
        
        if (offersArray.count > 0) {
            [self setupNewRowsPerSection];
            [self setRepeatable:repeatableAds];
            self.nativeTableView.dataSource = self;
            self.nativeTableView.delegate = self;
            
            [self.nativeTableView reloadData];
        }
        
    } failureBlock:^(NSError *error) {
        //
    }];
}


#pragma mark - Original IndexPath & Helpers

-(NSIndexPath *)getOriginalIndexPath:(NSIndexPath *)indexPath {
    int extraRows = 0;

    for (int i = 0; i < indexPath.row; i++) {
        if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:i]  isEqual:@(YES)]) {
            extraRows++;
        }
    }
    
    return [NSIndexPath indexPathForRow:indexPath.row - extraRows inSection:indexPath.section];
}



- (void)setupNewRowsPerSection {
    
    indexArrayOfAds = [NSMutableArray array];
    int count = 0;
    
    for (int i = 0; i < originalNumberOfsections; i++) {
        NSMutableArray *newRows = [NSMutableArray array];
        NSInteger total = [self totalRowsWithAdsForSection:i];
        
        for (int j = 0; j < total; j++) {
            
            if (count == startAd || (count > startAd && (count - startAd)%(frequencyAd + 1) == 0)) {
                [newRows addObject:@(YES)];
            } else {
                [newRows addObject:@(NO)];
            }
            count++;
        }
        [indexArrayOfAds addObject:newRows];
    }
    
}




-(NSInteger)totalRowsWithAdsForSection:(int)section {
    
    NSInteger originalRows = [self.originalDataSource tableView:self.nativeTableView numberOfRowsInSection:section];
    currentRows += originalRows;
    
    if (currentRows < startAd) {
        return originalRows;
    } else {
        
        if (startAd + 1 >= currentRows - originalRows && startAd + 1 <= currentRows) {
            NSInteger extraRows = (currentRows - startAd)/frequencyAd  + 1;
            totalExtraRows += extraRows;
            return extraRows + originalRows;
        } else {
            
            NSInteger extraRowsSoFar = (currentRows - startAd)/frequencyAd + 1;
            NSInteger extraRowsForSection = extraRowsSoFar - totalExtraRows;
            totalExtraRows += extraRowsForSection;
            
            return originalRows + extraRowsForSection;
        }
    }
}


-(int)getIndexOfAd:(NSIndexPath *)indexPath {
    
    int adsCount = 0;
    
    for (int i = 0; i < indexPath.section + 1; i++) {
        
        int rows = 0;
        
        if (indexPath.section > i) {
            rows = (int)[[indexArrayOfAds objectAtIndex:i] count];
        } else {
            rows = (int)indexPath.row + 1;
        }
        
        for (int j = 0; j < rows; j++) {
            if ([[[indexArrayOfAds objectAtIndex:i] objectAtIndex:j]  isEqual:@(YES)]) {
                adsCount++;
            }
        }
        
    }
    
    if (adsCount == offersArray.count) {
        return adsCount-1;
    } else {
        return adsCount%offersArray.count - 1;
    }
    
    
}



#pragma mark - TableView Datasource


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return originalNumberOfsections;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [[indexArrayOfAds objectAtIndex:section] count];
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]  isEqual:@(YES)]) {
        
        if (self.customCell) {
            
            NSString *customIdentifier = [NSString stringWithFormat:@"%@", self.customCellIdentifier];
            
            WLCustomNativeAdTableViewCell *customCell = (WLCustomNativeAdTableViewCell *)[tableView dequeueReusableCellWithIdentifier:customIdentifier];
            
            if (self.customCellNibName) {
                if (customCell == nil) {
                    customCell = [[[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:@"%@", self.customCellNibName] owner:self options:nil] objectAtIndex:0];
                }
            }
            
            if (offersArray.count > 0) {
                WLInboxItem *item = (WLInboxItem *)offersArray[[self getIndexOfAd:indexPath]];
                [customCell setupCustomCell:item];
            }
            [WLAnalyticsManager logEventWithEventId:[NSString stringWithFormat:@"native_campaign_view:%@",customCell.item.session_uuid] pageId:@"" actionMetadata:nil];
            NSLog(@"LOG EVENT with Event ID : %@", [NSString stringWithFormat:@"native_campaign_view:%@", customCell.item.session_uuid]);
            
            return customCell;
            
        } else {
            
            WLNativeAdTableViewCell *cell = (WLNativeAdTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"nativeCell"];
            
            if (cell == nil) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"WLNativeAdTableViewCell" owner:self options:nil] objectAtIndex:0];
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            if (offersArray.count > 0) {
                
                WLInboxItem *item = (WLInboxItem *)offersArray[[self getIndexOfAd:indexPath]];
                
                if ([item.display_type isEqualToString:@"list"]) {
                    [cell setupCellWithItem:item];
                    //                [cell loadContentwithURL:[item getPageURL]];
                } else if  ([item.display_type isEqualToString:@"feed"]){
                    [cell loadContentwithURL:[item getPageURL]];
                }
            }
            [WLAnalyticsManager logEventWithEventId:[NSString stringWithFormat:@"native_campaign_view:%@", cell.item.session_uuid] pageId:@"" actionMetadata:nil];
            NSLog(@"LOG EVENT with Event ID : %@", [NSString stringWithFormat:@"native_campaign_view:%@", cell.item.session_uuid]);
            
            return cell;
        }
        
        
    } else {
        UITableViewCell *original = [self.originalDataSource tableView:self.nativeTableView cellForRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
        original.selectionStyle = UITableViewCellSelectionStyleNone;
        return original;
    }
    
}


-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]  isEqual:@(YES)]) {
        return NO;
    }
    else {
        if ([self.originalDataSource respondsToSelector:@selector(tableView:canEditRowAtIndexPath:)]) {
            return [self.originalDataSource tableView:self.nativeTableView canEditRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
        }
    }
    return YES;
}

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.originalDataSource respondsToSelector:@selector(tableView:canMoveRowAtIndexPath:)]) {
        return [self.originalDataSource tableView:self.nativeTableView canMoveRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
    }
    return NO;
}


-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
    if ([[[indexArrayOfAds objectAtIndex:sourceIndexPath.section] objectAtIndex:sourceIndexPath.row]  isEqual:@(YES)]) {
        return;
    }
    else {
        if ([self.originalDataSource respondsToSelector:@selector(tableView:moveRowAtIndexPath:toIndexPath:)]) {
            [self.originalDataSource tableView:self.nativeTableView moveRowAtIndexPath:[self getOriginalIndexPath:sourceIndexPath] toIndexPath:[self getOriginalIndexPath:destinationIndexPath]];
        }
    }
}


-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.originalDataSource respondsToSelector:@selector(tableView:commitEditingStyle:forRowAtIndexPath:)]) {
        [self.originalDataSource tableView:self.nativeTableView commitEditingStyle:editingStyle forRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
    }
}


-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if ([self.originalDataSource respondsToSelector:@selector(tableView:titleForHeaderInSection:)]) {
        return [self.originalDataSource tableView:self.nativeTableView titleForHeaderInSection:section];
    }
    return nil;
}

-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
    if ([self.originalDataSource respondsToSelector:@selector(tableView:titleForFooterInSection:)]) {
        return [self.originalDataSource tableView:self.nativeTableView titleForFooterInSection:section];
    }
    return nil;
}




#pragma mark - TableView Delegate


-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
    if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]  isEqual:@(YES)]) {
//        NSLog(@"Ad accessory button pressed pressed");
    }
    else {
        
        if ([self.originalDelegate respondsToSelector:@selector(tableView:accessoryButtonTappedForRowWithIndexPath:)]) {
            [self.originalDelegate tableView:self.nativeTableView accessoryButtonTappedForRowWithIndexPath:[self getOriginalIndexPath:indexPath]];
        }
    }
}




-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
    if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]  isEqual:@(YES)]) {
        return NO;
    }
    else {
        if ([self.originalDelegate respondsToSelector:@selector(tableView:canPerformAction:forRowAtIndexPath:withSender:)]) {
            return [self.originalDelegate tableView:self.nativeTableView canPerformAction:(SEL)action forRowAtIndexPath:[self getOriginalIndexPath:indexPath] withSender:sender];
        }
    }
    return NO;
}



-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]  isEqual:@(YES)]) {
        //NSLog(@"Will display Ad cell");
    }
    else {
        if ([self.originalDelegate respondsToSelector:@selector(tableView:willDisplayCell:forRowAtIndexPath:)]) {
            [self.originalDelegate tableView:self.nativeTableView willDisplayCell:cell forRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
        }
    }
}

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:didEndDisplayingCell:forRowAtIndexPath:)]) {
        [self.originalDelegate tableView:self.nativeTableView didEndDisplayingCell:cell forRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
    }
}


-(NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:editActionsForRowAtIndexPath:)]) {
        return [self.originalDelegate tableView:self.nativeTableView editActionsForRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
    }
    
    return nil;
}


-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:editingStyleForRowAtIndexPath:)]) {
        return [self.originalDelegate tableView:self.nativeTableView editingStyleForRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
    }
    return UITableViewCellEditingStyleNone;
}


-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:estimatedHeightForRowAtIndexPath:)]) {
        return [self.originalDelegate tableView:self.nativeTableView estimatedHeightForRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
    }
    
    return 80;
}



-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:indentationLevelForRowAtIndexPath:)]) {
        return [self.originalDelegate tableView:self.nativeTableView indentationLevelForRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
    }
    
    return 2;
}


-(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:performAction:forRowAtIndexPath:withSender:)]) {
        [self.originalDelegate tableView:self.nativeTableView performAction:(SEL)action forRowAtIndexPath:[self getOriginalIndexPath:indexPath] withSender:sender];
    }
    
    return;
}


-(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:shouldShowMenuForRowAtIndexPath:)]) {
        return [self.originalDelegate tableView:self.nativeTableView shouldShowMenuForRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
    }
    
    return NO;
}




-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]  isEqual:@(YES)]) {
        // NSLog(@"Will begin editing Ad cell");
    }
    else {
        if ([self.originalDelegate respondsToSelector:@selector(tableView:willBeginEditingRowAtIndexPath:)]) {
            [self.originalDelegate tableView:self.nativeTableView willBeginEditingRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
        }
    }
}


-(void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:didEndEditingRowAtIndexPath:)]) {
        [self.originalDelegate tableView:self.nativeTableView didEndEditingRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
    }
}


-(void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:didHighlightRowAtIndexPath:)]) {
        [self.originalDelegate tableView:self.nativeTableView didHighlightRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
    }
}


-(void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([self.originalDelegate respondsToSelector:@selector(tableView:didUnhighlightRowAtIndexPath:)]) {
        [self.originalDelegate tableView:self.nativeTableView didUnhighlightRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
    }
}




-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]  isEqual:@(YES)]) {
        
        WLInboxItem *item = (WLInboxItem *)offersArray[[self getIndexOfAd:indexPath]];
        
        if ([item.display_type isEqualToString:@"list"]) {
            return nativeAdHeight;
        } else if  ([item.display_type isEqualToString:@"feed"]){
            return 300;
        }
        
        return nativeAdHeight;
    } else {
        if ([self.originalDelegate respondsToSelector:@selector(tableView:heightForRowAtIndexPath:)]) {
            return [self.originalDelegate tableView:self.nativeTableView heightForRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
        }
    }
    
    return tableView.rowHeight;
}



-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]  isEqual:@(YES)]) {
       // NSLog(@"Will select ad");
    }
    else {
        if ([self.originalDelegate respondsToSelector:@selector(tableView:willSelectRowAtIndexPath:)]) {
            [self.originalDelegate tableView:self.nativeTableView willSelectRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
        }
    }
    
    return indexPath;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]  isEqual:@(YES)]) {
        NSLog(@"Ad pressed");
        
        if (offersArray.count > 0) {
            
            WLInboxItem *item = (WLInboxItem *)offersArray[[self getIndexOfAd:indexPath]];
            
            if ([[self delegate] respondsToSelector:@selector(nativeAdDidSelectWithItem:)]) {
                [[self delegate] nativeAdDidSelectWithItem:item];
            }
            
            [WLAnalyticsManager logEventWithEventId:[NSString stringWithFormat:@"native_campaign_click:%@", item.session_uuid] pageId:@"" actionMetadata:nil];
            NSLog(@"LOG EVENT with Event ID : %@", [NSString stringWithFormat:@"native_campaign_click:%@", item.session_uuid]);
        }
        
    }
    else {
        if ([self.originalDelegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
            [self.originalDelegate tableView:self.nativeTableView didSelectRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
        }
    }
}


-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]  isEqual:@(YES)]) {
       // NSLog(@"Ad deselected");
    }
    else {
        if ([self.originalDelegate respondsToSelector:@selector(tableView:didDeselectRowAtIndexPath:)]) {
            [self.originalDelegate tableView:self.nativeTableView didDeselectRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
        }
    }
}


-(NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([[[indexArrayOfAds objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]  isEqual:@(YES)]) {
        //NSLog(@"Will deselect ad");
    }
    else {
        if ([self.originalDelegate respondsToSelector:@selector(tableView:willDeselectRowAtIndexPath:)]) {
            [self.originalDelegate tableView:self.nativeTableView willDeselectRowAtIndexPath:[self getOriginalIndexPath:indexPath]];
        }
    }
    
    return indexPath;
}




-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    if ([self.originalDelegate respondsToSelector:@selector(tableView:viewForFooterInSection:)]) {
        return [self.originalDelegate tableView:self.nativeTableView viewForFooterInSection:section];
    }
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}



-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    if ([self.originalDelegate respondsToSelector:@selector(tableView:viewForHeaderInSection:)]) {
        return [self.originalDelegate tableView:self.nativeTableView viewForHeaderInSection:section];
    }
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}



-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:heightForHeaderInSection:)]) {
        return [self.originalDelegate tableView:self.nativeTableView heightForHeaderInSection:section];
    }
    
    if ([self.originalDelegate respondsToSelector:@selector(tableView:viewForHeaderInSection:)]) {
        UIView *header =  (UIView *)[self.originalDelegate tableView:self.nativeTableView viewForHeaderInSection:section];
        return header.bounds.size.height;
    }
    
    
    return 0;
}


//-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section {
//    if ([self.originalDelegate respondsToSelector:@selector(tableView:estimatedHeightForHeaderInSection:)]) {
//        return [self.originalDelegate tableView:self.nativeTableView estimatedHeightForHeaderInSection:section];
//    }
//    return 0;
//}



- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:heightForFooterInSection:)]) {
        return [self.originalDelegate tableView:self.nativeTableView heightForFooterInSection:section];
    }
    
    if ([self.originalDelegate respondsToSelector:@selector(tableView:viewForFooterInSection:)]) {
        UIView *footer =  (UIView *)[self.originalDelegate tableView:self.nativeTableView viewForFooterInSection:section];
        return footer.bounds.size.height;
    }
    
    return 0;
}


//-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section {
//    if ([self.originalDelegate respondsToSelector:@selector(tableView:estimatedHeightForFooterInSection:)]) {
//        return [self.originalDelegate tableView:self.nativeTableView estimatedHeightForFooterInSection:section];
//    }
//    return 0;
//}



-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    
    if ([self.originalDelegate respondsToSelector:@selector(tableView:willDisplayHeaderView:forSection:)]) {
        [self.originalDelegate tableView:self.nativeTableView willDisplayHeaderView:view forSection:section];
    }
}

-(void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:didEndDisplayingHeaderView:forSection:)]) {
        [self.originalDelegate tableView:self.nativeTableView didEndDisplayingHeaderView:view forSection:section];
    }
}


-(void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section {
    
    if ([self.originalDelegate respondsToSelector:@selector(tableView:willDisplayFooterView:forSection:)]) {
        [self.originalDelegate tableView:self.nativeTableView willDisplayFooterView:view forSection:section];
    }
}


-(void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section {
    if ([self.originalDelegate respondsToSelector:@selector(tableView:didEndDisplayingFooterView:forSection:)]) {
        [self.originalDelegate tableView:self.nativeTableView didEndDisplayingFooterView:view forSection:section];
    }
}


@end