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.
 

209 lines
8.0 KiB

//
// WXYZ_BookBackSideViewController.m
// WXReader
//
// Created by LL on 2020/5/27.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_BookBackSideViewController.h"
#import "TFCommentsViewController.h"
#import "WXYZ_BookBackSideHeaderView.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "WXYZ_BookBackSideModel.h"
#import "TFBookStoreLabelModel.h"
@interface WXYZ_BookBackSideViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) WXYZ_BookBackSideModel *backSideModel;
@property (nonatomic, strong) WXYZ_BookBackSideHeaderView *headerView;
@property (nonatomic, assign) BOOL needRefresh;
@end
@implementation WXYZ_BookBackSideViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:@"1"];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
self.needRefresh = YES;
[self setNavigationBarTitle:self.bookModel.name ?: @""];
self.view.backgroundColor = [UIColor whiteColor];
UIButton *_rightBtn;
[self setNavigationBarRightButton:({
UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_rightBtn = rightBtn;
[rightBtn setImage:[UIImage imageNamed:@"public_home"] forState:UIControlStateNormal];
[rightBtn addTarget:self action:@selector(goHome) forControlEvents:UIControlEventTouchUpInside];
rightBtn;
})];
[_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view).offset(-kMargin);
make.centerY.equalTo(self.navigationBar.navTitleLabel);
}];
}
- (void)createSubviews
{
self.mainTableViewGroup.delegate = self;
self.mainTableViewGroup.dataSource = self;
[self.view addSubview:self.mainTableViewGroup];
[self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(PUB_NAVBAR_HEIGHT);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height);
}];
WS(weakSelf)
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
self.headerView = [[WXYZ_BookBackSideHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
self.headerView.commentClickBlock = ^{
TFCommentsViewController *vc = [[TFCommentsViewController alloc] init];
vc.production_id = weakSelf.bookModel.production_id;
vc.commentsSuccessBlock = ^(TFCommentsListModel *commentModel) {
weakSelf.backSideModel.comment_num ++;
weakSelf.headerView.headerModel = weakSelf.backSideModel;
};
[weakSelf.navigationController pushViewController:vc animated:YES];
};
[self.mainTableViewGroup setTableHeaderView:self.headerView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreLabelModel *labelModel = self.backSideModel.guess_like;
if (labelModel.ad_type == 0) {
switch (labelModel.style) {
case 1:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleOneCell.class indexPath:indexPath labelModel:labelModel];
break;
case 2:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleTwoCell.class indexPath:indexPath labelModel:labelModel];
break;
case 3:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleThreeCell.class indexPath:indexPath labelModel:labelModel];
break;
case 4:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleFourCell.class indexPath:indexPath labelModel:labelModel];
break;
default:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleOneCell.class indexPath:indexPath labelModel:labelModel];
break;
}
} else {
return [self createAdStyleCellWithTableView:tableView indexPath:indexPath adModel:labelModel];
}
}
- (UITableViewCell *)createCellWithTabelView:(UITableView *)tableView cellClass:(Class)cellClass indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
WS(weakSelf)
TFBookStoreNovelBasicViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(cellClass)];
if (!cell) {
cell = [[cellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(cellClass)];
}
cell.labelModel = labelModel;
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = production_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.index = indexPath;
cell.cellSelectRefreshBlock = ^(TFBookStoreLabelModel *labelModel, NSIndexPath *indexPath) {
[weakSelf refreshRequestWithLabelModel:labelModel indexPath:indexPath];
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (UITableViewCell *)createAdStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath adModel:(TFBookStoreLabelModel *)labelModel
{
static NSString *cellName = @"TFPublicAdvertisementViewCell";
TFPublicAdvertisementViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
[cell setAdModel:labelModel refresh:self.needRefresh];
cell.mainTableView = tableView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (void)netRequest
{
WS(weakSelf)
[TFNetworkTools POST:Book_Endof_Recommend parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:self.bookModel.production_id]} model:WXYZ_BookBackSideModel.class success:^(BOOL isSuccess, WXYZ_BookBackSideModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.backSideModel = t_model;
weakSelf.headerView.headerModel = t_model;
weakSelf.needRefresh = YES;
[weakSelf.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
}
[weakSelf.mainTableViewGroup endRefreshing];
} failure:nil];
}
- (void)refreshRequestWithLabelModel:(TFBookStoreLabelModel *)labelModel indexPath:(NSIndexPath *)indexPath
{
WS(weakSelf)
[TFNetworkTools POST:Book_Guess_Like parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:self.bookModel.production_id]} model:TFBookStoreLabelModel.class success:^(BOOL isSuccess, TFBookStoreLabelModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.backSideModel.guess_like.list = t_model.list;
TFBookStoreNovelBasicViewCell *cell = [weakSelf.mainTableViewGroup cellForRowAtIndexPath:indexPath];
cell.labelModel = t_model;
[cell stopRefreshing];
}
} failure:nil];
}
- (void)goHome
{
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Change_Tabbar_Index object:@"1"];
[self.navigationController popToRootViewControllerAnimated:YES];
}
@end