小说绘上架版本

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,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