小说绘上架版本

This commit is contained in:
xtfei2011
2021-02-07 11:24:08 +08:00
commit ee5c1c8b12
1762 changed files with 115892 additions and 0 deletions
@@ -0,0 +1,26 @@
//
// TFAdvertisementManager.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFAdvertisementBasicView.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFAdvertisementManager : TFAdvertisementBasicView
// 广告关闭时的回调
@property (nonatomic ,copy) void(^closeBlock)(void);
// 广告当前时间戳
@property (nonatomic ,assign ,class) NSInteger adTimestamp;
// 是否需要展示指定广告
+ (BOOL)whetherToLoadAdsWithAdvertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,162 @@
//
// TFAdvertisementManager.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAdvertisementManager.h"
#import "TFAdvertisementWebView.h"
#import "AppDelegate.h"
#if TF_Enable_Third_Party_Ad
#import <BUAdSDK/BUBannerAdView.h>
#endif
#import "WXYZ_ADPangolinView.h"
@interface TFAdvertisementManager ()
@property (nonatomic ,weak) TFAdvertisementWebView *webView;
@property (nonatomic ,weak) WXYZ_ADPangolinView *adPangolinView;
@end
@implementation TFAdvertisementManager
+ (BOOL)whetherToLoadAdsWithAdvertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position
{
AppDelegate *appDelegate = (AppDelegate *)kRCodeSync([[UIApplication sharedApplication] delegate]);
switch (position) {
case TFAdvertisementPositionEnd: {
if (type == TFAdvertisementTypeNovel) {
return appDelegate.checkSettingModel.ad_status_setting.chapter_read_end;
} else if (type == TFAdvertisementTypeComic) {
return appDelegate.checkSettingModel.ad_status_setting.comic_read_end;
} else {
return NO;
}
}
break;
case TFAdvertisementPositionBottom: {
if (type == TFAdvertisementTypeNovel) {
return appDelegate.checkSettingModel.ad_status_setting.chapter_read_bottom;
} else {
return NO;
}
}
break;
default:
return YES;
}
}
- (instancetype)initWithFrame:(CGRect)frame advertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position
{
if (![self.class whetherToLoadAdsWithAdvertisementType:type advertisementPosition:position]) return nil;
if (self = [super initWithFrame:frame advertisementType:type advertisementPosition:position]) {
[self initialize];
[self netRequest];
}
return self;
}
- (void)setAdvertModel:(TFAdvertModel *)advertModel
{
[super setAdvertModel:advertModel];
if (advertModel.ad_type == 1) { // 内部广告
self.webView.advertModel = advertModel;
self.webView.hidden = NO;
self.adPangolinView.hidden = YES;
return;
}
if (advertModel.ad_type == 2) { // 穿山甲广告
self.adPangolinView.advertModel = advertModel;
self.adPangolinView.hidden = NO;
self.webView.hidden = YES;
return;
}
}
- (void)setCloseBlock:(void (^)(void))closeBlock
{
_closeBlock = closeBlock;
self.adPangolinView.closeBlock = closeBlock;
}
- (void)initialize
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveTimestamp) name:UIApplicationWillResignActiveNotification object:nil];
}
- (void)createSubviews
{
TFAdvertisementWebView *webView = [[TFAdvertisementWebView alloc] initWithFrame:self.bounds advertisementType:self.type advertisementPosition:self.position];
webView.hidden = YES;
self.webView = webView;
[self addSubview:webView];
[webView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
WXYZ_ADPangolinView *adPangolinView = [[WXYZ_ADPangolinView alloc] initWithFrame:self.bounds advertisementType:self.type advertisementPosition:self.position];
adPangolinView.hidden = YES;
self.adPangolinView = adPangolinView;
[self addSubview:adPangolinView];
[adPangolinView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
}
- (void)netRequest
{
if (self.position == 0 || self.type == 0) return;
WS(weakSelf)
[super requestAdvertisementWithType:self.type advertisementPostion:self.position complete:^(TFAdvertModel * _Nullable adModel, NSString * _Nonnull msg) {
if (adModel) {
_adTimestamp = [adModel.timestamp integerValue];
weakSelf.advertModel = adModel;
} else {
weakSelf.frame = CGRectZero;
}
}];
}
- (void)dealloc
{
[self saveTimestamp];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
static NSInteger _adTimestamp;
+ (NSInteger)adTimestamp
{
if (!_adTimestamp) {
_adTimestamp = [[NSUserDefaults standardUserDefaults] integerForKey:TF_Reader_Ad_Timestamp];
}
return _adTimestamp;
}
+ (void)setAdTimestamp:(NSInteger)adTimestamp
{
_adTimestamp = adTimestamp;
}
- (void)saveTimestamp
{
[[NSUserDefaults standardUserDefaults] setInteger:_adTimestamp forKey:TF_Reader_Ad_Timestamp];
}
@end
@@ -0,0 +1,18 @@
//
// TFAdvertisementWebView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFAdvertisementBasicView.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFAdvertisementWebView : TFAdvertisementBasicView
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,153 @@
//
// 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