小说绘上架版本

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,31 @@
//
// TFAudioPlayViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@class TFProductionChapterModel;
@interface TFAudioPlayViewController : TFBasicViewController
@property (nonatomic ,strong) NSArray <TFProductionChapterModel *> *chapter_list;
@property (nonatomic ,assign ,readonly) BOOL speaking;
@property (nonatomic ,assign ,readonly) BOOL stoped; // 暂停不可播放状态
@property (nonatomic ,assign ,readonly) NSInteger chapter_id;
interface_singleton
- (void)loadDataWithAudio_id:(NSInteger)audio_id chapter_id:(NSInteger)chapter_id;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,863 @@
//
// TFAudioPlayViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAudioPlayViewController.h"
#import "WXYZ_BookAiPlayPageViewController.h"
#import "TFCommentsViewController.h"
#import "WXYZ_AudioDownloadViewController.h"
#import "TFReadNovelViewController.h"
#import "TFAudioPlayHeaderView.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFCommentsViewCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "WXYZ_PlayPageModel.h"
#import "TFAudioDetailModel.h"
#import "CXTextView.h"
#import "CXCustomTextView.h"
#import "WXYZ_TouchAssistantView.h"
#import "TFShareManager.h"
#import "TFKeyboardManager.h"
#import "WXYZ_AudioDownloadManager.h"
#import "WXYZ_AudioSettingHelper.h"
#import "TFCollectionManager.h"
#import "TFReadRecordManager.h"
#if __has_include(<iflyMSC/IFlyMSC.h>)
#import "iflyMSC/IFlyMSC.h"
#endif
@interface TFAudioPlayViewController ()<UITableViewDelegate, UITableViewDataSource>
{
CXTextView *commentTextView;
UIButton *addAudioRack;
TFKeyboardManager *keyboardManager;
}
@property (nonatomic ,strong) TFAudioPlayHeaderView *headerView;
@property (nonatomic ,strong) WXYZ_PlayPageModel *playPageModel;
@property (nonatomic ,strong) TFProductionChapterModel *audioChapterModel;
@property (nonatomic ,assign) NSInteger audio_id;
@property (nonatomic ,assign) NSInteger chapter_id;
@property (nonatomic ,strong) UIView *bottomMenu;
@property (nonatomic ,strong) UIView *sectionHeaderView;
@property (nonatomic ,strong) UILabel *sectionTitleLabel;
@property (nonatomic ,strong) UIButton *sectionBottomCommentButton;
@property (nonatomic ,strong) UILabel *commentConnerLabel;
@property (nonatomic ,assign) BOOL needRefresh;
@property (nonatomic ,weak) TFButton *collectButton;
@property (nonatomic ,weak) TFButton *commentButton;
@property (nonatomic ,weak) TFButton *downloadButton;
@end
@implementation TFAudioPlayViewController
implementation_singleton(TFAudioPlayViewController)
- (void)loadDataWithAudio_id:(NSInteger)audio_id chapter_id:(NSInteger)chapter_id
{
if (audio_id > 0) {
_audio_id = audio_id;
}
// 查找阅读记录
if (chapter_id == 0) {
chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] getReadingRecordChapter_idWithProduction_id:audio_id];
}
// 查找收藏记录
if (chapter_id == 0) {
TFProductionModel *productionModel = [[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] getCollectedProductionModelWithProduction_id:audio_id];
if ([productionModel.chapter_list firstObject]) {
TFProductionChapterModel *chapterModel = [productionModel.chapter_list firstObject];
chapter_id = chapterModel.chapter_id;
}
}
// 查找下载记录
if (chapter_id == 0) {
TFProductionModel *productionModel = [[WXYZ_DownloadHelper sharedManager] getDownloadProductionModelWithProduction_id:audio_id productionType:TFProductionTypeAudio];
if ([productionModel.chapter_list firstObject]) {
TFProductionChapterModel *chapterModel = [productionModel.chapter_list firstObject];
chapter_id = chapterModel.chapter_id;
}
}
if (chapter_id > 0) {
_chapter_id = chapter_id;
}
self.needRefresh = YES;
[self netRequest];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
[self hiddenNavigationBar:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeAudioChapter:) name:Notification_Change_Audio_Chapter object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLanguage) name:Notification_Switch_Language object:nil];
}
- (void)changeLanguage {
commentTextView.placeholder = TFLocalizedString(@"我来说两句...");
self.downloadButton.buttonTitle = TFLocalizedString(@"分享");
self.collectButton.buttonTitle = TFLocalizedString(@"听书下载");
self.commentButton.buttonTitle = TFLocalizedString(@"听书评论");
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
[[WXYZ_TouchAssistantView sharedManager] hiddenAssistiveTouchView];
[[WXYZ_TouchAssistantView sharedManager] setPlayerProductionType:TFProductionTypeAudio];
[self.mainTableViewGroup scrollToTop];
[[WXYZ_AudioSettingHelper sharedManager] playPageViewShow:YES productionType:TFProductionTypeAudio];
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] isCollectedWithProduction_id:self.audio_id]) {
[addAudioRack setTitleColor:kGrayTextColor forState:UIControlStateNormal];
[addAudioRack setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[addAudioRack mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(addAudioRack.intrinsicContentSize.width);
}];
addAudioRack.tag = 2;
} else {
[addAudioRack setTitleColor:kBlackColor forState:UIControlStateNormal];
[addAudioRack setTitle:TFLocalizedString(@"加入书架") forState:UIControlStateNormal];
[addAudioRack mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(addAudioRack.intrinsicContentSize.width);
}];
addAudioRack.tag = 1;
}
}
- (void)viewWillDisappear:(BOOL)animated
{
if (![WXYZ_BookAiPlayPageViewController sharedManager].speaking) {
[[WXYZ_TouchAssistantView sharedManager] showAssistiveTouchViewWithImageCover:self.audioChapterModel.cover productionType:TFProductionTypeAudio];
} else {
[[WXYZ_TouchAssistantView sharedManager] showAssistiveTouchView];
}
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)createSubviews
{
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(10, PUB_NAVBAR_OFFSET + 20, 44, 44);
backButton.backgroundColor = [UIColor clearColor];
backButton.adjustsImageWhenHighlighted = NO;
[backButton.titleLabel setFont:kMainFont];
[backButton setTitleColor:kBlackColor forState:UIControlStateNormal];
[backButton setImage:[[UIImage imageNamed:@"public_down_arrow"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[backButton setImageEdgeInsets:UIEdgeInsetsMake(12, 12, 12, 12)];
[backButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[backButton setTintColor:kBlackColor];
[backButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backButton];
addAudioRack = [UIButton buttonWithType:UIButtonTypeCustom];
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] isCollectedWithProduction_id:self.audio_id]) {
[addAudioRack setTitleColor:kGrayTextColor forState:UIControlStateNormal];
[addAudioRack setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
} else {
[addAudioRack setTitleColor:kBlackColor forState:UIControlStateNormal];
[addAudioRack setTitle:TFLocalizedString(@"加入书架") forState:UIControlStateNormal];
}
addAudioRack.enabled = YES;
addAudioRack.backgroundColor = kWhiteColor;
[addAudioRack.titleLabel setFont:kMainFont];
[addAudioRack setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
[addAudioRack addTarget:self action:@selector(addAudioClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:addAudioRack];
[addAudioRack mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.view.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(backButton.mas_centerY);
make.width.mas_equalTo(addAudioRack.intrinsicContentSize.width);
make.height.mas_equalTo(44);
}];
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);
}];
[self.mainTableViewGroup setTableHeaderView:self.headerView];
self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH);
[self.headerView setNeedsLayout];
[self.headerView layoutIfNeeded];
self.mainTableViewGroup.tableHeaderView = self.headerView;
self.bottomMenu = [[UIView alloc] init];
self.bottomMenu.backgroundColor = [UIColor whiteColor];
self.bottomMenu.layer.shadowColor = kBlackColor.CGColor;
self.bottomMenu.layer.shadowOpacity = 0.1;
self.bottomMenu.layer.shadowRadius = 1;
self.bottomMenu.layer.shadowOffset = CGSizeMake(0, - 1);
[self.view addSubview:self.bottomMenu];
[self.bottomMenu mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.view.mas_left);
make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(- PUB_TABBAR_OFFSET);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
}];
TFButton *downloadButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"分享") buttonImageName:@"public_share" buttonIndicator:TFButtonIndicatorTitleBottom];
self.downloadButton = downloadButton;
downloadButton.tag = 0;
downloadButton.buttonTitleFont = kFont12;
downloadButton.graphicDistance = 5;
downloadButton.buttonImageScale = 0.45;
downloadButton.buttonTitleColor = kGrayTextLightColor;
[downloadButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.bottomMenu addSubview:downloadButton];
[downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.bottomMenu.mas_right).with.offset(- kHalfMargin);
make.top.mas_equalTo(self.bottomMenu.mas_top).with.offset(5);
make.width.height.mas_equalTo(40);
}];
TFButton *collectButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"听书下载") buttonImageName:@"public_download" buttonIndicator:TFButtonIndicatorTitleBottom];
self.collectButton = collectButton;
collectButton.tag = 1;
collectButton.buttonTitleFont = kFont12;
collectButton.graphicDistance = 5;
collectButton.buttonImageScale = 0.45;
collectButton.buttonTitleColor = kGrayTextLightColor;
[collectButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.bottomMenu addSubview:collectButton];
[collectButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(downloadButton.mas_left).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(downloadButton.mas_centerY);
make.width.height.mas_equalTo(downloadButton);
}];
TFButton *commentButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"听书评论") buttonImageName:@"audio_comment" buttonIndicator:TFButtonIndicatorTitleBottom];
self.commentButton = commentButton;
commentButton.tag = 2;
commentButton.buttonTitleFont = kFont12;
commentButton.graphicDistance = 5;
commentButton.buttonImageScale = 0.45;
commentButton.buttonTitleColor = kGrayTextLightColor;
[commentButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.bottomMenu addSubview:commentButton];
[commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(collectButton.mas_left).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(downloadButton.mas_centerY);
make.width.height.mas_equalTo(downloadButton);
}];
self.commentConnerLabel = [[UILabel alloc] init];
self.commentConnerLabel.text = @"0";
self.commentConnerLabel.textAlignment = NSTextAlignmentCenter;
self.commentConnerLabel.textColor = kMainColor;
self.commentConnerLabel.backgroundColor = [UIColor whiteColor];
self.commentConnerLabel.font = [UIFont systemFontOfSize:6];
[commentButton addSubview:self.commentConnerLabel];
[self.commentConnerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(commentButton.mas_centerX).with.offset(1);
make.right.mas_equalTo(commentButton.mas_right).with.offset(- 5);
make.top.mas_equalTo(commentButton.mas_top).with.offset(- 1);
make.height.mas_equalTo(6);
}];
UIView *commentBottomView = [[UIView alloc] init];
commentBottomView.backgroundColor = kGrayViewColor;
commentBottomView.layer.cornerRadius = 20;
[self.bottomMenu addSubview:commentBottomView];
[commentBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.bottomMenu.mas_left).with.offset(kHalfMargin);
make.top.mas_equalTo(self.bottomMenu.mas_top).with.offset(5);
make.right.mas_equalTo(commentButton.mas_left).with.offset(- kHalfMargin);
make.height.mas_equalTo(40);
}];
UIImageView *leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"audio_pencil"]];
[commentBottomView addSubview:leftView];
[leftView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMoreHalfMargin);
make.top.mas_equalTo(commentBottomView.mas_top).with.offset(10);
make.height.width.mas_equalTo(16);
}];
WS(weakSelf)
commentTextView = [[CXTextView alloc] initWithFrame:CGRectMake(kMoreHalfMargin + 16 + kHalfMargin, 0, SCREEN_WIDTH - (kMoreHalfMargin + 16 + kHalfMargin + kHalfMargin + 3 * 40 + 5 * kHalfMargin), 40)];
commentTextView.placeholder = TFLocalizedString(@"我来说两句...");
commentTextView.maxLine = 5;
commentTextView.maxLength = 200;
commentTextView.v_margin = 10;
commentTextView.font = kMainFont;
commentTextView.backgroundColor = [UIColor clearColor];
commentTextView.layer.cornerRadius = 15;
commentTextView.textView.backgroundColor = [UIColor clearColor];
commentTextView.textHeightChangeBlock = ^(CGFloat height) {
[commentBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(height);
}];
[weakSelf.bottomMenu mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(10 + height);
}];
[weakSelf.mainTableViewGroup mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(weakSelf.view.mas_height).with.offset(- PUB_TABBAR_OFFSET - PUB_NAVBAR_HEIGHT - height - 10);
}];
};
commentTextView.returnHandlerBlock = ^{
[weakSelf sendCommentNetRequest];
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
};
[commentBottomView addSubview:commentTextView];
keyboardManager = [[TFKeyboardManager alloc] initObserverWithAdaptiveMovementView:commentBottomView];
keyboardManager.keyboardHeightChanged = ^(CGFloat keyboardHeight, CGFloat shouldMoveDistance, CGRect shouldMoveFrame) {
[weakSelf.bottomMenu mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(weakSelf.view.mas_bottom).with.offset(keyboardHeight == 0 ? - PUB_TABBAR_OFFSET:- keyboardHeight);
}];
};
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[TFKeyboardManager hideKeyboard];
}
#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section) {
case 0:
if (self.playPageModel.advert.ad_type != 0) {
return 1;
}
break;
case 1:
if (self.playPageModel.list.count > 0) {
return 1;
}
break;
case 2:
if (self.playPageModel.comment.list.count > 3) {
return 3;
} else {
return self.playPageModel.comment.list.count;
}
break;
default:
break;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.section) {
case 0:
return [self createAdCellWithTableView:tableView indexPath:indexPath];
break;
case 1:
return [self createSingleStyleCellWithTableView:tableView indexPath:indexPath listArray:self.playPageModel.list];
break;
case 2:
return [self createCommentCellWithTableView:tableView indexPath:indexPath labelModel:[self.playPageModel.comment.list objectOrNilAtIndex:indexPath.row]];
break;
default:
break;
}
return [[UITableViewCell alloc] init];
}
- (UITableViewCell *)createSingleStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath listArray:(NSArray *)listArray
{
WS(weakSelf)
static NSString *cellName = @"TFBookStoreNovelStyleOneCell";
TFBookStoreLabelModel *labelModel = [[TFBookStoreLabelModel alloc] init];
labelModel.list = listArray;
labelModel.label = TFLocalizedString(@"猜你喜欢");
for (TFProductionModel *t_model in labelModel.list) {
t_model.productionType = TFProductionTypeAudio;
}
TFBookStoreNovelStyleOneCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFBookStoreNovelStyleOneCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.labelModel = labelModel;
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init];
vc.audio_id = production_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
return cell;
}
- (UITableViewCell *)createCommentCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFCommentsListModel *)commentModel
{
static NSString *cellName = @"TFCommentsViewCell";
TFCommentsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFCommentsViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.commentModel = commentModel;
[cell setIsPreview:YES lastRow:(self.playPageModel.comment.list.count - 1 == indexPath.row)];
cell.hiddenEndLine = NO;
return cell;
}
- (UITableViewCell *)createAdCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
static NSString *cellName = @"TFPublicAdvertisementViewCell";
TFPublicAdvertisementViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
[cell setAdModel:self.playPageModel.advert refresh:self.needRefresh];
cell.mainTableView = tableView;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 2) {
TFCommentsListModel *t_model = [self.playPageModel.comment.list objectOrNilAtIndex:indexPath.row];
[self commentWithComment_id:t_model.comment_id];
}
}
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
#if TF_Comments_Mode
if (!self.playPageModel) {
return CGFLOAT_MIN;
}
if (section == 2) {// 评论头部高度
return 54;
}
#endif
return kQuarterMargin;
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 2) {
UIView *sectionView = self.sectionHeaderView;
self.sectionTitleLabel.text = [NSString stringWithFormat:@"%@(%@)", TFLocalizedString(@"本章评论"), [TFUtilsHelper formatStringWithInteger:self.playPageModel.comment_total_count]];
return sectionView;
}
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHalfMargin)];
view.backgroundColor = kGrayViewColor;
return view;
}
- (UIView *)sectionHeaderView
{
if (!_sectionHeaderView) {
_sectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 54)];
_sectionHeaderView.backgroundColor = [UIColor whiteColor];
UIView *grayLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
grayLine.backgroundColor = kGrayViewColor;
[_sectionHeaderView addSubview:grayLine];
UIImageView *mainTitleHoldView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"book_label_hold"]];
[_sectionHeaderView addSubview:mainTitleHoldView];
[mainTitleHoldView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.centerY.mas_equalTo(_sectionHeaderView.mas_centerY).with.offset(5);
make.width.height.mas_equalTo(kHalfMargin + kQuarterMargin);
}];
[_sectionHeaderView addSubview:self.sectionTitleLabel];
}
return _sectionHeaderView;
}
- (UILabel *)sectionTitleLabel
{
if (!_sectionTitleLabel) {
_sectionTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kMargin + kHalfMargin, 10, SCREEN_WIDTH - kMargin, 44)];
_sectionTitleLabel.textAlignment = NSTextAlignmentLeft;
_sectionTitleLabel.textColor = kBlackColor;
_sectionTitleLabel.backgroundColor = [UIColor whiteColor];
_sectionTitleLabel.font = kBoldFont16;
}
return _sectionTitleLabel;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
#if TF_Comments_Mode
if (!self.playPageModel) {
return CGFLOAT_MIN;
}
if (section == 2) {
return 56;
}
#endif
return CGFLOAT_MIN;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
view.backgroundColor = kWhiteColor;
if (section == 2) {
if (self.playPageModel) {
if (self.playPageModel.comment.list.count == 0) {
[self.sectionBottomCommentButton setTitle:TFLocalizedString(@"暂无评论,点击抢沙发") forState:UIControlStateNormal];
} else {
[self.sectionBottomCommentButton setTitle:[NSString stringWithFormat:@"%@(%@%@)", TFLocalizedString(@"查看全部评论"), [TFUtilsHelper formatStringWithInteger:self.playPageModel.comment_total_count], TFLocalizedString(@"")] forState:UIControlStateNormal];
}
[view addSubview:self.sectionBottomCommentButton];
}
}
return view;
}
- (UIButton *)sectionBottomCommentButton
{
if (!_sectionBottomCommentButton) {
_sectionBottomCommentButton = [UIButton buttonWithType:UIButtonTypeCustom];
_sectionBottomCommentButton.frame = CGRectMake(SCREEN_WIDTH / 4, kHalfMargin, SCREEN_WIDTH / 2 + kMargin, 36);
_sectionBottomCommentButton.backgroundColor = [UIColor whiteColor];
_sectionBottomCommentButton.layer.cornerRadius = 18;
_sectionBottomCommentButton.layer.borderColor = kMainColor.CGColor;
_sectionBottomCommentButton.layer.borderWidth = 0.4f;
[_sectionBottomCommentButton setTitleColor:kMainColor forState:UIControlStateNormal];
[_sectionBottomCommentButton.titleLabel setFont:kFont12];
[_sectionBottomCommentButton addTarget:self action:@selector(commentClick) forControlEvents:UIControlEventTouchUpInside];
}
return _sectionBottomCommentButton;
}
- (TFAudioPlayHeaderView *)headerView
{
if (!_headerView) {
WS(weakSelf)
_headerView = [[TFAudioPlayHeaderView alloc] initWithProductionType:TFProductionTypeAudio];
_headerView.checkRelationProductionBlock = ^(WXYZ_RelationModel * _Nonnull relationModel) {
[TFNetworkTools POST:Book_Catalog parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:relationModel.production_id]} model:TFProductionModel.class success:^(BOOL isSuccess, TFProductionModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
WXYZ_BookAiPlayPageViewController *vc = [WXYZ_BookAiPlayPageViewController sharedManager];
[vc loadDataWithBookModel:t_model chapterModel:nil];
if (!vc.presentedViewController) {
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:vc];
[[TFViewHelper getWindowRootController] presentViewController:nav animated:YES completion:nil];
} else {
[weakSelf popViewController];
}
}
} failure:nil];
};
_headerView.checkOriginalBlock = ^(TFProductionChapterModel * _Nonnull chapterModel) {
if (weakSelf.navigationController.view.tag == 2345) {
[weakSelf popViewController];
return;
}
[TFNetworkTools POST:Book_Catalog parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:chapterModel.relation_production_id]} model:TFProductionModel.class success:^(BOOL isSuccess, TFProductionModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
dispatch_async(dispatch_get_main_queue(), ^{
TFReadNovelViewController *vc = [[TFReadNovelViewController alloc] init];
vc.book_id = t_model.production_id;
vc.bookModel = t_model;
[weakSelf.navigationController pushViewController:vc animated:YES];
});
}
} failure:nil];
};
}
return _headerView;
}
- (BOOL)speaking
{
if (self.headerView.playerState == TFBasicVoicePlayerStatePlaying) {
return YES;
}
return NO;
}
- (BOOL)stoped
{
if (self.headerView.playerState == TFBasicVoicePlayerStateStoped) {
return YES;
}
return NO;
}
- (void)commentClick
{
[self commentWithComment_id:0];
}
- (void)commentWithComment_id:(NSInteger)comment_id
{
WS(weakSelf)
TFCommentsViewController *vc = [[TFCommentsViewController alloc] init];
vc.production_id = self.audio_id;
vc.chapter_id = self.chapter_id;
vc.comment_id = comment_id;
vc.productionType = TFProductionTypeAudio;
vc.commentsSuccessBlock = ^(TFCommentsListModel *commentModel) {
WXYZ_PlayPageModel *t_model = weakSelf.playPageModel;
// 评论数组model添加
NSMutableArray *t_array = [NSMutableArray arrayWithArray:weakSelf.playPageModel.comment.list];
[t_array insertObject:commentModel atIndex:0];
weakSelf.playPageModel.comment.list = [t_array copy];
weakSelf.playPageModel = t_model;
weakSelf.playPageModel.comment_total_count ++;
[weakSelf.mainTableViewGroup reloadData];
weakSelf.commentConnerLabel.text = [NSString stringWithFormat:@"%@", weakSelf.playPageModel.comment_total_count > 99?@"99+":[TFUtilsHelper formatStringWithInteger:weakSelf.playPageModel.comment_total_count]];
};
[self.navigationController pushViewController:vc animated:YES];
}
- (void)toolBarButtonClick:(TFButton *)sender
{
if (sender.tag == 0) {
[TFShareManager shareWithProduction_id:NSStringFromInteger(self.audioChapterModel.production_id) chapter_id:NSStringFromInteger(self.audioChapterModel.chapter_id) type:TFShareTypeAudio];
}
if (sender.tag == 1) {
WXYZ_AudioDownloadViewController *vc = [[WXYZ_AudioDownloadViewController alloc] init];
vc.production_id = self.audioChapterModel.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
if (sender.tag == 2) {
[self commentWithComment_id:0];
}
}
- (void)addAudioClick:(UIButton *)sender
{
if (![[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] isCollectedWithProduction_id:self.audio_id]) {
[TFUtilsHelper synchronizationRackProductionWithProduction_id:self.audio_id productionType:TFProductionTypeAudio complete:nil];
[TFNetworkTools POST:Audio_Info parameters:@{@"audio_id":[TFUtilsHelper formatStringWithInteger:self.audio_id]} model:TFAudioDetailModel.class success:^(BOOL isSuccess, TFAudioDetailModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
[sender setTitleColor:kGrayTextColor forState:UIControlStateNormal];
[sender setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] addCollectionWithProductionModel:t_model.audio];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"已加入书架")];
}
} failure:nil];
}
}
- (void)changeAudioChapter:(NSNotification *)noti
{
self.chapter_id = [[noti object] integerValue];
[self netRequest];
}
- (void)netRequest
{
if ([TFNetworkManager networkingStatus] == NO) {
TFProductionModel *productionModel = [[WXYZ_DownloadHelper sharedManager] getDownloadProductionModelWithProduction_id:self.audio_id productionType:TFProductionTypeAudio];
TFProductionChapterModel *chapterModel = [[WXYZ_AudioDownloadManager sharedManager] getDownloadChapterModelWithProduction_id:self.audio_id chapter_id:self.chapter_id];
if (!chapterModel) {
for (TFProductionChapterModel *t_chapterModel in productionModel.chapter_list) {
if (self.chapter_id == t_chapterModel.chapter_id) {
chapterModel = t_chapterModel;
}
}
}
chapterModel.cover = productionModel.cover;
self.audioChapterModel = chapterModel;
self.headerView.chapter_list = productionModel.chapter_list;
self.headerView.productionChapterModel = self.audioChapterModel;
self.headerView.relationModel = [[WXYZ_RelationModel alloc] init];
[self.mainTableViewGroup setTableHeaderView:self.headerView];
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] addReadingRecordWithProduction_id:chapterModel.production_id chapter_id:chapterModel.chapter_id chapterTitle:chapterModel.chapter_title];
return;
}
WS(weakSelf)
[TFNetworkTools POST:Audio_Chapter_Info parameters:@{@"audio_id":[TFUtilsHelper formatStringWithInteger:self.audio_id], @"chapter_id":[TFUtilsHelper formatStringWithInteger:self.chapter_id]} model:TFProductionChapterModel.class success:^(BOOL isSuccess, TFProductionChapterModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.chapter_id = t_model.chapter_id;
weakSelf.audioChapterModel = t_model;
weakSelf.headerView.productionChapterModel = weakSelf.audioChapterModel;
[weakSelf.mainTableViewGroup setTableHeaderView:weakSelf.headerView];
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] addReadingRecordWithProduction_id:t_model.production_id chapter_id:t_model.chapter_id chapterTitle:t_model.chapter_title];
if (t_model.is_preview == 0) {
// 如果是自动订阅后,将通知刷新目录内容
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Auto_Buy_Audio_Chapter object:[TFUtilsHelper formatStringWithInteger:t_model.chapter_id]];
}
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:nil];
[TFNetworkTools POST:Audio_Chapter_Detail parameters:@{@"audio_id":[TFUtilsHelper formatStringWithInteger:self.audio_id], @"chapter_id":[TFUtilsHelper formatStringWithInteger:self.chapter_id]} model:WXYZ_PlayPageModel.class success:^(BOOL isSuccess, WXYZ_PlayPageModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.playPageModel = t_model;
weakSelf.commentConnerLabel.text = [NSString stringWithFormat:@"%@", weakSelf.playPageModel.comment_total_count > 99?@"99+":[TFUtilsHelper formatStringWithInteger:weakSelf.playPageModel.comment_total_count]];
weakSelf.headerView.relationModel = weakSelf.playPageModel.relation;
}
weakSelf.needRefresh = YES;
[weakSelf.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
weakSelf.needRefresh = NO;
[weakSelf.mainTableViewGroup reloadData];
}];
[TFNetworkTools POST:Audio_Add_Read_Log parameters:@{@"audio_id":[TFUtilsHelper formatStringWithInteger:self.audio_id], @"chapter_id":[TFUtilsHelper formatStringWithInteger:self.chapter_id]} model:nil success:nil failure:nil];
if (!self.chapter_list || self.chapter_list.count == 0) {
[TFNetworkTools POST:Audio_Catalog parameters:@{@"audio_id":[TFUtilsHelper formatStringWithInteger:self.audio_id]} model:TFProductionModel.class success:^(BOOL isSuccess, TFProductionModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
// 更新本地记录
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] modificationCollectionWithProductionModel:t_model];
weakSelf.chapter_list = t_model.chapter_list;
weakSelf.headerView.chapter_list = t_model.chapter_list;
}
} failure:nil];
} else {
self.headerView.chapter_list = [self.chapter_list copy];
self.chapter_list = [NSArray array];
}
}
- (void)sendCommentNetRequest
{
if (!TFUserInfoManager.isLogin) {
TFAlertView *alert = [[TFAlertView alloc] init];
alert.alertDetailContent = TFLocalizedString(@"登录后才可以进行评论");
alert.confirmTitle = TFLocalizedString(@"去登录");
alert.cancelTitle = TFLocalizedString(@"暂不");
alert.confirmButtonClickBlock = ^{
[TFLoginOptionsViewController presentLoginView:nil];
};
[alert showAlertView];
return;
}
if ([commentTextView.text isEqualToString:@""]) {
return;
}
NSString *t_text = commentTextView.text;
commentTextView.text = @"";
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:@{@"audio_id":[TFUtilsHelper formatStringWithInteger:self.audioChapterModel.production_id]?:@"", @"chapter_id":[TFUtilsHelper formatStringWithInteger:self.audioChapterModel.chapter_id], @"content":t_text}];
WS(weakSelf)
[TFNetworkTools POST:Audio_Comment_Post parameters:parameters model:TFCommentsListModel.class success:^(BOOL isSuccess, TFCommentsListModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"评论成功")];
// 评论数组model添加
NSMutableArray<TFCommentsListModel *> *t_arr = [NSMutableArray arrayWithArray:weakSelf.playPageModel.comment.list];
[t_arr insertObject:t_model atIndex:0];
weakSelf.playPageModel.comment.list = [t_arr copy];
weakSelf.playPageModel.comment_total_count++;
[weakSelf.mainTableViewGroup reloadSection:2 withRowAnimation:UITableViewRowAnimationNone];
weakSelf.commentConnerLabel.text = [NSString stringWithFormat:@"%@", weakSelf.playPageModel.comment_total_count > 99?@"99+":[TFUtilsHelper formatStringWithInteger:weakSelf.playPageModel.comment_total_count]];
} else if (Compare_Json_isEqualTo(requestModel.code, 315)) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:requestModel.msg];
} else {
commentTextView.text = t_text;
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:nil];
}
@end
@@ -0,0 +1,18 @@
//
// TFAudioPlayHeaderView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicVoiceHeaderView.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFAudioPlayHeaderView : TFBasicVoiceHeaderView
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,248 @@
//
// TFAudioPlayHeaderView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAudioPlayHeaderView.h"
#import "WXYZ_BookAiPlayPageViewController.h"
#import "WXYZ_AudioSettingHelper.h"
#import "TFReadRecordManager.h"
#import "WXYZ_AudioDownloadManager.h"
#import "WXYZ_ChapterBottomPayBar.h"
#import "WXYZ_TouchAssistantView.h"
#import "CKAudioProgressView.h"
#import "WXYZ_PlayPageModel.h"
#if __has_include(<iflyMSC/IFlyMSC.h>)
#import "iflyMSC/IFlyMSC.h"
#endif
#import "WXYZ_Player.h"
@interface TFAudioPlayHeaderView ()<WXYZ_PlayerDelegate, WXYZ_PlayerDataSource, CKAudioProgressViewDelegate>
@end
@implementation TFAudioPlayHeaderView
- (instancetype)initWithProductionType:(TFProductionType)productionType
{
[self initAVAudio];
return [super initWithProductionType:productionType];
}
- (void)initAVAudio
{
[[WXYZ_Player sharedPlayer] initPlayerWithUserId:nil];
[WXYZ_Player sharedPlayer].dataSource = self;
[WXYZ_Player sharedPlayer].delegate = self;
[WXYZ_Player sharedPlayer].playMode = WXYZ_PlayerModeOnlyOnce;
}
- (void)createSubviews
{
[super createSubviews];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(relationViewTitleChange) name:Notification_Change_AiBook_Chapter object:nil];
}
- (void)setProductionChapterModel:(TFProductionChapterModel *)productionChapterModel
{
[super setProductionChapterModel:productionChapterModel];
WS(weakSelf)
[[WXYZ_AudioSettingHelper sharedManager] getCurrentTimingBlock:^(NSUInteger currentTime) {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.timingButton.buttonTitle = [NSString stringWithFormat:@"%02zd:%02zd", (NSInteger)(currentTime / 60), (NSInteger)(currentTime % 60)];
});
} finishBlock:^{
dispatch_async(dispatch_get_main_queue(), ^{
if ([[WXYZ_AudioSettingHelper sharedManager] getReadTiming] == 1) {
weakSelf.timingButton.buttonTitle = TFLocalizedString(@"听完本章节");
} else if ([[WXYZ_AudioSettingHelper sharedManager] getReadTiming] == 0) {
weakSelf.timingButton.buttonTitle = TFLocalizedString(@"定时");
if (weakSelf.playerState == TFBasicVoicePlayerStatePlaying) {
[[WXYZ_Player sharedPlayer] pause];
}
}
});
}];
if ([TFNetworkManager networkingStatus] == NO) {
if (![[WXYZ_AudioDownloadManager sharedManager] isChapterDownloadedWithProduction_id:productionChapterModel.production_id chapter_id:productionChapterModel.chapter_id]) {
[[WXYZ_TouchAssistantView sharedManager] stopPlayerState];
[[WXYZ_TouchAssistantView sharedManager] changePlayProgress:0];
[[WXYZ_Player sharedPlayer] deallocPlayer];
self.playerState = TFBasicVoicePlayerStateStoped;
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"当前为离线状态,只可查看缓存内容哦")];
return;
}
}
// 如果是付费章节,弹出付费,停止播放
if (self.temp_chapterModel.chapter_id == productionChapterModel.chapter_id && self.temp_chapterModel.is_preview == productionChapterModel.is_preview) {
if (productionChapterModel.is_preview == 1) {
[self showPayView];
}
return;
}
if ([WXYZ_BookAiPlayPageViewController sharedManager].speaking && ![[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAi]) {
#if __has_include(<iflyMSC/IFlyMSC.h>)
[[IFlySpeechSynthesizer sharedInstance] pauseSpeaking];
#endif
[[WXYZ_Player sharedPlayer] play];
}
if ([[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAi]) {
[[WXYZ_AudioSettingHelper sharedManager] playPageViewShow:NO productionType:TFProductionTypeAi];
if ([WXYZ_BookAiPlayPageViewController sharedManager].speaking) {
self.playerState = TFBasicVoicePlayerStateStoped;
}
return;
}
self.temp_chapterModel = productionChapterModel;
[WXYZ_Player sharedPlayer].remoteCenterPreviousEnable = !(productionChapterModel.last_chapter == 0);
[WXYZ_Player sharedPlayer].remoteCenterNextEnable = !(productionChapterModel.next_chapter == 0);
if (productionChapterModel.is_preview == 1) {
[[WXYZ_TouchAssistantView sharedManager] stopPlayerState];
[[WXYZ_TouchAssistantView sharedManager] changePlayProgress:0];
[[WXYZ_Player sharedPlayer] deallocPlayer];
self.playerState = TFBasicVoicePlayerStateStoped;
[self showPayView];
return;
}
[[WXYZ_Player sharedPlayer] reloadData]; // 需在传入数据源后调用
[[WXYZ_Player sharedPlayer] playWithAudioId:0];
}
- (void)relationViewTitleChange
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self setRelationViewTitle:[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAi] getReadingRecordChapterTitleWithProduction_id:self.relationModel.production_id]?:self.relationModel.chapter_title?:@""];
});
}
#pragma mark - WXYZ_PlayerDelegate
- (NSArray<WXYZ_PlayerModel *> *)audioDataForPlayer:(WXYZ_Player *)player
{
WXYZ_PlayerModel *playerModel = [[WXYZ_PlayerModel alloc] init];
NSString *localAudioFilePath = [[WXYZ_AudioDownloadManager sharedManager] chapterDownloadedFilePathWithProduction_id:self.productionChapterModel.production_id chapter_id:self.productionChapterModel.chapter_id chapter_update_time:self.productionChapterModel.update_time];
// 使用本地环境播放
if ([[NSFileManager defaultManager] fileExistsAtPath:localAudioFilePath]) {
playerModel.audioUrl = [NSURL fileURLWithPath:[[WXYZ_AudioDownloadManager sharedManager] chapterDownloadedFilePathWithProduction_id:self.productionChapterModel.production_id chapter_id:self.productionChapterModel.chapter_id chapter_update_time:self.productionChapterModel.update_time]];
} else if ([TFNetworkManager networkingStatus] == YES) {
playerModel.audioUrl = [NSURL URLWithString:self.productionChapterModel.content?:@""];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"作品未下载")];
self.playerState = TFBasicVoicePlayerStateStoped;
return @[];
}
playerModel.audioId = 0;
return @[playerModel];
}
- (WXYZ_PlayerInfoModel *)audioInfoForPlayer:(WXYZ_Player *)player
{
WXYZ_PlayerInfoModel *infoModel = [[WXYZ_PlayerInfoModel alloc] init];
infoModel.audioName = self.productionChapterModel.chapter_title;
infoModel.audioAlbum = self.productionChapterModel.name;
infoModel.audioImage = [[YYImageCache sharedCache] getImageForKey:self.productionChapterModel.cover];
return infoModel;
}
// 远程控制切换上一首
- (void)audioPlayerRemoteCenterSwitchToPrevious
{
[self skipToLastChapter];
}
// 远程控制切换下一首
- (void)audioPlayerRemoteCenterSwitchToNext
{
[self skipToNextChapter];
}
// 准备播放
- (void)playerReadyToPlay:(WXYZ_Player *)player
{
[[WXYZ_Player sharedPlayer] setRate:[[[[WXYZ_AudioSettingHelper sharedManager] getReadSpeedValuesWithProducitionType:self.productionType] objectAtIndex:[[WXYZ_AudioSettingHelper sharedManager] getReadSpeedWithProducitionType:self.productionType]] floatValue]];
self.playerState = TFBasicVoicePlayerStateLoading;
if ([[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeNovel] && [[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAudio] && [WXYZ_BookAiPlayPageViewController sharedManager].speaking) {
[[WXYZ_Player sharedPlayer] pause];
} else {
if ([WXYZ_BookAiPlayPageViewController sharedManager].speaking) {
#if __has_include(<iflyMSC/IFlyMSC.h>)
[[IFlySpeechSynthesizer sharedInstance] pauseSpeaking];
#endif
}
}
// 播放进度记录百分比 0 - 1
CGFloat progress = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] getPlayingProgressWithProduction_id:self.productionChapterModel.production_id chapter_id:self.productionChapterModel.chapter_id];
if (progress > 0.05) {
[[WXYZ_Player sharedPlayer] seekToTime:progress completionBlock:nil];
}
}
// 播放结束
- (void)playerDidPlayToEndTime:(WXYZ_Player *)player
{
// 听完本章结束播放
if ([[WXYZ_AudioSettingHelper sharedManager] getReadTiming] == 1) {
[[WXYZ_AudioSettingHelper sharedManager] setReadTimingWithIndex:0];
self.timingButton.buttonTitle = TFLocalizedString(@"定时");
[[WXYZ_Player sharedPlayer] pause];
} else {
if (self.productionChapterModel.next_chapter > 0 && self.productionChapterModel.next_chapter) {
[self skipToNextChapter];
}
}
}
//播放进度代理
- (void)player:(WXYZ_Player *)player progress:(CGFloat)progress currentTime:(CGFloat)currentTime totalTime:(CGFloat)totalTime
{
[[WXYZ_TouchAssistantView sharedManager] changePlayProgress:progress];
[self.timelineProgress updateProgress:progress audioLength:totalTime];
// 记录阅读进度
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] addPlayingProgress:progress production_id:self.productionChapterModel.production_id chapter_id:self.productionChapterModel.chapter_id];
}
// 缓冲进度
- (void)player:(WXYZ_Player *)player bufferProgress:(CGFloat)bufferProgress
{
[self.timelineProgress updateCacheProgress:bufferProgress];
}
- (void)playerStateChange:(TFBasicVoicePlayerState)playerState
{
self.playerState = playerState;
}
@end
@@ -0,0 +1,22 @@
//
// TFBookRackCommViewController.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/1.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFBookRackCommViewController : TFBasicViewController
@property (nonatomic ,copy) void (^pushToReaderViewControllerBlock)(UIView *transitionView, TFProductionModel *productionModel);
// 结束编辑状态
- (void)endEdited;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,617 @@
//
// TFBookRackCommViewController.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/1.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookRackCommViewController.h"
#if TF_Enable_Book
#import "TFReadNovelViewController.h"
#endif
#if TF_Enable_Comic
#import "TFComicBrowseViewController.h"
#endif
#if TF_Enable_Audio
#import "TFAudioPlayViewController.h"
#endif
#import "TFAnnouncementController.h"
#import "TFTaskViewController.h"
#import "TFBookRackCommCell.h"
#import "TFBookRackAddMoreCell.h"
#import "TFBookRackHeaderView.h"
#import "TFCollectionManager.h"
#import "TFReadRecordManager.h"
#import "NSObject+Observer.h"
@interface TFBookRackCommViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic ,strong) TFBookRackHeaderView *headerView;
@property (nonatomic ,strong) UIView *toolBarView;
@property (nonatomic ,strong) UIButton *deleteBtn;
@property (nonatomic ,strong) UIButton *checkAllBtn;
@property (nonatomic ,strong) TFBookRackModel *bookRackModel;
@property (nonatomic ,strong) NSMutableArray *deleteSourceArray;
// 角标记录
@property (nonatomic ,strong) NSMutableDictionary *badges;
@property (nonatomic ,assign) BOOL editingProduction;
@end
@implementation TFBookRackCommViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
[self localSourceRequest];
[self netRequest];
}
- (void)initialize
{
[self hiddenNavigationBar:YES];
self.view.backgroundColor = kWhiteColor;
self.deleteSourceArray = [NSMutableArray array];
// 签到加入书架
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localSourceRequest) name:Notification_Reload_Rack_Production object:nil];
}
- (void)createSubviews
{
self.mainCollectionViewFlowLayout.minimumLineSpacing = kMargin;
self.mainCollectionViewFlowLayout.minimumInteritemSpacing = 0;
self.mainCollectionViewFlowLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, Rack_Header_Height);
self.mainCollectionViewFlowLayout.footerReferenceSize = CGSizeMake(SCREEN_WIDTH, kHalfMargin);
self.mainCollectionViewFlowLayout.itemSize = CGSizeMake(BOOK_WIDTH, BOOK_HEIGHT + BOOK_CELL_TITLE_HEIGHT / 2);
self.mainCollectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(0, kHalfMargin, 0, kHalfMargin);
self.mainCollectionView.delegate = self;
self.mainCollectionView.dataSource = self;
[self.mainCollectionView registerClass:[TFBookRackCommCell class] forCellWithReuseIdentifier:@"TFBookRackCommCell"];
[self.mainCollectionView registerClass:[TFBookRackAddMoreCell class] forCellWithReuseIdentifier:@"TFBookRackAddMoreCell"];
[self.mainCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];
[self.mainCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView"];
[self.view addSubview:self.mainCollectionView];
[self.mainCollectionView 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_NAVBAR_HEIGHT - PUB_TABBAR_HEIGHT);
}];
UILongPressGestureRecognizer *editLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(startEdited:)];
editLongPressGesture.minimumPressDuration = 1.0f;
editLongPressGesture.numberOfTouchesRequired = 1;
[self.mainCollectionView addGestureRecognizer:editLongPressGesture];
WS(weakSelf)
self.mainCollectionView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf localSourceRequest];
[weakSelf netRequest];
}];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (self.editingProduction) {
return self.dataSourceArray.count;
}
return self.dataSourceArray.count + 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (self.dataSourceArray.count == indexPath.row && !self.editingProduction) {
static NSString *CellIdentifier = @"TFBookRackAddMoreCell";
TFBookRackAddMoreCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
} else {
static NSString *CellIdentifier = @"TFBookRackCommCell";
TFBookRackCommCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
TFProductionModel *t_bookModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
cell.productionModel = t_bookModel;
cell.badgeNum = [TFUtilsHelper formatStringWithInteger:[[self.badges objectForKey:[TFUtilsHelper formatStringWithInteger:t_bookModel.production_id]] total_chapters]];
cell.bookSeleced = NO;
cell.startEditing = self.editingProduction;
for (TFProductionModel *t_model in self.deleteSourceArray) {
if (t_model.production_id == t_bookModel.production_id) {
cell.bookSeleced = YES;
}
}
return cell;
}
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
UICollectionReusableView *headerReusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
headerReusableView.backgroundColor = [UIColor clearColor];
if (self.bookRackModel && self.bookRackModel.recommendList.count > 0 && !self.editingProduction) {
self.headerView.rackModel = self.bookRackModel;
[self showHeaderViewWithAnimated:NO];
} else if (self.bookRackModel) {
[self hiddenHeaderViewWithAnimated:NO];
}
[headerReusableView addSubview:self.headerView];
return headerReusableView;
} else {
UICollectionReusableView *footerReusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
return footerReusableView;
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if (self.dataSourceArray.count == indexPath.row && !self.editingProduction) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Change_Tabbar_Index object:@"1"];
switch (self.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel:
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Rack_JumpToMallCenter object:@"novel"];
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic:
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Rack_JumpToMallCenter object:@"comic"];
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio:
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Rack_JumpToMallCenter object:@"audio"];
break;
#endif
default:
break;
}
} else {
TFBookRackCommCell *cell = (TFBookRackCommCell *)[collectionView cellForItemAtIndexPath:indexPath];
TFProductionModel *productionModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
if (!self.editingProduction) {
[[TFCollectionManager shareManagerWithProductionType:self.productionType] moveCollectionToTopWithProductionModel:productionModel];
switch (self.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel: {
if (self.pushToReaderViewControllerBlock) {
self.pushToReaderViewControllerBlock(cell.coverView, productionModel);
}
}
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic: {
TFComicBrowseViewController *comicBrowse = [[TFComicBrowseViewController alloc] init];
comicBrowse.comicProductionModel = productionModel;
comicBrowse.chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:productionModel.production_id];
[self.navigationController pushViewController:comicBrowse animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio: {
TFAudioPlayViewController *audioPlay = [[TFAudioPlayViewController alloc] init];
[audioPlay loadDataWithAudio_id:productionModel.production_id chapter_id:0];
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:audioPlay];
[[TFViewHelper getWindowRootController] presentViewController:nav animated:YES completion:nil];
}
break;
#endif
default:
break;
}
// 读书任务请求
[TFTaskViewController taskReadRequestWithProduction_id:productionModel.production_id];
// 如果有更新则更新本地数据源
if ([cell.badgeNum integerValue] > 0) {
TFProductionModel *t_model = [self.badges objectForKey:[TFUtilsHelper formatStringWithInteger:productionModel.production_id]];
if (t_model) {
[[TFCollectionManager shareManagerWithProductionType:self.productionType] modificationCollectionWithProductionModel:t_model];
}
}
return;
}
if (cell.bookSeleced) {
cell.bookSeleced = NO;
[self.deleteSourceArray removeObject:productionModel];
} else {
cell.bookSeleced = YES;
[self.deleteSourceArray addObject:productionModel];
}
[self reloadToolBarState];
}
}
#pragma mark - 点击事件
- (void)showHeaderViewWithAnimated:(BOOL)animated
{
if (self.bookRackModel.recommendList.count == 0) return;
[self.mainCollectionView showRefreshHeader];
[UIView animateWithDuration:animated?kAnimatedDuration:0.0f animations:^{
if (self.bookRackModel.announcement.count > 0) {
self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, Rack_Header_Height);
self.mainCollectionViewFlowLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, Rack_Header_Height);
} else {
self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, Rack_Header_Height_NoRecommend);
self.mainCollectionViewFlowLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, Rack_Header_Height_NoRecommend);
}
[self.mainCollectionView setCollectionViewLayout:self.mainCollectionViewFlowLayout animated:animated];
}];
}
- (void)hiddenHeaderViewWithAnimated:(BOOL)animated
{
[self.mainCollectionView hideRefreshHeader];
[UIView animateWithDuration:animated?kAnimatedDuration:0.0f animations:^{
self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 0);
self.mainCollectionViewFlowLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, 10);
[self.mainCollectionView setCollectionViewLayout:self.mainCollectionViewFlowLayout animated:animated];
}];
}
// 工具栏点击
- (void)toolBarActionClick:(UIButton *)sender
{
switch (sender.tag) {
case 11: // 取消操作
[self endEdited];
break;
case 22: { // 删除操作
if (self.deleteSourceArray.count == 0) {
return;
}
NSMutableArray *t_deleteArray = [NSMutableArray array];
for (TFProductionModel *t_model in self.deleteSourceArray) {
[[TFCollectionManager shareManagerWithProductionType:self.productionType] removeCollectionWithProductionModel:t_model];
[t_deleteArray addObject:[TFUtilsHelper formatStringWithInteger:t_model.production_id]];
}
NSString *url = @"";
NSString *production_key = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Delete_Collect;
production_key = @"book_id";
break;
case TFProductionTypeComic:
url = Comic_Collect_Delete;
production_key = @"comic_id";
break;
case TFProductionTypeAudio:
url = Audio_Collection_Delete;
production_key = @"audio_id";
break;
default:
break;
}
[TFNetworkTools POST:url parameters:@{production_key:[t_deleteArray componentsJoinedByString:@","]} model:nil success:nil failure:nil];
[self endEdited];
[self localSourceRequest];
}
case 33: { // 全选/取消操作
[self.deleteSourceArray removeAllObjects];
if (!sender.selected) {
self.deleteSourceArray = [self.dataSourceArray mutableCopy];
[sender setTitle:TFLocalizedString(@"取消全选") forState:UIControlStateNormal];
} else {
[sender setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
[self.deleteSourceArray removeAllObjects];
}
sender.selected = !sender.selected;
[self.mainCollectionView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[TFBookRackCommCell class]]) {
TFBookRackCommCell *cell = (TFBookRackCommCell *)obj;
cell.bookSeleced = sender.selected;
}
}];
[self reloadToolBarState];
}
break;
default:
break;
}
}
// 开启编辑状态
- (void)startEdited:(UILongPressGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
return;
}
if (self.editingProduction) {
return;
}
self.editingProduction = YES;
[self.deleteSourceArray removeAllObjects];
CGPoint pointTouch = [gestureRecognizer locationInView:self.mainCollectionView];
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
NSIndexPath *indexPath = [self.mainCollectionView indexPathForItemAtPoint:pointTouch];
if ([[self.mainCollectionView cellForItemAtIndexPath:indexPath] isKindOfClass:[TFBookRackCommCell class]]) {
// 获取当前被点击的书籍,默认选中
TFBookRackCommCell *t_cell = (TFBookRackCommCell *)[self.mainCollectionView cellForItemAtIndexPath:indexPath];
[self.deleteSourceArray addObject:t_cell.productionModel];
// 隐藏推荐栏
[self hiddenHeaderViewWithAnimated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((kAnimatedDuration + 0.1) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.mainCollectionView reloadData];
});
[UIView animateWithDuration:kAnimatedDuration animations:^{
self.toolBarView.frame = CGRectMake(0, SCREEN_HEIGHT - PUB_TABBAR_HEIGHT, SCREEN_WIDTH, PUB_TABBAR_HEIGHT);
}];
[self reloadToolBarState];
} else {
self.editingProduction = NO;
}
}
}
- (void)endEdited
{
self.editingProduction = NO;
[self showHeaderViewWithAnimated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kAnimatedDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.mainCollectionView reloadData];
});
[UIView animateWithDuration:kAnimatedDuration animations:^{
self.toolBarView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, PUB_TABBAR_HEIGHT);
}];
[self reloadToolBarState];
}
- (void)reloadToolBarState
{
if (self.deleteSourceArray.count == 0) {
self.deleteBtn.backgroundColor = kGrayLineColor;
self.deleteBtn.enabled = NO;
[self.deleteBtn setTitle:TFLocalizedString(@"删除(0)") forState:UIControlStateNormal];
[self.deleteBtn setTitleColor:kGrayTextColor forState:UIControlStateNormal];
self.checkAllBtn.selected = NO;
[self.checkAllBtn setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
} else {
self.deleteBtn.backgroundColor = kRedColor;
self.deleteBtn.enabled = YES;
[self.deleteBtn setTitle:[NSString stringWithFormat:@"%@(%@)", TFLocalizedString(@"删除"), [TFUtilsHelper formatStringWithInteger:self.deleteSourceArray.count]] forState:UIControlStateNormal];
[self.deleteBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
if (self.deleteSourceArray.count == self.dataSourceArray.count) {
self.checkAllBtn.selected = YES;
[self.checkAllBtn setTitle:TFLocalizedString(@"取消全选") forState:UIControlStateNormal];
} else {
self.checkAllBtn.selected = NO;
[self.checkAllBtn setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
}
}
}
- (TFBookRackHeaderView *)headerView
{
if (!_headerView) {
WS(weakSelf)
_headerView = [[TFBookRackHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Rack_Header_Height)];
_headerView.backgroundColor = [UIColor whiteColor];
_headerView.productionType = self.productionType;
_headerView.adBannerClickBlock = ^(NSString * _Nonnull title, NSString * _Nonnull content) {
TFAnnouncementController *vc = [[TFAnnouncementController alloc] init];
vc.titleText = title?:@"";
vc.contentText = content?:@"";
[weakSelf.navigationController pushViewController:vc animated:YES];
};
_headerView.recommendBannerClickBlock = ^(NSInteger production_id) {
switch (weakSelf.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel: {
TFNovelDetailViewController *novelDetail = [[TFNovelDetailViewController alloc] init];
novelDetail.book_id = production_id;
[weakSelf.navigationController pushViewController:novelDetail animated:YES];
}
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic: {
TFComicDetailViewController *comicDetail = [[TFComicDetailViewController alloc] init];
comicDetail.comic_id = production_id;
[weakSelf.navigationController pushViewController:comicDetail animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio: {
TFAudioDetailViewController *audioDetail = [[TFAudioDetailViewController alloc] init];
audioDetail.audio_id = production_id;
[weakSelf.navigationController pushViewController:audioDetail animated:YES];
}
break;
#endif
default:
break;
}
};
_headerView.collectionClickBlock = ^{
[weakSelf.navigationController pushViewController:[[TFTaskViewController alloc] init] animated:YES];
};
}
return _headerView;
}
- (UIView *)toolBarView
{
if (!_toolBarView) {
_toolBarView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, PUB_TABBAR_HEIGHT)];
_toolBarView.backgroundColor = kWhiteColor;
WS(weakSelf)
[_toolBarView addObserver:KEY_PATH(_toolBarView, frame) complete:^(UIView * _Nonnull toolBarView, id _Nullable oldVal, id _Nullable newVal) {
CGRect frame = [newVal CGRectValue];
if (CGRectGetMinY(frame) >= SCREEN_HEIGHT) {
toolBarView.hidden = YES;
weakSelf.tabBarController.tabBar.hidden = NO;
} else {
toolBarView.hidden = NO;
weakSelf.tabBarController.tabBar.hidden = YES;
}
}];
[self.view addSubview:_toolBarView];
UIButton *checkAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
checkAllBtn.tag = 33;
checkAllBtn.selected = NO;
checkAllBtn.frame = CGRectMake(0, 0, SCREEN_WIDTH / 3, PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
checkAllBtn.adjustsImageWhenHighlighted = NO;
[checkAllBtn setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
[checkAllBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
[checkAllBtn.titleLabel setFont:kMainFont];
[checkAllBtn addTarget:self action:@selector(toolBarActionClick:) forControlEvents:UIControlEventTouchUpInside];
[_toolBarView addSubview:checkAllBtn];
self.checkAllBtn = checkAllBtn;
UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
deleteBtn.frame = CGRectMake(SCREEN_WIDTH / 3, 0, SCREEN_WIDTH / 3, PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
deleteBtn.backgroundColor = kGrayLineColor;
deleteBtn.tag = 22;
[deleteBtn setTitleColor:kGrayTextColor forState:UIControlStateNormal];
[deleteBtn setTitle:TFLocalizedString(@"删除") forState:UIControlStateNormal];
[deleteBtn.titleLabel setFont:kMainFont];
[deleteBtn addTarget:self action:@selector(toolBarActionClick:) forControlEvents:UIControlEventTouchUpInside];
[_toolBarView addSubview:deleteBtn];
self.deleteBtn = deleteBtn;
UIButton *cancleButton = [UIButton buttonWithType:UIButtonTypeCustom];
cancleButton.frame = CGRectMake(SCREEN_WIDTH / 3 * 2, 0, SCREEN_WIDTH / 3, PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
cancleButton.tag = 11;
[cancleButton setTitle:TFLocalizedString(@"取消") forState:UIControlStateNormal];
[cancleButton setTitleColor:kBlackColor forState:UIControlStateNormal];
[cancleButton.titleLabel setFont:kMainFont];
[cancleButton addTarget:self action:@selector(toolBarActionClick:) forControlEvents:UIControlEventTouchUpInside];
[_toolBarView addSubview:cancleButton];
}
return _toolBarView;
}
// 加载本地书籍缓存
- (void)localSourceRequest
{
NSArray *cacheArray = [[TFCollectionManager shareManagerWithProductionType:self.productionType] getAllCollection];
if (![cacheArray isEqualToArray:self.dataSourceArray]) {
self.dataSourceArray = [cacheArray mutableCopy];
[self.mainCollectionView reloadData];
}
[self.mainCollectionView scrollToTop];
[self.mainCollectionView endRefreshing];
}
- (void)netRequest
{
// 书籍更新角标
self.badges = [NSMutableDictionary dictionary];
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Rack;
break;
case TFProductionTypeComic:
url = Comic_Rack;
break;
case TFProductionTypeAudio:
url = Audio_Rack;
break;
default:
break;
}
WS(weakSelf)
[TFNetworkTools POST:url parameters:nil model:TFBookRackModel.class success:^(BOOL isSuccess, TFBookRackModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.bookRackModel = t_model;
for (TFProductionModel *t_model in weakSelf.bookRackModel.productionList) {
[weakSelf.badges setObject:t_model forKey:[TFUtilsHelper formatStringWithInteger:t_model.production_id]];
}
}
[weakSelf.mainCollectionView endRefreshing];
[weakSelf.mainCollectionView reloadData];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainCollectionView endRefreshing];
[weakSelf.mainCollectionView reloadData];
}];
}
@end
@@ -0,0 +1,17 @@
//
// TFBookRackViewController.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/1.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFBookRackViewController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,169 @@
//
// TFBookRackViewController.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/1.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookRackViewController.h"
#import "TFTaskViewController.h"
#import "TFBookRackCommViewController.h"
#if TF_Enable_Book
#import "TFReadNovelViewController.h"
#endif
#import "NSObject+DZM.h"
#import "UINavigationController+TFExtension.h"
@interface TFBookRackViewController ()<SGPageTitleViewDelegate, SGPageContentCollectionViewDelegate>
@property (nonatomic ,strong) SGPageTitleView *pageTitleView;
@property (nonatomic ,strong) SGPageContentCollectionView *pageContentView;
@property (nonatomic ,strong) NSMutableArray *childControllers;
@end
@implementation TFBookRackViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Show_Tabbar object:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
[self hiddenNavigationBarLeftButton];
[self hiddenSeparator];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(synchronizationRack) name:Notification_Login_Success object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(synchronizationRack) name:Notification_Reload_Rack_Production object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(synchronizationRack) name:UIApplicationWillEnterForegroundNotification object:nil];
}
- (void)synchronizationRack
{
[TFUtilsHelper synchronizationRack];
}
- (void)createSubviews
{
#if TF_Enable_Book
WS(weakSelf)
TFBookRackCommViewController *novel = [[TFBookRackCommViewController alloc] init];
novel.productionType = TFProductionTypeNovel;
novel.pushToReaderViewControllerBlock = ^(UIView * _Nonnull transitionView, TFProductionModel * _Nonnull productionModel) {
weakSelf.ATTarget = transitionView;
TFReadNovelViewController *vc = [[TFReadNovelViewController alloc] init];
vc.book_id = productionModel.production_id;
[weakSelf.navigationController jumpNextViewController:vc animated:YES];
};
novel.view.backgroundColor = kWhiteColor;
[self addChildViewController:novel];
#endif
#if TF_Enable_Comic
TFBookRackCommViewController *comic = [[TFBookRackCommViewController alloc] init];
comic.productionType = TFProductionTypeComic;
comic.view.backgroundColor = kWhiteColor;
[self addChildViewController:comic];
#endif
#if TF_Enable_Audio
TFBookRackCommViewController *audio = [[TFBookRackCommViewController alloc] init];
audio.productionType = TFProductionTypeAudio;
audio.view.backgroundColor = kWhiteColor;
[self addChildViewController:audio];
#endif
NSMutableArray *titleArray = [NSMutableArray array];
self.childControllers = [NSMutableArray array];
for (NSNumber *siteNumber in [TFUtilsHelper getSiteState]) {
#if TF_Enable_Book
if ([siteNumber integerValue] == 1) {
[titleArray addObject:TFLocalizedString(@"小说")];
[self.childControllers addObject:novel];
}
#endif
#if TF_Enable_Comic
if ([siteNumber integerValue] == 2) {
[titleArray addObject:TFLocalizedString(@"漫画")];
[self.childControllers addObject:comic];
}
#endif
#if TF_Enable_Audio
if ([siteNumber integerValue] == 3) {
[titleArray addObject:TFLocalizedString(@"听书")];
[self.childControllers addObject:audio];
}
#endif
}
if ([TFUtilsHelper getSiteState].count == 1) {
[titleArray removeAllObjects];
[titleArray addObject:TFLocalizedString(@"书架")];
}
self.pageContentView = [[SGPageContentCollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) parentVC:self childVCs:self.childControllers];
self.pageContentView.delegatePageContentCollectionView = self;
[self.view addSubview:self.pageContentView];
self.pageConfigure.indicatorStyle = SGIndicatorStyleDynamic;
self.pageConfigure.indicatorDynamicWidth = 14;
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.showIndicator = YES;
CGFloat width = 0;
for (NSString *obj in titleArray) {
CGFloat t_width = [TFViewHelper getDynamicWidthWithLabelFont:kBoldFont16 labelHeight:43.0 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:titleArray configure:self.pageConfigure];
self.pageTitleView.backgroundColor = [UIColor clearColor];
[self.navigationBar addSubview:self.pageTitleView];
}
- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex
{
[self.pageContentView setPageContentCollectionViewCurrentIndex:selectedIndex];
}
- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex
{
[self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}
- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView index:(NSInteger)index
{
for (UIViewController *viewController in self.childControllers) {
[viewController performSelector:@selector(endEdited)];
}
}
@end
@@ -0,0 +1,38 @@
//
// TFBookRackModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/11.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFBaseInfoModel, TFAnnouncementModel, TFProductionModel, WXYZ_TaskModel;
@interface TFBookRackModel : NSObject
@property (nonatomic ,strong) TFBaseInfoModel *base_info;
@property (nonatomic ,strong) NSArray <TFAnnouncementModel *>* announcement; // 公告
@property (nonatomic ,strong) NSArray <TFProductionModel *>* recommendList; // 推荐
@property (nonatomic ,strong) NSArray <TFProductionModel *>* productionList; // 作品列表
@end
@interface TFBaseInfoModel : NSObject
@property (nonatomic ,assign) NSInteger sign_status;
@end
@interface TFAnnouncementModel : NSObject
@property (nonatomic ,copy) NSString *title;
@property (nonatomic ,copy) NSString *content;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,40 @@
//
// TFBookRackModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/11.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookRackModel.h"
@implementation TFBookRackModel
+ (NSDictionary *)modelCustomPropertyMapper
{
return @{
@"rackDescription" : @"description",
@"announcement" : @[@"announce", @"announcement"],
@"recommendList" : @[@"recommend_list", @"recommend"],
@"productionList" : @[@"list"]
};
}
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{
@"announcement" : [TFAnnouncementModel class],
@"recommendList" : [TFProductionModel class],
@"productionList" : [TFProductionModel class]
};
}
@end
@implementation TFBaseInfoModel
@end
@implementation TFAnnouncementModel
@end
@@ -0,0 +1,21 @@
//
// TFBookRackAddMoreCell.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 TFBookRackAddMoreCell : UICollectionViewCell
- (void)startEditState;
- (void)endEditState;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,56 @@
//
// TFBookRackAddMoreCell.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookRackAddMoreCell.h"
@implementation TFBookRackAddMoreCell
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor clearColor];
[self createSubviews];
}
return self;
}
- (void)createSubviews
{
UIView *borderView = [[UIView alloc] init];
borderView.backgroundColor = kGrayViewColor;
borderView.layer.cornerRadius = 2;
[self addSubview:borderView];
[borderView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.mas_centerX);
make.top.mas_equalTo(self.mas_top);
make.width.mas_equalTo(BOOK_WIDTH);
make.height.mas_equalTo(BOOK_HEIGHT);
}];
UIImageView *addImageView = [[UIImageView alloc] init];
addImageView.image = [UIImage imageNamed:@"public_rack_add"];
[borderView addSubview:addImageView];
[addImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(borderView.mas_centerX);
make.centerY.mas_equalTo(borderView.mas_centerY);
make.height.width.mas_equalTo(30);
}];
}
- (void)startEditState
{
self.hidden = YES;
}
- (void)endEditState
{
self.hidden = NO;
}
@end
@@ -0,0 +1,28 @@
//
// TFBookRackCommCell.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/1.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class TFProductionModel;
@interface TFBookRackCommCell : UICollectionViewCell
@property (nonatomic ,strong) TFProductionModel *productionModel;
@property (nonatomic ,assign) BOOL bookSeleced;
@property (nonatomic ,strong) TFProductionCoverView *coverView;
@property (nonatomic ,strong) NSString *badgeNum;
@property (nonatomic ,assign) BOOL startEditing;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,180 @@
//
// TFBookRackCommCell.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/1.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookRackCommCell.h"
@interface TFBookRackCommCell ()
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) UILabel *finishedLabel;
@property (nonatomic ,strong) UIImageView *selectView;
@property (nonatomic ,strong) UIImageView *recommendView;
@property (nonatomic ,strong) UILabel *badgeLabel;
@end
@implementation TFBookRackCommCell
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = kWhiteColor;
[self createSubviews];
}
return self;
}
- (void)createSubviews
{
self.coverView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical];
self.coverView.userInteractionEnabled = YES;
[self addSubview:self.coverView];
[self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.mas_centerX);
make.top.mas_equalTo(self.mas_top);
make.width.mas_equalTo(BOOK_WIDTH);
make.height.mas_equalTo(BOOK_HEIGHT);
}];
self.recommendView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:TFLocalizedString(@"book_rack_recommend_conner")]];
self.recommendView.hidden = YES;
[self.coverView addSubview:self.recommendView];
[self.recommendView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(BOOK_WIDTH / 3);
make.height.mas_equalTo(kGeometricHeight((BOOK_WIDTH / 3), 102, 54));
}];
self.badgeLabel = [[UILabel alloc] init];
self.badgeLabel.hidden = YES;
self.badgeLabel.textAlignment = NSTextAlignmentCenter;
self.badgeLabel.textColor = kWhiteColor;
self.badgeLabel.backgroundColor = kColorRGBA(229, 91, 94, 1);
self.badgeLabel.font = kFont9;
self.badgeLabel.numberOfLines = 1;
self.badgeLabel.layer.cornerRadius = 8;
self.badgeLabel.layer.borderColor = [UIColor whiteColor].CGColor;
self.badgeLabel.layer.borderWidth = 2;
self.badgeLabel.clipsToBounds = YES;
[self.coverView addSubview:self.badgeLabel];
[self.badgeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.coverView.mas_right).with.offset(- 3);
make.centerY.mas_equalTo(self.coverView.mas_top).with.offset(3);
make.width.height.mas_equalTo(16);
}];
self.selectView = [[UIImageView alloc] init];
self.selectView.hidden = YES;
self.selectView.userInteractionEnabled = YES;
self.selectView.image = [UIImage imageNamed:@"audio_download_unselect"];
[self addSubview:self.selectView];
[self.selectView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.coverView.mas_right).with.offset(- 5);
make.bottom.mas_equalTo(self.coverView.mas_bottom).with.offset(- 5);
make.height.width.mas_equalTo(18);
}];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.numberOfLines = 1;
self.titleLabel.backgroundColor = kGrayViewColor;
self.titleLabel.font = kFont12;
self.titleLabel.textAlignment = NSTextAlignmentLeft;
self.titleLabel.textColor = kBlackColor;
[self addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.coverView.mas_left);
make.top.mas_equalTo(self.coverView.mas_bottom).with.offset(kHalfMargin);
make.width.mas_equalTo(self.coverView.mas_width);
make.height.mas_equalTo(BOOK_CELL_TITLE_HEIGHT / 2);
}];
}
- (void)setProductionModel:(TFProductionModel *)productionModel
{
_productionModel = productionModel;
self.coverView.productionType = productionModel.productionType;
if (productionModel.cover.length > 0) {
self.coverView.coverImageUrl = productionModel.cover;
} else if (productionModel.vertical_cover.length > 0) {
self.coverView.coverImageUrl = productionModel.vertical_cover;
} else if (productionModel.horizontal_cover.length > 0) {
self.coverView.coverImageUrl = productionModel.horizontal_cover;
}
self.recommendView.hidden = !productionModel.is_recommend;
self.titleLabel.backgroundColor = kWhiteColor;
self.titleLabel.text = productionModel.name ? : @"";
self.badgeLabel.hidden = YES;
}
- (void)setBookSeleced:(BOOL)bookSeleced
{
_bookSeleced = bookSeleced;
if (bookSeleced) {
self.selectView.image = [UIImage imageNamed:@"audio_download_select"];
self.coverView.alpha = 1.0f;
} else {
self.selectView.image = [UIImage imageNamed:@"audio_download_unselect"];
self.coverView.alpha = 0.5f;
}
}
- (void)setBadgeNum:(NSString *)badgeNum
{
if ([badgeNum isEqualToString:@"0"]) {
return;
}
if (_productionModel.total_chapters == 0) {
return;
}
badgeNum = [NSString stringWithFormat:@"%@", [TFUtilsHelper formatStringWithInteger:abs((int)_productionModel.total_chapters - [badgeNum intValue])]];
if (badgeNum && ![badgeNum isEqualToString:@"0"]) {
self.badgeLabel.hidden = NO;
self.badgeLabel.text = badgeNum;
if (badgeNum.length == 2) {
[self.badgeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(21);
}];
} else if (badgeNum.length >= 3) {
[self.badgeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(26);
}];
}
} else {
self.badgeLabel.hidden = YES;
}
_badgeNum = badgeNum;
}
- (void)setStartEditing:(BOOL)startEditing
{
_startEditing = startEditing;
if (startEditing) {
self.coverView.alpha = 0.5f;
self.selectView.hidden = NO;
} else {
self.coverView.alpha = 1.0f;
self.selectView.hidden = YES;
}
}
@end
@@ -0,0 +1,20 @@
//
// TFBookRackHeaderCell.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/1.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFBookRackHeaderCell : UICollectionViewCell
@property (nonatomic, strong) TFProductionModel *productionModel;
@property (nonatomic, assign) TFProductionType productionType;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,114 @@
//
// TFBookRackHeaderCell.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/1.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookRackHeaderCell.h"
@interface TFBookRackHeaderCell ()
{
UIView *bottomView;
TFProductionCoverView *bookImageView;
UILabel *titleLabel;
YYLabel *bookDetailLabel;
}
@end
@implementation TFBookRackHeaderCell
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = kWhiteColor;
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
bottomView = [[UIView alloc] init];
bottomView.backgroundColor = kGrayViewColor;
bottomView.layer.cornerRadius = 8;
[self addSubview:bottomView];
[bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin + kQuarterMargin);
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin - kQuarterMargin);
make.top.mas_equalTo(self.mas_top).with.offset(kHalfMargin);
make.height.mas_equalTo(self.mas_height).with.offset(- kMargin);
}];
bookImageView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical];
[bottomView addSubview:bookImageView];
[bookImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bottomView.mas_left).with.offset(kHalfMargin);
make.centerY.mas_equalTo(bottomView.mas_centerY);
make.height.mas_equalTo(bottomView.mas_height).with.offset(- kMargin);
make.width.mas_equalTo(kGeometricWidth((self.height - 2 * kMargin), 3, 4));
}];
titleLabel = [[UILabel alloc] init];
titleLabel.textColor = kBlackColor;
titleLabel.textAlignment = NSTextAlignmentLeft;
titleLabel.numberOfLines = 1;
titleLabel.font = kMainFont;
[self addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookImageView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(bookImageView.mas_top).with.offset(kQuarterMargin);
make.right.mas_equalTo(bottomView.mas_right).with.offset(- kHalfMargin);
make.height.mas_equalTo(30);
}];
bookDetailLabel = [[YYLabel alloc] init];
bookDetailLabel.textColor = kGrayTextColor;
bookDetailLabel.textAlignment = NSTextAlignmentLeft;
bookDetailLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter;
bookDetailLabel.numberOfLines = 2;
bookDetailLabel.font = kFont13;
[self addSubview:bookDetailLabel];
[bookDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(titleLabel.mas_left);
make.top.mas_equalTo(titleLabel.mas_bottom);
make.bottom.mas_equalTo(bookImageView.mas_bottom).with.offset(- kHalfMargin);
make.right.mas_equalTo(titleLabel.mas_right);
}];
}
- (void)setProductionModel:(TFProductionModel *)productionModel
{
_productionModel = productionModel;
if (productionModel.vertical_cover.length > 0) {
bookImageView.coverImageUrl = productionModel.vertical_cover;
} else if (productionModel.horizontal_cover.length > 0) {
bookImageView.coverImageUrl = productionModel.horizontal_cover;
} else {
bookImageView.coverImageUrl = productionModel.cover;
}
titleLabel.text = productionModel.name?:@"";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString: productionModel.production_descirption?:@""];
attributedString.lineSpacing = 3;
attributedString.font = kFont13;
attributedString.color = kGrayTextColor;
bookDetailLabel.attributedText = attributedString;
}
- (void)setProductionType:(TFProductionType)productionType
{
_productionType = productionType;
bookImageView.productionType = productionType;
}
@end
@@ -0,0 +1,34 @@
//
// TFBookRackHeaderView.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/1.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
#define Rack_Header_Height (kGeometricHeight(SCREEN_WIDTH, 3, 1) + kLabelHeight + kMargin + kQuarterMargin)
#define Rack_Header_Height_NoRecommend (kGeometricHeight(SCREEN_WIDTH, 3, 1) + kQuarterMargin)
typedef void(^RecommendBannerClickBlock)(NSInteger production_id);
typedef void(^AdBannerClickBlock)(NSString *title, NSString *content);
@interface TFBookRackHeaderView : UIView
@property (nonatomic, assign) TFProductionType productionType;
@property (nonatomic, strong) TFBookRackModel *rackModel;
@property (nonatomic, copy) RecommendBannerClickBlock recommendBannerClickBlock;
@property (nonatomic, copy) AdBannerClickBlock adBannerClickBlock;
@property (nonatomic, copy) void (^collectionClickBlock)(void);
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,221 @@
//
// TFBookRackHeaderView.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/1.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookRackHeaderView.h"
#import "TFBookRackHeaderCell.h"
#import "TFSignModel.h"
#import "WXYZ_AnnouncementView.h"
#import "YJBannerView.h"
#import "TFSignAlertView.h"
@interface TFBookRackHeaderView () <YJBannerViewDelegate, YJBannerViewDataSource>
@property (nonatomic ,strong) YJBannerView *recommendBannerView;
@property (nonatomic ,strong) WXYZ_AnnouncementView *announceBannerView;
@property (nonatomic ,strong) NSMutableArray *bannerArray;
@end
@implementation TFBookRackHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.clipsToBounds = YES;
self.backgroundColor = [UIColor clearColor];
[self createSubviews];
}
return self;
}
- (void)createSubviews
{
self.backgroundColor = kWhiteColor;
[self addSubview:self.recommendBannerView];
[self.recommendBannerView reloadData];
[self addSubview:self.announceBannerView];
[self.announceBannerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin + kQuarterMargin);
make.top.mas_equalTo(self.recommendBannerView.mas_bottom).with.offset(kHalfMargin);
make.right.mas_equalTo(self.recommendBannerView.mas_right).with.offset(- kHalfMargin - kQuarterMargin);
make.height.mas_equalTo(kLabelHeight);
}];
#if TF_Sign_Mode
TFButton *collectionButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"签到") buttonImageName:@"public_sign_in" buttonIndicator:TFButtonIndicatorTitleRight];
collectionButton.graphicDistance = 5;
collectionButton.buttonImageScale = 0.45;
collectionButton.buttonTintColor = kMainColor;
[collectionButton addTarget:self action:@selector(rackCollectionClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:collectionButton];
[collectionButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.announceBannerView.mas_right).with.offset(- kQuarterMargin);
make.centerY.mas_equalTo(self.announceBannerView.mas_centerY);
make.height.mas_equalTo(self.announceBannerView.mas_height);
make.width.mas_equalTo(80);
}];
#endif
}
- (WXYZ_AnnouncementView *)announceBannerView
{
if (!_announceBannerView) {
WS(weakSelf)
_announceBannerView = [[WXYZ_AnnouncementView alloc] init];
_announceBannerView.layer.cornerRadius = kLabelHeight / 2;
_announceBannerView.backgroundColor = kGrayViewColor;
_announceBannerView.clickAdBlock = ^(NSString *path, NSUInteger index) {
if (weakSelf.adBannerClickBlock) {
TFAnnouncementModel *t_ann = [weakSelf.rackModel.announcement objectAtIndex:index];
weakSelf.adBannerClickBlock(t_ann.title, t_ann.content);
}
};
}
return _announceBannerView;
}
- (YJBannerView *)recommendBannerView
{
if (!_recommendBannerView) {
_recommendBannerView = [YJBannerView bannerViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kGeometricHeight(SCREEN_WIDTH, 3, 1)) dataSource:self delegate:self emptyImage:nil placeholderImage:nil selectorString:NSStringFromSelector(@selector(setImageWithURL:placeholder:))];
_recommendBannerView.backgroundColor = kWhiteColor;
_recommendBannerView.repeatCount = 9999;
_recommendBannerView.autoDuration = 5.0f;
_recommendBannerView.pageControlAliment = PageControlAlimentRight;
_recommendBannerView.pageControlStyle = PageControlCustom;
_recommendBannerView.pageControlDotSize = CGSizeMake(5, 5);
_recommendBannerView.pageControlBottomMargin = 20;
_recommendBannerView.pageControlHorizontalEdgeMargin = 25;
_recommendBannerView.pageControlPadding = 3;
_recommendBannerView.customPageControlHighlightImage = [UIImage imageNamed:@"pageControl_H"];
_recommendBannerView.customPageControlNormalImage = [UIImage imageNamed:@"pageControl_N"];
}
return _recommendBannerView;
}
- (NSMutableArray *)bannerArray
{
if (!_bannerArray) {
_bannerArray = [NSMutableArray array];
[_bannerArray addObject:@""];
}
return _bannerArray;
}
// 将网络图片或者本地图片 或者混合数组
- (NSArray *)bannerViewImages:(YJBannerView *)bannerView
{
return self.bannerArray;
}
- (NSArray *)bannerViewRegistCustomCellClass:(YJBannerView *)bannerView
{
return @[[TFBookRackHeaderCell class]];
}
/** 根据 Index 选择使用哪个 reuseIdentifier */
- (Class)bannerView:(YJBannerView *)bannerView reuseIdentifierForIndex:(NSInteger)index
{
return [TFBookRackHeaderCell class];
}
/** 自定义 View 刷新数据或者其他配置 */
- (UICollectionViewCell *)bannerView:(YJBannerView *)bannerView customCell:(UICollectionViewCell *)customCell index:(NSInteger)index
{
TFBookRackHeaderCell *cell = (TFBookRackHeaderCell *)customCell;
cell.productionModel = [_rackModel.recommendList objectOrNilAtIndex:index];
cell.productionType = self.productionType;
return cell;
}
// 代理方法 点击了哪个bannerView 的 第几个元素
- (void)bannerView:(YJBannerView *)bannerView didSelectItemAtIndex:(NSInteger)index
{
if ([[self.bannerArray objectAtIndex:index] length] > 0) {
WS(weakSelf)
if (self.recommendBannerClickBlock) {
self.recommendBannerClickBlock([weakSelf.rackModel.recommendList objectAtIndex:index].production_id);
}
}
}
- (void)rackCollectionClick
{
if (!TFUserInfoManager.isLogin) {
[TFLoginOptionsViewController presentLoginView:nil];
return;
}
WS(weakSelf)
[TFNetworkTools POST:Sign_Click parameters:nil model:TFSignModel.class success:^(BOOL isSuccess, TFSignModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
if ((t_model.book.count > 0 || t_model.comic.count > 0) && t_model.award.length > 0 && t_model.tomorrow_award.length > 0) {
NSMutableArray *t_arr = [NSMutableArray array];
for (TFProductionModel *t in t_model.book) {
t.productionType = TFProductionTypeNovel;
[t_arr addObject:t];
}
for (TFProductionModel *t in t_model.comic) {
t.productionType = TFProductionTypeComic;
[t_arr addObject:t];
}
for (TFProductionModel *t in t_model.audio) {
t.productionType = TFProductionTypeAudio;
[t_arr addObject:t];
}
TFSignAlertView *alert = [[TFSignAlertView alloc] init];
alert.alertTitle = t_model.award;
alert.alertDetailContent = t_model.tomorrow_award;
alert.bookList = [t_arr copy];
[alert showAlertView];
}
} else {
!weakSelf.collectionClickBlock ?: weakSelf.collectionClickBlock();
}
} failure:nil];
}
- (void)setRackModel:(TFBookRackModel *)rackModel
{
if (_rackModel != rackModel) {
_rackModel = rackModel;
// 公告
if (rackModel.announcement.count > 0) {
self.announceBannerView.modelArr = rackModel.announcement;
self.announceBannerView.hidden = NO;
} else {
self.announceBannerView.hidden = YES;
}
// 设置推荐
[self.bannerArray removeAllObjects];
for (TFProductionModel *model in rackModel.recommendList) {
NSString *imageURL = (model.vertical_cover.length > 0?model.vertical_cover:model.horizontal_cover)?:model.cover?:@"";
[self.bannerArray addObject:imageURL];
}
[self.recommendBannerView reloadData];
}
}
@end
@@ -0,0 +1,19 @@
//
// TFReadNovelBackgroundController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFReadNovelBackgroundController : UIViewController
- (void)updateWithViewController:(UIViewController *)viewController;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,64 @@
//
// TFReadNovelBackgroundController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFReadNovelBackgroundController.h"
#import "TFReaderSettingHelper.h"
#import "TFAdvertisementManager.h"
@interface TFReadNovelBackgroundController ()
@property (nonatomic ,weak) UIImageView *backgroundImageView;
@end
@implementation TFReadNovelBackgroundController
- (instancetype)init
{
if (self = [super init]) {
[self createSubviews];
}
return self;
}
- (void)createSubviews
{
self.view.backgroundColor = [[TFReaderSettingHelper sharedManager] getReaderBackgroundColor];
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
backgroundImageView.backgroundColor = self.view.backgroundColor;
self.backgroundImageView = backgroundImageView;
[self.view addSubview:backgroundImageView];
}
- (void)updateWithViewController:(UIViewController *)viewController
{
self.backgroundImageView.frame = viewController.view.bounds;
self.backgroundImageView.image = [self captureView:viewController.view];
self.backgroundImageView.alpha = 0.6;
}
- (UIImage *)captureView:(UIView *)view
{
UIImage * __block image = nil;
kCodeSync({
CGRect rect = view.bounds;
UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform transform = CGAffineTransformMake(-1.0, 0.0, 0.0, 1.0, rect.size.width, 0.0);
CGContextConcatCTM(context,transform);
[view.layer renderInContext:context];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
});
return image;
}
@end
@@ -0,0 +1,19 @@
//
// TFReadNovelTextController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFReadNovelTextController : UIViewController
@property (nonatomic ,copy) NSAttributedString *contentString;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,269 @@
//
// TFReadNovelTextController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFReadNovelTextController.h"
#import "TYAttributedLabel.h"
#import "TFReaderBookManager.h"
#import "TFReaderSettingHelper.h"
#import "WXYZ_BatteryView.h"
#import "TFEmptyViewHeader.h"
#import "WXYZ_BookReaderMenuPayView.h"
#import "NSAttributedString+TReaderPage.h"
#import "TFNetworkManager.h"
#import "TFReaderBookManager.h"
@interface TFReadNovelTextController ()
{
UILabel *emptyTitleLabel;
UIButton *emptyButton;
}
@property (nonatomic ,strong) UILabel *chapterTitleLabel;
@property (nonatomic ,strong) UILabel *bookNameLabel;
@property (nonatomic ,strong) UILabel *pageNumberLabel;
@property (nonatomic ,strong) TYAttributedLabel *chapterContentLabel;
@property (nonatomic ,strong) WXYZ_BatteryView *battery;
@property (nonatomic ,strong) WXYZ_BookReaderMenuPayView *payView;
@end
@implementation TFReadNovelTextController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [[TFReaderSettingHelper sharedManager] getReaderBackgroundColor];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadFrame) name:Notification_Check_Setting_Update object:nil];
WS(weakSelf)
[TFReaderSettingHelper sharedManager].readerBackgroundViewChanged = ^() {
[weakSelf reloadSubviews];
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Retry_Chapter object:nil];
};
}
- (void)setContentString:(NSAttributedString *)contentString
{
if ([contentString.string isEqualToString:k_Chapter_RequstFail] || !contentString) {
[self createEmptyView];
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_EmptyView_Changed object:@1];
return;
}
[self reloadSubviews];
if ([[TFReaderBookManager sharedManager] isPreviewChapter] && contentString.length > 1) {
CGSize size = CGSizeMake(CGRectGetWidth(self.chapterContentLabel.bounds), CGRectGetHeight(self.chapterContentLabel.bounds) / 2.0);
NSArray<NSValue *> *t_arr = [contentString pageRangeArrayWithConstrainedToSize:size];
if (t_arr.count > 0) {
NSRange range = [t_arr.firstObject rangeValue];
contentString = [contentString attributedSubstringFromRange:range];
}
[self payView];
} else {
TFReaderBookManager *manager = [TFReaderBookManager sharedManager];
NSString *chapter_id = [NSString stringWithFormat:@"%zd", manager.chapter_id];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Production_Pay_Success object:@[chapter_id]];
_payView.hidden = YES;
}
_contentString = contentString;
self.chapterContentLabel.attributedText = contentString;
// 总章节页数
NSUInteger totalChapterPagerCount = [[TFReaderBookManager sharedManager] totalChapterPagerCount];
NSUInteger readedPagerCount = ([[TFReaderBookManager sharedManager] currentPagerIndex] + 1) + (([[TFReaderBookManager sharedManager] currentChapterPagerCount]) * ([[TFReaderBookManager sharedManager] currentChapterIndex]));
float progressValue = [[NSNumber numberWithUnsignedInteger:readedPagerCount] floatValue] / [[NSNumber numberWithUnsignedInteger:totalChapterPagerCount] floatValue] * 100;
dispatch_async(dispatch_get_main_queue(), ^{
self.pageNumberLabel.text = [NSString stringWithFormat:@"%.1lf%@", progressValue < 0.1?0.1f:progressValue, @"%"];
});
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_EmptyView_Changed object:@0];
}
- (void)reloadSubviews
{
kCodeSync({
self.view.backgroundColor = [[TFReaderSettingHelper sharedManager] getReaderBackgroundColor];
UIColor *textColor = [[TFReaderSettingHelper sharedManager] getReaderTextColor];
UIColor *titleTextColor = [[TFReaderSettingHelper sharedManager] getReaderTitleTextColor];
self.chapterContentLabel.font = [UIFont systemFontOfSize:[[TFReaderSettingHelper sharedManager] getReaderFontSize]];
self.chapterContentLabel.linesSpacing = [[TFReaderSettingHelper sharedManager] getReaderLinesSpacing];
self.bookNameLabel.text = [[TFReaderBookManager sharedManager] getBookName];
self.bookNameLabel.textColor = titleTextColor;
self.chapterTitleLabel.text = [[TFReaderBookManager sharedManager] getChapterTitle];
self.chapterTitleLabel.textColor = titleTextColor;
self.chapterContentLabel.textColor = textColor;
self.battery.batteryTintColor = titleTextColor;
self.pageNumberLabel.textColor = [[TFReaderSettingHelper sharedManager] getReaderTitleTextColor];
self.pageNumberLabel.hidden = NO;
emptyButton.hidden = YES;
emptyTitleLabel.hidden = YES;
if ([TFReaderBookManager sharedManager].currentChapterIndex == 0 && [TFReaderBookManager sharedManager].currentPagerIndex == 0) {
self.chapterTitleLabel.hidden = YES;
self.battery.hidden = YES;
self.pageNumberLabel.hidden = YES;
self.bookNameLabel.hidden = YES;
} else {
self.chapterTitleLabel.hidden = NO;
self.battery.hidden = NO;
self.pageNumberLabel.hidden = NO;
self.bookNameLabel.hidden = NO;
}
});
}
- (void)reloadFrame
{
[self reloadSubviews];
_pageNumberLabel.frame = CGRectMake(SCREEN_WIDTH / 2, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, (SCREEN_WIDTH - 2 * kMargin) / 2, kMargin);
_battery.frame = CGRectMake(kMargin, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, SCREEN_WIDTH / 2, kMargin);
_bookNameLabel.frame = CGRectMake(SCREEN_WIDTH / 3, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, SCREEN_WIDTH / 3, kMargin);
_chapterContentLabel.frame = [[TFReaderSettingHelper sharedManager] getReaderViewFrame];
}
- (UILabel *)pageNumberLabel
{
if (!_pageNumberLabel) {
_pageNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, (SCREEN_WIDTH - 2 * kMargin) / 2, kMargin)];
_pageNumberLabel.text = @"0.1%";
_pageNumberLabel.font = kFont12;
_pageNumberLabel.hidden = YES;
_pageNumberLabel.textAlignment = NSTextAlignmentRight;
[self.view addSubview:_pageNumberLabel];
}
return _pageNumberLabel;
}
- (WXYZ_BatteryView *)battery
{
if (!_battery) {
_battery = [[WXYZ_BatteryView alloc] initWithFrame:CGRectMake(kMargin, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, SCREEN_WIDTH / 2, kMargin)];
[self.view addSubview:_battery];
}
return _battery;
}
- (UILabel *)bookNameLabel
{
if (!_bookNameLabel) {
_bookNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 3, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, SCREEN_WIDTH / 3, kMargin)];
_bookNameLabel.font = kFont12;
_bookNameLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:_bookNameLabel];
}
return _bookNameLabel;
}
- (UILabel *)chapterTitleLabel
{
if (!_chapterTitleLabel) {
_chapterTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kMargin, kMargin + PUB_NAVBAR_OFFSET, (SCREEN_WIDTH - 2 * kMargin) / 2, kMargin)];
_chapterTitleLabel.font = kFont12;
_chapterTitleLabel.textAlignment = NSTextAlignmentLeft;
[self.view addSubview:_chapterTitleLabel];
}
return _chapterTitleLabel;
}
- (TYAttributedLabel *)chapterContentLabel
{
if (!_chapterContentLabel) {
_chapterContentLabel = nil;
kCodeSync({
_chapterContentLabel = [[TYAttributedLabel alloc] init];
_chapterContentLabel.frame = [[TFReaderSettingHelper sharedManager] getReaderViewFrame];
_chapterContentLabel.font = [UIFont systemFontOfSize:[[TFReaderSettingHelper sharedManager] getReaderFontSize]];
_chapterContentLabel.backgroundColor = [UIColor clearColor];
_chapterContentLabel.linesSpacing = [[TFReaderSettingHelper sharedManager] getReaderLinesSpacing];
_chapterContentLabel.lineBreakMode = NSLineBreakByWordWrapping;
[self.view addSubview:_chapterContentLabel];
});
}
return _chapterContentLabel;
}
- (WXYZ_BookReaderMenuPayView *)payView
{
if (!_payView) {
_payView = [[WXYZ_BookReaderMenuPayView alloc] init];
[self.view addSubview:_payView];
}
_payView.hidden = NO;
return _payView;
}
- (void)createEmptyView
{
if (!emptyTitleLabel) {
emptyTitleLabel = [[UILabel alloc] init];
emptyTitleLabel.textColor = [TFReaderSettingHelper sharedManager].getReaderTextColor;
emptyTitleLabel.font = kFont16;
emptyTitleLabel.text = TFLocalizedString(@"内容加载失败");
emptyTitleLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:emptyTitleLabel];
[emptyTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.view.mas_centerY).with.offset(- kHalfMargin);
make.left.mas_equalTo(0);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(kLabelHeight);
}];
}
if (!emptyButton) {
emptyButton = [UIButton buttonWithType:UIButtonTypeCustom];
emptyButton.backgroundColor = [UIColor clearColor];
emptyButton.layer.cornerRadius = 15;
emptyButton.layer.borderColor = [TFReaderSettingHelper sharedManager].getReaderTextColor.CGColor;
emptyButton.layer.borderWidth = 1.0;
[emptyButton setTitle:TFLocalizedString(@"重试") forState:UIControlStateNormal];
[emptyButton setTitleColor:[TFReaderSettingHelper sharedManager].getReaderTextColor forState:UIControlStateNormal];
[emptyButton.titleLabel setFont:kFont12];
[emptyButton addTarget:self action:@selector(retryClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:emptyButton];
[emptyButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view.mas_centerX);
make.top.mas_equalTo(emptyTitleLabel.mas_bottom);
make.width.mas_equalTo(80);
make.height.mas_equalTo(kLabelHeight);
}];
}
emptyButton.hidden = NO;
emptyTitleLabel.hidden = NO;
}
- (void)retryClick:(UIButton *)sender
{
if (![TFNetworkManager networkingStatus] || [TFNetworkManager currentNetworkStatus] == kCTCellularDataRestrictedStateUnknown) {
return;
}
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Retry_Chapter object:@"1"];
}
@end
@@ -0,0 +1,32 @@
//
// TFReadNovelViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@class TFProductionModel;
@interface TFReadNovelViewController : TFBasicViewController
- (instancetype)initWithSpecificIndex:(NSInteger)specificIndex chapterSort:(NSInteger)chapterSort;
- (instancetype)initWithChapterIndex:(NSInteger)specifiedChapter;
@property (nonatomic ,assign) NSInteger book_id;
@property (nonatomic ,strong) TFProductionModel *bookModel;
/// 跳转到指定章节
@property (nonatomic ,assign) NSInteger specifiedChapter;
/// 跳转到指定页码
@property (nonatomic ,assign) NSInteger specifiedPage;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,116 @@
//
// TFReaderBookManager.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFReaderBookManager : NSObject
// 当前阅读章节
@property (nonatomic, assign) NSInteger currentChapterIndex;
// 当前页数
@property (nonatomic, assign) NSInteger currentPagerIndex;
// 书籍id
@property (nonatomic, assign) NSInteger book_id;
// 章节id
@property (nonatomic, assign) NSInteger chapter_id;
// 下一页
@property (nonatomic, assign) NSInteger nextPagerIndex;
// 上一页
@property (nonatomic, assign) NSInteger previousPagerIndex;
// 当前章节页数
@property (nonatomic, assign, readonly) NSInteger currentChapterPagerCount;
// 总章节数
@property (nonatomic, assign, readonly) NSInteger totalChapterCount;
// 书籍总页数
@property (nonatomic, assign, readonly) NSInteger totalChapterPagerCount;
@property (nonatomic, strong, readonly) TFProductionChapterModel *chapterModel;
@property (nonatomic, strong) TFProductionModel *bookModel;
/// 章节末尾投票数
@property (nonatomic, copy, nullable) NSString *reward_num;
/// 章节末尾月票数
@property (nonatomic, copy, nullable) NSString *ticket_num;
/// 书签标记位置
@property (nonatomic, assign) NSInteger markIndex;
interface_singleton
// 获取书籍名称
- (NSString *)getBookName;
// 获取章节名称
- (NSString *)getChapterTitle;
// 是否是预览章节
- (BOOL)isPreviewChapter;
// 是否有下章节
- (BOOL)haveNextChapter;
// 是否有上章节
- (BOOL)havePreChapter;
// 是否是最后一章最后一页
- (BOOL)isTheLastPager;
// 是否是第一章第一页
- (BOOL)isTheFormerPager;
// 是否有下一页
- (BOOL)haveNextPager;
// 上一章是否有缓存
- (BOOL)havePreCache;
// 下一章是否有缓存
- (BOOL)haveNextCache;
// 获取下一页
- (void)getNextPagerAttributedText:(void(^ _Nullable)(NSAttributedString *content))complete;
// 获取上一页
- (void)getPrePagerAttributedText:(void(^ _Nullable)(NSAttributedString * _Nullable content))complete;
// 获取某一章节某一页
- (void)getPagerAttributedTextWithChapterIndex:(NSInteger)chapterIndex pagerIndex:(NSInteger)pageIndex completionHandler:(void(^)(NSAttributedString *content))completionHandler;
// 获取某一章节全部内容
- (void)getChapterTextWithBook_id:(NSInteger)book_id chapter_index:(NSInteger)chapter_index completionHandler:(void(^)(NSString *content))completionHandler;
// 书籍model请求
- (void)requestBookModelWithBookId:(NSUInteger)book_id completionHandler:(void(^ _Nullable)(void))completionHandler;
// 获取章节所有内容
- (NSString *)getChapterContent;
// 获取章节详细内容
- (NSString *)getChapterDetailContent;
- (NSMutableArray *)chapterRangeArray;
// 预加载多个章节(不支持自动订阅 && 支持多章下载)
- (void)downloadPrestrainChaptersWithProductionModel:(TFProductionModel *)productionModel production_id:(NSInteger)production_id chapter_id:(NSInteger)chapter_id prestrainNumber:(NSInteger)prestrainNumber;
// 预加载章节(支持自动订阅 && 仅支持单章下载)
- (void)downloadPrestrainChapterWithProductionModel:(TFProductionModel *)productionModel production_id:(NSInteger)production_id chapter_id:(NSInteger)chapter_id completionHandler:(void(^ _Nullable)(NSString *chapterContentString, NSInteger production_id, NSInteger chapter_id))completionHandler;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,219 @@
//
// TFReaderSettingHelper.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, TFReaderTransitionStyle) {
TFReaderTransitionStylePageCurl = 0,
TFReaderTransitionStyleScroll = 1,
TFReaderTransitionStyleCover = 2,
TFReaderTransitionStyleNone = 3
};
typedef NS_ENUM(NSUInteger, TFReaderAutoReadState) {
TFReaderAutoReadStateStop = 0, // 停止
TFReaderAutoReadStateStart = 1, // 开启
TFReaderAutoReadStatePause = 2, // 暂停
TFReaderAutoReadStateResume = 3, // 恢复
};
typedef NS_ENUM(NSUInteger, TFReaderLineSpacingState) {
TFReaderLineSpacingStateBig = 0,
TFReaderLineSpacingStateMedium = 1,
TFReaderLineSpacingStateSmall = 2
};
typedef NS_ENUM(NSUInteger, TFReaderPatternMode) {
TFReaderPatternModeDaytime = 0,
TFReaderPatternModeNight = 1
};
typedef NS_ENUM(NSUInteger, TFReaderBackColorMode) {
TFReaderBackColorYellow,
TFReaderBackColorGreen,
TFReaderBackColorBlue,
TFReaderBackColorPink,
TFReaderBackColorWhite,
TFReaderBackColorGray,
TFReaderBackColorBlack
};
static CGFloat line_spacing_small = 5.0f;
static CGFloat line_spacing_medium = 10.0f;
static CGFloat line_spacing_big = 20.0f;
typedef void(^ReaderFontChanged)(void);
typedef void(^ReaderBackgroundViewChanged)(void);
typedef void(^ReaderBrightnessChanged)(void);
typedef void(^ReaderLinesSpacingChanged)(void);
typedef void(^ReaderTransitionStyleChanged)(TFReaderTransitionStyle transitionStyle);
typedef void(^ReaderAutoReaderStateChanged)(TFReaderAutoReadState state);
typedef void(^ReaderAutoReadSpeedChanged)(NSInteger readSpeed);
@interface TFReaderSettingHelper : NSObject
// 字体改变
@property (nonatomic, copy) ReaderFontChanged readerFontChanged;
// 背景改变
@property (nonatomic, copy) ReaderBackgroundViewChanged readerBackgroundViewChanged;
// 亮度改变
@property (nonatomic, copy) ReaderBrightnessChanged readerBrightnessChanged;
// 间距改变
@property (nonatomic, copy) ReaderLinesSpacingChanged readerLinesSpacingChanged;
// 翻页样式改变
@property (nonatomic, copy) ReaderTransitionStyleChanged readerTransitionStyleChanged;
// 自动阅读启动或者停止
@property (nonatomic, copy) ReaderAutoReaderStateChanged readerAutoReaderStateChanged;
// 改变自动阅读时间
@property (nonatomic, copy) ReaderAutoReadSpeedChanged readerAutoReadSpeedChanged;
/**
单例方法
@return self
*/
interface_singleton
@property (nonatomic, assign) TFReaderAutoReadState state;
// 开启屏幕常亮
- (void)openScreenKeep;
// 关闭屏幕常亮
- (void)closeScreenKeep;
// 隐藏状态栏
- (void)hiddenStatusBar;
// 显示状态栏
- (void)showStatusBar;
/*
Font
*/
// 设置字号
- (void)setReaderFontSize:(CGFloat)fontSize;
// 获取字号
- (CGFloat)getReaderFontSize;
- (CGFloat)getReaderMinFontSize;
- (CGFloat)getReaderMaxFontSize;
// 设置行间距
- (void)setReaderLinesSpacing:(CGFloat)linesSpacing;
// 获取行间距
- (CGFloat)getReaderLinesSpacing;
// 获取行间距类型
- (TFReaderLineSpacingState)getReaderLineSpacingState;
/*
Frame
*/
// 获取页面size
- (CGSize)getReaderViewSize;
// 获取页面frame
- (CGRect)getReaderViewFrame;
// 获取页面bottom
- (CGFloat)getReaderViewBottom;
/*
Color
*/
// 设置背景色
- (void)setReaderBackgroundColor:(TFReaderBackColorMode)colorMode;
// 获取背景色枚举值
- (TFReaderBackColorMode)getReaderBackgroundColorMode;
// 获取背景色
- (UIColor *)getReaderBackgroundColor;
// 背景颜色合集
- (NSArray *)getReaderBackgroundColorModeArray;
// 获取字体颜色
- (UIColor *)getReaderTextColor;
// 获取标题字体颜色
- (UIColor *)getReaderTitleTextColor;
// 获取夜间模式状态
- (TFReaderPatternMode)getNightModeState;
// 设置夜间模式状态
- (void)setNightModeState:(TFReaderPatternMode)state;
/*
Brightness
*/
// 获取屏幕亮度
- (CGFloat)getBrightness;
// 设定屏幕亮度
- (void)setBrightness:(CGFloat)brightness;
/*
TransitionStyle
*/
// 设置翻页类型
- (void)setTransitionStyle:(TFReaderTransitionStyle)transitionStyle;
// 获取翻页类型
- (TFReaderTransitionStyle)getTransitionStyle;
/*
RecordLocation
*/
// 获取记录章节
- (NSInteger)getMemoryChapterIndexWithBook_id:(NSUInteger)book_id;
// 获取记录页数
- (NSInteger)getMemoryPagerIndexWithBook_id:(NSUInteger)book_id;
// 记录章节 页数
- (void)setLocationMemoryOfChapterIndex:(NSInteger)chapterIndex pagerIndex:(NSInteger)pagerIndex book_id:(NSUInteger)book_id;
/*
设置阅读速度
*/
// 设置阅读速度
- (void)setReadSpeed:(NSUInteger)animationDuration;
// 获取阅读速度
- (NSUInteger)getReadSpeed;
// 开启或关闭自动阅读
- (void)setAutoReaderState:(TFReaderAutoReadState)state;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,409 @@
//
// TFReaderSettingHelper.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFReaderSettingHelper.h"
#import "AppDelegate.h"
#define PUB_DEFAULT_READ_SPEED 10
#define PUB_MIN_READ_SPEED 5
#define PUB_MAX_READ_SPEED 60
@implementation TFReaderSettingHelper
implementation_singleton(TFReaderSettingHelper)
#pragma mark - Screen
// 开启屏幕常亮
- (void)openScreenKeep
{
[UIApplication sharedApplication].idleTimerDisabled = YES;
}
// 关闭屏幕常亮
- (void)closeScreenKeep
{
[UIApplication sharedApplication].idleTimerDisabled = NO;
}
#pragma mark - Status
- (void)hiddenStatusBar
{
[UIApplication sharedApplication].statusBarHidden = YES;
}
- (void)showStatusBar
{
[UIApplication sharedApplication].statusBarHidden = NO;
}
#pragma mark - Font
- (void)setReaderFontSize:(CGFloat)fontSize
{
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithFloat:fontSize] forKey:TF_READER_FONT];
[[NSUserDefaults standardUserDefaults] synchronize];
if (self.readerFontChanged) {
self.readerFontChanged();
}
}
- (CGFloat)getReaderFontSize
{
CGFloat textFontSize = [[[NSUserDefaults standardUserDefaults] objectForKey:TF_READER_FONT] floatValue];
if (!textFontSize || textFontSize <= [self getReaderMinFontSize]) {
return [self getReaderMinFontSize];
}
if (textFontSize >= [self getReaderMaxFontSize]) {
return [self getReaderMaxFontSize];
}
return textFontSize;
}
- (CGFloat)getReaderMinFontSize
{
return kFontSize15;
}
- (CGFloat)getReaderMaxFontSize
{
return kFontSize30;
}
// 设置行间距
- (void)setReaderLinesSpacing:(CGFloat)linesSpacing
{
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithFloat:linesSpacing] forKey:TF_READER_LINESPACING];
[[NSUserDefaults standardUserDefaults] synchronize];
if (self.readerLinesSpacingChanged) {
self.readerLinesSpacingChanged();
}
}
// 获取行间距
- (CGFloat)getReaderLinesSpacing
{
CGFloat t_linesSpacing = [[[NSUserDefaults standardUserDefaults] objectForKey:TF_READER_LINESPACING] floatValue];
if (t_linesSpacing == 0) {
[self setReaderLinesSpacing:line_spacing_medium];
return line_spacing_medium;
}
return t_linesSpacing;
}
- (TFReaderLineSpacingState)getReaderLineSpacingState
{
CGFloat t_lineSpacing = [self getReaderLinesSpacing];
if (t_lineSpacing == line_spacing_small) {
return TFReaderLineSpacingStateSmall;
} else if (t_lineSpacing == line_spacing_medium) {
return TFReaderLineSpacingStateMedium;
} else {
return TFReaderLineSpacingStateBig;
}
}
#pragma mark - Frame
- (CGSize)getReaderViewSize
{
return [self getReaderViewFrame].size;
}
- (CGRect)getReaderViewFrame
{
AppDelegate *appDelegate = (AppDelegate *)kRCodeSync([[UIApplication sharedApplication] delegate]);
if (!appDelegate.checkSettingModel.ad_status_setting.chapter_read_bottom) {
return CGRectMake(kMargin,
2 * kMargin + PUB_NAVBAR_OFFSET + 10,
SCREEN_WIDTH - 2 * kMargin,
SCREEN_HEIGHT - 2 * kMargin - PUB_NAVBAR_OFFSET - PUB_TABBAR_OFFSET - 2 * kHalfMargin - kMargin);
}
return CGRectMake(kMargin,
2 * kMargin + PUB_NAVBAR_OFFSET + 10,
SCREEN_WIDTH - 2 * kMargin,
SCREEN_HEIGHT - 2 * kMargin - PUB_NAVBAR_OFFSET - 2 * kHalfMargin - kMargin - PUB_TABBAR_HEIGHT - (is_iPhoneX?-kMargin:0));
}
- (CGFloat)getReaderViewBottom
{
return [self getReaderViewFrame].origin.y + [self getReaderViewFrame].size.height;
}
#pragma mark - Color
// 设置背景色
- (void)setReaderBackgroundColor:(TFReaderBackColorMode)colorMode
{
if ([self getNightModeState] == TFReaderPatternModeNight) {
return;
}
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedInteger:colorMode] forKey:@"xtfei_back_color"];
[[NSUserDefaults standardUserDefaults] synchronize];
if ([self getNightModeState] == TFReaderPatternModeDaytime) {
if (self.readerBackgroundViewChanged) {
self.readerBackgroundViewChanged();
}
}
}
// 获取背景色枚举值
- (TFReaderBackColorMode)getReaderBackgroundColorMode
{
if ([self getNightModeState] == TFReaderPatternModeNight) {
return TFReaderBackColorBlack;
}
return [[[NSUserDefaults standardUserDefaults] objectForKey:@"xtfei_back_color"] integerValue];
}
// 获取背景色
- (UIColor *)getReaderBackgroundColor
{
return [UIColor colorWithPatternImage:[UIImage imageNamed:[[self getReaderBackgroundColorModeArray] objectAtIndex:[self getReaderBackgroundColorMode]]]];
}
- (NSArray *)getReaderBackgroundColorModeArray
{
return @[@"read_page_bg_yellow.png", @"read_page_bg_green.png", @"read_page_bg_blue.png", @"read_page_bg_pink.png", @"read_page_bg_white.png", @"read_page_bg_gray.png", @"read_page_bg_black.png"];
}
// 获取字体颜色
- (UIColor *)getReaderTextColor
{
switch ([self getReaderBackgroundColorMode]) {
case TFReaderBackColorYellow:
return kColorRGBA(92, 66, 45, 1);
case TFReaderBackColorGreen:
return kColorRGBA(69, 81, 72, 1);
break;
case TFReaderBackColorBlue:
return kColorRGBA(50, 63, 74, 1);
break;
case TFReaderBackColorPink:
return kColorRGBA(144, 38, 61, 1);
break;
case TFReaderBackColorWhite:
return kBlackColor;
break;
case TFReaderBackColorGray:
return kColorRGBA(159, 161, 163, 1);
break;
case TFReaderBackColorBlack:
return kColorRGBA(127, 127, 127, 1);
break;
default:
break;
}
}
// 获取标题字体颜色
- (UIColor *)getReaderTitleTextColor
{
CGFloat alpha = 0.5;
switch ([self getReaderBackgroundColorMode]) {
case TFReaderBackColorYellow:
return kColorRGBA(92, 66, 45, alpha);
case TFReaderBackColorGreen:
return kColorRGBA(69, 81, 72, alpha);
break;
case TFReaderBackColorBlue:
return kColorRGBA(50, 63, 74, alpha);
break;
case TFReaderBackColorPink:
return kColorRGBA(144, 38, 61, alpha);
break;
case TFReaderBackColorWhite:
return kColorRGBA(33, 34, 35, alpha);
break;
case TFReaderBackColorGray:
return kColorRGBA(159, 161, 163, alpha);
break;
case TFReaderBackColorBlack:
return kColorRGBA(127, 127, 127, alpha);
break;
default:
break;
}
}
// 获取夜间模式状态
- (TFReaderPatternMode)getNightModeState
{
NSInteger nightModeState = [[[NSUserDefaults standardUserDefaults] objectForKey:TF_READER_NIGHT_MODE] integerValue];
if (nightModeState == 0) {
return TFReaderPatternModeDaytime;
}
return TFReaderPatternModeNight;
}
// 设置夜间模式状态
- (void)setNightModeState:(TFReaderPatternMode)state
{
if (state == TFReaderPatternModeDaytime) {
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedInteger:0] forKey:TF_READER_NIGHT_MODE];
[[NSUserDefaults standardUserDefaults] synchronize];
} else {
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedInteger:1] forKey:TF_READER_NIGHT_MODE];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if (self.readerBackgroundViewChanged) {
self.readerBackgroundViewChanged();
}
}
#pragma mark - Brightness
// 获取屏幕亮度
- (CGFloat)getBrightness
{
CGFloat brightness = [UIScreen mainScreen].brightness;
return brightness;
}
// 设定屏幕亮度
- (void)setBrightness:(CGFloat)brightness
{
[[UIScreen mainScreen] setBrightness:brightness];
if (self.readerBrightnessChanged) {
self.readerBrightnessChanged();
}
}
#pragma mark - TransitionStyle
// 设置翻页类型
- (void)setTransitionStyle:(TFReaderTransitionStyle)transitionStyle
{
NSUInteger t_tStyle = 0;
switch (transitionStyle) {
case TFReaderTransitionStylePageCurl:
t_tStyle = 0;
break;
case TFReaderTransitionStyleScroll:
t_tStyle = 1;
break;
case TFReaderTransitionStyleCover:
t_tStyle = 2;
break;
case TFReaderTransitionStyleNone:
t_tStyle = 3;
break;
default:
break;
}
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedInteger:t_tStyle] forKey:TF_READER_TRANSITION_STYLE];
[[NSUserDefaults standardUserDefaults] synchronize];
if (self.readerTransitionStyleChanged) {
self.readerTransitionStyleChanged(transitionStyle);
}
}
// 获取翻页类型
- (TFReaderTransitionStyle)getTransitionStyle
{
NSUInteger t_transitionStyle = [[[NSUserDefaults standardUserDefaults] objectForKey:TF_READER_TRANSITION_STYLE] unsignedIntegerValue];
switch (t_transitionStyle) {
case 0:
return TFReaderTransitionStylePageCurl;
break;
case 1:
return TFReaderTransitionStyleScroll;
break;
case 2:
return TFReaderTransitionStyleCover;
break;
case 3:
return TFReaderTransitionStyleNone;
break;
default:
break;
}
return t_transitionStyle;
}
#pragma mark - RecordLocation
// 获取记录章节
- (NSInteger)getMemoryChapterIndexWithBook_id:(NSUInteger)book_id
{
NSUInteger t_chapterIndex = [[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@_%@",TF_READER_CHAPTER_INDEX, [TFUtilsHelper formatStringWithInteger:book_id]]] integerValue];
return t_chapterIndex;
}
// 获取记录页数
- (NSInteger)getMemoryPagerIndexWithBook_id:(NSUInteger)book_id
{
NSUInteger t_pagerIndex = [[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@_%@",TF_READER_PAGER_INDEX, [TFUtilsHelper formatStringWithInteger:book_id]]] unsignedIntegerValue];
return t_pagerIndex;
}
// 记录章节 页数
- (void)setLocationMemoryOfChapterIndex:(NSInteger)chapterIndex pagerIndex:(NSInteger)pagerIndex book_id:(NSUInteger)book_id
{
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedInteger:chapterIndex] forKey:[NSString stringWithFormat:@"%@_%@",TF_READER_CHAPTER_INDEX, [TFUtilsHelper formatStringWithInteger:book_id]]];
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedInteger:pagerIndex] forKey:[NSString stringWithFormat:@"%@_%@",TF_READER_PAGER_INDEX, [TFUtilsHelper formatStringWithInteger:book_id]]];
[[NSUserDefaults standardUserDefaults] synchronize];
}
/*
设置阅读速度
*/
// 设置阅读速度
- (void)setReadSpeed:(NSUInteger)animationDuration
{
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInteger:animationDuration] forKey:TF_READER_READ_SPEED];
[[NSUserDefaults standardUserDefaults] synchronize];
if (self.readerAutoReadSpeedChanged) {
self.readerAutoReadSpeedChanged(animationDuration);
}
}
// 获取阅读速度
- (NSUInteger)getReadSpeed
{
NSInteger t_readSpeed = [[[NSUserDefaults standardUserDefaults] objectForKey:TF_READER_READ_SPEED] unsignedIntegerValue];
if (t_readSpeed == 0) {
return PUB_DEFAULT_READ_SPEED;
}
if (t_readSpeed < PUB_MIN_READ_SPEED) {
return PUB_MIN_READ_SPEED;
}
if (t_readSpeed > kFontSize30) {
return PUB_MAX_READ_SPEED;
}
return t_readSpeed;
}
- (void)setAutoReaderState:(TFReaderAutoReadState)state
{
self.state = state;
if (self.readerAutoReaderStateChanged) {
self.readerAutoReaderStateChanged(state);
}
}
@end
@@ -0,0 +1,21 @@
//
// TFAnnouncementController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/14.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFAnnouncementController : TFBasicViewController
@property (nonatomic ,copy) NSString *titleText;
@property (nonatomic ,copy) NSString *contentText;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,73 @@
//
// TFAnnouncementController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/14.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAnnouncementController.h"
@interface TFAnnouncementController ()
@end
@implementation TFAnnouncementController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
[self setNavigationBarTitle:self.titleText.length > 0 ? self.titleText:TFLocalizedString(@"公告栏")];
self.view.backgroundColor = kWhiteColor;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:nil];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Show_Tabbar object:@"animation"];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)createSubviews
{
YYTextView *textView = [[YYTextView alloc] init];
textView.editable = NO;
textView.textColor = kBlackColor;
textView.font = kMainFont;
[self.view addSubview:textView];
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString: self.contentText.length > 0 ? self.contentText:@""];
text.lineSpacing = 5;
text.font = kMainFont;
textView.attributedText = text;
[textView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.top.mas_equalTo(PUB_NAVBAR_HEIGHT + kHalfMargin);
make.width.mas_equalTo(SCREEN_WIDTH - kMargin);
make.height.mas_equalTo(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT - kHalfMargin);
}];
}
@end
@@ -0,0 +1,22 @@
//
// TFBookStoreAudioController.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 TFBookStoreAudioController : TFBasicViewController
@property (nonatomic ,assign) CGFloat channel;
@property (nonatomic ,assign) CGFloat scrollViewContentOffsetY;
@property (nonatomic ,strong) NSArray *hotwordArray;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,366 @@
//
// TFBookStoreAudioController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreAudioController.h"
#import "TFLimitFreeViewController.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "TFBookStoreMenuView.h"
#import "TFBookStoreLabelModel.h"
#import "TFBannerActionManager.h"
// 分类
#import "TFSortViewController.h"
// 排行榜
#import "TFPopularityViewController.h"
// 包月
#import "TFMemberViewController.h"
// 完本
#import "TFCompleteViewController.h"
// 限免
#import "TFFreeViewController.h"
@interface TFBookStoreAudioController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) TFBookStoreMenuView *headerView;
@property (nonatomic ,strong) TFBookStoreModel *audioMallModel;
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFBookStoreAudioController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Restore_Network object:nil];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenNavigationBar:YES];
self.hotwordArray = [NSArray array];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Channel_Change 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(0);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_TABBAR_HEIGHT);
}];
WS(weakSelf)
self.headerView = [[TFBookStoreMenuView alloc] init];
self.headerView.productionType = self.productionType;
self.headerView.bannerrImageClickBlock = ^(TFBannerModel * _Nonnull bannerModel) {
if ([TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeAudio]) {
[weakSelf.navigationController pushViewController:[TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeAudio] animated:YES];
}
};
self.headerView.menuButtonClickBlock = ^(TFMenuButtonType menuButtonType, NSString * _Nonnull menuButtonTitle) {
switch (menuButtonType) {
case TFMenuButtonTypeFree: {
TFFreeViewController *free = [[TFFreeViewController alloc] init];
free.productionType = weakSelf.productionType;
free.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:free animated:YES];
}
break;
case TFMenuButtonTypeComplete: {
TFCompleteViewController *complete = [[TFCompleteViewController alloc] init];
complete.productionType = weakSelf.productionType;
complete.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:complete animated:YES];
}
break;
case TFMenuButtonTypeSort: {
TFSortViewController *sort = [[TFSortViewController alloc] init];
sort.productionType = weakSelf.productionType;
sort.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:sort animated:YES];
}
break;
case TFMenuButtonTypePopularity: {
TFPopularityViewController *popularity = [[TFPopularityViewController alloc] init];
popularity.productionType = weakSelf.productionType;
popularity.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:popularity animated:YES];
}
break;
case TFMenuButtonTypeMember: {
TFMemberViewController *member = [[TFMemberViewController alloc] init];
member.productionType = weakSelf.productionType;
[weakSelf.navigationController pushViewController:member animated:YES];
}
break;
default:
break;
}
};
self.mainTableViewGroup.tableHeaderView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH);
[self.mainTableViewGroup setTableHeaderView:self.headerView];
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.audioMallModel.label.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreLabelModel *labelModel = [self.audioMallModel.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.audioMallModel.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.audioMallModel.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)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pointY = scrollView.contentOffset.y;
self.scrollViewContentOffsetY = pointY;
[UIApplication sharedApplication].statusBarHidden = NO;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
CGFloat pointY = scrollView.contentOffset.y;
self.scrollViewContentOffsetY = pointY;
}
#pragma mark - 点击事件
- (void)moreButtonClick:(UIButton *)sender
{
TFBookStoreLabelModel *t_labelModel = [self.audioMallModel.label objectOrNilAtIndex:sender.tag];
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 changeBookRecommendRequestAtIndex:sender.tag complete:^{
[button stopSpin];
}];
}
- (void)netRequest
{
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"channel_id"] = (self.channel != 0) ? [TFUtilsHelper formatStringWithInteger:self.channel] : @(TFSystemInfoManager.sexChannel);
[TFNetworkTools POSTQuick:Audio_Mall parameters:params model:TFBookStoreModel.class success:^(BOOL isSuccess, TFBookStoreModel * _Nullable t_model, BOOL isCache, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.audioMallModel = t_model;
weakSelf.headerView.mallCenterModel = t_model;
weakSelf.hotwordArray = t_model.hot_word;
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Reload_Mall_Hot_Word object:nil];
}
[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)changeBookRecommendRequestAtIndex:(NSInteger)index complete:(void(^)(void))complete;
{
TFBookStoreLabelModel *t_labelModel = [self.audioMallModel.label objectOrNilAtIndex:index];
NSString *recommend_id = [TFUtilsHelper formatStringWithInteger:t_labelModel.recommend_id];
if (recommend_id.length <= 0) return;
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"recommend_id"] = recommend_id;
[TFNetworkTools POST:Audio_Refresh parameters:params model:TFBookStoreLabelModel.class success:^(BOOL isSuccess, TFBookStoreLabelModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
for (TFProductionModel *obj in t_model.list) {
obj.productionType = weakSelf.productionType;
}
[weakSelf.audioMallModel.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();
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
!complete ?: complete();
}];
}
@end
@@ -0,0 +1,22 @@
//
// TFBookStoreComicController.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 TFBookStoreComicController : TFBasicViewController
@property (nonatomic ,assign) CGFloat channel;
@property (nonatomic ,assign) CGFloat scrollViewContentOffsetY;
@property (nonatomic ,strong) NSArray *hotwordArray;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,353 @@
//
// TFBookStoreComicController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreComicController.h"
#import "TFLimitFreeViewController.h"
#import "TFBookStoreComicMaxStyleCell.h"
#import "TFBookStoreComicMiddleStyleCell.h"
#import "TFBookStoreComicNormalStyleCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "TFBookStoreMenuView.h"
#import "TFBookStoreLabelModel.h"
#import "TFBannerActionManager.h"
// 分类
#import "TFSortViewController.h"
// 排行榜
#import "TFPopularityViewController.h"
// 会员
#import "TFMemberViewController.h"
// 完本
#import "TFCompleteViewController.h"
// 限免
#import "TFFreeViewController.h"
@interface TFBookStoreComicController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) TFBookStoreMenuView *headerView;
@property (nonatomic ,strong) TFBookStoreModel *comicModel;
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFBookStoreComicController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenNavigationBar:YES];
self.hotwordArray = [NSArray array];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Channel_Change object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Restore_Network 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(0);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_TABBAR_HEIGHT);
}];
WS(weakSelf)
self.headerView = [[TFBookStoreMenuView alloc] init];
self.headerView.productionType = self.productionType;
self.headerView.bannerrImageClickBlock = ^(TFBannerModel * _Nonnull bannerModel) {
if ([TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeComic]) {
[weakSelf.navigationController pushViewController:[TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeComic] animated:YES];
}
};
self.headerView.menuButtonClickBlock = ^(TFMenuButtonType menuButtonType, NSString * _Nonnull menuButtonTitle) {
switch (menuButtonType) {
case TFMenuButtonTypeFree: {
TFFreeViewController *free = [[TFFreeViewController alloc] init];
free.productionType = weakSelf.productionType;
free.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:free animated:YES];
}
break;
case TFMenuButtonTypeComplete: {
TFCompleteViewController *complete = [[TFCompleteViewController alloc] init];
complete.productionType = weakSelf.productionType;
complete.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:complete animated:YES];
}
break;
case TFMenuButtonTypeSort: {
TFSortViewController *sort = [[TFSortViewController alloc] init];
sort.productionType = weakSelf.productionType;
sort.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:sort animated:YES];
}
break;
case TFMenuButtonTypePopularity: {
TFPopularityViewController *popularity = [[TFPopularityViewController alloc] init];
popularity.productionType = weakSelf.productionType;
popularity.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:popularity animated:YES];
}
break;
case TFMenuButtonTypeMember: {
TFMemberViewController *member = [[TFMemberViewController alloc] init];
member.productionType = weakSelf.productionType;
[weakSelf.navigationController pushViewController:member animated:YES];
}
break;
default:
break;
}
};
self.mainTableViewGroup.tableHeaderView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH);
[self.mainTableViewGroup setTableHeaderView:self.headerView];
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.comicModel.label.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreLabelModel *labelModel = [self.comicModel.label objectOrNilAtIndex:indexPath.section];
if (labelModel.ad_type == 0) {
return [self createCellWithTabelView:tableView indexPath:indexPath labelModel:labelModel];
} else {
return [self createAdStyleCellWithTableView:tableView indexPath:indexPath adModel:labelModel];
}
}
- (UITableViewCell *)createCellWithTabelView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
Class cellClass = TFBookStoreComicNormalStyleCell.class;
switch (labelModel.style) {
case 1:
cellClass = TFBookStoreComicMiddleStyleCell.class;
break;
case 2:
cellClass = TFBookStoreComicNormalStyleCell.class;
break;
case 3:
cellClass = TFBookStoreComicMaxStyleCell.class;
break;
default:
cellClass = TFBookStoreComicNormalStyleCell.class;
break;
}
WS(weakSelf)
TFBookStoreComicBasicViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(cellClass)];
if (!cell) {
cell = [[cellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(cellClass)];
}
cell.labelModel = labelModel;
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
TFComicDetailViewController *vc = [[TFComicDetailViewController alloc] init];
vc.comic_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.comicModel.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.comicModel.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)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pointY = scrollView.contentOffset.y;
self.scrollViewContentOffsetY = pointY;
[UIApplication sharedApplication].statusBarHidden = NO;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
CGFloat pointY = scrollView.contentOffset.y;
self.scrollViewContentOffsetY = pointY;
}
- (void)moreButtonClick:(UIButton *)sender
{
TFBookStoreLabelModel *t_labelModel = [self.comicModel.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)netRequest
{
WS(weakSelf)
[TFNetworkTools POSTQuick:Comic_Mall parameters:@{@"channel_id":self.channel != 0?[TFUtilsHelper formatStringWithInteger:self.channel]:@(TFSystemInfoManager.sexChannel)} model:TFBookStoreModel.class success:^(BOOL isSuccess, TFBookStoreModel * _Nullable t_model, BOOL isCache, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.comicModel = t_model;
weakSelf.headerView.mallCenterModel = t_model;
weakSelf.hotwordArray = t_model.hot_word;
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Reload_Mall_Hot_Word object:nil];
}
[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];
[weakSelf.mainTableViewGroup reloadData];
}];
}
- (void)changeRecommendRequestAtIndex:(NSInteger)index complete:(void(^)(void))complete
{
TFBookStoreLabelModel *t_labelModel = [self.comicModel.label objectOrNilAtIndex:index];
NSString *recommend_id = [TFUtilsHelper formatStringWithInteger:t_labelModel.recommend_id];
if (recommend_id.length <= 0 || [recommend_id isEqualToString:@"0"]) {
return;
}
WS(weakSelf)
[TFNetworkTools POST:Comic_Refresh parameters:@{@"recommend_id":recommend_id} model:TFBookStoreLabelModel.class success:^(BOOL isSuccess, TFBookStoreLabelModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
if (t_model.list.count > 0) {
[weakSelf.comicModel.label objectAtIndex:index].list = t_model.list;
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();
}];
}
@end
@@ -0,0 +1,31 @@
//
// TFBookStoreComicBasicItemCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFProductionCoverView.h"
NS_ASSUME_NONNULL_BEGIN
#define Comic_MaxCross_Geometric_Height(x) (((5 * x) / 9))
#define Comic_MiddleCross_Geometric_Height(x) (((2 * x) / 3))
#define Comic_Normal_Geometric_Height(x) (((4 * x) / 3))
#define Comic_Cell_Title_Height 40
#define Comic_Cell_Line_Space 3.0f
@interface TFBookStoreComicBasicItemCell : UICollectionViewCell
@property (nonatomic ,strong) TFProductionModel *productionModel;
@property (nonatomic ,strong) TFProductionCoverView *comicCoverView;
@property (nonatomic ,strong) UILabel *titileLabel;
@property (nonatomic ,strong) UILabel *describeLabel;
- (void)createSubViews;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,90 @@
//
// TFBookStoreComicBasicItemCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreComicBasicItemCell.h"
#import "TFBookStoreComicNormalItemCell.h"
@interface TFBookStoreComicBasicItemCell ()
@end
@implementation TFBookStoreComicBasicItemCell
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = kWhiteColor;
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
[self setupSubview];
[self setupSubviewFrame];
}
- (void)setupSubview
{
self.comicCoverView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeComic coverDirection:TFProductionCoverDirectionVertical];
[self addSubview:self.comicCoverView];
self.titileLabel = [[UILabel alloc] init];
self.titileLabel.textColor = kBlackColor;
self.titileLabel.textAlignment = NSTextAlignmentLeft;
self.titileLabel.font = kMainFont;
self.titileLabel.numberOfLines = 1;
[self addSubview:self.titileLabel];
self.describeLabel = [[UILabel alloc] init];
self.describeLabel.textColor = kGrayTextColor;
self.describeLabel.textAlignment = NSTextAlignmentLeft;
self.describeLabel.font = kFont12;
self.describeLabel.numberOfLines = 1;
[self addSubview:self.describeLabel];
}
- (void)setupSubviewFrame
{
[self.comicCoverView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left);
make.top.mas_equalTo(self.mas_top);
make.width.mas_equalTo(Comic_NormalVertical_Width);
make.height.mas_equalTo(Comic_NormalVertical_Height);
}];
[self.titileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).with.offset(kQuarterMargin);
make.top.mas_equalTo(self.comicCoverView.mas_bottom).with.offset(kQuarterMargin);
make.right.mas_equalTo(self.mas_right).with.offset(-kQuarterMargin);
make.height.mas_equalTo(Comic_Cell_Title_Height / 2);
}];
[self.describeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titileLabel.mas_left);
make.top.mas_equalTo(self.titileLabel.mas_bottom);
make.right.mas_equalTo(self.titileLabel.mas_right);
make.height.mas_equalTo(self.titileLabel.mas_height);
}];
}
- (void)setProductionModel:(TFProductionModel *)productionModel
{
if (!productionModel) return;
_productionModel = productionModel;
self.comicCoverView.coverTitleString = productionModel.flag ? : @"";
self.titileLabel.text = productionModel.name ? : @"";
}
@end
@@ -0,0 +1,27 @@
//
// TFBookStoreComicBasicViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreLabelModel.h"
NS_ASSUME_NONNULL_BEGIN
typedef void (^CellDidSelectItemBlock)(NSInteger production_id);
typedef void (^CellSelectMoreBlock)(TFBookStoreLabelModel *labelModel);
@interface TFBookStoreComicBasicViewCell : TFBasicTableViewCell
@property (nonatomic ,strong) UICollectionView *collectionView;
@property (nonatomic ,assign) BOOL showTopMoreButton;
@property (nonatomic ,strong) TFBookStoreLabelModel *labelModel;
@property (nonatomic ,copy) CellDidSelectItemBlock cellDidSelectItemBlock;
@property (nonatomic ,copy) CellSelectMoreBlock cellSelectMoreBlock;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,163 @@
//
// TFBookStoreComicBasicViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreComicBasicViewCell.h"
#import "TFBookStoreComicBasicItemCell.h"
#import "TFBookStoreComicNormalItemCell.h"
#import "TFBookStoreComicMiddleItemCell.h"
#import "TFBookStoreComicMaxItemCell.h"
@interface TFBookStoreComicBasicViewCell ()
@property (nonatomic ,strong) UIImageView *iconView;
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) TFButton *moreButton;
@end
@implementation TFBookStoreComicBasicViewCell
- (void)createSubviews
{
[super createSubviews];
[self setupSubview];
[self setupSubviewFrame];
}
- (void)setupSubview
{
self.iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"comic_label_hold"]];
self.iconView.hidden = YES;
[self.contentView addSubview:self.iconView];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.textAlignment = NSTextAlignmentLeft;
self.titleLabel.textColor = kBlackColor;
self.titleLabel.backgroundColor = kGrayViewColor;
self.titleLabel.font = kBoldFont16;
[self.contentView addSubview:self.titleLabel];
self.moreButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"查看更多") buttonImageName:@"public_more" buttonIndicator:TFButtonIndicatorTitleLeft];
self.moreButton.buttonTintColor = kGrayTextLightColor;
self.moreButton.graphicDistance = 5;
self.moreButton.buttonImageScale = 0.35;
self.moreButton.hidden = YES;
[self.moreButton addTarget:self action:@selector(moreButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.moreButton];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumInteritemSpacing = Comic_Cell_Line_Space;
flowLayout.minimumLineSpacing = 0.01;
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
flowLayout.itemSize = CGSizeMake(Comic_NormalVertical_Width, Comic_NormalVertical_Height);
flowLayout.sectionInset = UIEdgeInsetsMake(0, kHalfMargin, 0, kHalfMargin);
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
self.collectionView.scrollEnabled = NO;
self.collectionView.backgroundColor = [UIColor clearColor];
self.collectionView.alwaysBounceVertical = NO;
self.collectionView.showsVerticalScrollIndicator = NO;
self.collectionView.showsHorizontalScrollIndicator = NO;
[self.contentView addSubview:self.collectionView];
}
- (void)setupSubviewFrame
{
[self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
make.width.mas_equalTo(kHalfMargin + kHalfMargin);
make.height.mas_equalTo(kHalfMargin + kHalfMargin);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin + kHalfMargin + kQuarterMargin);
make.top.mas_equalTo(self.contentView.mas_top);
make.width.mas_equalTo(SCREEN_WIDTH / 2);
make.height.mas_equalTo(kLabelHeight + kHalfMargin);
}];
[self.moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
make.width.mas_equalTo(80);
make.height.mas_equalTo(30);
}];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.titleLabel.mas_bottom);
make.width.mas_equalTo(self.contentView.mas_width);
make.height.mas_equalTo(SCREEN_WIDTH);
make.bottom.mas_equalTo(self.contentView.mas_bottom).priorityLow();
}];
}
- (void)setLabelModel:(TFBookStoreLabelModel *)labelModel
{
if (labelModel && (_labelModel != labelModel)) {
_labelModel = labelModel;
if (labelModel.label.length > 0) {
self.titleLabel.text = labelModel.label;
}
self.titleLabel.backgroundColor = kWhiteColor;
[self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.titleLabel]);
}];
self.iconView.hidden = NO;
[self.collectionView reloadData];
switch (labelModel.style) {
case 1: {
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(labelModel.list.count < 3 ? Comic_MiddleCell_Height : Comic_MiddleCell_Height *2);
}];
}
break;
case 2: {
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(labelModel.list.count <= 3 ? Comic_NormalCell_Height : Comic_NormalCell_Height *2);
}];
}
break;
case 3: {
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(Comic_MaxCell_Height + (labelModel.list.count == 1 ? 0 : Comic_NormalCell_Height));
}];
}
break;
default:
break;
}
}
}
- (void)setShowTopMoreButton:(BOOL)showTopMoreButton
{
_showTopMoreButton = showTopMoreButton;
self.moreButton.hidden = !showTopMoreButton;
}
- (void)moreButtonClick
{
if (self.cellSelectMoreBlock) {
self.cellSelectMoreBlock(self.labelModel);
}
}
@end
@@ -0,0 +1,24 @@
//
// TFBookStoreComicMaxItemCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreComicBasicItemCell.h"
NS_ASSUME_NONNULL_BEGIN
// 大图设置
#define Comic_MaxCross_Width (SCREEN_WIDTH - 2 * kHalfMargin)
#define Comic_MaxCross_Height Comic_MaxCross_Geometric_Height(Comic_MaxCross_Width)
#define Comic_MaxCell_Width Comic_MaxCross_Width
#define Comic_MaxCell_Height (Comic_MaxCross_Height + Comic_Cell_Title_Height + kHalfMargin)
@interface TFBookStoreComicMaxItemCell : TFBookStoreComicBasicItemCell
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,38 @@
//
// TFBookStoreComicMaxItemCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreComicMaxItemCell.h"
@implementation TFBookStoreComicMaxItemCell
- (void)createSubViews
{
[super createSubViews];
self.comicCoverView.coverDirection = TFProductionCoverDirectionHorizontal;
[self.comicCoverView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(Comic_MaxCross_Width);
make.height.mas_equalTo(Comic_MaxCross_Height);
}];
}
- (void)setProductionModel:(TFProductionModel *)productionModel
{
[super setProductionModel:productionModel];
if (productionModel.horizontal_cover.length > 0) {
self.comicCoverView.coverImageUrl = productionModel.horizontal_cover;
} else if (productionModel.vertical_cover.length > 0) {
self.comicCoverView.coverImageUrl = productionModel.vertical_cover;
}
self.describeLabel.text = productionModel.production_descirption ? : @"";
}
@end
@@ -0,0 +1,18 @@
//
// TFBookStoreComicMaxStyleCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreComicBasicViewCell.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFBookStoreComicMaxStyleCell : TFBookStoreComicBasicViewCell
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,90 @@
//
// TFBookStoreComicMaxStyleCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreComicMaxStyleCell.h"
#import "TFBookStoreComicMaxItemCell.h"
#import "TFBookStoreComicNormalItemCell.h"
@interface TFBookStoreComicMaxStyleCell ()<UICollectionViewDelegate, UICollectionViewDataSource>
@end
@implementation TFBookStoreComicMaxStyleCell
static NSString *maxItem = @"TFBookStoreComicMaxItemCell";
static NSString *normalItem = @"TFBookStoreComicNormalItemCell";
- (void)createSubviews
{
[super createSubviews];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[TFBookStoreComicMaxItemCell class] forCellWithReuseIdentifier:maxItem];
[self.collectionView registerClass:[TFBookStoreComicNormalItemCell class] forCellWithReuseIdentifier:normalItem];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
if (self.labelModel.list.count == 0) {
return 0;
}
return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (section == 0) {
return 1;
} else {
return self.labelModel.list.count <= 3 ? self.labelModel.list.count : 3;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
TFBookStoreComicMaxItemCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:maxItem forIndexPath:indexPath];
cell.productionModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
return cell;
} else {
TFBookStoreComicNormalItemCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:normalItem forIndexPath:indexPath];
cell.productionModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row + 1];
return cell;
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
return CGSizeMake(Comic_MaxCell_Width ,Comic_MaxCell_Height);
}
return CGSizeMake(Comic_NormalCell_Width ,Comic_NormalCell_Height);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 10;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *production = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
if (indexPath.section != 0) {
production = [self.labelModel.list objectOrNilAtIndex:indexPath.row + 1];
}
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(production.production_id);
}
}
@end
@@ -0,0 +1,24 @@
//
// TFBookStoreComicMiddleItemCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreComicBasicItemCell.h"
NS_ASSUME_NONNULL_BEGIN
// 中图设置
#define Comic_MiddleCross_Width (SCREEN_WIDTH - Comic_Cell_Line_Space - 2 * kHalfMargin) / 2
#define Comic_MiddleCross_Height Comic_MiddleCross_Geometric_Height(Comic_MiddleCross_Width)
#define Comic_MiddleCell_Width Comic_MiddleCross_Width
#define Comic_MiddleCell_Height (Comic_MiddleCross_Height + Comic_Cell_Title_Height + kHalfMargin)
@interface TFBookStoreComicMiddleItemCell : TFBookStoreComicBasicItemCell
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,40 @@
//
// TFBookStoreComicMiddleItemCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreComicMiddleItemCell.h"
@implementation TFBookStoreComicMiddleItemCell
- (void)createSubViews
{
[super createSubViews];
self.comicCoverView.coverDirection = TFProductionCoverDirectionHorizontal;
[self.comicCoverView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(Comic_MiddleCross_Width);
make.height.mas_equalTo(Comic_MiddleCross_Height);
}];
}
- (void)setProductionModel:(TFProductionModel *)productionModel
{
[super setProductionModel:productionModel];
if (productionModel.horizontal_cover.length > 0) {
self.comicCoverView.coverImageUrl = productionModel.horizontal_cover;
} else if (productionModel.vertical_cover.length > 0) {
self.comicCoverView.coverImageUrl = productionModel.vertical_cover;
}
self.describeLabel.text = productionModel.production_descirption ? : @"";
}
@end
@@ -0,0 +1,18 @@
//
// TFBookStoreComicMiddleStyleCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreComicBasicViewCell.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFBookStoreComicMiddleStyleCell : TFBookStoreComicBasicViewCell
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,56 @@
//
// TFBookStoreComicMiddleStyleCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreComicMiddleStyleCell.h"
#import "TFBookStoreComicMiddleItemCell.h"
@interface TFBookStoreComicMiddleStyleCell ()<UICollectionViewDelegate, UICollectionViewDataSource>
@end
@implementation TFBookStoreComicMiddleStyleCell
static NSString *cellID = @"TFBookStoreComicMiddleItemCell";
- (void)createSubviews
{
[super createSubviews];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[TFBookStoreComicMiddleItemCell class] forCellWithReuseIdentifier:cellID];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.labelModel.list.count <= 4 ? self.labelModel.list.count : 4;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreComicMiddleItemCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
cell.productionModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(Comic_MiddleCell_Width, Comic_MiddleCell_Height);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *production = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(production.production_id);
}
}
@end
@@ -0,0 +1,24 @@
//
// TFBookStoreComicNormalItemCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreComicBasicItemCell.h"
NS_ASSUME_NONNULL_BEGIN
// 小图设置
#define Comic_NormalVertical_Width (SCREEN_WIDTH - 2 * Comic_Cell_Line_Space - 2 * kHalfMargin) / 3
#define Comic_NormalVertical_Height Comic_Normal_Geometric_Height(Comic_NormalVertical_Width)
#define Comic_NormalCell_Width Comic_NormalVertical_Width
#define Comic_NormalCell_Height (Comic_NormalVertical_Height + Comic_Cell_Title_Height + kHalfMargin)
@interface TFBookStoreComicNormalItemCell : TFBookStoreComicBasicItemCell
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,40 @@
//
// TFBookStoreComicNormalItemCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreComicNormalItemCell.h"
@implementation TFBookStoreComicNormalItemCell
- (void)createSubViews
{
[super createSubViews];
[self.comicCoverView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(Comic_NormalVertical_Width);
make.height.mas_equalTo(Comic_NormalVertical_Height);
}];
}
- (void)setProductionModel:(TFProductionModel *)productionModel
{
[super setProductionModel:productionModel];
if (productionModel.vertical_cover.length > 0) {
self.comicCoverView.coverImageUrl = productionModel.vertical_cover;
} else if (productionModel.horizontal_cover.length > 0) {
self.comicCoverView.coverImageUrl = productionModel.horizontal_cover;
}
NSString *describeStr = @"";
for (TFTagModel *tagModel in productionModel.tag) {
describeStr = [[describeStr stringByAppendingString:tagModel.tab ? : @""] stringByAppendingString:@" "];
}
self.describeLabel.text = describeStr ? : @"";
}
@end
@@ -0,0 +1,18 @@
//
// TFBookStoreComicNormalStyleCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreComicBasicViewCell.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFBookStoreComicNormalStyleCell : TFBookStoreComicBasicViewCell
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,55 @@
//
// TFBookStoreComicNormalStyleCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreComicNormalStyleCell.h"
#import "TFBookStoreComicNormalItemCell.h"
@interface TFBookStoreComicNormalStyleCell ()<UICollectionViewDelegate, UICollectionViewDataSource>
@end
@implementation TFBookStoreComicNormalStyleCell
static NSString *cellID = @"TFBookStoreComicNormalItemCell";
- (void)createSubviews
{
[super createSubviews];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[TFBookStoreComicNormalItemCell class] forCellWithReuseIdentifier:cellID];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.labelModel.list.count <= 6?self.labelModel.list.count:6;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreComicNormalItemCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
cell.productionModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(Comic_NormalCell_Width, Comic_NormalCell_Height);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *listModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(listModel.production_id);
}
}
@end
@@ -0,0 +1,19 @@
//
// TFBookStoreMoreViewController.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 TFBookStoreMoreViewController : TFBasicViewController
@property (nonatomic ,copy) NSString *recommend_id;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,189 @@
//
// TFBookStoreMoreViewController.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreMoreViewController.h"
#import "TFBookStoreRecommend.h"
#import "TFProductionListViewCell.h"
@interface TFBookStoreMoreViewController ()<UITableViewDelegate, UITableViewDataSource>
@end
@implementation TFBookStoreMoreViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
[self setStatusBarDefaultStyle];
}
- (void)createSubviews
{
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
[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(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT);
}];
WS(weakSelf)
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
weakSelf.currentPageNumber = 1;
[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.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellName = @"TFProductionListViewCell";
TFProductionListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFProductionListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.productionType = self.productionType;
cell.productionModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
cell.hiddenEndLine = (indexPath.row == self.dataSourceArray.count - 1);
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (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, PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *productionModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
switch (self.productionType) {
case TFProductionTypeNovel: {
TFNovelDetailViewController *novelDetail = [[TFNovelDetailViewController alloc] init];
novelDetail.book_id = productionModel.production_id;
[self.navigationController pushViewController:novelDetail animated:YES];
}
break;
#if TF_Enable_Comic
case TFProductionTypeComic: {
TFComicDetailViewController *comicDetail = [[TFComicDetailViewController alloc] init];
comicDetail.comic_id = productionModel.production_id;
[self.navigationController pushViewController:comicDetail animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio: {
TFAudioDetailViewController *audioDetail = [[TFAudioDetailViewController alloc] init];
audioDetail.audio_id = productionModel.production_id;
[self.navigationController pushViewController:audioDetail animated:YES];
}
break;
#endif
default:
break;
}
}
- (void)netRequest
{
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Recommend_More;
break;
case TFProductionTypeComic:
url = Comic_Recommend_More;
break;
case TFProductionTypeAudio:
url = Audio_Recommend_More;
break;
default:
break;
}
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"recommend_id"] = self.recommend_id;
params[@"page_num"] = [TFUtilsHelper formatStringWithInteger:self.currentPageNumber];
[TFNetworkTools POST:url parameters:params model:TFBookStoreRecommend.class success:^(BOOL isSuccess, TFBookStoreRecommend *_Nullable t_model, TFNetworkRequestModel *requestModel) {
[weakSelf.mainTableView endRefreshing];
if (isSuccess) {
[weakSelf setNavigationBarTitle:t_model.recommendTitle ? : TFLocalizedString(@"查看更多")];
if (weakSelf.currentPageNumber == 1) {
[weakSelf.dataSourceArray removeAllObjects];
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.recommendList.list];
} else {
[weakSelf.dataSourceArray addObjectsFromArray:t_model.recommendList.list];
}
if (t_model.recommendList.total_page <= t_model.recommendList.current_page) {
[weakSelf.mainTableView hideRefreshFooter];
}
}
[weakSelf.mainTableView reloadData];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView endRefreshing];
}];
}
@end
@@ -0,0 +1,21 @@
//
// TFBookStoreViewController.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFSearchView.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFBookStoreViewController : TFBasicViewController
@property (nonatomic ,strong) UIButton *sexChooseButton;
@property (nonatomic ,assign) BOOL isNavDark;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,456 @@
//
// TFBookStoreViewController.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreViewController.h"
#import "AppDelegate.h"
#if TF_Enable_Comic
#import "TFBookStoreComicController.h"
#endif
#if TF_Enable_Book
#import "TFBookStoreNovelController.h"
#endif
#if TF_Enable_Audio
#import "TFBookStoreAudioController.h"
#import "TFAudioPlayViewController.h"
#endif
#import "TFSearchViewController.h"
#import "TFLimitFreeViewController.h"
#import "TFWebViewController.h"
#import "TFCollectionManager.h"
#import "TFRecommendBookModel.h"
#import "NSObject+Observer.h"
#import "AppDelegate+TFStartTimes.h"
@interface TFBookStoreViewController ()<SGPageTitleViewDelegate, SGPageContentCollectionViewDelegate>
@property (nonatomic ,strong) NSMutableArray *childControllers;
@property (nonatomic ,weak) UIImageView *searchImageView;
@property (nonatomic ,strong) SGPageTitleView *pageTitleView;
@property (nonatomic ,strong) SGPageContentCollectionView *pageContentView;
@property (nonatomic ,assign) CGFloat contentOffsetY;
@end
@implementation TFBookStoreViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self changeNavBarColorWithContentOffsetY:self.contentOffsetY];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubViews];
// 首次安装增加推荐书籍
WS(weakSelf)
[TFNetworkManager networkingStatus:^(BOOL status) {
if (status) {
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
if ([delegate startTimes] == 1) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[weakSelf netRequest];
});
}
}
}];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self changeNavBarColorWithContentOffsetY:self.contentOffsetY];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Show_Tabbar object:nil];
}
- (void)initialize
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushFromMallCenter:) name:NSNotification_Rack_JumpToMallCenter object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadSearchBar) name:Notification_Reload_Mall_Hot_Word object:nil];
[self hiddenNavigationBarLeftButton];
[self hiddenSeparator];
}
- (void)createSubViews
{
self.navigationBar.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0];
WS(weakSelf)
#if TF_Enable_Book
TFBookStoreNovelController *bookStoreNovel = [[TFBookStoreNovelController alloc] init];
bookStoreNovel.productionType = TFProductionTypeNovel;
bookStoreNovel.channel = 0;
[bookStoreNovel addObserver:KEY_PATH(bookStoreNovel, scrollViewContentOffsetY) complete:^(TFBookStoreNovelController * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
[weakSelf changeNavBarColorWithContentOffsetY:[newVal floatValue]];
}];
[self addChildViewController:bookStoreNovel];
#endif
#if TF_Enable_Comic
TFBookStoreComicController *bookStoreComic = [[TFBookStoreComicController alloc] init];
bookStoreComic.productionType = TFProductionTypeComic;
bookStoreComic.channel = 0;
[bookStoreComic addObserver:KEY_PATH(bookStoreComic, scrollViewContentOffsetY) complete:^(TFBookStoreComicController * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
[weakSelf changeNavBarColorWithContentOffsetY:[newVal floatValue]];
}];
[self addChildViewController:bookStoreComic];
#endif
#if TF_Enable_Audio
TFBookStoreAudioController *bookStoreAudio = [[TFBookStoreAudioController alloc] init];
bookStoreAudio.productionType = TFProductionTypeAudio;
bookStoreAudio.channel = 0;
[bookStoreAudio addObserver:KEY_PATH(bookStoreAudio, scrollViewContentOffsetY) complete:^(TFBookStoreAudioController * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
[weakSelf changeNavBarColorWithContentOffsetY:[newVal floatValue]];
}];
[self addChildViewController:bookStoreAudio];
#endif
NSMutableArray *titleArr = [NSMutableArray array];
self.childControllers = [NSMutableArray array];
// 临时记录单站点状态
NSMutableArray *t_titleArr = [NSMutableArray array];
NSMutableArray *t_chailArr = [NSMutableArray array];
for (NSNumber *siteNumber in [TFUtilsHelper getSiteState]) {
#if TF_Enable_Book
if ([siteNumber integerValue] == 1) {
[titleArr addObject:TFLocalizedString(@"小说")];
[self.childControllers addObject:bookStoreNovel];
TFBookStoreNovelController *boyVC = [[TFBookStoreNovelController alloc] init];
boyVC.channel = 1;
boyVC.productionType = TFProductionTypeNovel;
[boyVC addObserver:KEY_PATH(boyVC, scrollViewContentOffsetY) complete:^(TFBookStoreNovelController * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
[weakSelf changeNavBarColorWithContentOffsetY:[newVal floatValue]];
}];
TFBookStoreNovelController *girlVC = [[TFBookStoreNovelController alloc] init];
girlVC.channel = 2;
girlVC.productionType = TFProductionTypeNovel;
[girlVC addObserver:KEY_PATH(girlVC, scrollViewContentOffsetY) complete:^(TFBookStoreNovelController * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
[weakSelf changeNavBarColorWithContentOffsetY:[newVal floatValue]];
}];
[t_titleArr addObjectsFromArray:@[TFLocalizedString(@"男生"), TFLocalizedString(@"女生")]];
[t_chailArr addObjectsFromArray:@[boyVC, girlVC]];
}
#endif
#if TF_Enable_Comic
if ([siteNumber integerValue] == 2) {
[titleArr addObject:TFLocalizedString(@"漫画")];
[self.childControllers addObject:bookStoreComic];
TFBookStoreComicController *boyVC = [[TFBookStoreComicController alloc] init];
boyVC.channel = 1;
boyVC.productionType = TFProductionTypeComic;
[boyVC addObserver:KEY_PATH(boyVC, scrollViewContentOffsetY) complete:^(TFBookStoreComicController * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
[weakSelf changeNavBarColorWithContentOffsetY:[newVal floatValue]];
}];
TFBookStoreComicController *girlVC = [[TFBookStoreComicController alloc] init];
girlVC.channel = 2;
girlVC.productionType = TFProductionTypeComic;
[girlVC addObserver:KEY_PATH(girlVC, scrollViewContentOffsetY) complete:^(TFBookStoreComicController * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
[weakSelf changeNavBarColorWithContentOffsetY:[newVal floatValue]];
}];
[t_titleArr addObjectsFromArray:@[TFLocalizedString(@"男生"), TFLocalizedString(@"女生")]];
[t_chailArr addObjectsFromArray:@[boyVC, girlVC]];
}
#endif
#if TF_Enable_Audio
if ([siteNumber integerValue] == 3) {
[titleArr addObject:TFLocalizedString(@"听书")];
[self.childControllers addObject:bookStoreAudio];
TFBookStoreAudioController *boyVC = [[TFBookStoreAudioController alloc] init];
boyVC.channel = 1;
boyVC.productionType = TFProductionTypeAudio;
[boyVC addObserver:KEY_PATH(boyVC, scrollViewContentOffsetY) complete:^(TFBookStoreAudioController * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
[weakSelf changeNavBarColorWithContentOffsetY:[newVal floatValue]];
}];
TFBookStoreAudioController *girlVC = [[TFBookStoreAudioController alloc] init];
girlVC.channel = 2;
girlVC.productionType = TFProductionTypeAudio;
[girlVC addObserver:KEY_PATH(girlVC, scrollViewContentOffsetY) complete:^(TFBookStoreAudioController * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
[weakSelf changeNavBarColorWithContentOffsetY:[newVal floatValue]];
}];
[t_titleArr addObjectsFromArray:@[TFLocalizedString(@"男生"), TFLocalizedString(@"女生")]];
[t_chailArr addObjectsFromArray:@[boyVC, girlVC]];
}
#endif
}
if ([TFUtilsHelper getSiteState].count == 1) {
titleArr = t_titleArr;
self.childControllers = t_chailArr;
}
self.pageContentView = [[SGPageContentCollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) parentVC:self childVCs:self.childControllers];
self.pageContentView.delegatePageContentCollectionView = self;
[self.view addSubview:self.pageContentView];
self.pageConfigure.indicatorColor = [UIColor whiteColor];
self.pageConfigure.indicatorStyle = SGIndicatorStyleDynamic;
self.pageConfigure.indicatorHeight = 3;
self.pageConfigure.indicatorFixedWidth = 10;
self.pageConfigure.indicatorDynamicWidth = 14;
self.pageConfigure.indicatorToBottomDistance = 3;
self.pageConfigure.titleSelectedColor = [UIColor whiteColor];
self.pageConfigure.titleFont = kBoldFont16;
self.pageConfigure.titleTextZoom = YES;
self.pageConfigure.titleTextZoomRatio = 0.2;
self.pageConfigure.titleColor = kColorRGBA(255, 255, 255, 0.9);
CGFloat width = 0;
for (NSString *obj in titleArr) {
CGFloat t_width = [TFViewHelper getDynamicWidthWithLabelFont:kBoldFont16 labelHeight:43.0 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:self.pageTitleView];
if ([TFUtilsHelper getSiteState].count > 1) {
self.sexChooseButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.sexChooseButton.adjustsImageWhenHighlighted = NO;
[self.sexChooseButton setImageEdgeInsets:UIEdgeInsetsMake(10, 20, 10, 0)];
[self.sexChooseButton addTarget:self action:@selector(secChooseButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.navigationBar addSubview:self.sexChooseButton];
if (TFSystemInfoManager.sexChannel == 1) { // 男
[self.sexChooseButton setImage:[UIImage imageNamed:@"comic_mall_boy_dark"] forState:UIControlStateNormal];
} else { // 女
[self.sexChooseButton setImage:[UIImage imageNamed:@"comic_mall_girl_dark"] forState:UIControlStateNormal];
}
[self.sexChooseButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.navigationBar.mas_right).with.offset(- kHalfMargin - kQuarterMargin);
make.centerY.mas_equalTo(self.pageTitleView.mas_centerY).with.offset(2);
make.width.height.mas_equalTo(44);
}];
}
UIImageView *searchImageView = [[UIImageView alloc] init];
searchImageView.image = [[UIImage imageNamed:@"public_search"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[searchImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(searchClick)]];
searchImageView.backgroundColor = [UIColor clearColor];
searchImageView.userInteractionEnabled = YES;
searchImageView.tintColor = kWhiteColor;
[self.navigationBar addSubview:searchImageView];
self.searchImageView = searchImageView;
[searchImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.pageTitleView).offset(2);
if ([TFUtilsHelper getSiteState].count > 1) {
make.right.equalTo(self.sexChooseButton.mas_left);
} else {
make.right.equalTo(self.navigationBar).offset(- kHalfMargin - kQuarterMargin);
}
make.width.height.mas_equalTo(24);
}];
}
- (void)searchClick
{
TFSearchViewController *vc = [[TFSearchViewController alloc] init];
vc.productionType = self.productionType;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)secChooseButtonClick
{
if (TFSystemInfoManager.sexChannel == 1) { // 男
if (self.isNavDark) {
[self.sexChooseButton setImage:[UIImage imageNamed:@"comic_mall_girl"] forState:UIControlStateNormal];
} else {
[self.sexChooseButton setImage:[UIImage imageNamed:@"comic_mall_girl_dark"] forState:UIControlStateNormal];
}
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"已切换至女频")];
TFSystemInfoManager.sexChannel = 2;
} else { // 女
if (self.isNavDark) {
[self.sexChooseButton setImage:[UIImage imageNamed:@"comic_mall_boy"] forState:UIControlStateNormal];
} else {
[self.sexChooseButton setImage:[UIImage imageNamed:@"comic_mall_boy_dark"] forState:UIControlStateNormal];
}
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"已切换至男频")];
TFSystemInfoManager.sexChannel = 1;
}
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Channel_Change object:nil];
}
- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex
{
[self.pageContentView setPageContentCollectionViewCurrentIndex:selectedIndex];
}
- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex
{
[self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}
- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView index:(NSInteger)index
{
[self reloadSearchBar];
}
- (void)reloadSearchBar
{
TFBasicViewController *vc = [self.childControllers objectOrNilAtIndex:self.pageTitleView.signBtnIndex];
self.productionType = vc.productionType;
CGFloat contentOffsetY = [[vc valueForKey:@"scrollViewContentOffsetY"] integerValue];
[self changeNavBarColorWithContentOffsetY:contentOffsetY];
}
- (void)netRequest
{
// 书架增加推荐书籍
[TFNetworkTools POST:Shelf_Recommend parameters:nil model:TFRecommendBookModel.class success:^(BOOL isSuccess, TFRecommendBookModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] getAllCollection].count == 0) {
for (TFProductionModel *model in t_model.book) {
model.productionType = TFProductionTypeNovel;
model.is_recommend = YES;
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] addCollectionWithProductionModel:model atIndex:0];
}
}
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] getAllCollection].count == 0) {
for (TFProductionModel *model in t_model.comic) {
model.productionType = TFProductionTypeComic;
model.is_recommend = YES;
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] addCollectionWithProductionModel:model atIndex:0];
}
}
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] getAllCollection].count == 0) {
for (TFProductionModel *model in t_model.audio) {
model.productionType = TFProductionTypeAudio;
model.is_recommend = YES;
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] addCollectionWithProductionModel:model atIndex:0];
}
}
}
} failure:nil];
}
- (void)changeNavBarColorWithContentOffsetY:(CGFloat)contentOffsetY
{
_contentOffsetY = contentOffsetY;
CGFloat alpha = [TFColorHelper getAlphaWithContentOffsetY:fabs(contentOffsetY)];
CGFloat rbgColor = [TFColorHelper getColorWithContentOffsetY:fabs(contentOffsetY)];
self.navigationBar.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:alpha];
[self.pageTitleView resetTitleColor:kColorRGBA(rbgColor, rbgColor, rbgColor, 1) titleSelectedColor:kColorRGBA(rbgColor, rbgColor, rbgColor, 1) indicatorColor:kColorRGBA(rbgColor, rbgColor, rbgColor, 1)];
self.searchImageView.tintColor = kColorRGBA(rbgColor, rbgColor, rbgColor, 1);
if (fabs(contentOffsetY) > 60) {
self.isNavDark = YES;
} else {
self.isNavDark = NO;
}
}
- (void)setIsNavDark:(BOOL)isNavDark
{
if (isNavDark) {
if ([[TFViewHelper getCurrentViewController] isEqual:self]) {
[self setStatusBarDefaultStyle];
}
if ([TFUtilsHelper getSiteState].count > 1) {
if (TFSystemInfoManager.sexChannel == 1) { // 男
[self.sexChooseButton setImage:[UIImage imageNamed:@"comic_mall_boy"] forState:UIControlStateNormal];
} else { // 女
[self.sexChooseButton setImage:[UIImage imageNamed:@"comic_mall_girl"] forState:UIControlStateNormal];
}
}
} else {
if ([[TFViewHelper getCurrentViewController] isEqual:self]) {
[self setStatusBarLightContentStyle];
}
if ([TFUtilsHelper getSiteState].count > 1) {
if (TFSystemInfoManager.sexChannel == 1) { // 男
[self.sexChooseButton setImage:[UIImage imageNamed:@"comic_mall_boy_dark"] forState:UIControlStateNormal];
} else { // 女
[self.sexChooseButton setImage:[UIImage imageNamed:@"comic_mall_girl_dark"] forState:UIControlStateNormal];
}
}
}
_isNavDark = isNavDark;
}
- (void)pushFromMallCenter:(NSNotification *)notification
{
#if TF_Enable_Comic
// 跳转到漫画相关内容
if ([notification.object isEqualToString:@"comic"]) {
for (NSInteger i = 0; i < self.pageContentView.childViewControllers.count ; i ++) {
if ([[self.pageContentView.childViewControllers objectOrNilAtIndex:i] isKindOfClass:[TFBookStoreComicController class]]) {
self.pageTitleView.resetSelectedIndex = i;
break;
}
}
}
#endif
#if TF_Enable_Book
// 跳转到小说相关内容
if ([notification.object isEqualToString:@"novel"]) {
for (NSInteger i = 0; i < self.pageContentView.childViewControllers.count ; i ++) {
if ([[self.pageContentView.childViewControllers objectOrNilAtIndex:i] isKindOfClass:[TFBookStoreNovelController class]]) {
self.pageTitleView.resetSelectedIndex = i;
break;
}
}
}
#endif
#if TF_Enable_Audio
// 跳转到听书相关内容
if ([notification.object isEqualToString:@"audio"]) {
for (NSInteger i = 0; i < self.pageContentView.childViewControllers.count ; i ++) {
if ([[self.pageContentView.childViewControllers objectOrNilAtIndex:i] isKindOfClass:[TFBookStoreAudioController class]]) {
self.pageTitleView.resetSelectedIndex = i;
break;
}
}
}
#endif
}
@end
@@ -0,0 +1,27 @@
//
// TFBookStoreLabelModel.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAdvertModel.h"
NS_ASSUME_NONNULL_BEGIN
@class TFProductionModel;
@interface TFBookStoreLabelModel : TFAdvertModel
@property (nonatomic ,assign) NSInteger recommend_id; // 推荐位id
@property (nonatomic ,assign) NSInteger style; // 展示风格
@property (nonatomic ,copy) NSString *label; // 名称
@property (nonatomic ,copy) NSString *total; // 漫画数
@property (nonatomic ,assign) BOOL can_more; // 是否有更多 true有,false没有
@property (nonatomic ,assign) BOOL can_refresh; // 是否有更多 true有,false没有
@property (nonatomic ,assign) NSInteger expire_time;
@property (nonatomic ,strong) NSArray <TFProductionModel *>*list; // 作品列表
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,18 @@
//
// TFBookStoreLabelModel.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreLabelModel.h"
@implementation TFBookStoreLabelModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{@"list" : [TFProductionModel class]};
}
@end
@@ -0,0 +1,33 @@
//
// TFBookStoreModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/22.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFBannerModel, TFBookStoreLabelModel, TFBookStoreMenusModel;
@interface TFBookStoreModel : NSObject
@property (nonatomic ,strong) NSArray <TFBannerModel *>*banner;
@property (nonatomic ,strong) NSArray <TFBookStoreLabelModel *>*label;
@property (nonatomic ,strong) NSArray <TFBookStoreMenusModel *> *menus_tabs;
@property (nonatomic ,strong) NSArray <NSString *>*hot_word;
@end
@interface TFBookStoreMenusModel : NSObject
@property (nonatomic ,copy) NSString *title;
@property (nonatomic ,copy) NSString *icon;
@property (nonatomic ,copy) NSString *action;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,28 @@
//
// TFBookStoreModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/22.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreModel.h"
#import "TFBookStoreLabelModel.h"
#import "TFUserCenterModel.h"
@implementation TFBookStoreModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{@"banner" : [TFBannerModel class],
@"label" : [TFBookStoreLabelModel class],
@"menus_tabs": [TFBookStoreMenusModel class]
};
}
@end
@implementation TFBookStoreMenusModel
@end
@@ -0,0 +1,21 @@
//
// TFBookStoreRecommend.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/12.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFProductionListModel;
@interface TFBookStoreRecommend : NSObject
@property (nonatomic ,copy) NSString *recommendTitle;
@property (nonatomic ,strong) TFProductionListModel *recommendList;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,21 @@
//
// TFBookStoreRecommend.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/12.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreRecommend.h"
@implementation TFBookStoreRecommend
+ (NSDictionary *)modelCustomPropertyMapper
{
return @{
@"recommendTitle":@"recommend.title",
@"recommendList": @[@"list", @"book"]
};
}
@end
@@ -0,0 +1,36 @@
//
// TFBookStoreMenuView.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 NS_ENUM(NSUInteger, TFMenuButtonType) {
TFMenuButtonTypeFree, // 免费
TFMenuButtonTypeComplete, // 完结
TFMenuButtonTypeSort, // 分类
TFMenuButtonTypePopularity, // 排行
TFMenuButtonTypeMember // 会员
};
typedef void(^BannerrImageClickBlock)(TFBannerModel *bannerModel);
@interface TFBookStoreMenuView : UIView
@property (nonatomic ,assign) TFProductionType productionType;
@property (nonatomic ,strong) TFBookStoreModel *mallCenterModel;
@property (nonatomic ,copy) void (^menuButtonClickBlock)(TFMenuButtonType menuButtonType, NSString *menuButtonTitle);
@property (nonatomic ,copy) void(^bannerrImageClickBlock)(TFBannerModel *bannerModel); // banner点击
- (void)createSubViews;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,186 @@
//
// TFBookStoreMenuView.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreMenuView.h"
#import "YJMallCollectionViewCell.h"
#import "YJBannerView.h"
#import "TFUserCenterModel.h"
@interface TFBookStoreMenuView () <YJBannerViewDelegate, YJBannerViewDataSource>
@property (nonatomic ,strong) YJBannerView *bannerView;
@property (nonatomic ,strong) UIView *menuBarView;
@end
@implementation TFBookStoreMenuView
- (instancetype)init
{
if (self = [super init]) {
CGFloat headerHeight = SCREEN_WIDTH - kHalfMargin;
if (is_iPhone6P) {
headerHeight = SCREEN_WIDTH - kMargin - kQuarterMargin;
} else if (is_iPhoneX) {
headerHeight = SCREEN_WIDTH;
} else if (is_iPhone6) {
headerHeight = SCREEN_WIDTH - kMargin;
}
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, headerHeight);
self.clipsToBounds = YES;
}
return self;
}
- (void)setProductionType:(TFProductionType)productionType
{
_productionType = productionType;
[self createSubViews];
}
- (void)createSubViews
{
self.backgroundColor = kWhiteColor;
[self addSubview:self.bannerView];
UIImageView *bannerBottonView = [[UIImageView alloc] init];
bannerBottonView.image = [UIImage imageNamed:@"banner_bottom_line.png"];
[self addSubview:bannerBottonView];
[bannerBottonView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(self.bannerView.mas_bottom).with.offset(1);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH, 800, 57));
}];
self.menuBarView = [[UIView alloc] init];
self.menuBarView.backgroundColor = kWhiteColor;
[self addSubview:self.menuBarView];
[self.menuBarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(self.mas_bottom);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(SCREEN_WIDTH / 5 - kQuarterMargin);
}];
}
- (YJBannerView *)bannerView
{
if (!_bannerView) {
_bannerView = [YJBannerView bannerViewWithFrame:CGRectMake(0, 0, self.width, self.height - (SCREEN_WIDTH / 5)) dataSource:self delegate:self emptyImage:HoldImage placeholderImage:HoldImage selectorString:NSStringFromSelector(@selector(setImageWithURL:placeholder:))];
_bannerView.repeatCount = 9999;
_bannerView.pageControlAliment = PageControlAlimentCenter;
_bannerView.autoDuration = 5.0f;
_bannerView.pageControlStyle = PageControlCustom;
_bannerView.pageControlDotSize = CGSizeMake(10, 5);
_bannerView.pageControlBottomMargin = 15;
_bannerView.customPageControlHighlightImage = [UIImage imageNamed:@"pageControlS"];
_bannerView.customPageControlNormalImage = [UIImage imageNamed:@"pageControlN"];
}
return _bannerView;
}
- (NSArray *)bannerViewImages:(YJBannerView *)bannerView
{
NSMutableArray *t_arr = [NSMutableArray array];
for (TFBannerModel *t_model in self.mallCenterModel.banner) {
[t_arr addObject:t_model.image];
}
return t_arr;
}
// 代理方法 点击了哪个bannerView 的 第几个元素
- (void)bannerView:(YJBannerView *)bannerView didSelectItemAtIndex:(NSInteger)index
{
if (self.bannerrImageClickBlock) {
self.bannerrImageClickBlock([self.mallCenterModel.banner objectOrNilAtIndex:index]);
}
}
- (NSArray *)bannerViewRegistCustomCellClass:(YJBannerView *)bannerView
{
return @[[YJMallCollectionViewCell class]];
}
/** 根据 Index 选择使用哪个 reuseIdentifier */
- (Class)bannerView:(YJBannerView *)bannerView reuseIdentifierForIndex:(NSInteger)index
{
return [YJMallCollectionViewCell class];
}
/** 自定义 View 刷新数据或者其他配置 */
- (UICollectionViewCell *)bannerView:(YJBannerView *)bannerView customCell:(UICollectionViewCell *)customCell index:(NSInteger)index
{
YJMallCollectionViewCell *cell = (YJMallCollectionViewCell *)customCell;
cell.bannerModel = [self.mallCenterModel.banner objectOrNilAtIndex:index];
return cell;
}
- (void)setMallCenterModel:(TFBookStoreModel *)mallCenterModel
{
_mallCenterModel = mallCenterModel;
[self.menuBarView removeAllSubviews];
[self.bannerView reloadData];
for (int i = 0; i < mallCenterModel.menus_tabs.count; i ++) {
TFBookStoreMenusModel *t_model = [mallCenterModel.menus_tabs objectAtIndex:i];
TFButton *button = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:t_model.title ? : @"" buttonImageName:t_model.icon ? : @"" buttonIndicator:TFButtonIndicatorTitleBottom showMaskView:YES];
button.graphicDistance = 0;
button.buttonImageScale = 0.6;
button.buttonTitleFont = kFont13;
button.buttonTag = t_model.action;
[button addTarget:self action:@selector(menuButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.menuBarView addSubview:button];
CGFloat buttonWidth = SCREEN_WIDTH / mallCenterModel.menus_tabs.count;
CGFloat buttonHeight = SCREEN_WIDTH / 5 - kQuarterMargin;
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(i * buttonWidth);
make.top.mas_equalTo(0);
make.width.mas_equalTo(buttonWidth);
make.height.mas_equalTo(buttonHeight);
}];
}
}
- (void)menuButtonClick:(TFButton *)sender
{
if (self.menuButtonClickBlock) {
if ([sender.buttonTag isEqualToString:@"free"]) {
self.menuButtonClickBlock(TFMenuButtonTypeFree, sender.buttonTitle ? : @"");
}
if ([sender.buttonTag isEqualToString:@"finished"]) {
self.menuButtonClickBlock(TFMenuButtonTypeComplete, sender.buttonTitle ? : @"");
}
if ([sender.buttonTag isEqualToString:@"category"]) {
self.menuButtonClickBlock(TFMenuButtonTypeSort, sender.buttonTitle ? : @"");
}
if ([sender.buttonTag isEqualToString:@"rank"]) {
self.menuButtonClickBlock(TFMenuButtonTypePopularity, sender.buttonTitle ? : @"");
}
if ([sender.buttonTag isEqualToString:@"vip"]) {
self.menuButtonClickBlock(TFMenuButtonTypeMember, sender.buttonTitle ? : @"");
}
}
}
@end
@@ -0,0 +1,24 @@
//
// TFBookStoreNovelController.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 TFBookStoreNovelController : TFBasicViewController
@property (nonatomic ,assign) CGFloat channel;
@property (nonatomic ,assign) CGFloat scrollViewContentOffsetY;
@property (nonatomic ,strong) NSArray *hotwordArray;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,400 @@
//
// TFBookStoreNovelController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelController.h"
#import "TFLimitFreeViewController.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "TFBookStoreMenuView.h"
#import "TFBookStoreLabelModel.h"
#import "TFBannerActionManager.h"
// 分类
#import "TFSortViewController.h"
// 排行榜
#import "TFPopularityViewController.h"
// 包月
#import "TFMemberViewController.h"
// 完结
#import "TFCompleteViewController.h"
// 限免
#import "TFFreeViewController.h"
#import "TFWebViewController.h"
@interface TFBookStoreNovelController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) TFBookStoreModel *bookStoreNovelModel;
@property (nonatomic ,strong) TFBookStoreMenuView *headerView;
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFBookStoreNovelController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Restore_Network object:nil];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenNavigationBar:YES];
self.hotwordArray = [NSArray array];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Channel_Change 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(0);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_TABBAR_HEIGHT);
}];
WS(weakSelf)
self.headerView = [[TFBookStoreMenuView alloc] init];
self.headerView.productionType = self.productionType;
self.headerView.bannerrImageClickBlock = ^(TFBannerModel * _Nonnull bannerModel) {
if ([TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeNovel]) {
[weakSelf.navigationController pushViewController:[TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeNovel] animated:YES];
}
};
self.headerView.menuButtonClickBlock = ^(TFMenuButtonType menuButtonType, NSString * _Nonnull menuButtonTitle) {
switch (menuButtonType) {
case TFMenuButtonTypeFree: {
TFFreeViewController *free = [[TFFreeViewController alloc] init];
free.productionType = weakSelf.productionType;
free.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:free animated:YES];
}
break;
case TFMenuButtonTypeComplete: {
TFCompleteViewController *complete = [[TFCompleteViewController alloc] init];
complete.productionType = weakSelf.productionType;
complete.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:complete animated:YES];
}
break;
case TFMenuButtonTypeSort: {
TFSortViewController *sort = [[TFSortViewController alloc] init];
sort.productionType = weakSelf.productionType;
sort.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:sort animated:YES];
}
break;
case TFMenuButtonTypePopularity: {
TFPopularityViewController *popularity = [[TFPopularityViewController alloc] init];
popularity.productionType = weakSelf.productionType;
popularity.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:popularity animated:YES];
}
break;
case TFMenuButtonTypeMember: {
TFMemberViewController *member = [[TFMemberViewController alloc] init];
member.productionType = weakSelf.productionType;
[weakSelf.navigationController pushViewController:member animated:YES];
}
break;
default:
break;
}
};
self.mainTableViewGroup.tableHeaderView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH);
[self.mainTableViewGroup setTableHeaderView:self.headerView];
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.bookStoreNovelModel.label.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreLabelModel *labelModel = [self.bookStoreNovelModel.label objectOrNilAtIndex:indexPath.section];
if (labelModel.ad_type == 0) {
return [self createCellWithTabelView:tableView indexPath:indexPath labelModel:labelModel];
} else {
return [self createAdStyleCellWithTableView:tableView indexPath:indexPath adModel:labelModel];
}
}
- (UITableViewCell *)createCellWithTabelView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
Class cellClass = TFBookStoreNovelStyleOneCell.class;
switch (labelModel.style) {
case 1:
cellClass = TFBookStoreNovelStyleOneCell.class;
break;
case 2:
cellClass = TFBookStoreNovelStyleTwoCell.class;
break;
case 3:
cellClass = TFBookStoreNovelStyleThreeCell.class;
break;
case 4:
cellClass = TFBookStoreNovelStyleFourCell.class;
break;
default:
cellClass = TFBookStoreNovelStyleOneCell.class;
break;
}
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) {
TFNovelDetailViewController *novelDetail = [[TFNovelDetailViewController alloc] init];
novelDetail.book_id = production_id;
[weakSelf.navigationController pushViewController:novelDetail animated:YES];
};
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;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
TFBookStoreLabelModel *labelModel = [self.bookStoreNovelModel.label objectOrNilAtIndex:section];
if (labelModel.ad_type != 0) {
return kHalfMargin;
}
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.bookStoreNovelModel.label objectOrNilAtIndex:section];
if (labelModel.can_more || labelModel.can_refresh) {
if (section == self.bookStoreNovelModel.label.count - 1) {
return 40;
}
return 30;
}
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
view.backgroundColor = [UIColor whiteColor];
CGFloat buttonX = SCREEN_WIDTH / 4;
CGFloat buttonW = SCREEN_WIDTH / 2;
CGFloat buttonH = 30;
TFBookStoreLabelModel *labelModel = [self.bookStoreNovelModel.label objectOrNilAtIndex:section];
if (!labelModel.can_more && !labelModel.can_refresh) {
return view;
}
if (labelModel.style == 5) { // 排行榜
TFButton *moreButton = [TFButton initWithFrame:CGRectMake(kMargin, 0, SCREEN_WIDTH - 2 * kMargin, buttonH) btnTitle:TFLocalizedString(@"查看更多排行榜") btnImageName:@"comic_mall_more" backgroundColor:kGrayViewColor btnTintColor:kGrayTextLightColor btnStyle:TFButtonIndicatorTitleLeft cornerRadius:15 target:self action:@selector(rankButtonClick:)];
moreButton.graphicDistance = 5;
moreButton.tag = section;
[view addSubview:moreButton];
return view;
}
TFButton *moreButton = [TFButton initWithFrame:CGRectMake(buttonX, 0, 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;
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;
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, 0, (SCREEN_WIDTH - 3 * kMargin) / 2, buttonH);
changeButton.frame = CGRectMake(2 * kMargin + (SCREEN_WIDTH - 3 * kMargin) / 2, 0, (SCREEN_WIDTH - 3 * kMargin) / 2, buttonH);
[view addSubview:moreButton];
[view addSubview:changeButton];
}
return view;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pointY = scrollView.contentOffset.y;
self.scrollViewContentOffsetY = pointY;
[UIApplication sharedApplication].statusBarHidden = NO;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
CGFloat pointY = scrollView.contentOffset.y;
self.scrollViewContentOffsetY = pointY;
}
#pragma mark - 点击事件
- (void)moreButtonClick:(UIButton *)sender
{
TFBookStoreLabelModel *t_labelModel = [self.bookStoreNovelModel.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:(TFButton *)sender
{
[sender startSpin];
[self changeBookRecommendRequestAtIndex:sender.tag complete:^{
[sender stopSpin];
}];
}
- (void)rankButtonClick:(UIButton *)sender
{
TFPopularityViewController *vc = [[TFPopularityViewController alloc] init];
vc.productionType = self.productionType;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)netRequest
{
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"channel_id"] = self.channel != 0 ? [TFUtilsHelper formatStringWithInteger:self.channel] : @(TFSystemInfoManager.sexChannel);
[TFNetworkTools POSTQuick:Book_Mall_Center parameters:params model:TFBookStoreModel.class success:^(BOOL isSuccess, TFBookStoreModel * _Nullable t_model, BOOL isCache, TFNetworkRequestModel * _Nonnull requestModel) {
if (weakSelf.bookStoreNovelModel && isCache) return;
if (isSuccess) {
weakSelf.bookStoreNovelModel = t_model;
weakSelf.headerView.mallCenterModel = t_model;
weakSelf.hotwordArray = t_model.hot_word;
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Reload_Mall_Hot_Word object:nil];
}
[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];
[weakSelf.mainTableViewGroup reloadData];
}];
}
- (void)changeBookRecommendRequestAtIndex:(NSInteger)index complete:(void(^)(void))complete
{
TFBookStoreLabelModel *t_labelModel = [self.bookStoreNovelModel.label objectOrNilAtIndex:index];
if (t_labelModel.recommend_id <= 0) {
return;
}
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"recommend_id"] = [TFUtilsHelper formatStringWithInteger:t_labelModel.recommend_id];
[TFNetworkTools POST:Book_Refresh parameters:params model:TFBookStoreLabelModel.class success:^(BOOL isSuccess, TFBookStoreLabelModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
[weakSelf.bookStoreNovelModel.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();
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
!complete ?: complete();
}];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
@@ -0,0 +1,33 @@
//
// TFBookStoreNovelBasicItemCell.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 TFBookStoreNovelBasicItemCell : UICollectionViewCell
@property (nonatomic ,strong) TFProductionCoverView *coverView;
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) UILabel *subtitleLabel;
@property (nonatomic ,strong) UIView *lineView;
@property (nonatomic ,strong) TFProductionModel *labelListModel;
@property (nonatomic ,strong) NSIndexPath *cellIndexPath;
@property (nonatomic ,assign) BOOL hiddenEndLine;
- (void)createSubviews;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,109 @@
//
// TFBookStoreNovelBasicItemCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelBasicItemCell.h"
@implementation TFBookStoreNovelBasicItemCell
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = kWhiteColor;
[self createSubviews];
}
return self;
}
- (void)createSubviews
{
// 封面
self.coverView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical];
self.coverView.userInteractionEnabled = YES;
[self addSubview:self.coverView];
[self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(kHalfMargin);
make.width.mas_equalTo(BOOK_WIDTH - 10);
make.height.mas_equalTo(kGeometricHeight(BOOK_WIDTH - 10, 3, 4));
make.bottom.mas_equalTo(self.mas_bottom).priorityLow();
}];
// 书名
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.numberOfLines = 1;
self.titleLabel.backgroundColor = kWhiteColor;
self.titleLabel.font = kMainFont;
self.titleLabel.textAlignment = NSTextAlignmentLeft;
[self addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.coverView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(self.coverView.mas_top);
make.right.mas_equalTo(self.mas_right);
make.height.mas_equalTo(BOOK_CELL_TITLE_HEIGHT / 2);
}];
// 子标题
self.subtitleLabel = [[UILabel alloc] init];
self.subtitleLabel.textColor = kGrayTextColor;
self.subtitleLabel.textAlignment = NSTextAlignmentLeft;
self.subtitleLabel.font = kFont11;
self.subtitleLabel.numberOfLines = 1;
self.subtitleLabel.hidden = YES;
[self addSubview:self.subtitleLabel];
[self.subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel.mas_left);
make.top.mas_equalTo(self.titleLabel.mas_bottom);
make.right.mas_equalTo(self.titleLabel.mas_right);
make.height.mas_equalTo(self.titleLabel.mas_height);
make.bottom.mas_equalTo(self.mas_bottom).priorityLow();
}];
// 横线
self.lineView = [[UIView alloc] init];
self.lineView.hidden = YES;
self.lineView.backgroundColor = kGrayLineColor;
[self addSubview:self.lineView];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(self.mas_bottom).with.offset(-kCellLineHeight);
make.right.mas_equalTo(self.mas_right).with.offset(kHalfMargin);
make.height.mas_equalTo(kCellLineHeight);
}];
}
- (void)setLabelListModel:(TFProductionModel *)labelListModel
{
_labelListModel = labelListModel;
if (!labelListModel) {
return;
}
self.coverView.coverImageUrl = labelListModel.cover;
self.coverView.productionType = labelListModel.productionType;
self.titleLabel.text = labelListModel.name ? : @"";
}
- (void)setHiddenEndLine:(BOOL)hiddenEndLine
{
_hiddenEndLine = hiddenEndLine;
self.lineView.hidden = hiddenEndLine;
}
- (void)setCellIndexPath:(NSIndexPath *)cellIndexPath
{
_cellIndexPath = cellIndexPath;
}
@end
@@ -0,0 +1,34 @@
//
// TFBookStoreNovelBasicViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreLabelModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFBookStoreNovelBasicViewCell : TFBasicTableViewCell
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) UICollectionView *collectionView;
// 默认 NO 与showTopRefreshButton 互斥
@property (nonatomic ,assign) BOOL showTopMoreBtn;
// 默认 NO 与showTopMoreButton 互斥
@property (nonatomic ,assign) BOOL showTopRefreshBtn;
@property (nonatomic ,strong) TFBookStoreLabelModel *labelModel;
@property (nonatomic ,copy) void (^cellDidSelectItemBlock)(NSInteger production_id);
@property (nonatomic ,copy) void (^cellSelectMoreBlock)(TFBookStoreLabelModel *labelModel);
@property (nonatomic ,copy) void (^cellSelectRefreshBlock)(TFBookStoreLabelModel *labelModel, NSIndexPath *indexPath);
// 停止刷新状态
- (void)stopRefreshing;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,242 @@
//
// TFBookStoreNovelBasicViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelBasicViewCell.h"
#import "TFBookStoreNovelHorizontalCell.h"
#import "TFBookStoreNovelVerticalCell.h"
#import "WXYZ_CountDownView.h"
@interface TFBookStoreNovelBasicViewCell ()
@property (nonatomic ,strong) UIImageView *iconView;
@property (nonatomic ,strong) WXYZ_CountDownView *countdownView;
@property (nonatomic ,strong) TFButton *moreBtn;
@property (nonatomic ,strong) TFButton *refreshBtn;
@end
@implementation TFBookStoreNovelBasicViewCell
- (void)createSubviews
{
[super createSubviews];
[self setupSubview];
[self setupSubviewFrame];
}
- (void)setupSubview
{
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.textAlignment = NSTextAlignmentLeft;
self.titleLabel.textColor = kBlackColor;
self.titleLabel.backgroundColor = kGrayViewColor;
self.titleLabel.font = kBoldFont16;
[self.contentView addSubview:self.titleLabel];
self.moreBtn = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"查看更多") buttonImageName:@"public_more" buttonIndicator:TFButtonIndicatorTitleLeft];
self.moreBtn.buttonTintColor = kGrayTextLightColor;
self.moreBtn.graphicDistance = 5;
self.moreBtn.buttonImageScale = 0.35;
self.moreBtn.hidden = YES;
[self.moreBtn addTarget:self action:@selector(moreButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.moreBtn];
self.refreshBtn = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"换一换") buttonImageName:@"comic_mall_refresh" buttonIndicator:TFButtonIndicatorTitleLeft];
self.refreshBtn.buttonTintColor = kGrayTextLightColor;
self.refreshBtn.graphicDistance = 5;
self.refreshBtn.buttonImageScale = 0.5;
self.refreshBtn.hidden = YES;
[self.refreshBtn addTarget:self action:@selector(refreshButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.refreshBtn];
self.iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"book_label_hold"]];
self.iconView.hidden = YES;
[self.contentView addSubview:self.iconView];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumLineSpacing = 0;
flowLayout.minimumInteritemSpacing = 0;
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
flowLayout.itemSize = CGSizeMake(BOOK_WIDTH , VerticalCellHeight);
flowLayout.sectionInset = UIEdgeInsetsMake(0, kHalfMargin, 0, kHalfMargin);
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
self.collectionView.scrollEnabled = NO;
self.collectionView.backgroundColor = [UIColor clearColor];
self.collectionView.alwaysBounceVertical = NO;
self.collectionView.showsVerticalScrollIndicator = NO;
self.collectionView.showsHorizontalScrollIndicator = NO;
if (@available(iOS 11.0, *)) {
self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[self.contentView addSubview:self.collectionView];
// 倒计时
self.countdownView = [[WXYZ_CountDownView alloc] init];
self.countdownView.hidden = YES;
[self.contentView addSubview:self.countdownView];
}
- (void)setupSubviewFrame
{
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin + kHalfMargin);
make.top.mas_equalTo(self.contentView.mas_top);
make.width.mas_equalTo(100);
make.height.mas_equalTo(kLabelHeight + kHalfMargin);
}];
[self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
make.width.mas_equalTo(80);
make.height.mas_equalTo(30);
}];
[self.refreshBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
make.width.mas_equalTo(80);
make.height.mas_equalTo(30);
}];
[self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
make.width.mas_equalTo(kHalfMargin + kQuarterMargin);
make.height.mas_equalTo(kHalfMargin + kQuarterMargin);
}];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.titleLabel.mas_bottom);
make.width.mas_equalTo(self.contentView.mas_width);
make.height.mas_equalTo(SCREEN_WIDTH);
make.bottom.mas_equalTo(self.contentView.mas_bottom).priorityLow();
}];
[self.countdownView 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(- kMargin);
make.height.mas_equalTo(20);
}];
}
- (void)setLabelModel:(TFBookStoreLabelModel *)labelModel
{
if (labelModel && _labelModel != labelModel) {
_labelModel = labelModel;
if (labelModel.label.length > 0) {
self.titleLabel.text = labelModel.label;
}
self.titleLabel.backgroundColor = kWhiteColor;
[self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.titleLabel]);
}];
if (labelModel.expire_time > 0) {
self.countdownView.hidden = NO;
self.countdownView.timeStamp = labelModel.expire_time;
} else if (labelModel.expire_time == -1) {
self.countdownView.hidden = YES;
self.countdownView.timeStamp = 0;
} else {
self.countdownView.hidden = YES;
}
self.iconView.hidden = NO;
[self.collectionView reloadData];
switch (labelModel.style) {
case 1: { // TFBookStoreNovelStyleOneCell
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(VerticalCellHeight + kHalfMargin);
}];
}
break;
case 2: { // TFBookStoreNovelStyleTwoCell
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(self.labelModel.list.count <= 3 ? (VerticalCellHeight + kHalfMargin) : ((VerticalCellHeight + kHalfMargin) *2));
}];
}
break;
case 3: { // TFBookStoreNovelStyleThreeCell
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(self.labelModel.list.count <= 3 ? (VerticalCellHeight + kHalfMargin) : VerticalCellHeight + (HorizontalCellHeight + kHalfMargin) * ((self.labelModel.list.count - 3) <= 3 ? (self.labelModel.list.count - 3) : 3));
}];
}
break;
case 4: { // TFBookStoreNovelStyleFourCell
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(self.labelModel.list.count <= 1 ? HorizontalCellHeight : VerticalCellHeight + HorizontalCellHeight + kHalfMargin);
}];
}
break;
default: {
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(VerticalCellHeight + kHalfMargin);
}];
}
break;
}
}
// self.refreshBtn.hidden = (labelModel.list.count == 0);
self.iconView.hidden = (labelModel.list.count == 0);
self.titleLabel.hidden = (labelModel.list.count == 0);
}
- (void)setShowTopMoreBtn:(BOOL)showTopMoreBtn
{
_showTopMoreBtn = showTopMoreBtn;
self.moreBtn.hidden = !showTopMoreBtn;
self.refreshBtn.hidden = showTopMoreBtn;
}
- (void)setShowTopRefreshBtn:(BOOL)showTopRefreshBtn
{
_showTopRefreshBtn = showTopRefreshBtn;
self.refreshBtn.hidden = !showTopRefreshBtn;
self.moreBtn.hidden = showTopRefreshBtn;
}
- (void)stopRefreshing
{
[self.refreshBtn stopSpin];
}
- (void)moreButtonClick
{
if (self.cellSelectMoreBlock) {
self.cellSelectMoreBlock(self.labelModel);
}
}
- (void)refreshButtonClick
{
[self.refreshBtn startSpin];
if (self.cellSelectRefreshBlock) {
self.cellSelectRefreshBlock(self.labelModel, self.index);
} else {
[self.refreshBtn stopSpin];
}
}
@end
@@ -0,0 +1,32 @@
//
// TFBookStoreNovelHorizontalCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicItemCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
横排布书籍cell
┌──────────────┐ ┌────────────────────────┐
│ │ │ book Name │
│ │ └────────────────────────┘
│ │ ┌────────────────────────┐
│ photo │ │ │
│ │ │ describe │
│ │ │ │
│ │ │ │
└──────────────┘ └────────────────────────┘
*/
#define HorizontalCellHeight (kGeometricHeight(BOOK_WIDTH - 10, 3, 4) + kHalfMargin)
@interface TFBookStoreNovelHorizontalCell : TFBookStoreNovelBasicItemCell
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,118 @@
//
// TFBookStoreNovelHorizontalCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelHorizontalCell.h"
#import "TFTagboardView.h"
@interface TFBookStoreNovelHorizontalCell ()
@property (nonatomic ,strong) UILabel *authorLabel;
@property (nonatomic ,strong) TFTagboardView *tagboardView;
@property (nonatomic ,strong) YYLabel *introductionLabel;
@end
@implementation TFBookStoreNovelHorizontalCell
- (void)createSubviews
{
[super createSubviews];
[self setupSubview];
[self setupSubviewFrame];
}
- (void)setupSubview
{
// 作者
self.authorLabel = [[UILabel alloc] init];
self.authorLabel.numberOfLines = 1;
self.authorLabel.backgroundColor = kWhiteColor;
self.authorLabel.font = kFont11;
self.authorLabel.textColor = kColorRGBA(176, 176, 177, 1);
self.authorLabel.textAlignment = NSTextAlignmentLeft;
[self addSubview:self.authorLabel];
// 标签
self.tagboardView = [[TFTagboardView alloc] init];
self.tagboardView.font = kFont11;
self.tagboardView.textAlignment = TFTagboardTextAlignmentRight;
self.tagboardView.borderStyle = TFTagboardBorderStyleBorder;
self.tagboardView.cornerRadius = 3;
self.tagboardView.spacing = 10;
[self addSubview:self.tagboardView];
// 简介
self.introductionLabel = [[YYLabel alloc] init];
self.introductionLabel.numberOfLines = 3;
self.introductionLabel.textVerticalAlignment = YYTextVerticalAlignmentTop;
self.introductionLabel.backgroundColor = kWhiteColor;
self.introductionLabel.font = kFont13;
self.introductionLabel.textColor = kColorRGBA(102, 102, 102, 1);
self.introductionLabel.textAlignment = NSTextAlignmentLeft;
[self addSubview:self.introductionLabel];
}
- (void)setupSubviewFrame
{
[self.coverView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(BOOK_WIDTH - 10);
make.height.mas_equalTo(kGeometricHeight(BOOK_WIDTH - 10, 3, 4));
}];
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.coverView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(self.coverView.mas_top);
make.right.mas_equalTo(self.mas_right);
make.height.mas_equalTo(BOOK_CELL_TITLE_HEIGHT / 2);
}];
[self.authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel.mas_left);
make.bottom.mas_equalTo(self.coverView.mas_bottom);
make.width.mas_equalTo(10);
make.height.mas_equalTo(self.titleLabel.mas_height);
}];
[self.tagboardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.authorLabel.mas_right).with.offset(kHalfMargin);
make.right.mas_equalTo(self.titleLabel.mas_right);
make.centerY.mas_equalTo(self.authorLabel.mas_centerY);
make.height.mas_equalTo(self.authorLabel.mas_height);
}];
[self.introductionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel.mas_left);
make.right.mas_equalTo(self.titleLabel.mas_right);
make.top.mas_equalTo(self.titleLabel.mas_bottom).with.offset(kHalfMargin);
make.bottom.mas_equalTo(self.authorLabel.mas_top).with.offset(- kHalfMargin);
}];
}
- (void)setLabelListModel:(TFProductionModel *)labelListModel
{
[super setLabelListModel:labelListModel];
self.authorLabel.text = labelListModel.author ? : @"";
[self.authorLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.authorLabel]);
}];
self.tagboardView.tagboardArray = labelListModel.tag;
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString: labelListModel.production_descirption ? : @""];
text.lineSpacing = 5;
text.font = kFont13;
text.color = kColorRGBA(118, 118, 118, 1);
self.introductionLabel.attributedText = text;
}
@end
@@ -0,0 +1,43 @@
//
// TFBookStoreNovelStyleFourCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicViewCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
横一竖三排布方式
┌──────────────┐ ┌──────────────────────────────────┐
│ │ │ book Name │
│ │ └──────────────────────────────────┘
│ │ ┌──────────────────────────────────┐
│ photo │ │ │
│ │ │ describe │
│ │ │ │
│ │ │ │
└──────────────┘ └──────────────────────────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ photo │ │ photo │ │ photo │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ book Name │ │ book Name │ │ book Name │
└──────────────┘ └──────────────┘ └──────────────┘
*/
@interface TFBookStoreNovelStyleFourCell : TFBookStoreNovelBasicViewCell <UICollectionViewDelegate, UICollectionViewDataSource>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,82 @@
//
// TFBookStoreNovelStyleFourCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFBookStoreNovelVerticalCell.h"
#import "TFBookStoreNovelHorizontalCell.h"
@implementation TFBookStoreNovelStyleFourCell
static NSString *verticalCell = @"TFBookStoreNovelVerticalCell";
static NSString *horizontalCell = @"TFBookStoreNovelHorizontalCell";
- (void)createSubviews
{
[super createSubviews];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[TFBookStoreNovelVerticalCell class] forCellWithReuseIdentifier:verticalCell];
[self.collectionView registerClass:[TFBookStoreNovelHorizontalCell class] forCellWithReuseIdentifier:horizontalCell];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
if (self.labelModel.list.count <= 1) {
return 1;
}
return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (self.labelModel.list.count <= 1) {
return 1;
}
if (section == 0) {
return 1;
} else {
return self.labelModel.list.count > 3?3:self.labelModel.list.count - 1;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
TFBookStoreNovelHorizontalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:horizontalCell forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
cell.hiddenEndLine = YES;
return cell;
} else {
TFBookStoreNovelVerticalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:verticalCell forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row + 1];
return cell;
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
return CGSizeMake(SCREEN_WIDTH - kMargin, HorizontalCellHeight);
}
return CGSizeMake(BOOK_WIDTH, VerticalCellHeight);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.section + indexPath.row];
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(labelListModel.production_id);
}
}
@end
@@ -0,0 +1,35 @@
//
// TFBookStoreNovelStyleOneCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicViewCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
一排三列 排布方式
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ photo │ │ photo │ │ photo │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ book Name │ │ book Name │ │ book Name │
└──────────────┘ └──────────────┘ └──────────────┘
*/
@interface TFBookStoreNovelStyleOneCell : TFBookStoreNovelBasicViewCell <UICollectionViewDelegate, UICollectionViewDataSource>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,50 @@
//
// TFBookStoreNovelStyleOneCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelVerticalCell.h"
@implementation TFBookStoreNovelStyleOneCell
static NSString *cellID = @"TFBookStoreNovelVerticalCell";
- (void)createSubviews
{
[super createSubviews];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[TFBookStoreNovelVerticalCell class] forCellWithReuseIdentifier:cellID];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (!self.labelModel.list) {
return 3;
}
return self.labelModel.list.count <= 3 ? self.labelModel.list.count : 3;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreNovelVerticalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(labelListModel.production_id);
}
}
@end
@@ -0,0 +1,61 @@
//
// TFBookStoreNovelStyleThreeCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicViewCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
横三竖三排布方式
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ photo │ │ photo │ │ photo │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ book Name │ │ book Name │ │ book Name │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────────────────────────┐
│ │ │ book Name │
│ │ └──────────────────────────────────┘
│ │ ┌──────────────────────────────────┐
│ photo │ │ │
│ │ │ describe │
│ │ │ │
│ │ │ │
└──────────────┘ └──────────────────────────────────┘
┌──────────────┐ ┌──────────────────────────────────┐
│ │ │ book Name │
│ │ └──────────────────────────────────┘
│ │ ┌──────────────────────────────────┐
│ photo │ │ │
│ │ │ describe │
│ │ │ │
│ │ │ │
└──────────────┘ └──────────────────────────────────┘
┌──────────────┐ ┌──────────────────────────────────┐
│ │ │ book Name │
│ │ └──────────────────────────────────┘
│ │ ┌──────────────────────────────────┐
│ photo │ │ │
│ │ │ describe │
│ │ │ │
│ │ │ │
└──────────────┘ └──────────────────────────────────┘
*/
@interface TFBookStoreNovelStyleThreeCell : TFBookStoreNovelBasicViewCell <UICollectionViewDelegate, UICollectionViewDataSource>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,96 @@
//
// TFBookStoreNovelStyleThreeCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelVerticalCell.h"
#import "TFBookStoreNovelHorizontalCell.h"
@implementation TFBookStoreNovelStyleThreeCell
static NSString *verticalCell = @"TFBookStoreNovelVerticalCell";
static NSString *horizontalCell = @"TFBookStoreNovelHorizontalCell";
- (void)createSubviews
{
[super createSubviews];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[TFBookStoreNovelVerticalCell class] forCellWithReuseIdentifier:verticalCell];
[self.collectionView registerClass:[TFBookStoreNovelHorizontalCell class] forCellWithReuseIdentifier:horizontalCell];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
if (self.labelModel.list.count <= 3) {
return 1;
}
return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (self.labelModel.list.count <= 3) {
return self.labelModel.list.count;
}
if (section == 0) {
return 3;
}
return self.labelModel.list.count - 3;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
TFBookStoreNovelVerticalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:verticalCell forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
return cell;
} else {
TFBookStoreNovelHorizontalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:horizontalCell forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row + 3];
cell.hiddenEndLine = indexPath.row == self.labelModel.list.count - 3 - 1;
return cell;
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
return CGSizeMake(BOOK_WIDTH, VerticalCellHeight);
}
return CGSizeMake(SCREEN_WIDTH - kMargin, HorizontalCellHeight);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
if (section == 0) {
return UIEdgeInsetsMake(0, kHalfMargin, 0, kHalfMargin);
}
return UIEdgeInsetsMake(kHalfMargin, kHalfMargin, 0, kHalfMargin);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return kHalfMargin;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.section * 3 + indexPath.row];
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(labelListModel.production_id);
}
}
@end
@@ -0,0 +1,46 @@
//
// TFBookStoreNovelStyleTwoCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicViewCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
两排三列排布方式
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ photo │ │ photo │ │ photo │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ book Name │ │ book Name │ │ book Name │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ photo │ │ photo │ │ photo │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ book Name │ │ book Name │ │ book Name │
└──────────────┘ └──────────────┘ └──────────────┘
*/
@interface TFBookStoreNovelStyleTwoCell : TFBookStoreNovelBasicViewCell <UICollectionViewDelegate, UICollectionViewDataSource>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,53 @@
//
// TFBookStoreNovelStyleTwoCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelVerticalCell.h"
@implementation TFBookStoreNovelStyleTwoCell
static NSString *cellID = @"TFBookStoreNovelVerticalCell";
- (void)createSubviews
{
[super createSubviews];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[TFBookStoreNovelVerticalCell class] forCellWithReuseIdentifier:cellID];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.labelModel.list.count <= 6 ? self.labelModel.list.count : 6;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreNovelVerticalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
return cell;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return kHalfMargin;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *production = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(production.production_id);
}
}
@end
@@ -0,0 +1,36 @@
//
// TFBookStoreNovelVerticalCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicItemCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
竖直排布书籍cell
┌──────────────┐
│ │
│ │
│ │
│ photo │
│ │
│ │
│ │
└──────────────┘
┌──────────────┐
│ book Name │
└──────────────┘
*/
#define VerticalCellHeight (BOOK_HEIGHT + BOOK_CELL_TITLE_HEIGHT + kQuarterMargin)
@interface TFBookStoreNovelVerticalCell : TFBookStoreNovelBasicItemCell
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,51 @@
//
// TFBookStoreNovelVerticalCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelVerticalCell.h"
@implementation TFBookStoreNovelVerticalCell
- (void)createSubviews
{
[super createSubviews];
[self.coverView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.mas_centerX);
make.top.mas_equalTo(self.mas_top);
make.width.mas_equalTo(BOOK_WIDTH);
make.height.mas_equalTo(BOOK_HEIGHT);
}];
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.coverView.mas_left);
make.top.mas_equalTo(self.coverView.mas_bottom).with.offset(kQuarterMargin);
make.width.mas_equalTo(self.coverView.mas_width);
make.height.mas_equalTo(BOOK_CELL_TITLE_HEIGHT / 2);
}];
self.subtitleLabel.hidden = NO;
}
- (void)setLabelListModel:(TFProductionModel *)labelListModel
{
[super setLabelListModel:labelListModel];
NSString *str = @"";
for (TFTagModel *tagModel in labelListModel.tag) {
if (tagModel.tab.length > 0) {
str = [[str stringByAppendingString:tagModel.tab ? : @""] stringByAppendingString:@" "];
}
}
if (str.length == 0) {
str = labelListModel.production_descirption;
}
self.subtitleLabel.text = str;
}
@end
@@ -0,0 +1,20 @@
//
// TFCompleteCommController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFCompleteCommController : TFBasicViewController
@property (nonatomic ,copy) NSString *channel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,221 @@
//
// TFCompleteCommController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFCompleteCommController.h"
#import "TFProductionListViewCell.h"
#import "TFPublicAdvertisementViewCell.h"
@interface TFCompleteCommController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFCompleteCommController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenNavigationBar:YES];
}
- (void)createSubviews
{
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
[self.view addSubview:self.mainTableView];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.view.mas_top);
make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(- PUB_NAVBAR_HEIGHT - self.pageViewHeight);
make.width.mas_equalTo(self.view.mas_width);
}];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无数据") buttonTitle:@"" tapBlock:^{
}];
WS(weakSelf)
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
weakSelf.currentPageNumber = 1;
[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.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
if (t_model.ad_type == 0) {
TFProductionListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFProductionListViewCell"];
if (!cell) {
cell = [[TFProductionListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFProductionListViewCell"];
}
cell.productionType = self.productionType;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.productionModel = t_model;
cell.hiddenEndLine = (indexPath.row == self.dataSourceArray.count - 1);
return cell;
} else {
TFPublicAdvertisementViewCell *cell = [self.advertDict objectForKey:[TFUtilsHelper formatStringWithInteger:indexPath.row]];
if (!cell) {
static NSString *cellName = @"TFPublicAdvertisementViewCell";
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
cell.mainTableView = tableView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[self.advertDict setObject:cell forKey:[TFUtilsHelper formatStringWithInteger:indexPath.row]];
}
[cell setAdModel:t_model refresh:self.needRefresh];
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return kHalfMargin;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHalfMargin)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (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, PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
switch (self.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel: {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic: {
TFComicDetailViewController *comicDetail = [[TFComicDetailViewController alloc] init];
comicDetail.comic_id = t_model.production_id;
[self.navigationController pushViewController:comicDetail animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio: {
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init];
vc.audio_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
default:
break;
}
}
- (void)netRequest
{
WS(weakSelf)
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Finish;
break;
case TFProductionTypeComic:
url = Comic_Finish;
break;
case TFProductionTypeAudio:
url = Audio_Finish;
break;
default:
break;
}
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"channel_id"] = self.channel;
params[@"page_num"] = [TFUtilsHelper formatStringWithInteger:self.currentPageNumber];
[TFNetworkTools POST:url parameters:params model:TFProductionListModel.class success:^(BOOL isSuccess, TFProductionListModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
[weakSelf.mainTableView endRefreshing];
if (isSuccess) {
if (weakSelf.currentPageNumber == 1) {
[weakSelf.mainTableView showRefreshFooter];
[weakSelf.dataSourceArray removeAllObjects];
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.list];
} else {
[weakSelf.dataSourceArray addObjectsFromArray:t_model.list];
}
if (t_model.total_page <= t_model.current_page) {
[weakSelf.mainTableView hideRefreshFooter];
}
}
weakSelf.needRefresh = YES;
[weakSelf.mainTableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
[weakSelf.mainTableView xtfei_endLoading];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView endRefreshing];
[weakSelf.mainTableView xtfei_endLoading];
[TFPromptManager showPromptWithError:error defaultText:nil];
}];
}
@end
@@ -0,0 +1,18 @@
//
// TFCompleteViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFCompleteViewController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,89 @@
//
// TFCompleteViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFCompleteViewController.h"
#import "TFCompleteCommController.h"
@interface TFCompleteViewController ()<
#if TF_Enable_PageControl
SGPageTitleViewDelegate,
#endif
SGPageContentCollectionViewDelegate>
#if TF_Enable_PageControl
@property (nonatomic ,strong) SGPageTitleView *pageTitleView;
#endif
@property (nonatomic ,strong) SGPageContentCollectionView *pageContentCollectionView;
@end
@implementation TFCompleteViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
[self setNavigationBarTitle:self.navTitle ? : TFLocalizedString(@"完结")];
[self hiddenSeparator];
}
- (void)createSubviews
{
TFCompleteCommController *boyVC = [[TFCompleteCommController alloc] init];
boyVC.productionType = self.productionType;
boyVC.channel = @"1";
#if TF_Enable_PageControl
TFCompleteCommController *girlVC = [[TFCompleteCommController alloc] init];
girlVC.productionType = self.productionType;
girlVC.channel = @"2";
#endif
NSArray *childArr = @[boyVC
#if TF_Enable_PageControl
, girlVC
#endif
];
self.pageContentCollectionView = [[SGPageContentCollectionView alloc] initWithFrame:
#if TF_Enable_PageControl
CGRectMake(0, PUB_NAVBAR_HEIGHT + 44, SCREEN_WIDTH, SCREEN_HEIGHT)
#else
CGRectMake(0, PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)
#endif
parentVC:self childVCs:childArr];
_pageContentCollectionView.delegatePageContentCollectionView = self;
[self.view addSubview:self.pageContentCollectionView];
#if TF_Enable_PageControl
NSArray *titleArr = @[TFLocalizedString(@"男生"), TFLocalizedString(@"女生")];
self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, 44) delegate:self titleNames:titleArr configure:self.pageConfigure];
self.pageTitleView.backgroundColor = kWhiteColor;
[self.view addSubview:_pageTitleView];
#endif
}
#if TF_Enable_PageControl
- (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];
}
#endif
@end
@@ -0,0 +1,20 @@
//
// TFFreeCommViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFFreeCommViewController : TFBasicViewController
@property (nonatomic ,copy) NSString *channel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,220 @@
//
// TFFreeCommViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFFreeCommViewController.h"
#import "TFProductionListViewCell.h"
#import "TFPublicAdvertisementViewCell.h"
@interface TFFreeCommViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFFreeCommViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenNavigationBar:YES];
}
- (void)createSubviews
{
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
[self.view addSubview:self.mainTableView];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.view.mas_top);
make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(- PUB_NAVBAR_HEIGHT - self.pageViewHeight);
make.width.mas_equalTo(self.view.mas_width);
}];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无数据") buttonTitle:@"" tapBlock:^{
}];
WS(weakSelf)
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
weakSelf.currentPageNumber = 1;
[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.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
if (t_model.ad_type == 0) {
TFProductionListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFProductionListViewCell"];
if (!cell) {
cell = [[TFProductionListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFProductionListViewCell"];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.productionType = self.productionType;
cell.productionModel = t_model;
cell.hiddenEndLine = (indexPath.row == self.dataSourceArray.count - 1);
return cell;
} else {
TFPublicAdvertisementViewCell *cell = [self.advertDict objectForKey:[TFUtilsHelper formatStringWithInteger:indexPath.row]];
if (!cell) {
static NSString *cellName = @"TFPublicAdvertisementViewCell";
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
[cell setAdModel:t_model refresh:self.needRefresh];
cell.mainTableView = tableView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[self.advertDict setObject:cell forKey:[TFUtilsHelper formatStringWithInteger:indexPath.row]];
}
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return kHalfMargin;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHalfMargin)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (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, PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
switch (self.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel: {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic: {
TFComicDetailViewController *comicDetail = [[TFComicDetailViewController alloc] init];
comicDetail.comic_id = t_model.production_id;
[self.navigationController pushViewController:comicDetail animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio: {
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init];
vc.audio_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
default:
break;
}
}
- (void)netRequest
{
WS(weakSelf)
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Free;
break;
case TFProductionTypeComic:
url = Comic_Free;
break;
case TFProductionTypeAudio:
url = Audio_Free;
break;
default:
break;
}
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"channel_id"] = self.channel;
params[@"page_num"] = [TFUtilsHelper formatStringWithInteger:self.currentPageNumber];
[TFNetworkTools POST:url parameters:params model:TFProductionListModel.class success:^(BOOL isSuccess, TFProductionListModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
[weakSelf.mainTableView endRefreshing];
if (isSuccess) {
if (weakSelf.currentPageNumber == 1) {
[weakSelf.mainTableView showRefreshFooter];
[weakSelf.dataSourceArray removeAllObjects];
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.list];
} else {
[weakSelf.dataSourceArray addObjectsFromArray:t_model.list];
}
if (t_model.total_page <= t_model.current_page) {
[weakSelf.mainTableView hideRefreshFooter];
}
}
weakSelf.needRefresh = YES;
[weakSelf.mainTableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
[weakSelf.mainTableView xtfei_endLoading];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView endRefreshing];
[weakSelf.mainTableView xtfei_endLoading];
}];
}
@end
@@ -0,0 +1,18 @@
//
// TFFreeViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFFreeViewController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,97 @@
//
// TFFreeViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFFreeViewController.h"
#import "TFFreeCommViewController.h"
@interface TFFreeViewController ()<
#if TF_Enable_PageControl
SGPageTitleViewDelegate,
#endif
SGPageContentCollectionViewDelegate>
#if TF_Enable_PageControl
@property (nonatomic ,strong) SGPageTitleView *pageTitleView;
#endif
@property (nonatomic ,strong) SGPageContentCollectionView *pageContentCollectionView;
@end
@implementation TFFreeViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
[self setNavigationBarTitle:self.navTitle ? : TFLocalizedString(@"免费")];
[self hiddenSeparator];
}
- (void)createSubviews
{
TFFreeCommViewController *boyVC = [[TFFreeCommViewController alloc] init];
boyVC.productionType = self.productionType;
boyVC.channel = @"1";
#if TF_Enable_PageControl
TFFreeCommViewController *girlVC = [[TFFreeCommViewController alloc] init];
girlVC.productionType = self.productionType;
girlVC.channel = @"2";
#endif
NSArray *childArr = @[boyVC
#if TF_Enable_PageControl
, girlVC
#endif
];
self.pageContentCollectionView = [[SGPageContentCollectionView alloc] initWithFrame:
#if TF_Enable_PageControl
CGRectMake(0, PUB_NAVBAR_HEIGHT + 44, SCREEN_WIDTH, SCREEN_HEIGHT)
#else
CGRectMake(0, PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)
#endif
parentVC:self childVCs:childArr];
_pageContentCollectionView.delegatePageContentCollectionView = self;
[self.view addSubview:self.pageContentCollectionView];
#if TF_Enable_PageControl
NSArray *titleArr = @[TFLocalizedString(@"男生"), TFLocalizedString(@"女生")];
self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, 44) delegate:self titleNames:titleArr configure:self.pageConfigure];
self.pageTitleView.backgroundColor = kWhiteColor;
[self.view addSubview:_pageTitleView];
#endif
}
#if TF_Enable_PageControl
- (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];
}
#endif
@end
@@ -0,0 +1,20 @@
//
// TFLimitFreeCommController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFLimitFreeCommController : TFBasicViewController
@property (nonatomic ,copy) NSString *channel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,215 @@
//
// TFLimitFreeCommController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFLimitFreeCommController.h"
#import "TFProductionListViewCell.h"
#import "TFPublicAdvertisementViewCell.h"
@interface TFLimitFreeCommController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFLimitFreeCommController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenNavigationBar:YES];
}
- (void)createSubviews
{
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
[self.view addSubview:self.mainTableView];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.view.mas_top);
make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(- PUB_NAVBAR_HEIGHT - self.pageViewHeight);
make.width.mas_equalTo(self.view.mas_width);
}];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无数据") buttonTitle:@"" tapBlock:^{
}];
WS(weakSelf)
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
weakSelf.currentPageNumber = 1;
[weakSelf netRequest];
}];
self.mainTableView.mj_footer = [TFRefreshFooter footerWithRefreshingBlock:^{
weakSelf.currentPageNumber ++;
[weakSelf netRequest];
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
if (t_model.ad_type == 0) {
TFProductionListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFProductionListViewCell"];
if (!cell) {
cell = [[TFProductionListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFProductionListViewCell"];
}
cell.productionType = self.productionType;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.productionModel = t_model;
cell.hiddenEndLine = (indexPath.row == self.dataSourceArray.count - 1);
return cell;
} else {
TFPublicAdvertisementViewCell *cell = [self.advertDict objectForKey:[TFUtilsHelper formatStringWithInteger:indexPath.row]];
if (!cell) {
static NSString *cellName = @"TFPublicAdvertisementViewCell";
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
[cell setAdModel:t_model refresh:self.needRefresh];
cell.mainTableView = tableView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[self.advertDict setObject:cell forKey:[TFUtilsHelper formatStringWithInteger:indexPath.row]];
}
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
switch (self.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel:
{
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic:
{
TFComicDetailViewController *vc = [[TFComicDetailViewController alloc] init];
vc.comic_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio:
break;
#endif
default:
break;
}
}
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
//section头部视图
- (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;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
// return PUB_TABBAR_OFFSET == 0 ? kHalfMargin : PUB_TABBAR_OFFSET;
return CGFLOAT_MIN;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_TABBAR_OFFSET)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)netRequest
{
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Free_Time;
break;
case TFProductionTypeComic:
url = Comic_Free_Time;
break;
case TFProductionTypeAudio:
url = @"";
break;
default:
break;
}
WS(weakSelf)
[TFNetworkTools POST:url parameters:@{@"channel_id":self.channel, @"page_num":[TFUtilsHelper formatStringWithInteger:self.currentPageNumber]} model:TFProductionListModel.class success:^(BOOL isSuccess, TFProductionListModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
if (weakSelf.currentPageNumber == 1) {
[weakSelf.mainTableView showRefreshFooter];
[weakSelf.dataSourceArray removeAllObjects];
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.list];
} else {
[weakSelf.dataSourceArray addObjectsFromArray:t_model.list];
}
if (t_model.total_page <= t_model.current_page) {
[weakSelf.mainTableView hideRefreshFooter];
}
}
[weakSelf.mainTableView endRefreshing];
weakSelf.needRefresh = YES;
[weakSelf.mainTableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
[weakSelf.mainTableView xtfei_endLoading];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView endRefreshing];
[weakSelf.mainTableView xtfei_endLoading];
}];
}
@end
@@ -0,0 +1,18 @@
//
// TFLimitFreeViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFLimitFreeViewController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,93 @@
//
// TFLimitFreeViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFLimitFreeViewController.h"
#import "TFLimitFreeCommController.h"
#import "SGPagingView.h"
@interface TFLimitFreeViewController ()<
#if TF_Enable_PageControl
SGPageTitleViewDelegate,
#endif
SGPageContentCollectionViewDelegate>
#if TF_Enable_PageControl
@property (nonatomic ,strong) SGPageTitleView *pageTitleView;
#endif
@property (nonatomic ,strong) SGPageContentCollectionView *pageContentCollectionView;
@end
@implementation TFLimitFreeViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
[self setNavigationBarTitle:TFLocalizedString(@"限时免费")];
[self hiddenSeparator];
}
- (void)createSubviews
{
TFLimitFreeCommController *boyVC = [[TFLimitFreeCommController alloc] init];
boyVC.channel = @"1";
boyVC.productionType = self.productionType;
#if TF_Enable_PageControl
TFLimitFreeCommController *girlVC = [[TFLimitFreeCommController alloc] init];
girlVC.channel = @"2";
girlVC.productionType = self.productionType;
#endif
NSArray *childArr = @[boyVC
#if TF_Enable_PageControl
, girlVC
#endif
];
self.pageContentCollectionView = [[SGPageContentCollectionView alloc] initWithFrame:
#if TF_Enable_PageControl
CGRectMake(0, PUB_NAVBAR_HEIGHT + 44, SCREEN_WIDTH, SCREEN_HEIGHT)
#else
CGRectMake(0, PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)
#endif
parentVC:self childVCs:childArr];
_pageContentCollectionView.delegatePageContentCollectionView = self;
[self.view addSubview:self.pageContentCollectionView];
#if TF_Enable_PageControl
NSArray *titleArr = @[TFLocalizedString(@"男生"), TFLocalizedString(@"女生")];
self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, 44) delegate:self titleNames:titleArr configure:self.pageConfigure];
self.pageTitleView.backgroundColor = kWhiteColor;
[self.view addSubview:_pageTitleView];
if (TFSystemInfoManager.sexChannel == 2) {
[self.pageTitleView setSelectedIndex:1];
}
#endif
}
#if TF_Enable_PageControl
- (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];
}
#endif
@end
@@ -0,0 +1,17 @@
//
// TFMemberViewController.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 TFMemberViewController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,383 @@
//
// TFMemberViewController.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFMemberViewController.h"
#import "TFSortViewController.h"
#import "TFUpgradeMemberController.h"
#import "TFMemberHeaderView.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFBookStoreComicMaxStyleCell.h"
#import "TFBookStoreComicMiddleStyleCell.h"
#import "TFBookStoreComicNormalStyleCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "TFMemberModel.h"
#import "TFBannerActionManager.h"
@interface TFMemberViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) TFMemberHeaderView *headerView;
@property (nonatomic ,strong) TFMemberModel *monthlyModel;
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFMemberViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
[self netRequest];
}
- (void)initialize
{
self.needRefresh = YES;
[self setNavigationBarTitle:TFLocalizedString(@"会员中心")];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Recharge_Success 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(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT);
}];
WS(weakSelf)
self.headerView = [[TFMemberHeaderView alloc] init];
self.headerView.functionButtonClickBlock = ^(TFPrivilegeModel *privilegeModel) {
if ([privilegeModel.action isEqualToString:@"library"]) {
TFSortViewController *vc = [[TFSortViewController alloc] init];
vc.productionType = weakSelf.productionType;
vc.isMemberStore = YES;
[weakSelf.navigationController pushViewController:vc animated:YES];
} else {
if (!TFUserInfoManager.isLogin) {
[TFLoginOptionsViewController presentLoginView:nil];
return;
}
[weakSelf.navigationController pushViewController:[[TFUpgradeMemberController alloc] init] animated:YES];
}
};
self.headerView.bannerrImageClickBlock = ^(TFBannerModel *bannerModel) {
if ([TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:weakSelf.productionType]) {
[weakSelf.navigationController pushViewController:[TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:weakSelf.productionType] animated:YES];
}
};
[self.mainTableViewGroup setTableHeaderView:self.headerView];
[self setEmptyOnView:self.mainTableViewGroup title:TFLocalizedString(@"暂无数据") tapBlock:^{
}];
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.monthlyModel.label.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreLabelModel *labelModel = [self.monthlyModel.label objectOrNilAtIndex:indexPath.section];
if (labelModel.ad_type == 0) {
if (self.productionType == TFProductionTypeComic) {
switch (labelModel.style) {
case 1:
return [self createMiddleStyleComicCellWithTableView:tableView indexPath:indexPath labelModel:labelModel];
break;
case 2:
return [self createNormalStyleComicCellWithTableView:tableView indexPath:indexPath labelModel:labelModel];
break;
case 3:
return [self createMaxStyleComicCellWithTableView:tableView indexPath:indexPath labelModel:labelModel];
break;
default:
return [self createNormalStyleComicCellWithTableView:tableView indexPath:indexPath labelModel:labelModel];
break;
}
} else {
for (TFProductionModel *t_model in labelModel.list) {
t_model.productionType = self.productionType;
}
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.cellSelectMoreBlock = ^(TFBookStoreLabelModel * _Nonnull labelModel) {
TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init];
vc.productionType = weakSelf.productionType;
vc.recommend_id = [TFUtilsHelper formatStringWithInteger:labelModel.recommend_id];
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
[weakSelf pushToMallDetail:production_id];
};
cell.showTopMoreBtn = labelModel.can_more;
return cell;
}
- (UITableViewCell *)createMaxStyleComicCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
WS(weakSelf)
static NSString *cellName = @"TFBookStoreComicMaxStyleCell";
TFBookStoreComicMaxStyleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFBookStoreComicMaxStyleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.labelModel = labelModel;
cell.showTopMoreButton = labelModel.can_more;
cell.cellSelectMoreBlock = ^(TFBookStoreLabelModel * _Nonnull labelModel) {
TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init];
vc.productionType = weakSelf.productionType;
vc.recommend_id = [TFUtilsHelper formatStringWithInteger:labelModel.recommend_id];
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
[weakSelf pushToMallDetail:production_id];
};
return cell;
}
- (UITableViewCell *)createMiddleStyleComicCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
WS(weakSelf)
static NSString *cellName = @"TFBookStoreComicMiddleStyleCell";
TFBookStoreComicMiddleStyleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFBookStoreComicMiddleStyleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.labelModel = labelModel;
cell.showTopMoreButton = labelModel.can_more;
cell.cellSelectMoreBlock = ^(TFBookStoreLabelModel * _Nonnull labelModel) {
TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init];
vc.productionType = weakSelf.productionType;
vc.recommend_id = [TFUtilsHelper formatStringWithInteger:labelModel.recommend_id];
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
[weakSelf pushToMallDetail:production_id];
};
return cell;
}
- (UITableViewCell *)createNormalStyleComicCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
WS(weakSelf)
static NSString *cellName = @"TFBookStoreComicNormalStyleCell";
TFBookStoreComicNormalStyleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFBookStoreComicNormalStyleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.labelModel = labelModel;
cell.showTopMoreButton = labelModel.can_more;
cell.cellSelectMoreBlock = ^(TFBookStoreLabelModel * _Nonnull labelModel) {
TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init];
vc.productionType = weakSelf.productionType;
vc.recommend_id = [TFUtilsHelper formatStringWithInteger:labelModel.recommend_id];
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
[weakSelf pushToMallDetail:production_id];
};
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;
return cell;
}
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return kHalfMargin;
}
return CGFLOAT_MIN;
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHalfMargin)];
view.backgroundColor = kGrayViewColor;
return view;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == self.monthlyModel.label.count - 1) {
return PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET;
}
return CGFLOAT_MIN;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)pushToMallDetail:(NSInteger)production_id
{
switch (self.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel: {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic: {
TFComicDetailViewController *comicDetail = [[TFComicDetailViewController alloc] init];
comicDetail.comic_id = production_id;
[self.navigationController pushViewController:comicDetail animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio: {
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init];
vc.audio_id = production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
default:
break;
}
}
- (void)netRequest
{
NSString *site_type = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
site_type = @"1";
break;
case TFProductionTypeComic:
site_type = @"2";
break;
case TFProductionTypeAudio:
site_type = @"3";
break;
default:
break;
}
WS(weakSelf)
[TFNetworkTools POST:Member_Monthly parameters:@{@"site_id":site_type} model:TFMemberModel.class success:^(BOOL isSuccess, TFMemberModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
weakSelf.monthlyModel = t_model;
}
weakSelf.headerView.userInfoModel = weakSelf.monthlyModel.user;
weakSelf.headerView.banner = weakSelf.monthlyModel.banner;
weakSelf.headerView.privilege = weakSelf.monthlyModel.privilege;
if (weakSelf.monthlyModel.banner.count > 0) {
weakSelf.emptyView.contentViewY = 350;
} else {
weakSelf.emptyView.contentViewY = 200;
}
[weakSelf.mainTableViewGroup setTableHeaderView:weakSelf.headerView];
[weakSelf.mainTableViewGroup endRefreshing];
weakSelf.needRefresh = YES;
[weakSelf.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
[weakSelf.mainTableViewGroup xtfei_endLoading];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableViewGroup endRefreshing];
[weakSelf.mainTableViewGroup xtfei_endLoading];
}];
}
@end
@@ -0,0 +1,39 @@
//
// TFMemberModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TFUpgradeMemberModel.h"
#import "TFBookStoreLabelModel.h"
NS_ASSUME_NONNULL_BEGIN
@class TFMemberInfoModel;
@interface TFMemberModel : NSObject
@property (nonatomic ,strong) TFMemberInfoModel *user;
@property (nonatomic ,strong) NSArray<TFPrivilegeModel *> *privilege;
@property (nonatomic ,strong) NSArray <TFBannerModel *>*banner;
@property (nonatomic ,strong) NSArray<TFBookStoreLabelModel *> *label;
@end
@interface TFMemberInfoModel : NSObject
// 昵称
@property (nonatomic ,copy) NSString *nickname;
// 头像
@property (nonatomic ,copy) NSString *avatar;
// 包月状态 0未开通包月 1已开通包月
@property (nonatomic ,assign) NSInteger baoyue_status;
// 包月有效期
@property (nonatomic ,copy) NSString *expiry_date;
@property (nonatomic ,copy) NSString *vip_desc;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,26 @@
//
// TFMemberModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFMemberModel.h"
@implementation TFMemberModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{@"privilege" : [TFPrivilegeModel class],
@"banner" : [TFBannerModel class],
@"label" : [TFBookStoreLabelModel class]
};
}
@end
@implementation TFMemberInfoModel
@end
@@ -0,0 +1,25 @@
//
// TFMemberHeaderView.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFMemberModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFMemberHeaderView : UIView
@property (nonatomic ,copy) void (^bannerrImageClickBlock)(TFBannerModel *bannerModel); //banner点击
@property (nonatomic ,copy) void (^functionButtonClickBlock)(TFPrivilegeModel *privilegeModel);
@property (nonatomic ,strong) TFMemberInfoModel *userInfoModel;
@property (nonatomic ,strong) NSArray <TFBannerModel *>*banner;
@property (nonatomic ,strong) NSArray<TFPrivilegeModel *> *privilege;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,279 @@
//
// TFMemberHeaderView.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFMemberHeaderView.h"
#import "TFDiscoverHeaderViewCell.h"
#import "YJBannerView.h"
#define UserView_Height 80
#define Button_Width 70
@interface TFMemberHeaderView ()<YJBannerViewDelegate, YJBannerViewDataSource>
{
UIImageView *userAvatar;
UILabel *userNickname;
UIImageView *vipImageView;
UILabel *noticeLabel;
UIButton *memberButton;
}
@property (nonatomic, strong) YJBannerView *bannerView;
@property (nonatomic, strong) NSMutableArray *bannerImageArr;
@end
@implementation TFMemberHeaderView
- (instancetype)init
{
if (self = [super init]) {
self.backgroundColor = kWhiteColor;
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, UserView_Height + kMoreHalfMargin + kMoreHalfMargin + SCREEN_WIDTH / 5);
self.bannerImageArr = [NSMutableArray array];
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
//banner
[self addSubview:self.bannerView];
userAvatar = [[UIImageView alloc] initWithCornerRadiusAdvance:(UserView_Height - 2 * kHalfMargin) / 2 rectCornerType:UIRectCornerAllCorners];
userAvatar.image = HoldUserAvatar;
[self addSubview:userAvatar];
[userAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.top.mas_equalTo(self.bannerView.mas_bottom).with.offset(kMoreHalfMargin);
make.width.height.mas_equalTo(UserView_Height - 2 * kHalfMargin);
}];
userNickname = [[UILabel alloc] init];
userNickname.backgroundColor = kGrayViewColor;
userNickname.textColor = kBlackColor;
userNickname.font = kMainFont;
userNickname.textAlignment = NSTextAlignmentLeft;
[self addSubview:userNickname];
[userNickname mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(userAvatar.mas_right).with.offset(kHalfMargin);
make.bottom.mas_equalTo(userAvatar.mas_centerY).with.offset(- 3);
make.width.mas_equalTo(10);
make.height.mas_equalTo(20);
}];
vipImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"public_vip_normal"]];
vipImageView.hidden = YES;
[self addSubview:vipImageView];
[vipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(userNickname.mas_right).with.offset(kQuarterMargin);
make.centerY.mas_equalTo(userNickname.mas_centerY);
make.height.mas_equalTo(12);
make.width.mas_equalTo(kGeometricWidth(12, 138, 48));
}];
memberButton = [UIButton buttonWithType:UIButtonTypeCustom];
memberButton.hidden = YES;
memberButton.layer.cornerRadius = 4;
[memberButton.titleLabel setFont:kFont12];
[memberButton setTitle:TFLocalizedString(@"开通") forState:UIControlStateNormal];
[memberButton setTitleColor:kColorRGB(120, 79, 18) forState:UIControlStateNormal];
[memberButton setBackgroundImage:[UIImage imageNamed:@"monthly_member"] forState:UIControlStateNormal];
[memberButton addTarget:self action:@selector(jumpToMember) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:memberButton];
[memberButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(userAvatar.mas_centerY);
make.width.mas_equalTo(kGeometricWidth(30, 210, 80));
make.height.mas_equalTo(30);
}];
noticeLabel = [[UILabel alloc] init];
noticeLabel.backgroundColor = kGrayViewColor;
noticeLabel.textColor = kGrayTextColor;
noticeLabel.font = kFont12;
noticeLabel.textAlignment = NSTextAlignmentLeft;
[self addSubview:noticeLabel];
[noticeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(userNickname.mas_left);
make.top.mas_equalTo(userAvatar.mas_centerY).with.offset(3);
make.right.mas_equalTo(memberButton.mas_left).with.offset(- kHalfMargin);
make.height.mas_equalTo(userNickname.mas_height);
}];
// 横线
UIView *line = [[UIView alloc] init];
line.hidden = NO;
line.backgroundColor = kGrayLineColor;
[self addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.top.mas_equalTo(userAvatar.mas_bottom).with.offset(kMoreHalfMargin);
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
make.height.mas_equalTo(kCellLineHeight);
}];
}
- (void)setUserInfoModel:(TFMemberInfoModel *)userInfoModel
{
_userInfoModel = userInfoModel;
[userAvatar setImageWithURL:[NSURL URLWithString:userInfoModel.avatar?:@""] placeholder:HoldUserAvatar options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
noticeLabel.text = userInfoModel.vip_desc;
if (userInfoModel.nickname.length == 0 || !userInfoModel.nickname) {
userNickname.text = TFLocalizedString(@"未登录");
vipImageView.hidden = YES;
} else {
userNickname.text = userInfoModel.nickname?:@"";
vipImageView.hidden = NO;
if (userInfoModel.baoyue_status == 1) {
noticeLabel.text = userInfoModel.expiry_date.length > 0 ? userInfoModel.expiry_date :userInfoModel.vip_desc;
vipImageView.image = [UIImage imageNamed:@"public_vip_select"];
[memberButton setTitle:TFLocalizedString(@"续费") forState:UIControlStateNormal];
} else {
vipImageView.image = [UIImage imageNamed:@"public_vip_normal"];
[memberButton setTitle:TFLocalizedString(@"开通") forState:UIControlStateNormal];
}
}
userNickname.backgroundColor = [UIColor whiteColor];
[userNickname mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:userNickname]);
}];
noticeLabel.backgroundColor = [UIColor whiteColor];
memberButton.hidden = NO;
}
- (void)setPrivilege:(NSArray<TFPrivilegeModel *> *)privilege
{
if (!_privilege && privilege) {
for (int i = 0; i < privilege.count; i ++) {
TFPrivilegeModel *t_model = [privilege objectAtIndex:i];
TFButton *button = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:t_model.label?:@"" buttonImageName:t_model.icon?:@"" buttonIndicator:TFButtonIndicatorTitleBottom showMaskView:YES];
button.graphicDistance = 0;
button.buttonImageScale = 0.6;
button.buttonTitleFont = kFont13;
[button addTarget:self action:@selector(functionButtonClick:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[self addSubview:button];
CGFloat buttonWidth = SCREEN_WIDTH / privilege.count;
CGFloat buttonHeight = SCREEN_WIDTH / 5;
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(i * buttonWidth);
make.top.mas_equalTo(userAvatar.mas_bottom).with.offset(kMoreHalfMargin * 2);
make.width.mas_equalTo(buttonWidth);
make.height.mas_equalTo(buttonHeight);
}];
}
}
_privilege = privilege;
}
- (void)setBanner:(NSArray<TFBannerModel *> *)banner
{
if (banner) {
_banner = banner;
[_bannerImageArr removeAllObjects];
if (banner.count == 0) {
self.bannerView.frame = CGRectMake(0, kHalfMargin, SCREEN_WIDTH, 0);
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, UserView_Height + kMoreHalfMargin + kMoreHalfMargin + SCREEN_WIDTH / 5);
[userAvatar mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.bannerView.mas_bottom).with.offset(CGFLOAT_MIN);
}];
} else {
self.bannerView.frame = CGRectMake(0, kHalfMargin, SCREEN_WIDTH, SCREEN_WIDTH / 4);
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH / 4 + kMoreHalfMargin + UserView_Height + kMoreHalfMargin + kMoreHalfMargin + SCREEN_WIDTH / 5);
[userAvatar mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.bannerView.mas_bottom).with.offset(kMoreHalfMargin);
}];
for (TFBannerModel *t_model in banner) {
[_bannerImageArr addObject:t_model.image];
}
[self.bannerView reloadData];
}
}
}
- (YJBannerView *)bannerView
{
if (!_bannerView) {
_bannerView = [YJBannerView bannerViewWithFrame:CGRectMake(0, kHalfMargin, SCREEN_WIDTH, SCREEN_WIDTH / 4) dataSource:self delegate:self emptyImage:HoldImage placeholderImage:HoldImage selectorString:NSStringFromSelector(@selector(setImageWithURL:placeholder:))];
_bannerView.pageControlAliment = PageControlAlimentCenter;
_bannerView.repeatCount = 9999;
_bannerView.autoDuration = 5.0f;
_bannerView.pageControlStyle = PageControlCustom;
_bannerView.pageControlDotSize = CGSizeMake(10, 5);
_bannerView.customPageControlHighlightImage = [UIImage imageNamed:@"pageControlS"];
_bannerView.customPageControlNormalImage = [UIImage imageNamed:@"pageControlN"];
}
return _bannerView;
}
- (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)jumpToMember
{
if (self.functionButtonClickBlock) {
self.functionButtonClickBlock([[TFPrivilegeModel alloc] init]);
}
}
- (void)functionButtonClick:(UIButton *)sender
{
if (self.functionButtonClickBlock) {
self.functionButtonClickBlock([self.privilege objectAtIndex:sender.tag]);
}
}
@end
@@ -0,0 +1,20 @@
//
// TFPopularityCommViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFPopularityCommViewController : TFBasicViewController
@property (nonatomic ,copy) NSString *channel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,165 @@
//
// TFPopularityCommViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFPopularityCommViewController.h"
#import "TFPopularityDetailViewController.h"
#import "TFPopularityViewCell.h"
#import "TFPopularityModel.h"
@interface TFPopularityCommViewController ()<UITableViewDelegate, UITableViewDataSource>
@end
@implementation TFPopularityCommViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
[self hiddenNavigationBar:YES];
}
- (void)createSubviews
{
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
[self.view addSubview:self.mainTableView];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.view.mas_top);
make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(- PUB_NAVBAR_HEIGHT - self.pageViewHeight);
make.width.mas_equalTo(self.view.mas_width);
}];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无数据") buttonTitle:@"" tapBlock:^{
}];
WS(weakSelf)
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
[self.mainTableView.mj_header beginRefreshing];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFPopularityViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WXBookRankListTableViewCell"];
if (!cell) {
cell = [[TFPopularityViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WXBookRankListTableViewCell"];
}
if (self.dataSourceArray.count) {
cell.rankListModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
}
cell.productionType = self.productionType;
cell.hiddenEndLine = (indexPath.row == self.dataSourceArray.count - 1);
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
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_TABBAR_OFFSET)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.dataSourceArray && self.dataSourceArray.count > 0) {
TFPopularityModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
TFPopularityDetailViewController *vc = [[TFPopularityDetailViewController alloc] init];
vc.channel = self.channel;
vc.productionType = self.productionType;
vc.rank_type = t_model.rank_type;
vc.navTitle = t_model.list_name?:@"";
[self.navigationController pushViewController:vc animated:YES];
}
}
- (void)netRequest
{
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Rank_List;
break;
case TFProductionTypeComic:
url = Comic_Rank_List;
break;
case TFProductionTypeAudio:
url = Audio_Rank_List;
break;
default:
break;
}
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"channel_id"] = self.channel;
[TFNetworkTools POST:url parameters:params model:nil success:^(BOOL isSuccess, NSDictionary *_Nullable t_model, TFNetworkRequestModel *requestModel) {
[weakSelf.mainTableView endRefreshing];
if (isSuccess) {
NSArray *t_arr = t_model[@"data"];
[weakSelf.dataSourceArray removeAllObjects];
for (NSDictionary *t_dic in t_arr) {
TFPopularityModel *t_model = [TFPopularityModel modelWithDictionary:t_dic];
[weakSelf.dataSourceArray addObject:t_model];
}
}
[weakSelf.mainTableView reloadData];
[weakSelf.mainTableView xtfei_endLoading];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView endRefreshing];
[weakSelf.mainTableView reloadData];
[weakSelf.mainTableView xtfei_endLoading];
}];
}
@end

Some files were not shown because too many files have changed in this diff Show More