小说绘上架版本

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,22 @@
//
// TFNovelDetailViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFNovelDetailViewController : TFBasicViewController
@property (nonatomic ,assign) NSInteger book_id; //书籍id
/// 是不是从阅读器进入
@property (nonatomic ,assign) BOOL isReader;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,905 @@
//
// TFNovelDetailViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFNovelDetailViewController.h"
#import "TFCommentsViewController.h"
#import "TFTaskViewController.h"
#import "TFNovelCatalogueBookmarkController.h"
#import "TFNovelDetailHeaderView.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFCommentsViewCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "TFReadNovelViewController.h"
#import "TFCollectionManager.h"
#import "TFReadRecordManager.h"
#import "WXYZ_BookDownloadManager.h"
#import "TFReaderBookManager.h"
#import "TFNovelDetailModel.h"
#import "TFReaderSettingHelper.h"
#import "TFCatalogModel.h"
#import "TFShareManager.h"
#import "AppDelegate.h"
#import "TFNovelDownloadMenuView.h"
#import "TFDownloadCacheViewController.h"
#import "WXYZ_BookAiPlayPageViewController.h"
@interface TFNovelDetailViewController ()<UITableViewDelegate, UITableViewDataSource
#if TF_Enable_Third_Party_Ad
,BUBannerAdViewDelegate>
#else
>
#endif
@property (nonatomic ,strong) TFNovelDetailModel *bookDetailModel;
@property (nonatomic ,strong) UIView *commentSectionView;
@property (nonatomic ,strong) UIButton *sectionBottomCommentButton;
@property (nonatomic ,weak) UIButton *shareButton;
@property (nonatomic ,strong) UIButton *readBookButton;
@property (nonatomic ,weak) UIButton *addBookRack;
@property (nonatomic ,weak) UIButton *downloadButton;
@property (nonatomic ,strong) NSArray *sectionTagArray;
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFNovelDetailViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenSeparator];
[self setStatusBarLightContentStyle];
self.navigationBar.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0];
self.navigationBar.navTitleLabel.textColor = kBlackColor;
self.navigationBar.navTitleLabel.alpha = 0.0;
[self.navigationBar setLightLeftButton];
#if TF_Enable_Ai
[WXYZ_BookAiPlayPageViewController sharedManager];
#endif
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self changeNavBarColorState:self.mainTableViewGroup.contentOffset.y withAnimate:NO];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToDownload) name:Notification_Push_To_Download object:nil];
if (self.addBookRack) {
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookDetailModel.bookModel]) {
self.addBookRack.enabled = NO;
[self.addBookRack setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[self.addBookRack setTitleColor:kMainColorAlpha(0.5) forState:UIControlStateNormal];
self.addBookRack.userInteractionEnabled = NO;
} else {
self.addBookRack.enabled = YES;
[self.addBookRack setTitle:TFLocalizedString(@"加入书架") forState:UIControlStateNormal];
[self.addBookRack setTitleColor:kMainColor forState:UIControlStateNormal];
[self.addBookRack addTarget:self action:@selector(addBookRackClick:) forControlEvents:UIControlEventTouchUpInside];
self.addBookRack.userInteractionEnabled = YES;
}
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] productionHasReadedWithProduction_id:self.bookDetailModel.bookModel.production_id]) {
[self.readBookButton setTitle:TFLocalizedString(@"继续阅读") forState:UIControlStateNormal];
} else {
[self.readBookButton setTitle:TFLocalizedString(@"开始阅读") forState:UIControlStateNormal];
}
}
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:Notification_Reload_BookDetail object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:Notification_Push_To_Download object:nil];
}
- (void)createSubviews
{
UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.shareButton = shareButton;
shareButton.hidden = YES;
shareButton.adjustsImageWhenHighlighted = NO;
shareButton.tintColor = kWhiteColor;
[shareButton setImage:[[UIImage imageNamed:@"public_share"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[shareButton setImageEdgeInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
[shareButton addTarget:self action:@selector(UMShareClick) forControlEvents:UIControlEventTouchUpInside];
[self.navigationBar addSubview:shareButton];
[shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.navigationBar.mas_right).with.offset(- kHalfMargin);
make.bottom.mas_equalTo(self.navigationBar.mas_bottom).with.offset(- 7);
make.width.height.mas_equalTo(30);
}];
#if TF_Download_Mode
if ([TFUtilsHelper getAiReadSwitchState]) {
UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.downloadButton = downloadButton;
downloadButton.hidden = YES;
downloadButton.adjustsImageWhenHighlighted = NO;
downloadButton.tintColor = kWhiteColor;
[downloadButton setImage:[[UIImage imageNamed:@"public_download"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[downloadButton setImageEdgeInsets:UIEdgeInsetsMake(6, 6, 5.5, 5.5)];
[downloadButton addTarget:self action:@selector(downloadClick) forControlEvents:UIControlEventTouchUpInside];
[self.navigationBar addSubview:downloadButton];
[downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(shareButton.mas_left).with.offset(- kHalfMargin);
make.bottom.mas_equalTo(self.navigationBar.mas_bottom).with.offset(- 7);
make.width.height.mas_equalTo(30);
}];
}
#endif
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);
}];
WS(weakSelf)
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
}
- (void)createToolBar
{
[self.mainTableViewGroup mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_TABBAR_HEIGHT);
}];
UIView *toolBarView = [[UIView alloc] init];
toolBarView.backgroundColor = kGrayViewColor;
[self.view addSubview:toolBarView];
[toolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(self.view.mas_bottom);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT);
}];
// 加入书架
UIButton *addBookRack = [UIButton buttonWithType:UIButtonTypeCustom];
self.addBookRack = addBookRack;
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookDetailModel.bookModel]) {
self.addBookRack.enabled = NO;
[addBookRack setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[addBookRack setTitleColor:kMainColorAlpha(0.5) forState:UIControlStateNormal];
} else {
self.addBookRack.enabled = YES;
[addBookRack setTitle:TFLocalizedString(@"加入书架") forState:UIControlStateNormal];
[addBookRack setTitleColor:kMainColor forState:UIControlStateNormal];
[addBookRack addTarget:self action:@selector(addBookRackClick:) forControlEvents:UIControlEventTouchUpInside];
}
addBookRack.backgroundColor = kGrayViewColor;
[addBookRack.titleLabel setFont:kMainFont];
[addBookRack addBorderLineWithBorderWidth:0.5 borderColor:kGrayViewColor cornerRadius:0 borderType:UIBorderSideTypeRight];
[toolBarView addSubview:addBookRack];
// 开始阅读
self.readBookButton = [UIButton buttonWithType:UIButtonTypeCustom];
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] productionHasReadedWithProduction_id:self.bookDetailModel.bookModel.production_id]) {
[self.readBookButton setTitle:TFLocalizedString(@"继续阅读") forState:UIControlStateNormal];
} else {
[self.readBookButton setTitle:TFLocalizedString(@"开始阅读") forState:UIControlStateNormal];
}
self.readBookButton.backgroundColor = kMainColor;
[self.readBookButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.readBookButton.titleLabel setFont:[UIFont boldSystemFontOfSize:kFontSize13]];
[self.readBookButton addTarget:self action:@selector(readBookClick) forControlEvents:UIControlEventTouchUpInside];
[toolBarView addSubview:self.readBookButton];
// 听书
UIButton *audioButton = [UIButton buttonWithType:UIButtonTypeCustom];
audioButton.backgroundColor = kGrayViewColor;
[audioButton setTitleColor:kMainColor forState:UIControlStateNormal];
[audioButton.titleLabel setFont:kMainFont];
[audioButton addTarget:self action:@selector(audioButtonClick:) forControlEvents:UIControlEventTouchUpInside];
#if TF_Enable_Ai
if ([TFUtilsHelper getAiReadSwitchState]) {
[audioButton setTitle:TFLocalizedString(@"听书详情") forState:UIControlStateNormal];
} else {
[audioButton setTitle:TFLocalizedString(@"下载书籍") forState:UIControlStateNormal];
}
#else
[audioButton setTitle:TFLocalizedString(@"下载书籍") forState:UIControlStateNormal];
#endif
[toolBarView addSubview:audioButton];
NSArray *viewArray = @[audioButton, self.readBookButton, addBookRack];
[viewArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:0 tailSpacing:0];
[viewArray mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.height.mas_equalTo(toolBarView.mas_height).with.offset(- PUB_TABBAR_OFFSET);
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSMutableArray *t_sectionTagArray = [NSMutableArray array];
// 简介
// if (self.bookDetailModel.bookModel.production_descirption.length > 0) {
[t_sectionTagArray addObject:@"descirption"];
// }
// 广告
if (self.bookDetailModel.advert.ad_type != 0) {
[t_sectionTagArray addObject:@"ad"];
}
// 评论
#if TF_Comments_Mode
[t_sectionTagArray addObject:@"comment"];
#endif
// 猜你喜欢
if (self.bookDetailModel.label.firstObject.list.count > 0) {
[t_sectionTagArray addObject:@"label"];
}
if (t_sectionTagArray.count == 0 || t_sectionTagArray.count == 1) {
[t_sectionTagArray addObject:@"descirption"];
}
self.sectionTagArray = [t_sectionTagArray copy];
return t_sectionTagArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"descirption"]) {
return 1;
}
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"ad"]) {
return 1;
}
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
return self.bookDetailModel.comment.count;
}
#endif
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"label"]) {
return self.bookDetailModel.label.count;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"descirption"]) {
return [self createHeaderViewCellWithTableView:tableView indexPath:indexPath];
}
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"ad"]) {
return [self createAdCellWithTableView:tableView indexPath:indexPath];
}
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"comment"]) {
return [self createCommentCellWithTableView:tableView indexPath:indexPath];
}
#endif
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"label"]) {
return [self createCellWithTabelView:tableView indexPath:indexPath];
}
return [[UITableViewCell alloc] init];
}
- (UITableViewCell *)createHeaderViewCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
WS(weakSelf)
static NSString *cellName = @"TFNovelDetailHeaderView";
TFNovelDetailHeaderView *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFNovelDetailHeaderView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.bookModel = self.bookDetailModel.bookModel;
cell.catalogueButtonClickBlock = ^{
if (!weakSelf.bookDetailModel.bookModel) return;
TFNovelCatalogueBookmarkController *vc = [[TFNovelCatalogueBookmarkController alloc] init];
vc.isReader = weakSelf.isReader;
vc.bookModel = weakSelf.bookDetailModel.bookModel;
vc.isBookDetailPush = YES;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
return cell;
}
- (UITableViewCell *)createCellWithTabelView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
TFBookStoreLabelModel *labelModel = [self.bookDetailModel.label objectOrNilAtIndex:indexPath.row];
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 *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = production_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
return cell;
}
- (UITableViewCell *)createCommentCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
static NSString *cellName = @"TFCommentsViewCell";
TFCommentsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFCommentsViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.commentModel = [self.bookDetailModel.comment objectOrNilAtIndex:indexPath.row];
cell.hiddenEndLine = NO;
[cell setIsPreview:YES lastRow:(self.bookDetailModel.comment.count - 1 == indexPath.row)];
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.bookDetailModel.advert refresh:self.needRefresh];
cell.mainTableView = tableView;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"comment"]) {
TFCommentsListModel *t_model = [self.bookDetailModel.comment objectOrNilAtIndex:indexPath.row];
[self commentWithComment_id:t_model.comment_id];
}
#endif
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
#if TF_Comments_Mode
if (!self.bookDetailModel) {
return CGFLOAT_MIN;
}
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
return 54;
}
#endif
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
return self.commentSectionView;
}
#endif
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (UIView *)commentSectionView
{
if (!_commentSectionView) {
_commentSectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 54)];
_commentSectionView.backgroundColor = [UIColor whiteColor];
if (self.bookDetailModel.advert.ad_type == 0) {
UIView *grayLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
grayLine.backgroundColor = kGrayViewColor;
[_commentSectionView addSubview:grayLine];
}
UIImageView *mainTitleHoldView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"book_label_hold"]];
[_commentSectionView addSubview:mainTitleHoldView];
[mainTitleHoldView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.centerY.mas_equalTo(_commentSectionView.mas_centerY).with.offset(5);
make.width.height.mas_equalTo(kHalfMargin + kQuarterMargin);
}];
UILabel *t_title = [[UILabel alloc] init];
t_title.textAlignment = NSTextAlignmentLeft;
t_title.textColor = kBlackColor;
t_title.backgroundColor = [UIColor whiteColor];
t_title.font = kBoldFont16;
t_title.text = TFLocalizedString(@"最新书评");
[t_title addBorderLineWithBorderWidth:0.5 borderColor:kGrayLineColor cornerRadius:0 borderType:UIBorderSideTypeBottom];
[_commentSectionView addSubview:t_title];
[t_title mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_commentSectionView).offset(kMargin + kHalfMargin);
make.top.equalTo(_commentSectionView).offset(kHalfMargin);
make.height.mas_equalTo(44.0);
}];
UIButton *commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
commentButton.backgroundColor = [UIColor whiteColor];
[commentButton setTitle:TFLocalizedString(@"写评论") forState:UIControlStateNormal];
[commentButton setTitleColor:kMainColor forState:UIControlStateNormal];
[commentButton.titleLabel setFont:kFont12];
[commentButton addTarget:self action:@selector(commentClick) forControlEvents:UIControlEventTouchUpInside];
[_commentSectionView addSubview:commentButton];
[commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(t_title.mas_right).offset(kHalfMargin);
make.right.equalTo(_commentSectionView).offset(-kHalfMargin);
make.centerY.equalTo(t_title);
make.height.mas_equalTo(40.0);
}];
}
return _commentSectionView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
#if TF_Comments_Mode
if (!self.bookDetailModel) {
return CGFLOAT_MIN;
}
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
return 50;
}
#endif
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
view.backgroundColor = kWhiteColor;
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
if (self.bookDetailModel) {
if (self.bookDetailModel.bookModel.total_comment == 0) {
[self.sectionBottomCommentButton setTitle:TFLocalizedString(@"暂无评论,点击抢沙发") forState:UIControlStateNormal];
} else {
[self.sectionBottomCommentButton setTitle:[NSString stringWithFormat:@"%@(%@%@)", TFLocalizedString(@"查看全部评论"), [TFUtilsHelper formatStringWithInteger:self.bookDetailModel.bookModel.total_comment], TFLocalizedString(@"")] forState:UIControlStateNormal];
}
[view addSubview:self.sectionBottomCommentButton];
}
}
#endif
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;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pointY = scrollView.contentOffset.y;
[self changeNavBarColorState:pointY withAnimate:YES];
}
- (void)pushToDownload
{
#if TF_Download_Mode
TFDownloadCacheViewController *vc = [[TFDownloadCacheViewController alloc] init];
vc.onlyBookMode = YES;
[self.navigationController pushViewController:vc animated:YES];
#endif
}
- (void)commentClick
{
[self commentWithComment_id:0];
}
- (void)commentWithComment_id:(NSInteger)comment_id
{
WS(weakSelf)
TFCommentsViewController *vc = [[TFCommentsViewController alloc] init];
vc.production_id = self.book_id;
vc.comment_id = comment_id;
vc.productionType = TFProductionTypeNovel;
vc.commentsSuccessBlock = ^(TFCommentsListModel *commentModel) {
TFNovelDetailModel *t_model = weakSelf.bookDetailModel;
// 评论数++
t_model.bookModel.total_comment ++;
// 评论数组model添加
NSMutableArray *t_array = [NSMutableArray arrayWithArray:t_model.comment];
[t_array insertObject:commentModel atIndex:0];
t_model.comment = [t_array copy];
weakSelf.bookDetailModel = t_model;
[weakSelf.mainTableViewGroup reloadData];
};
[self.navigationController pushViewController:vc animated:YES];
}
- (void)audioButtonClick:(UIButton *)sender
{
if ([TFNetworkManager networkingStatus] == NO) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"听书功能仅支持在线使用")];
return;
}
if (self.bookDetailModel.bookModel.chapter_list.count == 0) {
sender.enabled = NO;
[sender setTitleColor:kGrayViewColor forState:UIControlStateNormal];
UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicatorView.frame = CGRectMake(0, 0, 30, 30);
indicatorView.center = sender.center;
[indicatorView startAnimating];
[sender addSubview:indicatorView];
WS(weakSelf)
[TFNetworkTools POST:Book_Catalog parameters:@{@"book_id" : [TFUtilsHelper formatStringWithInteger:self.book_id]} model:TFProductionModel.class success:^(BOOL isSuccess, TFProductionModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
sender.enabled = YES;
[indicatorView removeFromSuperview];
[sender setTitleColor:kMainColor forState:UIControlStateNormal];
if (isSuccess) {
weakSelf.bookDetailModel.bookModel.chapter_list = t_model.chapter_list;
[weakSelf saveCatalog:requestModel.data];
if (t_model.chapter_list.count > 0) {
[weakSelf audioButtonClick:sender];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"书籍获取失败")];
}
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg ?: TFLocalizedString(@"书籍获取失败")];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
sender.enabled = YES;
[indicatorView removeFromSuperview];
[sender setTitleColor:kMainColor forState:UIControlStateNormal];
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"书籍获取失败")];
}];
return;
}
#if TF_Enable_Ai
if ([TFUtilsHelper getAiReadSwitchState]) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Reset_Player_Inof object:nil];
WXYZ_BookAiPlayPageViewController *vc = [WXYZ_BookAiPlayPageViewController sharedManager];
[vc loadDataWithBookModel:self.bookDetailModel.bookModel chapterModel:nil];
for (UIViewController *vc in self.navigationController.viewControllers) {
if ([vc isKindOfClass:[WXYZ_BookAiPlayPageViewController class]]) {
[self popViewController];
return;
}
}
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:vc];
[[TFViewHelper getWindowRootController] presentViewController:nav animated:YES completion:nil];
}
#endif
#if TF_Download_Mode
if (![TFUtilsHelper getAiReadSwitchState]) {
[self downloadClick];
}
#endif
}
- (void)downloadClick
{
if (!self.book_id) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"书籍获取失败")];
return;
}
if (self.bookDetailModel.bookModel.list.count == 0) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"书籍获取失败")];
return;
}
self.downloadButton.enabled = NO;
TFNovelDownloadMenuView *downloadBar = [[TFNovelDownloadMenuView alloc] init];
downloadBar.book_id = [TFUtilsHelper formatStringWithInteger:self.book_id];
downloadBar.chapter_id = [TFUtilsHelper formatStringWithInteger:[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] getReadingRecordChapter_idWithProduction_id:self.book_id]];
WS(weakSelf)
downloadBar.menuBarDidHiddenBlock = ^{
weakSelf.downloadButton.enabled = YES;
};
[kMainWindow addSubview:downloadBar];
[downloadBar showDownloadPayView];
}
- (void)UMShareClick
{
[TFShareManager shareWithProduction_id:NSStringFromInteger(self.bookDetailModel.bookModel.production_id) chapter_id:nil type:TFShareTypeBook];
}
- (void)addBookRackClick:(UIButton *)sender
{
[TFUtilsHelper synchronizationRackProductionWithProduction_id:self.book_id productionType:TFProductionTypeNovel complete:nil];
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] addCollectionWithProductionModel:self.bookDetailModel.bookModel atIndex:0]) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"已加入书架")];
[sender setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[sender setTitleColor:kMainColorAlpha(0.5) forState:UIControlStateNormal];
sender.enabled = NO;
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"添加失败")];
}
}
- (void)readBookClick
{
if (self.isReader) {
[self.navigationController popViewControllerAnimated:YES];
return;
}
if (!self.bookDetailModel.bookModel) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"书籍获取失败")];
return;
}
[TFTaskViewController taskReadRequestWithProduction_id:self.book_id];
// 删除多余的阅读器和书籍详情页
NSArray<UIViewController *> *t_arr = self.navigationController.viewControllers;
NSMutableArray<UIViewController *> *tt_arr = [t_arr mutableCopy];
for (UIViewController *obj in t_arr) {
if ([obj isKindOfClass:TFReadNovelViewController.class] ||
([obj isKindOfClass:TFNovelDetailViewController.class] && obj != self)) {
[tt_arr removeObject:obj];
}
}
if (tt_arr.count != self.navigationController.viewControllers.count) {
self.navigationController.viewControllers = tt_arr;
}
TFReadNovelViewController *vc = [[TFReadNovelViewController alloc] init];
vc.book_id = self.book_id;
// vc.bookModel = self.bookDetailModel.bookModel;
[self.navigationController pushViewController:vc animated:YES];
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] moveCollectionToTopWithProductionModel:self.bookDetailModel.bookModel];
}
- (void)jumpToReader:(NSNotification *)noti
{
if ([noti.object isEqualToString:@"TFNovelDetailViewController"]) {
TFProductionModel *t_model = [noti.userInfo objectForKey:@"bookModel"];
TFReadNovelViewController *vc = [[TFReadNovelViewController alloc] init];
vc.book_id = t_model.production_id;
vc.bookModel = t_model;
[self.navigationController pushViewController:vc animated:YES];
}
}
- (void)netRequest
{
if ([TFNetworkManager networkingStatus] == NO) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"当前无网络连接")];
return;
}
WS(weakSelf)
[TFNetworkTools POST:Book_Mall_Detail parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:self.book_id]} model:TFNovelDetailModel.class success:^(BOOL isSuccess, TFNovelDetailModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.bookDetailModel = t_model;
[weakSelf createToolBar];
[weakSelf requestCatalog];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg ?: TFLocalizedString(@"书籍获取失败")];
}
weakSelf.shareButton.hidden = NO;
#if TF_Download_Mode
weakSelf.downloadButton.hidden = NO;
#endif
[weakSelf.mainTableViewGroup endRefreshing];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"书籍获取失败")];
[weakSelf.mainTableViewGroup endRefreshing];
}];
}
// 获取目录信息
- (void)requestCatalog {
NSInteger chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] getReadingRecordChapter_idWithProduction_id:self.book_id];
NSDictionary *params = @{
@"book_id" : [TFUtilsHelper formatStringWithInteger:self.book_id],
@"chapter_id" : @(chapter_id),
@"scroll_type": @(1), // 1:向下加载;2:向上加载
};
TFCatalogModel * __block catalogModel = nil;
NSDictionary * __block catalogDict = nil;
WS(weakSelf)
[TFNetworkTools POST:Book_New_Catalog parameters:params model:TFCatalogModel.class success:^(BOOL isSuccess, TFCatalogModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
catalogModel = t_model;
weakSelf.bookDetailModel.bookModel.list = t_model.list;
weakSelf.bookDetailModel.bookModel.author_name = t_model.author.author_name;
weakSelf.bookDetailModel.bookModel.author_id = t_model.author.author_id;
weakSelf.bookDetailModel.bookModel.author_note = t_model.author.author_note;
weakSelf.bookDetailModel.bookModel.author_avatar = t_model.author.author_avatar;
// 预下载第一章
if (t_model.list.count > 0) {
[[TFReaderBookManager sharedManager] downloadPrestrainChapterWithProductionModel:weakSelf.bookDetailModel.bookModel production_id:weakSelf.book_id chapter_id:[[t_model.list firstObject].chapter_id integerValue] completionHandler:nil];
}
if (catalogDict) {
NSString *str = [t_model.author modelToJSONString];
NSDictionary *t_dict = [TFUtilsHelper dictionaryWithJsonString:str];
NSMutableDictionary *tt_dict = [NSMutableDictionary dictionaryWithDictionary:catalogDict];
[tt_dict setObject:t_dict forKey:@"author"];
[weakSelf saveCatalog:tt_dict];
}
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg ?: TFLocalizedString(@"书籍获取失败")];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"书籍获取失败")];
}];
[TFNetworkTools POST:Book_Catalog parameters:@{@"book_id" : [TFUtilsHelper formatStringWithInteger:self.book_id]} model:TFProductionModel.class success:^(BOOL isSuccess, TFProductionModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.bookDetailModel.bookModel.chapter_list = t_model.chapter_list;
if (catalogModel) {
NSString *str = [catalogModel.author modelToJSONString];
NSDictionary *t_dict = [TFUtilsHelper dictionaryWithJsonString:str];
NSMutableDictionary *tt_dict = [NSMutableDictionary dictionaryWithDictionary:requestModel.data];
[tt_dict setObject:t_dict forKey:@"author"];
[weakSelf saveCatalog:tt_dict];
} else {
catalogDict = requestModel.data;
}
}
} failure:nil];
}
- (void)setBookDetailModel:(TFNovelDetailModel *)bookDetailModel
{
_bookDetailModel = bookDetailModel;
[self.navigationBar setNavigationBarTitle:bookDetailModel.bookModel.name?:@""];
self.needRefresh = YES;
[self.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
self.needRefresh = NO;
});
}
- (void)changeNavBarColorState:(CGFloat)contentOffsetY withAnimate:(BOOL)animate
{
CGFloat alpha = [TFColorHelper getAlphaWithContentOffsetY:contentOffsetY];
CGFloat rbgColor = [TFColorHelper getColorWithContentOffsetY:contentOffsetY];
self.navigationBar.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:alpha];
self.navigationBar.navTitleLabel.backgroundColor = [UIColor clearColor];
self.navigationBar.navTitleLabel.alpha = alpha;
self.navigationBar.navTitleLabel.textColor = kColorRGBA(rbgColor, rbgColor, rbgColor, 1);
[self.navigationBar setLeftButtonTintColor:kColorRGBA(rbgColor, rbgColor, rbgColor, 1)];
self.shareButton.tintColor = kColorRGBA(rbgColor, rbgColor, rbgColor, 1);
#if TF_Download_Mode
self.downloadButton.tintColor = kColorRGBA(rbgColor, rbgColor, rbgColor, 1);
#endif
if (contentOffsetY > 60) {
[self setStatusBarDefaultStyle];
} else {
[self setStatusBarLightContentStyle];
}
}
/// 保存目录列表到本地
- (void)saveCatalog:(NSDictionary *)catalog {
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
path = [path stringByAppendingPathComponent:[TFUtilsHelper stringToMD5:@"book_catalog"]];
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:@{} error:nil];
}
NSString *catalogName = [NSString stringWithFormat:@"%zd_%@", self.book_id, @"catalog"];
NSString *fullPath = [path stringByAppendingFormat:@"/%@.plist", [TFUtilsHelper stringToMD5:catalogName]];
[catalog writeToFile:fullPath atomically:YES];
}
@end
@@ -0,0 +1,23 @@
//
// TFNovelDetailModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFCommentsListModel, TFTagModel, TFProductionModel, TFProductionModel, TFBookStoreLabelModel;
@interface TFNovelDetailModel : NSObject
@property (nonatomic ,strong) NSArray <TFCommentsListModel *> *comment; // 作品评论列表
@property (nonatomic ,strong) NSArray <TFBookStoreLabelModel *> *label; // 推荐作品label
@property (nonatomic ,strong) TFProductionModel *bookModel; // 作品基本信息
@property (nonatomic ,strong) TFAdvertModel *advert; // 广告
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,29 @@
//
// TFNovelDetailModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFNovelDetailModel.h"
#import "TFBookStoreLabelModel.h"
@implementation TFNovelDetailModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{
@"label" : [TFBookStoreLabelModel class],
@"comment" : [TFCommentsListModel class],
@"advert" : [TFAdvertModel class]
};
}
+ (NSDictionary *)modelCustomPropertyMapper
{
return @{
@"bookModel" : @"book"
};
}
@end
@@ -0,0 +1,22 @@
//
// TFNovelDetailHeaderView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef void(^CatalogueButtonClickBlock)(void);
@interface TFNovelDetailHeaderView : TFBasicTableViewCell
@property (nonatomic ,strong) TFProductionModel *bookModel;
@property (nonatomic ,copy) CatalogueButtonClickBlock catalogueButtonClickBlock;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,338 @@
//
// TFNovelDetailHeaderView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFNovelDetailHeaderView.h"
#import "TFTagboardView.h"
#import "UIImage+Blur.h"
@interface TFNovelDetailHeaderView ()
{
TFProductionCoverView *bookImageView;
UILabel *bookNameLabel;
UILabel *authorLabel;
UILabel *introductionLabel;
UILabel *commontNumLabel;
UILabel *collecitonNumLabel;
UILabel *bookDescriptionLabel;
UILabel *timeLabel;
UIButton *catalogueButton;
UILabel *catalogueDetailLabel;
TFTagboardView *tagView;
}
@property (nonatomic, strong) UIImageView __block *headBackImageView;
@end
@implementation TFNovelDetailHeaderView
- (void)createSubviews
{
[super createSubviews];
// 背景图
_headBackImageView = [[UIImageView alloc] init];
_headBackImageView.backgroundColor = [UIColor whiteColor];
_headBackImageView.contentMode = UIViewContentModeScaleAspectFill;
_headBackImageView.clipsToBounds = YES;
_headBackImageView.image = HoldImage;
[self.contentView addSubview:_headBackImageView];
[_headBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left);
make.top.mas_equalTo(self.contentView.mas_top);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(SCREEN_WIDTH / 2 + PUB_NAVBAR_OFFSET + kMargin);
}];
// 书籍图片
bookImageView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical];
bookImageView.userInteractionEnabled = YES;
[self.contentView addSubview:bookImageView];
[bookImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.bottom.mas_equalTo(_headBackImageView.mas_bottom).with.offset(kMargin);
make.width.mas_equalTo(BOOK_WIDTH);
make.height.mas_equalTo(BOOK_HEIGHT);
}];
// 书名
bookNameLabel = [[UILabel alloc] init];
bookNameLabel.textAlignment = NSTextAlignmentLeft;
bookNameLabel.textColor = [UIColor whiteColor];
bookNameLabel.backgroundColor = [UIColor clearColor];
bookNameLabel.font = kBoldFont16;
[self.contentView addSubview:bookNameLabel];
[bookNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookImageView.mas_right).with.offset(kMargin);
make.top.mas_equalTo(bookImageView.mas_top);
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
make.height.mas_equalTo(kLabelHeight);
}];
// 作者
authorLabel = [[UILabel alloc] init];
authorLabel.backgroundColor = [UIColor clearColor];
authorLabel.textColor = [UIColor whiteColor];
authorLabel.textAlignment = NSTextAlignmentLeft;
authorLabel.font = kFont12;
[self.contentView addSubview:authorLabel];
[authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookNameLabel.mas_left);
make.top.mas_equalTo(bookNameLabel.mas_bottom).with.offset(5);
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5);
make.height.mas_equalTo(17);
}];
// 书籍标签
introductionLabel = [[UILabel alloc] init];
introductionLabel.backgroundColor = [UIColor clearColor];
introductionLabel.textColor = [UIColor whiteColor];
introductionLabel.textAlignment = NSTextAlignmentLeft;
introductionLabel.font = kFont12;
[self.contentView addSubview:introductionLabel];
[introductionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookNameLabel.mas_left);
make.top.mas_equalTo(authorLabel.mas_bottom).with.offset(5);
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5);
make.height.mas_equalTo(authorLabel.mas_height);
}];
// 评价数
commontNumLabel = [[UILabel alloc] init];
commontNumLabel.backgroundColor = [UIColor clearColor];
commontNumLabel.textColor = [UIColor whiteColor];
commontNumLabel.textAlignment = NSTextAlignmentLeft;
commontNumLabel.font = kFont12;
[self.contentView addSubview:commontNumLabel];
[commontNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookNameLabel.mas_left);
make.top.mas_equalTo(introductionLabel.mas_bottom).with.offset(kQuarterMargin);
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5);
make.height.mas_equalTo(authorLabel.mas_height);
}];
collecitonNumLabel = [[UILabel alloc] init];
collecitonNumLabel.backgroundColor = [UIColor clearColor];
collecitonNumLabel.textColor = [UIColor whiteColor];
collecitonNumLabel.textAlignment = NSTextAlignmentLeft;
collecitonNumLabel.font = kFont12;
[self.contentView addSubview:collecitonNumLabel];
[collecitonNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookNameLabel.mas_left);
make.top.mas_equalTo(commontNumLabel.mas_bottom).with.offset(kQuarterMargin);
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5);
make.height.mas_equalTo(authorLabel.mas_height);
}];
// 简介
bookDescriptionLabel = [[UILabel alloc] init];
bookDescriptionLabel.backgroundColor = [UIColor whiteColor];
bookDescriptionLabel.textColor = kBlackColor;
bookDescriptionLabel.textAlignment = NSTextAlignmentLeft;
bookDescriptionLabel.font = kMainFont;
bookDescriptionLabel.numberOfLines = 0;
[self.contentView addSubview:bookDescriptionLabel];
[bookDescriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(bookImageView.mas_bottom).with.offset(kHalfMargin);
make.width.mas_equalTo(self.mas_width).with.offset(- 2 * kMargin);
make.height.mas_equalTo(50);
}];
// 目录列
catalogueButton = [UIButton buttonWithType:UIButtonTypeCustom];
catalogueButton.backgroundColor = [UIColor clearColor];
catalogueButton.hidden = YES;
[catalogueButton addTarget:self action:@selector(catalogueClick) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:catalogueButton];
[catalogueButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(bookDescriptionLabel.mas_bottom).with.offset(kHalfMargin);
make.width.mas_equalTo(self.contentView.mas_width);
make.height.mas_equalTo(kLabelHeight + kHalfMargin);
}];
UIImageView *catalogueIcon = [[UIImageView alloc] init];
catalogueIcon.image = [UIImage imageNamed:@"book_directory"];
catalogueIcon.userInteractionEnabled = YES;
[catalogueButton addSubview:catalogueIcon];
[catalogueIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.centerY.mas_equalTo(catalogueButton.mas_centerY);
make.height.mas_equalTo(kMargin);
make.width.mas_equalTo(kMargin);
}];
UILabel *catalogueTitle = [[UILabel alloc] init];
catalogueTitle.text = TFLocalizedString(@"目录");
catalogueTitle.font = kMainFont;
catalogueTitle.textColor = kBlackColor;
catalogueTitle.textAlignment = NSTextAlignmentLeft;
[catalogueButton addSubview:catalogueTitle];
[catalogueTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(catalogueIcon.mas_right).with.offset(5);
make.centerY.mas_equalTo(catalogueIcon.mas_centerY);
make.width.mas_equalTo(catalogueTitle.intrinsicContentSize.width);
make.height.mas_equalTo(catalogueIcon.mas_height);
}];
// 横线
for (int i = 0; i < 2; i ++) {
UIView *cellLine = [[UIView alloc] init];
cellLine.hidden = NO;
cellLine.backgroundColor = kGrayLineColor;
[catalogueButton addSubview:cellLine];
[cellLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
if (i == 0) {
make.top.mas_equalTo(kCellLineHeight);
} else {
make.bottom.mas_equalTo(catalogueButton.mas_bottom).with.offset(- kCellLineHeight);
}
make.width.mas_equalTo(self.mas_width).with.offset( - kMargin);
make.height.mas_equalTo(kCellLineHeight);
}];
}
UIImageView *connerImageView = [[UIImageView alloc] init];
connerImageView.image = [[UIImage imageNamed:@"public_more"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
connerImageView.userInteractionEnabled = YES;
connerImageView.tintColor = kGrayTextColor;
[catalogueButton addSubview:connerImageView];
[connerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(catalogueButton.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(catalogueButton.mas_centerY);
make.width.height.mas_equalTo(10);
}];
timeLabel = [[UILabel alloc] init];
timeLabel.textAlignment = NSTextAlignmentRight;
timeLabel.font = kFont10;
timeLabel.textColor = kGrayTextColor;
[catalogueButton addSubview:timeLabel];
[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(connerImageView.mas_left).with.offset(- kQuarterMargin);
make.top.mas_equalTo(0);
make.width.mas_equalTo(CGFLOAT_MIN);
make.height.mas_equalTo(catalogueButton.mas_height);
}];
catalogueDetailLabel = [[UILabel alloc] init];
catalogueDetailLabel.backgroundColor = [UIColor clearColor];
catalogueDetailLabel.textAlignment = NSTextAlignmentLeft;
catalogueDetailLabel.font = kFont12;
catalogueDetailLabel.textColor = kGrayTextColor;
[catalogueButton addSubview:catalogueDetailLabel];
[catalogueDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(catalogueTitle.mas_right).offset(kQuarterMargin);
make.top.mas_equalTo(0);
make.right.mas_equalTo(timeLabel.mas_left).with.offset(- kQuarterMargin);
make.height.mas_equalTo(catalogueButton.mas_height);
}];
// 标签
tagView = [[TFTagboardView alloc] init];
tagView.textAlignment = TFTagboardTextAlignmentLeft;
tagView.borderStyle = TFTagboardBorderStyleFill;
tagView.layoutStyle = TFTagboardLayoutStyleScroll;
[self.contentView addSubview:tagView];
[tagView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(catalogueButton.mas_bottom).with.offset(kHalfMargin);
make.width.mas_equalTo(self.contentView.mas_width).with.offset(- 2 * kMargin);
make.height.mas_equalTo(20);
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kHalfMargin).priorityLow();
}];
}
- (void)catalogueClick
{
if (self.catalogueButtonClickBlock) {
self.catalogueButtonClickBlock();
}
}
- (void)setBookModel:(TFProductionModel *)bookModel
{
if (bookModel && (_bookModel != bookModel)) {
_bookModel = bookModel;
WS(weakSelf)
[[YYWebImageManager sharedManager] requestImageWithURL:[NSURL URLWithString:bookModel.cover?:@""] options:YYWebImageOptionSetImageWithFadeAnimation progress:nil transform:nil completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.headBackImageView.image = [image imgWithLightAlpha:0.4 radius:3 colorSaturationFactor:1.8];
});
}];
bookImageView.coverImageUrl = bookModel.cover;
bookNameLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.name?:@""];
authorLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.author?:@""];
[introductionLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookNameLabel.mas_left);
make.top.mas_equalTo(authorLabel.mas_bottom).with.offset(5);
make.width.mas_equalTo(bookNameLabel.mas_width);
make.height.mas_equalTo(authorLabel.mas_height);
}];
commontNumLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.hot_num?:@""];
collecitonNumLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.total_favors?:@""];
// 截取简介
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:bookModel.production_descirption?:@""];
attributedString.lineSpacing = 5;
attributedString.font = kFont(13);
attributedString.color = kBlackColor;
NSAttributedString *separatedString = [TFViewHelper getSubContentWithOriginalContent:attributedString labelWidth:(SCREEN_WIDTH - 2 * (kMargin + kHalfMargin)) labelMaxLine:4];
bookDescriptionLabel.attributedText = separatedString;
if (separatedString.length == 0) {
[bookDescriptionLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(0.0);
}];
} else {
[bookDescriptionLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo([TFViewHelper boundsWithFont:kFont(13) attributedText:separatedString needWidth:(SCREEN_WIDTH - 2 * (kMargin + kHalfMargin)) lineSpacing:6] + kHalfMargin);
}];
}
tagView.tagboardArray = bookModel.tag;
timeLabel.text = bookModel.last_chapter_time?:@"";
[timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:timeLabel]);
}];
catalogueDetailLabel.text = bookModel.last_chapter?:@"";
catalogueButton.hidden = NO;
}
}
@end