小说绘上架版本
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// TFComicDetailLeftViewController.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/19.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TFComicDetailModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef void(^PushToComicDetailBlock)(NSInteger production_id);
|
||||
|
||||
@interface TFComicDetailLeftViewController : TFBasicViewController
|
||||
|
||||
@property (nonatomic ,assign) BOOL canScroll;
|
||||
@property (nonatomic ,strong) TFComicDetailModel *detailModel;
|
||||
@property (nonatomic ,copy) PushToComicDetailBlock pushToComicDetailBlock;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+341
@@ -0,0 +1,341 @@
|
||||
//
|
||||
// TFComicDetailLeftViewController.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/19.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFComicDetailLeftViewController.h"
|
||||
#import "TFCommentsViewController.h"
|
||||
|
||||
#import "TFComicDetailIntroductionCell.h"
|
||||
#import "TFCommentsViewCell.h"
|
||||
#import "TFBookStoreComicNormalStyleCell.h"
|
||||
#import "TFPublicAdvertisementViewCell.h"
|
||||
|
||||
@interface TFComicDetailLeftViewController ()<UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
@property (nonatomic ,strong) UIButton *sectionBottomCommentButton;
|
||||
|
||||
@property (nonatomic ,strong) NSArray *sectionTagArray;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFComicDetailLeftViewController
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
[self initialize];
|
||||
[self createSubviews];
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
[self hiddenNavigationBar:YES];
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
self.mainTableViewGroup.delegate = self;
|
||||
self.mainTableViewGroup.dataSource = self;
|
||||
[self.view addSubview:self.mainTableViewGroup];
|
||||
|
||||
[self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self.view);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||
|
||||
if (!self.canScroll) {
|
||||
scrollView.contentOffset = CGPointZero;
|
||||
}
|
||||
if (scrollView.contentOffset.y <= 0) {
|
||||
self.canScroll = NO;
|
||||
scrollView.contentOffset = CGPointZero;
|
||||
//到顶通知父视图改变状态
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Can_Leave_Top object:@YES];
|
||||
} else {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Can_Leave_Top object:@NO];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||
{
|
||||
NSMutableArray *t_sectionTagArray = [NSMutableArray array];
|
||||
// 简介
|
||||
if (self.detailModel.productionModel.production_descirption.length > 0) {
|
||||
[t_sectionTagArray addObject:@"descirption"];
|
||||
}
|
||||
|
||||
// 广告
|
||||
if (self.detailModel.advert.ad_type != 0) {
|
||||
[t_sectionTagArray addObject:@"ad"];
|
||||
}
|
||||
|
||||
// 评论
|
||||
#if TF_Comments_Mode
|
||||
[t_sectionTagArray addObject:@"comment"];
|
||||
#endif
|
||||
|
||||
// 猜你喜欢
|
||||
if (self.detailModel.label.count > 0) {
|
||||
[t_sectionTagArray addObject:@"label"];
|
||||
}
|
||||
|
||||
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.detailModel.comment.count;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"label"]) {
|
||||
return self.detailModel.label.count;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"descirption"]) {
|
||||
return [self createIntroductionStyleCellWithTableView:tableView indexPath:indexPath labelModel:self.detailModel.productionModel];
|
||||
}
|
||||
|
||||
|
||||
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"]) {
|
||||
TFCommentsListModel *commentModel = [self.detailModel.comment objectOrNilAtIndex:indexPath.row];
|
||||
return [self createCommentCellWithTableView:tableView indexPath:indexPath labelModel:commentModel];
|
||||
}
|
||||
#endif
|
||||
|
||||
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"label"]) {
|
||||
TFBookStoreLabelModel *labelModel = [self.detailModel.label objectOrNilAtIndex:indexPath.row];
|
||||
return [self createNormalStyleComicCellWithTableView:tableView indexPath:indexPath labelModel:labelModel];
|
||||
}
|
||||
|
||||
return [[UITableViewCell alloc] init];
|
||||
}
|
||||
|
||||
- (UITableViewCell *)createIntroductionStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFProductionModel *)comicModel
|
||||
{
|
||||
static NSString *cellName = @"TFComicDetailIntroductionCell";
|
||||
TFComicDetailIntroductionCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
|
||||
if (!cell) {
|
||||
cell = [[TFComicDetailIntroductionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
|
||||
}
|
||||
cell.comicModel = comicModel;
|
||||
|
||||
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.cellDidSelectItemBlock = ^(NSInteger production_id) {
|
||||
if (weakSelf.pushToComicDetailBlock) {
|
||||
weakSelf.pushToComicDetailBlock(production_id);
|
||||
}
|
||||
};
|
||||
|
||||
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.detailModel.comment.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.detailModel.advert refresh:NO];
|
||||
cell.mainTableView = tableView;
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
//section头部间距
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
#if TF_Comments_Mode
|
||||
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
|
||||
return 54;
|
||||
}
|
||||
#endif
|
||||
|
||||
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 = kWhiteColor;
|
||||
|
||||
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
|
||||
view.frame = CGRectMake(0, 0, SCREEN_WIDTH, 54);
|
||||
|
||||
if (self.detailModel.advert.ad_type == 0) {
|
||||
UIView *grayLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
|
||||
grayLine.backgroundColor = kGrayViewColor;
|
||||
[view addSubview:grayLine];
|
||||
}
|
||||
|
||||
UIImageView *mainTitleHoldView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"comic_label_hold"]];
|
||||
mainTitleHoldView.frame = CGRectMake(kHalfMargin, 10 + 22 - kMargin / 2, kMargin, kMargin);
|
||||
[view addSubview:mainTitleHoldView];
|
||||
|
||||
UILabel *t_title = [[UILabel alloc] initWithFrame:CGRectMake(kMargin + kHalfMargin + kQuarterMargin, 10, SCREEN_WIDTH - kMargin, 44)];
|
||||
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];
|
||||
[view addSubview:t_title];
|
||||
|
||||
UIButton *commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont12 labelHeight:43.0 labelText:TFLocalizedString(@"写评论") maxWidth:SCREEN_WIDTH / 2.0 - kMargin];
|
||||
commentButton.frame = CGRectMake(SCREEN_WIDTH - width - kHalfMargin, 10, width, 43);
|
||||
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];
|
||||
[view addSubview:commentButton];
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
//section底部间距
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
||||
{
|
||||
#if TF_Comments_Mode
|
||||
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
|
||||
return 64;
|
||||
}
|
||||
#endif
|
||||
return CGFLOAT_MIN;
|
||||
}
|
||||
|
||||
//section底部视图
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
|
||||
view.backgroundColor = kWhiteColor;
|
||||
|
||||
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
|
||||
if (self.detailModel.productionModel.total_comment == 0) {
|
||||
[self.sectionBottomCommentButton setTitle:TFLocalizedString(@"暂无评论,点击抢沙发") forState:UIControlStateNormal];
|
||||
} else {
|
||||
[self.sectionBottomCommentButton setTitle:[NSString stringWithFormat:@"%@(%@%@)", TFLocalizedString(@"查看全部评论"), [TFUtilsHelper formatStringWithInteger:self.detailModel.productionModel.total_comment], TFLocalizedString(@"条")] forState:UIControlStateNormal];
|
||||
|
||||
}
|
||||
|
||||
[view addSubview:self.sectionBottomCommentButton];
|
||||
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.sectionBottomCommentButton.frame) + kHalfMargin, SCREEN_WIDTH, 10)];
|
||||
lineView.backgroundColor = kGrayViewColor;
|
||||
[view addSubview:lineView];
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"comment"]) {
|
||||
[self commentWithComment_id:[[self.detailModel.comment objectOrNilAtIndex:indexPath.row] comment_id]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)commentClick
|
||||
{
|
||||
[self commentWithComment_id:0];
|
||||
}
|
||||
|
||||
- (void)commentWithComment_id:(NSInteger)comment_id
|
||||
{
|
||||
WS(weakSelf)
|
||||
TFCommentsViewController *vc = [[TFCommentsViewController alloc] init];
|
||||
vc.production_id = self.detailModel.productionModel.production_id;
|
||||
vc.comment_id = comment_id;
|
||||
vc.productionType = TFProductionTypeComic;
|
||||
vc.commentsSuccessBlock = ^(TFCommentsListModel *commentModel) {
|
||||
NSMutableArray *array = [weakSelf.detailModel.comment mutableCopy];
|
||||
[array insertObject:commentModel atIndex:0];
|
||||
weakSelf.detailModel.comment = [array copy];
|
||||
weakSelf.detailModel.productionModel.total_comment ++;
|
||||
[weakSelf.mainTableViewGroup reloadData];
|
||||
};
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
}
|
||||
|
||||
|
||||
- (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)setDetailModel:(TFComicDetailModel *)detailModel
|
||||
{
|
||||
_detailModel = detailModel;
|
||||
[self.mainTableViewGroup reloadData];
|
||||
}
|
||||
|
||||
@end
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// TFComicDetailRightViewController.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
|
||||
|
||||
@interface TFComicDetailRightViewController : TFBasicViewController
|
||||
|
||||
@property (nonatomic ,assign) BOOL canScroll;
|
||||
@property (nonatomic ,assign) CGFloat contentOffSetY;
|
||||
@property (nonatomic ,strong) TFProductionModel *comicModel;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+342
@@ -0,0 +1,342 @@
|
||||
//
|
||||
// TFComicDetailRightViewController.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/19.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFComicDetailRightViewController.h"
|
||||
#import "TFComicDetailRightViewCell.h"
|
||||
#import "TFComicBrowseViewController.h"
|
||||
#import "TFReadRecordManager.h"
|
||||
|
||||
#define MenuButtonHeight 50
|
||||
|
||||
@interface TFComicDetailRightViewController ()<UITableViewDelegate, UITableViewDataSource>
|
||||
{
|
||||
TFButton *gotoCurrent;
|
||||
TFButton *gotoEnd;
|
||||
|
||||
CGFloat beginOffSetY;
|
||||
|
||||
BOOL clickGotoButton;
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) UILabel *headTitleLabel;
|
||||
@property (nonatomic, strong) TFButton *sortButton;
|
||||
/// 已阅读章节索引
|
||||
@property (nonatomic, assign) NSInteger readIndex;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFComicDetailRightViewController
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[self.mainTableView reloadData];
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
[self initialize];
|
||||
[self createSubviews];
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
// 计算已读章节的位置
|
||||
NSInteger readIndex = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:self.comicModel.production_id];
|
||||
NSArray<NSNumber *> *t_arr = [self.comicModel.chapter_list valueForKeyPath:@"chapter_id"];
|
||||
self.readIndex = [t_arr indexOfObject:@(readIndex)];
|
||||
if (self.readIndex == NSNotFound) {
|
||||
self.readIndex = -1;
|
||||
}
|
||||
[self hiddenNavigationBar:YES];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadRecordData) name:NSNotification_Updata_Read_Record object:nil];
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
self.mainTableView.delegate = self;
|
||||
self.mainTableView.dataSource = self;
|
||||
[self.view addSubview:self.mainTableView];
|
||||
|
||||
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self.view);
|
||||
}];
|
||||
|
||||
gotoCurrent = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - MenuButtonHeight - kHalfMargin, SCREEN_HEIGHT - Comic_Detail_HeaderView_Height - PUB_TABBAR_HEIGHT - 44 - 44 - MenuButtonHeight - kMargin - kHalfMargin, MenuButtonHeight, MenuButtonHeight) buttonTitle:TFLocalizedString(@"当前") buttonImageName:@"comic_goto_current" buttonIndicator:TFButtonIndicatorTitleBottom];
|
||||
gotoCurrent.layer.cornerRadius = 25;
|
||||
gotoCurrent.layer.borderWidth = 1;
|
||||
gotoCurrent.layer.borderColor = kGrayViewColor.CGColor;
|
||||
gotoCurrent.clipsToBounds = YES;
|
||||
gotoCurrent.backgroundColor = kWhiteColor;
|
||||
gotoCurrent.buttonMargin = 8;
|
||||
gotoCurrent.buttonTitleFont = kFont10;
|
||||
gotoCurrent.graphicDistance = 0;
|
||||
gotoCurrent.buttonImageScale = 0.4;
|
||||
[gotoCurrent addTarget:self action:@selector(gotoCurrentClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:gotoCurrent];
|
||||
|
||||
gotoEnd = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - MenuButtonHeight - kHalfMargin, SCREEN_HEIGHT - Comic_Detail_HeaderView_Height - PUB_TABBAR_HEIGHT - 44 - 44 - kMargin, MenuButtonHeight, MenuButtonHeight) buttonTitle:TFLocalizedString(@"到底") buttonImageName:@"comic_goto_bottom" buttonIndicator:TFButtonIndicatorTitleBottom];
|
||||
gotoEnd.layer.cornerRadius = 25;
|
||||
gotoEnd.layer.borderWidth = 1;
|
||||
gotoEnd.layer.borderColor = kGrayViewColor.CGColor;
|
||||
gotoEnd.clipsToBounds = YES;
|
||||
gotoEnd.tag = 0;
|
||||
gotoEnd.backgroundColor = kWhiteColor;
|
||||
gotoEnd.buttonMargin = 8;
|
||||
gotoEnd.buttonTitleFont = kFont10;
|
||||
gotoEnd.graphicDistance = 0;
|
||||
gotoEnd.buttonImageScale = 0.4;
|
||||
[gotoEnd addTarget:self action:@selector(gotoEndClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:gotoEnd];
|
||||
|
||||
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无目录列表") buttonTitle:@"" tapBlock:^{}];
|
||||
if (self.comicModel.chapter_list.count == 0) {
|
||||
gotoCurrent.hidden = YES;
|
||||
gotoEnd.hidden = YES;
|
||||
self.sortButton.hidden = YES;
|
||||
self.headTitleLabel.hidden = YES;
|
||||
} else {
|
||||
gotoCurrent.hidden = NO;
|
||||
gotoEnd.hidden = NO;
|
||||
self.sortButton.hidden = NO;
|
||||
self.headTitleLabel.hidden = NO;
|
||||
}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.mainTableView xtfei_endLoading];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
|
||||
{
|
||||
beginOffSetY = scrollView.contentOffset.y;
|
||||
clickGotoButton = NO;
|
||||
}
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
||||
{
|
||||
if (!clickGotoButton) {
|
||||
if ([scrollView isEqual:self.mainTableView]) {
|
||||
if (!self.canScroll) {
|
||||
scrollView.contentOffset = CGPointZero;
|
||||
}
|
||||
if (scrollView.contentOffset.y <= 0) {
|
||||
self.canScroll = NO;
|
||||
scrollView.contentOffset = CGPointZero;
|
||||
//到顶通知父视图改变状态
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Can_Leave_Top object:@YES];
|
||||
} else {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Can_Leave_Top object:@NO];
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollView.contentOffset.y > beginOffSetY) {
|
||||
gotoEnd.buttonImageName = @"comic_goto_bottom";
|
||||
gotoEnd.buttonTitle = TFLocalizedString(@"到底");
|
||||
gotoEnd.tag = 0;
|
||||
} else if (scrollView.contentOffset.y < beginOffSetY) {
|
||||
gotoEnd.buttonImageName = @"comic_goto_top";
|
||||
gotoEnd.buttonTitle = TFLocalizedString(@"到顶");
|
||||
gotoEnd.tag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
||||
if (scrollView.contentSize.height - scrollView.contentOffset.y <= CGRectGetHeight(scrollView.bounds)) {// 滑到了底部
|
||||
gotoEnd.buttonImageName = @"comic_goto_top";
|
||||
gotoEnd.buttonTitle = TFLocalizedString(@"到顶");
|
||||
gotoEnd.tag = 1;
|
||||
} else if (scrollView.contentOffset.y == 0) {// 滑到了顶部
|
||||
gotoEnd.buttonImageName = @"comic_goto_bottom";
|
||||
gotoEnd.buttonTitle = TFLocalizedString(@"到底");
|
||||
gotoEnd.tag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
|
||||
if (!decelerate) {
|
||||
if (scrollView.contentSize.height - scrollView.contentOffset.y <= CGRectGetHeight(scrollView.bounds)) {// 滑到了底部
|
||||
gotoEnd.buttonImageName = @"comic_goto_top";
|
||||
gotoEnd.buttonTitle = TFLocalizedString(@"到顶");
|
||||
gotoEnd.tag = 1;
|
||||
} else if (scrollView.contentOffset.y == 0) {// 滑到了顶部
|
||||
gotoEnd.buttonImageName = @"comic_goto_bottom";
|
||||
gotoEnd.buttonTitle = TFLocalizedString(@"到底");
|
||||
gotoEnd.tag = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
|
||||
if (scrollView.contentSize.height - scrollView.contentOffset.y <= CGRectGetHeight(scrollView.bounds)) {// 滑到了底部
|
||||
gotoEnd.buttonImageName = @"comic_goto_top";
|
||||
gotoEnd.buttonTitle = TFLocalizedString(@"到顶");
|
||||
gotoEnd.tag = 1;
|
||||
} else if (scrollView.contentOffset.y == 0) {// 滑到了顶部
|
||||
gotoEnd.buttonImageName = @"comic_goto_bottom";
|
||||
gotoEnd.buttonTitle = TFLocalizedString(@"到底");
|
||||
gotoEnd.tag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setContentOffSetY:(CGFloat)contentOffSetY
|
||||
{
|
||||
gotoCurrent.frame = CGRectMake(SCREEN_WIDTH - MenuButtonHeight - kHalfMargin, SCREEN_HEIGHT - Comic_Detail_HeaderView_Height - PUB_TABBAR_HEIGHT - 44 - 44 - MenuButtonHeight - kMargin - kHalfMargin + contentOffSetY, MenuButtonHeight, MenuButtonHeight);
|
||||
gotoEnd.frame = CGRectMake(SCREEN_WIDTH - MenuButtonHeight - kHalfMargin, SCREEN_HEIGHT - Comic_Detail_HeaderView_Height - PUB_TABBAR_HEIGHT - 44 - 44 - kMargin + contentOffSetY, MenuButtonHeight, MenuButtonHeight);
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return self.comicModel.chapter_list.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TFProductionChapterModel *t_chapterList = [self.comicModel.chapter_list objectOrNilAtIndex:indexPath.row];
|
||||
TFComicDetailRightViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFComicDetailRightViewCell"];
|
||||
|
||||
if (!cell) {
|
||||
cell = [[TFComicDetailRightViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFComicDetailRightViewCell"];
|
||||
}
|
||||
cell.chapterModel = t_chapterList;
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
return 44;
|
||||
}
|
||||
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
|
||||
view.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
[view addSubview:self.headTitleLabel];
|
||||
|
||||
[view addSubview:self.sortButton];
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
self.readIndex = indexPath.row;
|
||||
TFProductionChapterModel *t_chapterModel = [self.comicModel.chapter_list objectOrNilAtIndex:indexPath.row];
|
||||
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] addReadingRecordWithProduction_id:t_chapterModel.production_id chapter_id:t_chapterModel.chapter_id chapterTitle:t_chapterModel.chapter_title];
|
||||
|
||||
TFComicBrowseViewController *vc = [[TFComicBrowseViewController alloc] init];
|
||||
vc.comicProductionModel = self.comicModel;
|
||||
vc.chapter_id = t_chapterModel.chapter_id;
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - 点击事件
|
||||
- (void)changeDirectorySort:(TFButton *)sender
|
||||
{
|
||||
if (self.comicModel.chapter_list.count == 0) return;
|
||||
if (sender.tag == 0) {
|
||||
sender.tag = 1;
|
||||
sender.buttonImageName = @"comic_reverse_order";
|
||||
sender.buttonTitle = TFLocalizedString(@"倒序");
|
||||
} else {
|
||||
sender.tag = 0;
|
||||
sender.buttonImageName = @"comic_positive_order";
|
||||
sender.buttonTitle = TFLocalizedString(@"正序");
|
||||
}
|
||||
self.comicModel.chapter_list = [[self.comicModel.chapter_list reverseObjectEnumerator] allObjects];
|
||||
// 计算已读章节的位置
|
||||
NSInteger readIndex = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:self.comicModel.production_id];
|
||||
NSArray<NSNumber *> *t_arr = [self.comicModel.chapter_list valueForKeyPath:@"chapter_id"];
|
||||
self.readIndex = [t_arr indexOfObject:@(readIndex)];
|
||||
if (self.readIndex == NSNotFound) {
|
||||
self.readIndex = -1;
|
||||
}
|
||||
[self.mainTableView reloadData];
|
||||
}
|
||||
|
||||
- (void)gotoCurrentClick:(UIButton *)sender
|
||||
{
|
||||
if (self.comicModel.chapter_list.count == 0) return;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Directory_Move object:@"bottom"];
|
||||
if (self.readIndex != -1) {
|
||||
[self.mainTableView scrollToRow:self.readIndex inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)gotoEndClick:(UIButton *)sender
|
||||
{
|
||||
if (self.comicModel.chapter_list.count == 0) return;
|
||||
clickGotoButton = YES;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Can_Leave_Top object:@NO];
|
||||
if (sender.tag == 0) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Directory_Move object:@"bottom"];
|
||||
[self.mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.comicModel.chapter_list.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
|
||||
gotoEnd.buttonImageName = @"comic_goto_top";
|
||||
gotoEnd.buttonTitle = TFLocalizedString(@"到顶");
|
||||
gotoEnd.tag = 1;
|
||||
} else {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Directory_Move object:@"top"];
|
||||
[self.mainTableView setContentOffset:CGPointMake(0,0) animated:YES];
|
||||
gotoEnd.buttonImageName = @"comic_goto_bottom";
|
||||
gotoEnd.buttonTitle = TFLocalizedString(@"到底");
|
||||
gotoEnd.tag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - 懒加载
|
||||
- (UILabel *)headTitleLabel
|
||||
{
|
||||
if (!_headTitleLabel) {
|
||||
_headTitleLabel = [[UILabel alloc] init];
|
||||
_headTitleLabel.text = self.comicModel.flag?:@"";
|
||||
_headTitleLabel.frame = CGRectMake(kHalfMargin, 0, SCREEN_WIDTH - kMargin, 44);
|
||||
_headTitleLabel.font = kFont11;
|
||||
_headTitleLabel.textColor = kGrayTextColor;
|
||||
_headTitleLabel.textAlignment = NSTextAlignmentLeft;
|
||||
}
|
||||
return _headTitleLabel;
|
||||
}
|
||||
|
||||
- (TFButton *)sortButton
|
||||
{
|
||||
if (!_sortButton) {
|
||||
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont11 labelHeight:30.0 labelText:TFLocalizedString(@"正序") maxWidth:SCREEN_WIDTH / 2.0 - kMargin];
|
||||
width += kLabelHeight;
|
||||
_sortButton = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - kHalfMargin - width, 7, width, 30) buttonTitle:TFLocalizedString(@"正序") buttonSubTitle:@"" buttonImageName:@"comic_positive_order" buttonIndicator:TFButtonIndicatorImageRightBothRight showMaskView:NO];
|
||||
_sortButton.buttonImageScale = 0.4;
|
||||
_sortButton.buttonTitleFont = kFont11;
|
||||
_sortButton.graphicDistance = 5;
|
||||
_sortButton.buttonTitleColor = kGrayTextColor;
|
||||
_sortButton.tag = 0;
|
||||
[_sortButton addTarget:self action:@selector(changeDirectorySort:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _sortButton;
|
||||
}
|
||||
|
||||
- (void)setComicModel:(TFProductionModel *)comicModel
|
||||
{
|
||||
_comicModel = comicModel;
|
||||
|
||||
if (self.sortButton.tag == 1) {
|
||||
self.comicModel.chapter_list = [[comicModel.chapter_list reverseObjectEnumerator] allObjects];
|
||||
}
|
||||
[self reloadRecordData];
|
||||
}
|
||||
|
||||
- (void)reloadRecordData
|
||||
{
|
||||
[self.mainTableView reloadData];
|
||||
}
|
||||
|
||||
@end
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// TFComicDetailViewController.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
|
||||
|
||||
#define Comic_Detail_HeaderView_Height (round(SCREEN_WIDTH * 0.8) - 50.0)
|
||||
|
||||
@interface TFComicDetailViewController : TFBasicViewController
|
||||
|
||||
@property (nonatomic ,assign) NSInteger comic_id;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+435
@@ -0,0 +1,435 @@
|
||||
//
|
||||
// TFComicDetailViewController.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/19.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFComicDetailViewController.h"
|
||||
#import "TFComicBrowseViewController.h"
|
||||
#import "TFComicDownloadViewController.h"
|
||||
#import "TFTaskViewController.h"
|
||||
#import "TFComicDetailHeaderView.h"
|
||||
#import "TFComicDetailFooterView.h"
|
||||
#import "WXYZ_CompositeEmbeddedTableView.h"
|
||||
#import "TFComicDetailModel.h"
|
||||
#import "TFComicCatalogueModel.h"
|
||||
#import "TFReadRecordManager.h"
|
||||
#import "TFShareManager.h"
|
||||
#import "WXYZ_DownloadHelper.h"
|
||||
|
||||
@interface TFComicDetailViewController ()<UITableViewDelegate, UITableViewDataSource>
|
||||
{
|
||||
UIButton *menuButton;
|
||||
UILabel *menuTitle;
|
||||
}
|
||||
|
||||
@property (nonatomic ,assign) BOOL canScroll;
|
||||
// 是否到顶 到底
|
||||
@property (nonatomic ,assign) BOOL isAutoScroll;
|
||||
|
||||
@property (nonatomic ,strong) UIView *bottomMenuBar;
|
||||
|
||||
@property (nonatomic ,strong) UIButton *shareButton;
|
||||
|
||||
@property (nonatomic ,strong) UIButton *downloadButton;
|
||||
|
||||
@property (nonatomic ,strong) TFComicDetailHeaderView *headerView;
|
||||
|
||||
@property (nonatomic ,strong) TFComicDetailFooterView *footerView;
|
||||
|
||||
@property (nonatomic ,strong) TFComicDetailModel *comicDetailModel;
|
||||
|
||||
@property (nonatomic ,strong) WXYZ_CompositeEmbeddedTableView *mallTableView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFComicDetailViewController
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:nil];
|
||||
|
||||
[self setStatusBarLightContentStyle];
|
||||
[self reloadToolBarState];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:nil];
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
[self initialize];
|
||||
[self createSubviews];
|
||||
[self netRequest];
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
[self hiddenSeparator];
|
||||
|
||||
self.navigationBar.backgroundColor = [UIColor clearColor];
|
||||
self.navigationBar.navTitleLabel.alpha = 0;
|
||||
self.navigationBar.navTitleLabel.textColor = kWhiteColor;
|
||||
[self.navigationBar setLightLeftButton];
|
||||
|
||||
self.shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
self.shareButton.adjustsImageWhenHighlighted = NO;
|
||||
self.shareButton.tintColor = kWhiteColor;
|
||||
self.shareButton.hidden = YES;
|
||||
[self.shareButton setImage:[[UIImage imageNamed:@"comic_share"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||
[self.shareButton setImageEdgeInsets:UIEdgeInsetsMake(4, 4, 3, 3)];
|
||||
[self.shareButton addTarget:self action:@selector(shareButtonClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.navigationBar addSubview:self.shareButton];
|
||||
|
||||
[self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.view.mas_right).with.offset(- kMargin);
|
||||
make.centerY.mas_equalTo(self.navigationBar.navTitleLabel.mas_centerY);
|
||||
make.width.height.mas_equalTo(30);
|
||||
}];
|
||||
|
||||
#if TF_Download_Mode
|
||||
self.downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
self.downloadButton.adjustsImageWhenHighlighted = NO;
|
||||
self.downloadButton.tintColor = kWhiteColor;
|
||||
self.downloadButton.hidden = YES;
|
||||
[self.downloadButton setImage:[[UIImage imageNamed:@"comic_download"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||
[self.downloadButton setImageEdgeInsets:UIEdgeInsetsMake(3, 3, 3, 3)];
|
||||
[self.downloadButton addTarget:self action:@selector(downloadButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.navigationBar addSubview:self.downloadButton];
|
||||
|
||||
[self.downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.shareButton.mas_left).with.offset(- kHalfMargin);
|
||||
make.centerY.mas_equalTo(self.navigationBar.navTitleLabel.mas_centerY);
|
||||
make.width.height.mas_equalTo(30);
|
||||
}];
|
||||
#endif
|
||||
|
||||
self.canScroll = YES;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeScrollStatus:) name:Notification_Can_Leave_Top object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollMove:) name:Notification_Directory_Move object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(catalogRequest) name:Notification_Production_Pay_Success object:nil];
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
self.mallTableView = [[WXYZ_CompositeEmbeddedTableView alloc] initWithFrame:CGRectMake(1, 1, 1, 1) style:UITableViewStylePlain];
|
||||
self.mallTableView.delegate = self;
|
||||
self.mallTableView.dataSource = self;
|
||||
[self.mallTableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
|
||||
[self.view addSubview:self.mallTableView];
|
||||
|
||||
[self.mallTableView 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);
|
||||
}];
|
||||
|
||||
self.headerView = [[TFComicDetailHeaderView alloc] init];
|
||||
self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, Comic_Detail_HeaderView_Height);
|
||||
[self.mallTableView setTableHeaderView:self.headerView];
|
||||
|
||||
[self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(0);
|
||||
make.top.mas_equalTo(0);
|
||||
make.width.mas_equalTo(SCREEN_WIDTH);
|
||||
make.height.mas_equalTo(Comic_Detail_HeaderView_Height);
|
||||
}];
|
||||
|
||||
WS(weakSelf)
|
||||
self.footerView = [[TFComicDetailFooterView alloc] init];
|
||||
self.footerView.view.hidden = YES;
|
||||
self.footerView.view.frame = CGRectMake(0, Comic_Detail_HeaderView_Height, SCREEN_WIDTH, SCREEN_HEIGHT - (Comic_Detail_HeaderView_Height));
|
||||
self.footerView.pushToComicDetailBlock = ^(NSInteger production_id) {
|
||||
TFComicDetailViewController *vc = [[TFComicDetailViewController alloc] init];
|
||||
vc.comic_id = production_id;
|
||||
[weakSelf.navigationController pushViewController:vc animated:YES];
|
||||
};
|
||||
[self.mallTableView setTableFooterView:self.footerView.view];
|
||||
[self addChildViewController:self.footerView];
|
||||
|
||||
self.bottomMenuBar = [[UIView alloc] init];
|
||||
self.bottomMenuBar.hidden = YES;
|
||||
self.bottomMenuBar.backgroundColor = kGrayViewColor;
|
||||
[self.view addSubview:self.bottomMenuBar];
|
||||
|
||||
[self.bottomMenuBar 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);
|
||||
}];
|
||||
|
||||
menuButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
menuButton.backgroundColor = kMainColor;
|
||||
[menuButton setTitle:TFLocalizedString(@"开始阅读") forState:UIControlStateNormal];
|
||||
[menuButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
|
||||
[menuButton.titleLabel setFont:[UIFont boldSystemFontOfSize:kFontSize13]];
|
||||
[menuButton addTarget:self action:@selector(startReading) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.bottomMenuBar addSubview:menuButton];
|
||||
|
||||
[menuButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.bottomMenuBar.mas_right);
|
||||
make.top.mas_equalTo(0);
|
||||
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
|
||||
make.width.mas_equalTo(120);
|
||||
}];
|
||||
|
||||
menuTitle = [[UILabel alloc] init];
|
||||
menuTitle.textColor = kBlackColor;
|
||||
menuTitle.textAlignment = NSTextAlignmentLeft;
|
||||
menuTitle.font = kFont13;
|
||||
[self.bottomMenuBar addSubview:menuTitle];
|
||||
|
||||
[menuTitle mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(kMargin);
|
||||
make.top.mas_equalTo(0);
|
||||
make.right.mas_equalTo(menuButton.mas_left);
|
||||
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)scrollMove:(NSNotification *)noti
|
||||
{
|
||||
self.isAutoScroll = YES;
|
||||
if ([noti.object isEqualToString:@"top"]) {
|
||||
self.footerView.canScroll = NO;
|
||||
self.canScroll = YES;
|
||||
self.mallTableView.contentOffset = CGPointMake(0, 0);
|
||||
} else {
|
||||
self.footerView.canScroll = YES;
|
||||
self.canScroll = NO;
|
||||
self.mallTableView.contentOffset = CGPointMake(0, Comic_Detail_HeaderView_Height - PUB_NAVBAR_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)changeScrollStatus:(NSNotification *)noti
|
||||
{
|
||||
self.canScroll = [noti.object boolValue];
|
||||
}
|
||||
|
||||
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
|
||||
{
|
||||
self.isAutoScroll = NO;
|
||||
}
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
||||
{
|
||||
if (self.isAutoScroll) {
|
||||
return;
|
||||
}
|
||||
if (scrollView.contentOffset.y <= Comic_Detail_HeaderView_Height - PUB_NAVBAR_HEIGHT) {
|
||||
if (self.canScroll) {
|
||||
self.canScroll = YES;
|
||||
self.footerView.canScroll = NO;
|
||||
if (scrollView.contentOffset.y <= 0) {
|
||||
scrollView.contentOffset = CGPointMake(0, 0);
|
||||
}
|
||||
} else {
|
||||
scrollView.contentOffset = CGPointMake(0, Comic_Detail_HeaderView_Height - PUB_NAVBAR_HEIGHT);
|
||||
}
|
||||
|
||||
} else {
|
||||
self.canScroll = NO;
|
||||
scrollView.contentOffset = CGPointMake(0, Comic_Detail_HeaderView_Height - PUB_NAVBAR_HEIGHT);
|
||||
self.footerView.canScroll = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return [[UITableViewCell alloc] init];
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return CGFLOAT_MIN;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
return CGFLOAT_MIN;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
||||
{
|
||||
return CGFLOAT_MIN;
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
|
||||
{
|
||||
if ([keyPath isEqualToString:@"contentOffset"]) {
|
||||
CGPoint point = [((NSValue *)[self.mallTableView valueForKey:@"contentOffset"]) CGPointValue];
|
||||
if (self.canScroll) {
|
||||
self.footerView.contentOffSetY = point.y;
|
||||
} else {
|
||||
self.footerView.contentOffSetY = Comic_Detail_HeaderView_Height - PUB_NAVBAR_HEIGHT;
|
||||
}
|
||||
|
||||
[self changeHeaderViewAlpha:point.y];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)changeHeaderViewAlpha:(CGFloat)contentOffsetY
|
||||
{
|
||||
if (contentOffsetY >= 120) {
|
||||
contentOffsetY = 120;
|
||||
}
|
||||
|
||||
if (contentOffsetY <= 0) {
|
||||
contentOffsetY = 0;
|
||||
}
|
||||
|
||||
CGFloat viewAlpha = (120 - contentOffsetY) / 120;
|
||||
|
||||
self.headerView.headerViewAlpha = viewAlpha;
|
||||
self.navigationBar.navTitleLabel.alpha = 1 - viewAlpha;
|
||||
}
|
||||
|
||||
#pragma mark - 点击事件
|
||||
#if TF_Download_Mode
|
||||
- (void)downloadButtonClick
|
||||
{
|
||||
if (self.comicDetailModel.productionModel.chapter_list.count == 0) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"章节正在更新中")];
|
||||
return;
|
||||
}
|
||||
TFComicDownloadViewController *vc = [[TFComicDownloadViewController alloc] init];
|
||||
vc.comicModel = self.comicDetailModel.productionModel;
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)shareButtonClick:(UIButton *)sender
|
||||
{
|
||||
NSInteger chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:self.comic_id];
|
||||
[TFShareManager shareWithProduction_id:NSStringFromInteger(self.comic_id) chapter_id:NSStringFromInteger(chapter_id) type:TFShareTypeComic];
|
||||
}
|
||||
|
||||
- (void)startReading
|
||||
{
|
||||
if (self.comicDetailModel.productionModel.chapter_list.count == 0) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"章节正在更新中")];
|
||||
return;
|
||||
}
|
||||
|
||||
[TFTaskViewController taskReadRequestWithProduction_id:self.comic_id];
|
||||
|
||||
TFComicBrowseViewController *vc = [[TFComicBrowseViewController alloc] init];
|
||||
vc.comicProductionModel = self.comicDetailModel.productionModel;
|
||||
vc.chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:self.comic_id];
|
||||
if (vc.chapter_id == 0) {// 如果没有阅读记录默认阅读第一章
|
||||
TFProductionChapterModel *t_model = self.comicDetailModel.productionModel.chapter_list.firstObject;
|
||||
if ([t_model.display_order isEqualToString:@"0"]) {// 判断一下目录的
|
||||
vc.chapter_id = t_model.chapter_id;
|
||||
} else {
|
||||
vc.chapter_id = self.comicDetailModel.productionModel.chapter_list.lastObject.chapter_id;
|
||||
}
|
||||
}
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
}
|
||||
|
||||
- (void)reloadToolBarState
|
||||
{
|
||||
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] productionHasReadedWithProduction_id:self.comicDetailModel.productionModel.production_id]) {
|
||||
menuTitle.text = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapterTitleWithProduction_id:self.comicDetailModel.productionModel.production_id]?:@"";
|
||||
[menuButton setTitle:TFLocalizedString(@"继续阅读") forState:UIControlStateNormal];
|
||||
[menuButton mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
if (menuButton.intrinsicContentSize.width + kMargin > 120.0) {
|
||||
make.width.mas_equalTo(menuButton.intrinsicContentSize.width + kMargin);
|
||||
} else {
|
||||
make.width.mas_equalTo(120.0);
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
if (self.comicDetailModel.productionModel.chapter_list.count > 0) {
|
||||
TFProductionChapterModel *t_chapterList = [self.comicDetailModel.productionModel.chapter_list objectOrNilAtIndex:0];
|
||||
menuTitle.text = t_chapterList.chapter_title?:@"";
|
||||
} else {
|
||||
menuTitle.text = self.comicDetailModel.productionModel.name?:@"";
|
||||
}
|
||||
[menuButton setTitle:TFLocalizedString(@"开始阅读") forState:UIControlStateNormal];
|
||||
[menuButton mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
if (menuButton.intrinsicContentSize.width + kMargin > 120.0) {
|
||||
make.width.mas_equalTo(menuButton.intrinsicContentSize.width + kMargin);
|
||||
} else {
|
||||
make.width.mas_equalTo(120.0);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
[self.headerView reloadHeaderView];
|
||||
}
|
||||
|
||||
- (void)netRequest
|
||||
{
|
||||
if ([TFNetworkManager networkingStatus] == NO) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"当前无网络连接")];
|
||||
return;
|
||||
}
|
||||
|
||||
WS(weakSelf)
|
||||
[TFNetworkTools POST:Comic_Detail parameters:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.comic_id]} model:TFComicDetailModel.class success:^(BOOL isSuccess, TFComicDetailModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
|
||||
if (isSuccess) {
|
||||
[weakSelf.navigationBar setNavigationBarTitle:t_model.productionModel.name?:@""];
|
||||
weakSelf.comicDetailModel = t_model;
|
||||
}
|
||||
weakSelf.bottomMenuBar.hidden = NO;
|
||||
weakSelf.footerView.view.hidden = NO;
|
||||
weakSelf.downloadButton.hidden = NO;
|
||||
weakSelf.shareButton.hidden = NO;
|
||||
[weakSelf catalogRequest];
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[weakSelf catalogRequest];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)catalogRequest
|
||||
{
|
||||
WS(weakSelf)
|
||||
[TFNetworkTools POST:Comic_Catalog parameters:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.comic_id]} model:TFComicCatalogueModel.class success:^(BOOL isSuccess, TFComicCatalogueModel *_Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
|
||||
if (isSuccess) {
|
||||
weakSelf.comicDetailModel.productionModel.chapter_list = t_model.chapter_list;
|
||||
weakSelf.headerView.comicProductionModel = weakSelf.comicDetailModel.productionModel;
|
||||
weakSelf.footerView.detailModel = weakSelf.comicDetailModel;
|
||||
|
||||
// 存储作品信息
|
||||
[[WXYZ_DownloadHelper sharedManager] recordDownloadProductionWithProductionModel:weakSelf.comicDetailModel.productionModel productionType:TFProductionTypeComic];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf reloadToolBarState];
|
||||
});
|
||||
} else {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg ?:TFLocalizedString(@"获取失败")];
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf.mallTableView reloadData];
|
||||
});
|
||||
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"获取失败")];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
@try {
|
||||
[self.mallTableView removeObserver:self forKeyPath:@"contentOffset" context:NULL];
|
||||
} @catch (NSException *exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user