|
//
// bannerCell.m
// ThePaperHD
//
// Created by scar1900 on 15/1/26.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "bannerCell.h"
#import <AdsameCubeMaxSDK/AdsameCubeMaxSDK.h>
@interface bannerCell()<AdsameCubeMaxDelegate> {
NSInteger isSuccess;
}
@property(nonatomic, strong)UIView *bannerView;
@end
@implementation bannerCell
@synthesize adUrl = _adUrl;
@synthesize adView = _adView;
@synthesize delegate;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
isSuccess = -1;
}
return self;
}
- (void)setAdView:(UIView *)view {
_adView = view;
}
- (void)setAdUrl:(NSString *)url {
_adUrl = url;
if (isBlankString(url)) {
if ([self.delegate respondsToSelector:@selector(loadAdFailed)]) {
[self.delegate loadAdFailed];
}
return;
}
self.bannerView.backgroundColor = [UIColor clearColor];
//【倒退】新闻详情页:调节字号后,下方的广告栏会空出一块空白(bug:5744)
NSArray *list = [self.adUrl componentsSeparatedByRegex:@"&"];
__block NSString *bannerID;
[list enumerateObjectsUsingBlock:^(NSString* obj, NSUInteger idx, BOOL *stop) {
if ([obj isMatchedByRegex:@"c="]) {
bannerID = [obj stringByReplacingOccurrencesOfString:@"c=" withString:@""];
}
}];
if (!isBlankString(bannerID)) {
self.bannerView = [AdsameCubeMaxSDK getBannerWithCID:[bannerID intValue]
width:660
height:220
delegate:self];
self.bannerView.frame = CGRectMake(0, 0, 660, 220);
}
}
- (UIView*)bannerView {
if (!_bannerView) {
NSArray *list = [self.adUrl componentsSeparatedByRegex:@"&"];
__block NSString *bannerID;
[list enumerateObjectsUsingBlock:^(NSString* obj, NSUInteger idx, BOOL *stop) {
if ([obj isMatchedByRegex:@"c="]) {
bannerID = [obj stringByReplacingOccurrencesOfString:@"c=" withString:@""];
}
}];
if (!isBlankString(bannerID)) {
_bannerView = [AdsameCubeMaxSDK getBannerWithCID:[bannerID intValue]
width:660
height:220
delegate:self];
_bannerView.frame = CGRectMake(0, 0, 660, 220);
}
}
return _bannerView;
}
-(void)onAdsDataReady {
// isSuccess = 1;
// TPLOG(@"=======ad data is ready!=========%@",self.description);
// [self addSubview:self.bannerView];
}
-(void)onAdsLoadingFailed:(adsErrorCode)errorCode {
// isSuccess = 0;
// TPLOG(@"========load AD failed!========%@",self.description);
// if ([self.delegate respondsToSelector:@selector(loadAdFailed)]) {
// [self.delegate loadAdFailed];
// }
TPLOG(@"========load add failed!:%d========",errorCode);
if (errorCode == ADSAME_ADSERROR_RESOURCES_LOADED) {
isSuccess = 1;
TPLOG(@"=======ad data is ready!=========%@",self.description);
[self.contentView addSubview:self.bannerView];
}else if(errorCode == ADSAME_ADSERROR_INVALID_ADS || errorCode == ADSAME_ADSERROR_REQUEST_FAILED){
isSuccess = 0;
TPLOG(@"========load AD failed!========%@",self.description);
if ([self.delegate respondsToSelector:@selector(loadAdFailed)]) {
[self.delegate loadAdFailed];
}
}
}
-(Boolean)onAdsClicked:(NSString *)clickUrl {
TPLOG(@"======Click Ads:%@======",clickUrl);
remotePushBO *pushBO = remotePushBO.new;
if ([clickUrl hasPrefix:@"http"]) {
NSMutableArray *comList = [NSMutableArray arrayWithArray:[clickUrl componentsSeparatedByString:@"|"]];
if (comList.count == 1) {
pushBO.linkType = @"6";
pushBO.contId = clickUrl;
}else {
NSString *lastStr = [comList lastObject];
if ([lastStr hasPrefix:@"http"]) {
if ([lastStr isMatchedByRegex:@"__IDFA__"]) {
[lastStr stringByReplacingOccurrencesOfString:@"__IDFA__" withString:[TPUserDefault instance].IDFA];
}
[comList removeLastObject];
[Remote doSimpleAction:0 requestUrl:lastStr];
}
pushBO.linkType = @"6";
pushBO.contId = comList[0];
}
}else {
NSMutableArray *comList = [NSMutableArray arrayWithArray:[clickUrl componentsSeparatedByString:@"|"]];
if ([comList[0] intValue] == 6) {
if (comList.count != 2) {
NSString *lastStr = [comList lastObject];
if ([lastStr hasPrefix:@"http"]) {
if ([lastStr isMatchedByRegex:@"__IDFA__"]) {
[lastStr stringByReplacingOccurrencesOfString:@"__IDFA__" withString:[TPUserDefault instance].IDFA];
}
[comList removeLastObject];
[Remote doSimpleAction:0 requestUrl:lastStr];
}
}
}else {
NSString *lastStr = [comList lastObject];
if ([lastStr hasPrefix:@"http"]) {
if ([lastStr isMatchedByRegex:@"__IDFA__"]) {
[lastStr stringByReplacingOccurrencesOfString:@"__IDFA__" withString:[TPUserDefault instance].IDFA];
}
[comList removeLastObject];
[Remote doSimpleAction:0 requestUrl:lastStr];
}
}
if (comList.count == 3) {
[comList removeLastObject];
}
if (comList.count == 2) {
pushBO.linkType = comList[0];
pushBO.contId = comList[1];
}
if (comList.count == 4) {
pushBO.linkType = comList[0];
pushBO.contId = comList[2];
}
}
pushBO.isComeFromRemote = @"0";
if ([self.delegate respondsToSelector:@selector(clickAdd:)]) {
[self.delegate clickAdd:pushBO];
return YES;
}else return NO;
}
- (void)layoutSubviews {
CGFloat padding = 0;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
padding = 125;
}
self.bannerView.frame = CGRectMake(padding, CGRectGetHeight(self.bounds)/2-220/2, 660, 220);
[super layoutSubviews];
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|