You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
6.0 KiB
154 lines
6.0 KiB
4 years ago
|
//
|
||
|
// TFAdvertisementWebView.m
|
||
|
// TFReader
|
||
|
//
|
||
|
// Created by 谢腾飞 on 2020/12/23.
|
||
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TFAdvertisementWebView.h"
|
||
|
#import "TFWebViewController.h"
|
||
|
#import "TFReaderSettingHelper.h"
|
||
|
#import "AppDelegate.h"
|
||
|
#import "UIView+LayoutCallback.h"
|
||
|
#import "WXYZ_ADPangolinVideo.h"
|
||
|
|
||
|
@interface TFAdvertisementWebView ()
|
||
|
|
||
|
@property (nonatomic ,weak) YYAnimatedImageView *webImageView;
|
||
|
@property (nonatomic ,weak) UILabel *titleLabel;
|
||
|
@property (nonatomic ,weak) UILabel *subtitle;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation TFAdvertisementWebView
|
||
|
|
||
|
- (instancetype)initWithFrame:(CGRect)frame advertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position
|
||
|
{
|
||
|
if (self = [super initWithFrame:frame advertisementType:type advertisementPosition:position]) {
|
||
|
[self createSubViews];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)createSubViews
|
||
|
{
|
||
|
self.backgroundColor = [UIColor clearColor];
|
||
|
YYAnimatedImageView *webImageView = [[YYAnimatedImageView alloc] init];
|
||
|
self.webImageView = webImageView;
|
||
|
webImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||
|
webImageView.layer.masksToBounds = YES;
|
||
|
webImageView.userInteractionEnabled = YES;
|
||
|
[webImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAd)]];
|
||
|
[self addSubview:webImageView];
|
||
|
|
||
|
if (self.position == TFAdvertisementPositionEnd && self.type == TFAdvertisementTypeNovel) {
|
||
|
UILabel *subtitle = [[UILabel alloc] init];
|
||
|
self.subtitle = subtitle;
|
||
|
subtitle.backgroundColor = [UIColor clearColor];
|
||
|
UIColor *textColor = [TFReaderSettingHelper sharedManager].getReaderTextColor;
|
||
|
subtitle.textColor = textColor;
|
||
|
subtitle.font = kFont14;
|
||
|
AppDelegate *delegate = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
|
||
|
subtitle.text = [NSString stringWithFormat:@"%@%@", delegate.checkSettingModel.ad_status_setting.video_ad_text ?: @"", @">"];
|
||
|
[self addSubview:subtitle];
|
||
|
subtitle.frameBlock = ^(UIView * _Nonnull view) {
|
||
|
[view addBorderLineWithBorderWidth:1.0 borderColor:textColor cornerRadius:0.0 borderType:UIBorderSideTypeBottom];
|
||
|
};
|
||
|
subtitle.userInteractionEnabled = YES;
|
||
|
[subtitle addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(watchVideo)]];
|
||
|
|
||
|
UILabel *titleLabel = [[UILabel alloc] init];
|
||
|
self.titleLabel = titleLabel;
|
||
|
titleLabel.backgroundColor = [UIColor clearColor];
|
||
|
titleLabel.text = TFLocalizedString(@"点击/滑动可继续阅读");
|
||
|
textColor = [textColor colorWithAlphaComponent:0.4];
|
||
|
titleLabel.textColor = textColor;
|
||
|
titleLabel.textAlignment = NSTextAlignmentCenter;
|
||
|
titleLabel.font = kFont17;
|
||
|
[self addSubview:titleLabel];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)setAdvertModel:(TFAdvertModel *)advertModel
|
||
|
{
|
||
|
[super setAdvertModel:advertModel];
|
||
|
|
||
|
[self.webImageView setImageWithURL:[NSURL URLWithString:advertModel.ad_image ? : @""] placeholder:HoldImage options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
|
||
|
|
||
|
switch (self.position) {
|
||
|
case TFAdvertisementPositionNone: {
|
||
|
self.webImageView.layer.cornerRadius = 9.5;
|
||
|
[self.webImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.edges.equalTo(self);
|
||
|
}];
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case TFAdvertisementPositionEnd: {
|
||
|
if (self.type == TFAdvertisementTypeNovel) {
|
||
|
self.titleLabel.hidden = NO;
|
||
|
AppDelegate *delegate = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
|
||
|
self.subtitle.hidden = !delegate.checkSettingModel.ad_status_setting.video_ad_switch;
|
||
|
}
|
||
|
self.webImageView.layer.cornerRadius = 12.5;
|
||
|
CGFloat scale = 1.0 / 1.2;
|
||
|
|
||
|
[self.webImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.center.width.equalTo(self);
|
||
|
make.height.equalTo(self.mas_width).multipliedBy(scale);
|
||
|
}];
|
||
|
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.top.equalTo(self.webImageView.mas_bottom);
|
||
|
make.bottom.equalTo(self.subtitle.mas_top);
|
||
|
make.left.right.equalTo(self);
|
||
|
}];
|
||
|
[self.subtitle mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.bottom.equalTo(self).offset(-kHalfMargin);
|
||
|
make.centerX.equalTo(self);
|
||
|
make.height.mas_equalTo(20);
|
||
|
}];
|
||
|
}
|
||
|
break;
|
||
|
default:
|
||
|
{
|
||
|
[self.webImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.edges.equalTo(self);
|
||
|
}];
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)clickAd
|
||
|
{
|
||
|
[super clickAd];
|
||
|
if (kObjectIsEmpty(self.advertModel.ad_skip_url)) {
|
||
|
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"链接错误,请联系客服")];
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (self.advertModel.ad_url_type == 1) {
|
||
|
TFWebViewController *vc = [[TFWebViewController alloc] init];
|
||
|
vc.navTitle = self.advertModel.ad_title;
|
||
|
vc.URLString = self.advertModel.ad_skip_url;
|
||
|
vc.isPresentState = NO;
|
||
|
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:nil];
|
||
|
[[TFViewHelper getCurrentNavigationController] pushViewController:vc animated:YES];
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (self.advertModel.ad_url_type == 2) {
|
||
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.advertModel.ad_skip_url] options:@{} completionHandler:nil];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 观看激励视频
|
||
|
- (void)watchVideo
|
||
|
{
|
||
|
WXYZ_ADPangolinVideo *video = [[WXYZ_ADPangolinVideo alloc] initWithFrame:CGRectZero advertisementType:self.type advertisementPosition:self.position];
|
||
|
// [video show];
|
||
|
}
|
||
|
|
||
|
@end
|