小说绘上架版本

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
@@ -0,0 +1,54 @@
//
// TFAdvertisementBasicView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/*** 广告类型 ***/
typedef NS_ENUM(NSUInteger, TFAdvertisementType) {
TFAdvertisementTypeNone = 0, /*** 列表广告 ***/
TFAdvertisementTypeNovel = 1, /*** 小说广告 ***/
TFAdvertisementTypeComic = 2, /*** 漫画广告 ***/
};
/*** 广告位置 ***/
typedef NS_ENUM(NSUInteger, TFAdvertisementPosition) {
TFAdvertisementPositionNone = 0, /*** 列表广告 ***/
TFAdvertisementPositionEnd = 8, /*** 阅读器章节末尾广告 ***/
TFAdvertisementPositionBottom = 12, /*** 阅读器底部广告 ***/
TFAdvertisementPositionVideo = 13, /*** 激励视频广告 ***/
};
@interface TFAdvertisementBasicView : UIView
@property (nonatomic ,strong) TFAdvertModel *advertModel;
@property (nonatomic ,assign) TFAdvertisementPosition position;
@property (nonatomic ,assign) TFAdvertisementType type;
- (instancetype)initWithFrame:(CGRect)frame advertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position;
+ (instancetype)allocWithZone:(struct _NSZone *)zone UNAVAILABLE_ATTRIBUTE;
+ (instancetype)new UNAVAILABLE_ATTRIBUTE;
- (instancetype)init UNAVAILABLE_ATTRIBUTE;
- (instancetype)initWithFrame:(CGRect)frame UNAVAILABLE_ATTRIBUTE;
- (void)createSubviews;
// 广告点击
- (void)clickAd;
// 请求指定广告信息
- (void)requestAdvertisementWithType:(TFAdvertisementType)type advertisementPostion:(TFAdvertisementPosition)position complete:(void(^)(TFAdvertModel * _Nullable advertModel, NSString *msg))complete;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,52 @@
//
// TFAdvertisementBasicView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAdvertisementBasicView.h"
@implementation TFAdvertisementBasicView
- (instancetype)initWithFrame:(CGRect)frame advertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position
{
if (self = [super initWithFrame:frame]) {
self.type = type;
self.position = position;
[self createSubviews];
}
return self;
}
- (void)createSubviews
{
self.backgroundColor = kGrayViewColor;
}
- (void)clickAd
{
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"advert_id"] = [TFUtilsHelper formatStringWithInteger:self.advertModel.advert_id];
[TFNetworkTools POST:AdVert_Click parameters:params model:nil success:nil failure:nil];
}
- (void)requestAdvertisementWithType:(TFAdvertisementType)type advertisementPostion:(TFAdvertisementPosition)position complete:(void(^)(TFAdvertModel * _Nullable advertModel, NSString *msg))complete
{
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"type"] = @(type);
params[@"position"] = @(position);
[TFNetworkTools POST:Advert_Info parameters:params model:TFAdvertModel.class success:^(BOOL isSuccess, TFAdvertModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
!complete ?: complete(t_model, requestModel.msg ?: @"");
} else {
!complete ?: complete(nil, requestModel.msg ?: @"");
}
} failure:nil];
}
@end
@@ -0,0 +1,21 @@
//
// TFDiscoverComicAdvertisementCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFDiscoverComicAdvertisementCell : TFBasicTableViewCell
- (void)setAdModel:(TFAdvertModel * _Nonnull)adModel refresh:(BOOL)refresh;
@property (nonatomic ,weak) UITableView *mainTableView;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,100 @@
//
// TFDiscoverComicAdvertisementCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFDiscoverComicAdvertisementCell.h"
#import "TFAdvertisementManager.h"
@interface TFDiscoverComicAdvertisementCell ()
@property (nonatomic ,strong) TFAdvertModel *advertModel;
@property (nonatomic ,weak) TFAdvertisementManager *adView;
@property (nonatomic ,weak) UILabel *titleLabel;
@end
@implementation TFDiscoverComicAdvertisementCell
- (void)createSubviews
{
[super createSubviews];
TFAdvertisementManager *adView = [[TFAdvertisementManager alloc] initWithFrame:CGRectMake(kHalfMargin, kHalfMargin, SCREEN_WIDTH - kMargin, (SCREEN_WIDTH - 2 * kHalfMargin) / 2) advertisementType:TFAdvertisementTypeNone advertisementPosition:TFAdvertisementPositionNone];
self.adView = adView;
__weak typeof(adView) weakView = adView;
WS(weakSelf)
adView.closeBlock = ^{
[weakView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(1.0);
make.top.equalTo(self.contentView);
}];
[weakSelf.mainTableView reloadData];
};
adView.userInteractionEnabled = YES;
adView.layer.cornerRadius = 8.0f;
[self.contentView addSubview:adView];
[adView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kHalfMargin);
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kHalfMargin);
make.width.mas_equalTo(SCREEN_WIDTH - kMargin);
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH - kMargin, 7, 4));
}];
UILabel *titleLabel = [[UILabel alloc] init];
self.titleLabel = titleLabel;
titleLabel.textColor = kBlackColor;
titleLabel.textAlignment = NSTextAlignmentLeft;
titleLabel.font = kMainFont;
[self.contentView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.top.mas_equalTo(adView.mas_bottom).with.offset(kHalfMargin);
make.height.mas_equalTo(kMargin);
make.right.mas_equalTo(self.contentView.mas_right);
}];
UIView *splitLine = [[UIView alloc] init];
splitLine.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:splitLine];
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(titleLabel.mas_bottom).priorityLow();
make.left.right.bottom.equalTo(self.contentView);
make.height.mas_equalTo(0.1);
}];
}
- (void)setAdModel:(TFAdvertModel * _Nonnull)adModel refresh:(BOOL)refresh
{
if (refresh || (adModel.advert_id != _advertModel.advert_id)) {
adModel.ad_width = CGRectGetWidth(self.contentView.bounds);
adModel.ad_height = CGRectGetHeight(self.contentView.bounds);
_advertModel = adModel;
self.adView.advertModel = adModel;
if (adModel.ad_type == 1) {
[self.adView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo((SCREEN_WIDTH - 2 * kHalfMargin) / 2.0);
}];
} else {
[self.adView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo((SCREEN_WIDTH - 2 * kHalfMargin) * 1.0 / 3.0);
}];
}
self.titleLabel.text = adModel.ad_title ?: @"";
[self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
if (self.titleLabel.text.length == 0 || adModel.ad_type == 2) {
make.height.mas_equalTo(CGFLOAT_MIN);
} else {
make.height.mas_equalTo(kMargin);
}
}];
}
}
@end
@@ -0,0 +1,21 @@
//
// TFPublicAdvertisementViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFPublicAdvertisementViewCell : TFBasicTableViewCell
- (void)setAdModel:(TFAdvertModel * _Nonnull)adModel refresh:(BOOL)refresh;
@property (nonatomic ,weak) UITableView *mainTableView;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,63 @@
//
// TFPublicAdvertisementViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFPublicAdvertisementViewCell.h"
#import "TFWebViewController.h"
#import "TFAdvertisementManager.h"
@interface TFPublicAdvertisementViewCell ()
@property (nonatomic ,weak) TFAdvertisementManager *adView;
@property (nonatomic ,strong) TFAdvertModel *advertModel;
@end
@implementation TFPublicAdvertisementViewCell
- (void)createSubviews
{
[super createSubviews];
TFAdvertisementManager *adView = [[TFAdvertisementManager alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - kMargin, kGeometricHeight(SCREEN_WIDTH - kMargin, 3, 1)) advertisementType:TFAdvertisementTypeNone advertisementPosition:TFAdvertisementPositionNone];
__weak typeof(adView) weakView = adView;
WS(weakSelf)
adView.closeBlock = ^{
[weakView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(1.0);
}];
[weakSelf.mainTableView reloadData];
};
self.adView = adView;
[self.contentView addSubview:adView];
[adView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kHalfMargin);
make.centerY.mas_equalTo(self.contentView.mas_centerY);
make.width.mas_equalTo(SCREEN_WIDTH - kMargin);
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH - kMargin, 3, 1));
make.bottom.mas_equalTo(self.contentView.mas_bottom).priorityLow();
}];
}
- (void)setAdModel:(TFAdvertModel *)adModel refresh:(BOOL)refresh
{
if (refresh || (adModel.advert_id != _advertModel.advert_id)) {
_advertModel = adModel;
self.adView.advertModel = adModel;
if (adModel.ad_width > 0 && adModel.ad_height > 0) {
CGFloat scale = (CGFloat)adModel.ad_height / adModel.ad_width;
[self.adView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(CGRectGetWidth(self.adView.bounds) * scale);
}];
}
}
}
@end