小说绘上架版本

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,18 @@
//
// TFDiscoverAudioViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFDiscoverAudioViewController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,303 @@
//
// TFDiscoverAudioViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFDiscoverAudioViewController.h"
#import "TFLimitFreeViewController.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "TFDiscoverHeaderView.h"
#import "TFBannerActionManager.h"
@interface TFDiscoverAudioViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) TFBookStoreModel *audioDiscoverModel;
@property (nonatomic ,strong) TFDiscoverHeaderView *headerView;
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFDiscoverAudioViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenNavigationBar:YES];
}
- (void)createSubviews
{
self.mainTableViewGroup.delegate = self;
self.mainTableViewGroup.dataSource = self;
[self.view addSubview:self.mainTableViewGroup];
[self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(PUB_NAVBAR_HEIGHT);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_TABBAR_HEIGHT - PUB_NAVBAR_HEIGHT);
}];
WS(weakSelf)
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
self.headerView = [[TFDiscoverHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
self.headerView.bannerrImageClickBlock = ^(TFBannerModel * _Nonnull bannerModel) {
TFBasicViewController *vc = [TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeAudio];
if (vc) {
[weakSelf.navigationController pushViewController:vc animated:YES];
}
};
[self.mainTableViewGroup setTableHeaderView:self.headerView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.audioDiscoverModel.label.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreLabelModel *labelModel = [self.audioDiscoverModel.label objectOrNilAtIndex:indexPath.section];
for (TFProductionModel *t_model in labelModel.list) {
t_model.productionType = self.productionType;
}
if (labelModel.ad_type == 0) {
switch (labelModel.style) {
case 1:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleOneCell.class indexPath:indexPath labelModel:labelModel];
break;
case 2:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleTwoCell.class indexPath:indexPath labelModel:labelModel];
break;
case 3:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleThreeCell.class indexPath:indexPath labelModel:labelModel];
break;
case 4:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleFourCell.class indexPath:indexPath labelModel:labelModel];
break;
default:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleOneCell.class indexPath:indexPath labelModel:labelModel];
break;
}
} else {
return [self createAdStyleCellWithTableView:tableView indexPath:indexPath adModel:labelModel];
}
}
- (UITableViewCell *)createCellWithTabelView:(UITableView *)tableView cellClass:(Class)cellClass indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
WS(weakSelf)
TFBookStoreNovelBasicViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(cellClass)];
if (!cell) {
cell = [[cellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(cellClass)];
}
cell.labelModel = labelModel;
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init];
vc.audio_id = production_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (UITableViewCell *)createAdStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath adModel:(TFBookStoreLabelModel *)labelModel
{
static NSString *cellName = @"TFPublicAdvertisementViewCell";
TFPublicAdvertisementViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
[cell setAdModel:labelModel refresh:self.needRefresh];
cell.mainTableView = tableView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
TFBookStoreLabelModel *labelModel = [self.audioDiscoverModel.label objectOrNilAtIndex:section];
if (labelModel.can_more || labelModel.can_refresh) {
return 50;
}
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
view.backgroundColor = [UIColor whiteColor];
CGFloat buttonX = SCREEN_WIDTH / 4;
CGFloat buttonY = 10;
CGFloat buttonW = SCREEN_WIDTH / 2;
CGFloat buttonH = 30;
TFBookStoreLabelModel *labelModel = [self.audioDiscoverModel.label objectOrNilAtIndex:section];
if (!labelModel.can_more && !labelModel.can_refresh) {
return view;
}
TFButton *moreButton = [TFButton initWithFrame:CGRectMake(buttonX, buttonY, buttonW, buttonH) btnTitle:TFLocalizedString(@"更多") btnImageName:@"comic_mall_more" backgroundColor:kGrayViewColor btnTintColor:kGrayTextLightColor btnStyle:TFButtonIndicatorTitleLeft cornerRadius:15 target:self action:@selector(moreButtonClick:)];
moreButton.graphicDistance = 5;
moreButton.tag = section;
[moreButton addTarget:self action:@selector(moreButtonClick:) forControlEvents:UIControlEventTouchUpInside];
TFButton *changeButton = [TFButton initWithFrame:CGRectMake(buttonX, 0, buttonW, buttonH) btnTitle:TFLocalizedString(@"换一换") btnImageName:@"comic_mall_refresh" backgroundColor:kGrayViewColor btnTintColor:kGrayTextLightColor btnStyle:TFButtonIndicatorTitleLeft cornerRadius:15 target:self action:@selector(changeButtonClick:)];
changeButton.graphicDistance = 5;
changeButton.buttonImageScale = 0.5;
changeButton.tag = section;
[changeButton addTarget:self action:@selector(changeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
if (labelModel.can_more && !labelModel.can_refresh) {
[view addSubview:moreButton];
}
if (!labelModel.can_more && labelModel.can_refresh) {
[view addSubview:changeButton];
}
if (labelModel.can_more && labelModel.can_refresh) {
moreButton.frame = CGRectMake(kMargin, buttonY, (SCREEN_WIDTH - 3 * kMargin) / 2, buttonH);
changeButton.frame = CGRectMake(2 * kMargin + (SCREEN_WIDTH - 3 * kMargin) / 2, buttonY, (SCREEN_WIDTH - 3 * kMargin) / 2, buttonH);
[view addSubview:moreButton];
[view addSubview:changeButton];
}
return view;
}
- (void)moreButtonClick:(UIButton *)sender
{
TFBookStoreLabelModel *t_labelModel = [self.audioDiscoverModel.label objectOrNilAtIndex:sender.tag];
if (t_labelModel.expire_time > 0) {
TFLimitFreeViewController *vc = [[TFLimitFreeViewController alloc] init];
vc.productionType = self.productionType;
[self.navigationController pushViewController:vc animated:YES];
} else {
TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init];
vc.productionType = self.productionType;
vc.recommend_id = [TFUtilsHelper formatStringWithInteger:t_labelModel.recommend_id];
[self.navigationController pushViewController:vc animated:YES];
}
}
- (void)changeButtonClick:(UIButton *)sender
{
TFButton *button = (TFButton *)sender;
[button startSpin];
[self changeRecommendRequestAtIndex:sender.tag complete:^{
[button stopSpin];
}];
}
- (void)changeRecommendRequestAtIndex:(NSInteger)index complete:(void(^)(void))complete
{
TFBookStoreLabelModel *t_labelModel = [self.audioDiscoverModel.label objectOrNilAtIndex:index];
if (t_labelModel.recommend_id <= 0) {
return;
}
WS(weakSelf)
[TFNetworkTools POST:Audio_Refresh parameters:@{@"recommend_id":[TFUtilsHelper formatStringWithInteger:t_labelModel.recommend_id]} model:TFBookStoreLabelModel.class success:^(BOOL isSuccess, TFBookStoreLabelModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess && t_model.list.count > 0) {
for (TFProductionModel *obj in t_model.list) {
obj.productionType = weakSelf.productionType;
}
[weakSelf.audioDiscoverModel.label objectAtIndex:index].list = t_model.list;
TFBookStoreNovelBasicViewCell *cell = [weakSelf.mainTableViewGroup cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:index]];
t_model.style = cell.labelModel.style;
cell.labelModel = t_model;
!complete ?: complete();
} else {
!complete ?: complete();
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
!complete ?: complete();
}];
}
- (void)netRequest
{
WS(weakSelf)
[TFNetworkTools POSTQuick:Audio_Discover parameters:nil model:TFBookStoreModel.class success:^(BOOL isSuccess, TFBookStoreModel * _Nullable t_model, BOOL isCache, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.headerView.banner = t_model.banner;
if (t_model.banner.count > 0) {
weakSelf.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH / 4);
} else {
weakSelf.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN);
}
weakSelf.audioDiscoverModel = t_model;
}
[weakSelf.mainTableViewGroup endRefreshing];
weakSelf.needRefresh = YES;
[weakSelf.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableViewGroup endRefreshing];
}];
}
@end
@@ -0,0 +1,18 @@
//
// TFDiscoverComicViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFDiscoverComicViewController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,161 @@
//
// TFDiscoverComicViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFDiscoverComicViewController.h"
#import "TFDiscoverComicViewCell.h"
#import "TFDiscoverComicAdvertisementCell.h"
#import "TFDiscoverHeaderView.h"
#import "TFDiscoverComicModel.h"
#import "TFBannerActionManager.h"
@interface TFDiscoverComicViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) TFDiscoverComicModel *comicDiscoverModel;
@property (nonatomic ,strong) TFDiscoverHeaderView *headerView;
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFDiscoverComicViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenNavigationBar:YES];
}
- (void)createSubviews
{
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
[self.view addSubview:self.mainTableView];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(PUB_NAVBAR_HEIGHT);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height).with.offset(-PUB_TABBAR_HEIGHT - PUB_NAVBAR_HEIGHT);
}];
WS(weakSelf)
self.headerView = [[TFDiscoverHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
self.headerView.bannerrImageClickBlock = ^(TFBannerModel * _Nonnull bannerModel) {
if ([TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeComic]) {
[weakSelf.navigationController pushViewController:[TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeComic] animated:YES];
}
};
[self.mainTableView setTableHeaderView:self.headerView];
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
[self.mainTableView.mj_header beginRefreshing];
self.mainTableView.mj_footer = [TFRefreshFooter footerWithRefreshingBlock:^{
weakSelf.currentPageNumber ++;
[weakSelf netRequest];
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.comicDiscoverModel.item_list.list.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *productionModel = [self.comicDiscoverModel.item_list.list objectOrNilAtIndex:indexPath.row];
if (productionModel.ad_type == 0) {
TFDiscoverComicViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFDiscoverComicViewCell"];
if (!cell) {
cell = [[TFDiscoverComicViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFDiscoverComicViewCell"];
}
cell.discoverComic = [self.comicDiscoverModel.item_list.list objectOrNilAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
} else {
static NSString *cellName = @"TFDiscoverComicAdvertisementCell";
TFDiscoverComicAdvertisementCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFDiscoverComicAdvertisementCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
[cell setAdModel:productionModel refresh:self.needRefresh];
cell.mainTableView = tableView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *productionModel = [self.comicDiscoverModel.item_list.list objectOrNilAtIndex:indexPath.row];
TFComicDetailViewController *comicDetail = [[TFComicDetailViewController alloc] init];
comicDetail.comic_id = productionModel.production_id;
[self.navigationController pushViewController:comicDetail animated:YES];
}
- (void)netRequest
{
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"channel_id"] = @(TFSystemInfoManager.sexChannel);
params[@"page_num"] = @(self.currentPageNumber);
[TFNetworkTools POSTQuick:Comic_Discover parameters:params model:TFDiscoverComicModel.class success:^(BOOL isSuccess, TFDiscoverComicModel * _Nullable discoverComicModel, BOOL isCache, TFNetworkRequestModel * _Nonnull requestModel) {
[weakSelf.mainTableView endRefreshing];
if (isSuccess) {
weakSelf.headerView.banner = discoverComicModel.banner;
weakSelf.comicDiscoverModel = discoverComicModel;
if (weakSelf.comicDiscoverModel.banner.count > 0) {
weakSelf.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH / 4);
} else {
weakSelf.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN);
}
if (discoverComicModel.item_list.current_page >= discoverComicModel.item_list.total_page) {
[weakSelf.mainTableView hideRefreshFooter];
}
[weakSelf.mainTableView setTableHeaderView:weakSelf.headerView];
}
weakSelf.needRefresh = YES;
[weakSelf.mainTableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
} failure:nil];
}
@end
@@ -0,0 +1,21 @@
//
// TFDiscoverComicModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFProductionModel, TFTagModel, TFBannerModel;
@interface TFDiscoverComicModel : NSObject
@property (nonatomic ,strong) NSArray <TFBannerModel *>*banner;
@property (nonatomic ,strong) TFProductionListModel *item_list;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,18 @@
//
// TFDiscoverComicModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFDiscoverComicModel.h"
@implementation TFDiscoverComicModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{@"banner" : [TFBannerModel class]};
}
@end
@@ -0,0 +1,19 @@
//
// TFDiscoverComicViewCell.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 TFDiscoverComicViewCell : TFBasicTableViewCell
@property (nonatomic ,strong) TFProductionModel *discoverComic;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,111 @@
//
// TFDiscoverComicViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFDiscoverComicViewCell.h"
#import "TFTagboardView.h"
@interface TFDiscoverComicViewCell ()
@property (nonatomic ,strong) UIImageView *coverView;
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) UILabel *flagLabel;
@property (nonatomic ,strong) TFTagboardView *tagboardView;
@end
@implementation TFDiscoverComicViewCell
- (void)createSubviews
{
[super createSubviews];
self.coverView = [[UIImageView alloc] initWithCornerRadiusAdvance:8 rectCornerType:UIRectCornerAllCorners];
self.coverView.frame = CGRectMake(kHalfMargin, kHalfMargin, SCREEN_WIDTH - kMargin, kGeometricHeight(SCREEN_WIDTH - kMargin, 7, 4));
self.coverView.image = HoldImage;
self.coverView.layer.shadowColor = [UIColor blackColor].CGColor;
self.coverView.layer.shadowOffset = CGSizeMake(0, 0);
self.coverView.layer.shadowOpacity = 0.1f;
self.coverView.layer.shadowRadius = 2.0f;
self.coverView.contentMode = UIViewContentModeScaleAspectFill;
[self.coverView.layer setShadowPath:[[UIBezierPath bezierPathWithRect:self.coverView.bounds] CGPath]];
[self.contentView addSubview:self.coverView];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.textColor = kBlackColor;
self.titleLabel.textAlignment = NSTextAlignmentLeft;
self.titleLabel.font = kMainFont;
[self.contentView addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.top.mas_equalTo(self.coverView.height + kHalfMargin + kHalfMargin);
make.height.mas_equalTo(20);
make.width.mas_equalTo(20);
}];
// 标签
self.tagboardView = [[TFTagboardView alloc] init];
self.tagboardView.font = kFont10;
self.tagboardView.cornerRadius = 4;
[self.contentView addSubview:self.tagboardView];
[self.tagboardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel.mas_right).with.offset(kHalfMargin);
make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
make.right.mas_equalTo(self.contentView.mas_right).with.offset(-kHalfMargin);
make.height.mas_equalTo(20);
}];
self.flagLabel = [[UILabel alloc] init];
self.flagLabel.textColor = kGrayTextColor;
self.flagLabel.textAlignment = NSTextAlignmentLeft;
self.flagLabel.font = kFont11;
[self.contentView addSubview:self.flagLabel];
[self.flagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel.mas_left);
make.top.mas_equalTo(self.titleLabel.mas_bottom).with.offset(kQuarterMargin);
make.right.mas_equalTo(self.contentView.mas_right).with.offset(-kHalfMargin);
make.height.mas_equalTo(15);
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(-kQuarterMargin).priorityLow();
}];
}
- (void)setDiscoverComic:(TFProductionModel *)discoverComic
{
_discoverComic = discoverComic;
[self.coverView setImageWithURL:[NSURL URLWithString:discoverComic.cover ? : @""] placeholder:HoldImage options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
self.titleLabel.text = discoverComic.name ? : @"";
[self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.titleLabel]);
}];
if (discoverComic.flag.length > 0) {
self.flagLabel.text = discoverComic.flag ? : @"";
[self.flagLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(15);
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(-kQuarterMargin).priorityLow();
}];
} else {
[self.flagLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(CGFLOAT_MIN);
make.bottom.mas_equalTo(self.contentView.mas_bottom).priorityLow();
}];
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.tagboardView.tagboardArray = discoverComic.tag;
});
}
@end
@@ -0,0 +1,17 @@
//
// TFDiscoverViewController.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFDiscoverViewController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,143 @@
//
// TFDiscoverViewController.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFDiscoverViewController.h"
#if TF_Enable_Comic
#import "TFDiscoverComicViewController.h"
#endif
#if TF_Enable_Book
#import "TFDiscoverNovelViewController.h"
#endif
#if TF_Enable_Audio
#import "TFDiscoverAudioViewController.h"
#endif
#import "TFLimitFreeViewController.h"
#import "SGPagingView.h"
@interface TFDiscoverViewController ()<SGPageTitleViewDelegate, SGPageContentCollectionViewDelegate>
@property (nonatomic ,strong) SGPageTitleView *pageTitleView;
@property (nonatomic ,strong) SGPageContentCollectionView *pageContentCollectionView;
@end
@implementation TFDiscoverViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
[self hiddenNavigationBarLeftButton];
[self hiddenSeparator];
}
- (void)createSubviews
{
#if TF_Enable_Comic
TFDiscoverComicViewController *comicVC = [[TFDiscoverComicViewController alloc] init];
comicVC.productionType = TFProductionTypeComic;
[self addChildViewController:comicVC];
#endif
#if TF_Enable_Book
TFDiscoverNovelViewController *bookVC = [[TFDiscoverNovelViewController alloc] init];
bookVC.productionType = TFProductionTypeNovel;
[self addChildViewController:bookVC];
#endif
#if TF_Enable_Audio
TFDiscoverAudioViewController *audioVC = [[TFDiscoverAudioViewController alloc] init];
audioVC.productionType = TFProductionTypeAudio;
[self addChildViewController:audioVC];
#endif
NSMutableArray *titleArr = [NSMutableArray array];
NSMutableArray *childArr = [NSMutableArray array];
for (NSNumber *siteNumber in [TFUtilsHelper getSiteState]) {
#if TF_Enable_Book
if ([siteNumber integerValue] == 1) {
[titleArr addObject:TFLocalizedString(@"小说")];
[childArr addObject:bookVC];
}
#endif
#if TF_Enable_Comic
if ([siteNumber integerValue] == 2) {
[titleArr addObject:TFLocalizedString(@"漫画")];
[childArr addObject:comicVC];
}
#endif
#if TF_Enable_Audio
if ([siteNumber integerValue] == 3) {
[titleArr addObject:TFLocalizedString(@"听书")];
[childArr addObject:audioVC];
}
#endif
}
if ([TFUtilsHelper getSiteState].count == 1) {
[titleArr removeAllObjects];
[titleArr addObject:TFLocalizedString(@"发现")];
}
self.pageContentCollectionView = [[SGPageContentCollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) parentVC:self childVCs:childArr];
_pageContentCollectionView.delegatePageContentCollectionView = self;
[self.view addSubview:self.pageContentCollectionView];
self.pageConfigure.indicatorStyle = SGIndicatorStyleDynamic;
self.pageConfigure.indicatorHeight = 3;
self.pageConfigure.indicatorFixedWidth = 10;
self.pageConfigure.indicatorToBottomDistance = 3;
self.pageConfigure.titleSelectedColor = kBlackColor;
self.pageConfigure.titleFont = kBoldFont16;
self.pageConfigure.titleTextZoom = YES;
self.pageConfigure.titleGradientEffect = YES;
self.pageConfigure.titleTextZoomRatio = 0.2;
self.pageConfigure.indicatorDynamicWidth = 14;
self.pageConfigure.showIndicator = YES;
CGFloat width = 0;
for (NSString *obj in titleArr) {
CGFloat t_width = [TFViewHelper getDynamicWidthWithLabelFont:kBoldFont16 labelHeight:TFPageView_H labelText:obj maxWidth:140.0];
width += t_width;
width += kLabelHeight;
}
self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(kHalfMargin, (is_iPhoneX?kQuarterMargin:kHalfMargin) + kHalfMargin + PUB_NAVBAR_OFFSET, width, TFPageView_H) delegate:self titleNames:titleArr configure:self.pageConfigure];
self.pageTitleView.backgroundColor = [UIColor clearColor];
[self.navigationBar addSubview:_pageTitleView];
}
- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex
{
[self.pageContentCollectionView setPageContentCollectionViewCurrentIndex:selectedIndex];
}
- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex
{
[self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}
@end
@@ -0,0 +1,22 @@
//
// TFDiscoverHeaderView.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef void(^BannerrImageClickBlock)(TFBannerModel *bannerModel);
@interface TFDiscoverHeaderView : UIView
@property (nonatomic ,copy) BannerrImageClickBlock bannerrImageClickBlock; //banner点击
@property (nonatomic ,strong) NSArray <TFBannerModel *>*banner;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,106 @@
//
// TFDiscoverHeaderView.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFDiscoverHeaderView.h"
#import "YJBannerView.h"
#import "TFDiscoverHeaderViewCell.h"
@interface TFDiscoverHeaderView ()<YJBannerViewDelegate, YJBannerViewDataSource>
@property (nonatomic ,strong) YJBannerView *normalBannerView;
@property (nonatomic ,strong) NSMutableArray *bannerImageArr;
@end
@implementation TFDiscoverHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.clipsToBounds = YES;
[self initialize];
[self createSubviews];
}
return self;
}
- (void)initialize
{
_bannerImageArr = [NSMutableArray array];
}
- (void)createSubviews
{
self.backgroundColor = kWhiteColor;
[self addSubview:self.normalBannerView];
}
//banner
- (YJBannerView *)normalBannerView
{
if (!_normalBannerView) {
_normalBannerView = [YJBannerView bannerViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH / 4) dataSource:self delegate:self emptyImage:HoldImage placeholderImage:HoldImage selectorString:NSStringFromSelector(@selector(setImageWithURL:placeholder:))];
_normalBannerView.pageControlAliment = PageControlAlimentCenter;
_normalBannerView.repeatCount = 9999;
_normalBannerView.autoDuration = 5.0f;
_normalBannerView.pageControlStyle = PageControlCustom;
_normalBannerView.pageControlDotSize = CGSizeMake(10, 5);
_normalBannerView.customPageControlHighlightImage = [UIImage imageNamed:@"pageControlS"];
_normalBannerView.customPageControlNormalImage = [UIImage imageNamed:@"pageControlN"];
}
return _normalBannerView;
}
- (NSArray *)bannerViewRegistCustomCellClass:(YJBannerView *)bannerView
{
return @[[TFDiscoverHeaderViewCell class]];
}
/** 根据 Index 选择使用哪个 reuseIdentifier */
- (Class)bannerView:(YJBannerView *)bannerView reuseIdentifierForIndex:(NSInteger)index
{
return [TFDiscoverHeaderViewCell class];
}
/** 自定义 View 刷新数据或者其他配置 */
- (UICollectionViewCell *)bannerView:(YJBannerView *)bannerView customCell:(UICollectionViewCell *)customCell index:(NSInteger)index
{
TFDiscoverHeaderViewCell *cell = (TFDiscoverHeaderViewCell *)customCell;
cell.imageURL = [self.bannerImageArr objectOrNilAtIndex:index];
return cell;
}
// 将网络图片或者本地图片 或者混合数组
- (NSArray *)bannerViewImages:(YJBannerView *)bannerView
{
return _bannerImageArr;
}
// 代理方法 点击了哪个bannerView 的 第几个元素
- (void)bannerView:(YJBannerView *)bannerView didSelectItemAtIndex:(NSInteger)index
{
if (self.bannerrImageClickBlock) {
self.bannerrImageClickBlock([self.banner objectOrNilAtIndex:index]);
}
}
- (void)setBanner:(NSArray<TFBannerModel *> *)banner
{
_banner = banner;
[_bannerImageArr removeAllObjects];
for (TFBannerModel *t_model in banner) {
[_bannerImageArr addObject:t_model.image];
}
[_normalBannerView reloadData];
}
@end
@@ -0,0 +1,19 @@
//
// TFDiscoverHeaderViewCell.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFDiscoverHeaderViewCell : UICollectionViewCell
@property (nonatomic ,copy) NSString *imageURL;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,48 @@
//
// TFDiscoverHeaderViewCell.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFDiscoverHeaderViewCell.h"
@interface TFDiscoverHeaderViewCell ()
{
UIImageView *bannerImageView;
}
@end
@implementation TFDiscoverHeaderViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = kWhiteColor;
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
bannerImageView = [[UIImageView alloc] initWithCornerRadiusAdvance:8 rectCornerType:UIRectCornerAllCorners];
bannerImageView.contentMode = UIViewContentModeScaleAspectFill;
[self addSubview:bannerImageView];
[bannerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).with.offset(kHalfMargin);
make.top.mas_equalTo(self.mas_top);
make.width.mas_equalTo(self.mas_width).with.offset(- kMargin);
make.height.mas_equalTo(self.mas_height);
}];
}
- (void)setImageURL:(NSString *)imageURL
{
_imageURL = imageURL;
[bannerImageView setImageWithURL:[NSURL URLWithString:imageURL] placeholder:HoldImage options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
}
@end
@@ -0,0 +1,18 @@
//
// TFDiscoverNovelViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFDiscoverNovelViewController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,350 @@
//
// TFDiscoverNovelViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFDiscoverNovelViewController.h"
#import "TFLimitFreeViewController.h"
#import "TFBookStoreComicBasicViewCell.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "TFDiscoverHeaderView.h"
#import "TFBannerActionManager.h"
@interface TFDiscoverNovelViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) TFDiscoverHeaderView *headerView;
@property (nonatomic ,strong) TFBookStoreModel *bookDiscoverModel;
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFDiscoverNovelViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenNavigationBar:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_EndOfTimeLimit object:nil];
}
- (void)createSubviews
{
self.mainTableViewGroup.delegate = self;
self.mainTableViewGroup.dataSource = self;
[self.view addSubview:self.mainTableViewGroup];
[self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(PUB_NAVBAR_HEIGHT);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_TABBAR_HEIGHT - PUB_NAVBAR_HEIGHT);
}];
WS(weakSelf)
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
self.headerView = [[TFDiscoverHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
self.headerView.bannerrImageClickBlock = ^(TFBannerModel * _Nonnull bannerModel) {
if ([TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeNovel]) {
[weakSelf.navigationController pushViewController:[TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeNovel] animated:YES];
}
};
[self.mainTableViewGroup setTableHeaderView:self.headerView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.bookDiscoverModel.label.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreLabelModel *labelModel = [self.bookDiscoverModel.label objectOrNilAtIndex:indexPath.section];
if (labelModel.ad_type == 0) {
switch (labelModel.style) {
case 1:
return [self createSingleStyleCellWithTableView:tableView indexPath:indexPath labelModel:labelModel];
break;
case 2:
return [self createDoubleStyleCellWithTableView:tableView indexPath:indexPath labelModel:labelModel];
break;
case 3:
return [self createMixtureStyleCellWithTableView:tableView indexPath:indexPath labelModel:labelModel];
break;
case 4:
return [self createMixtureMoreStyleCellWithTableView:tableView indexPath:indexPath labelModel:labelModel];
break;
default:
return [self createSingleStyleCellWithTableView:tableView indexPath:indexPath labelModel:labelModel];
break;
}
} else {
return [self createAdStyleCellWithTableView:tableView indexPath:indexPath adModel:labelModel];
}
}
- (UITableViewCell *)createSingleStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
WS(weakSelf)
static NSString *cellName = @"TFBookStoreNovelStyleOneCell";
TFBookStoreNovelStyleOneCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFBookStoreNovelStyleOneCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.labelModel = labelModel;
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = production_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (UITableViewCell *)createDoubleStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
WS(weakSelf)
static NSString *cellName = @"TFBookStoreNovelStyleTwoCell";
TFBookStoreNovelStyleTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFBookStoreNovelStyleTwoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.labelModel = labelModel;
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = production_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (UITableViewCell *)createMixtureStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
WS(weakSelf)
static NSString *cellName = @"TFBookStoreNovelStyleThreeCell";
TFBookStoreNovelStyleThreeCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFBookStoreNovelStyleThreeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.labelModel = labelModel;
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = production_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (UITableViewCell *)createMixtureMoreStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
WS(weakSelf)
static NSString *cellName = @"TFBookStoreNovelStyleFourCell";
TFBookStoreNovelStyleFourCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFBookStoreNovelStyleFourCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.labelModel = labelModel;
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = production_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (UITableViewCell *)createAdStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath adModel:(TFBookStoreLabelModel *)labelModel
{
static NSString *cellName = @"TFPublicAdvertisementViewCell";
TFPublicAdvertisementViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
[cell setAdModel:labelModel refresh:self.needRefresh];
cell.mainTableView = tableView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
TFBookStoreLabelModel *labelModel = [self.bookDiscoverModel.label objectOrNilAtIndex:section];
if (labelModel.can_more || labelModel.can_refresh) {
return 50;
}
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
view.backgroundColor = [UIColor whiteColor];
CGFloat buttonX = SCREEN_WIDTH / 4;
CGFloat buttonY = 10;
CGFloat buttonW = SCREEN_WIDTH / 2;
CGFloat buttonH = 30;
TFBookStoreLabelModel *labelModel = [self.bookDiscoverModel.label objectOrNilAtIndex:section];
if (!labelModel.can_more && !labelModel.can_refresh) {
return view;
}
TFButton *moreButton = [TFButton initWithFrame:CGRectMake(buttonX, buttonY, buttonW, buttonH) btnTitle:TFLocalizedString(@"更多") btnImageName:@"comic_mall_more" backgroundColor:kGrayViewColor btnTintColor:kGrayTextLightColor btnStyle:TFButtonIndicatorTitleLeft cornerRadius:15 target:self action:@selector(moreButtonClick:)];
moreButton.graphicDistance = 5;
moreButton.tag = section;
[moreButton addTarget:self action:@selector(moreButtonClick:) forControlEvents:UIControlEventTouchUpInside];
TFButton *changeButton = [TFButton initWithFrame:CGRectMake(buttonX, 0, buttonW, buttonH) btnTitle:TFLocalizedString(@"换一换") btnImageName:@"comic_mall_refresh" backgroundColor:kGrayViewColor btnTintColor:kGrayTextLightColor btnStyle:TFButtonIndicatorTitleLeft cornerRadius:15 target:self action:@selector(changeButtonClick:)];
changeButton.graphicDistance = 5;
changeButton.buttonImageScale = 0.5;
changeButton.tag = section;
[changeButton addTarget:self action:@selector(changeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
if (labelModel.can_more && !labelModel.can_refresh) {
[view addSubview:moreButton];
}
if (!labelModel.can_more && labelModel.can_refresh) {
[view addSubview:changeButton];
}
if (labelModel.can_more && labelModel.can_refresh) {
moreButton.frame = CGRectMake(kMargin, buttonY, (SCREEN_WIDTH - 3 * kMargin) / 2, buttonH);
changeButton.frame = CGRectMake(2 * kMargin + (SCREEN_WIDTH - 3 * kMargin) / 2, buttonY, (SCREEN_WIDTH - 3 * kMargin) / 2, buttonH);
[view addSubview:moreButton];
[view addSubview:changeButton];
}
return view;
}
- (void)moreButtonClick:(UIButton *)sender
{
TFBookStoreLabelModel *t_labelModel = [self.bookDiscoverModel.label objectOrNilAtIndex:sender.tag];
if (t_labelModel.expire_time > 0) {
TFLimitFreeViewController *vc = [[TFLimitFreeViewController alloc] init];
vc.productionType = self.productionType;
[self.navigationController pushViewController:vc animated:YES];
} else {
TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init];
vc.productionType = self.productionType;
vc.recommend_id = [TFUtilsHelper formatStringWithInteger:t_labelModel.recommend_id];
[self.navigationController pushViewController:vc animated:YES];
}
}
- (void)changeButtonClick:(UIButton *)sender
{
TFButton *button = (TFButton *)sender;
[button startSpin];
[self changeRecommendRequestAtIndex:sender.tag complete:^{
[button stopSpin];
}];
}
- (void)changeRecommendRequestAtIndex:(NSInteger)index complete:(void(^)(void))complete
{
TFBookStoreLabelModel *t_labelModel = [self.bookDiscoverModel.label objectOrNilAtIndex:index];
if (t_labelModel.recommend_id <= 0) {
return;
}
WS(weakSelf)
[TFNetworkTools POST:Book_Refresh parameters:@{@"recommend_id":[TFUtilsHelper formatStringWithInteger:t_labelModel.recommend_id]} model:TFBookStoreLabelModel.class success:^(BOOL isSuccess, TFBookStoreLabelModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
if (t_model.list.count > 0) {
[weakSelf.bookDiscoverModel.label objectAtIndex:index].list = t_model.list;
t_model.style = t_labelModel.style;
TFBookStoreComicBasicViewCell *cell = [weakSelf.mainTableViewGroup cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:index]];
cell.labelModel = t_model;
!complete ?: complete();
}
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
!complete ?: complete();
}];
}
- (void)netRequest
{
WS(weakSelf)
[TFNetworkTools POSTQuick:Book_Discover parameters:nil model:TFBookStoreModel.class success:^(BOOL isSuccess, TFBookStoreModel * _Nullable t_model, BOOL isCache, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.headerView.banner = t_model.banner;
if (t_model.banner.count > 0) {
weakSelf.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH / 4);
} else {
weakSelf.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN);
}
weakSelf.bookDiscoverModel = t_model;
}
[weakSelf.mainTableViewGroup endRefreshing];
weakSelf.needRefresh = YES;
[weakSelf.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableViewGroup endRefreshing];
}];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end