You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

906 lines
37 KiB

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