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.
188 lines
6.1 KiB
188 lines
6.1 KiB
// |
|
// TFAppraiseCommViewController.m |
|
// TFReader |
|
// |
|
// Created by 谢腾飞 on 2020/12/21. |
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved. |
|
// |
|
|
|
#import "TFAppraiseCommViewController.h" |
|
#import "TFAppraiseDetailViewController.h" |
|
#import "TFAppraiseCommViewCell.h" |
|
|
|
@interface TFAppraiseCommViewController ()<UITableViewDelegate, UITableViewDataSource> |
|
|
|
@end |
|
|
|
@implementation TFAppraiseCommViewController |
|
|
|
- (void)viewWillAppear:(BOOL)animated |
|
{ |
|
[super viewWillAppear:animated]; |
|
|
|
[self setStatusBarDefaultStyle]; |
|
} |
|
|
|
- (void)viewDidLoad |
|
{ |
|
[super viewDidLoad]; |
|
|
|
[self initialize]; |
|
[self createSubviews]; |
|
[self netRequest]; |
|
} |
|
|
|
- (void)initialize |
|
{ |
|
[self hiddenNavigationBar:YES]; |
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Login_Success object:nil]; |
|
} |
|
|
|
- (void)createSubviews |
|
{ |
|
self.mainTableView.delegate = self; |
|
self.mainTableView.dataSource = self; |
|
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0); |
|
[self.view addSubview:self.mainTableView]; |
|
|
|
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(0); |
|
make.top.mas_equalTo(self.view.mas_top); |
|
make.height.mas_equalTo(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT - self.pageViewHeight); |
|
make.width.mas_equalTo(self.view.mas_width); |
|
}]; |
|
|
|
WS(weakSelf) |
|
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{ |
|
weakSelf.currentPageNumber = 1; |
|
[weakSelf netRequest]; |
|
}]; |
|
[self.mainTableView.mj_header beginRefreshing]; |
|
|
|
self.mainTableView.mj_footer = [TFRefreshFooter footerWithRefreshingBlock:^{ |
|
weakSelf.currentPageNumber ++; |
|
[weakSelf netRequest]; |
|
}]; |
|
|
|
[self createEmptyView]; |
|
} |
|
|
|
- (void)createEmptyView |
|
{ |
|
WS(weakSelf) |
|
if (!TFUserInfoManager.isLogin) { |
|
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"登录后可查看评论内容") buttonTitle:TFLocalizedString(@"立即登录") tapBlock:^{ |
|
[TFLoginOptionsViewController presentLoginView:^(TFUserInfoManager * _Nonnull userInfo) { |
|
weakSelf.emptyView = nil; |
|
[weakSelf createEmptyView]; |
|
}]; |
|
}]; |
|
} else { |
|
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无评论内容") buttonTitle:nil tapBlock:^{ |
|
}]; |
|
} |
|
} |
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section |
|
{ |
|
return self.dataSourceArray.count; |
|
} |
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
static NSString *cellName = @"TFAppraiseCommViewCell"; |
|
TFAppraiseCommViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName]; |
|
if (!cell) { |
|
cell = [[TFAppraiseCommViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName]; |
|
} |
|
cell.commentsDetailModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row]; |
|
cell.hiddenEndLine = indexPath.row == self.dataSourceArray.count - 1; |
|
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
return cell; |
|
} |
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section |
|
{ |
|
return CGFLOAT_MIN; |
|
} |
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section |
|
{ |
|
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)]; |
|
view.backgroundColor = [UIColor clearColor]; |
|
return view; |
|
} |
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section |
|
{ |
|
return CGFLOAT_MIN; |
|
} |
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section |
|
{ |
|
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET)]; |
|
view.backgroundColor = [UIColor clearColor]; |
|
return view; |
|
} |
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
TFCommentsListModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row]; |
|
|
|
TFAppraiseDetailViewController *vc = [[TFAppraiseDetailViewController alloc] init]; |
|
vc.productionType = self.productionType; |
|
vc.comment_id = t_model.comment_id; |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
} |
|
|
|
- (void)netRequest |
|
{ |
|
if ([TFNetworkManager networkingStatus] == NO) { |
|
[self.mainTableView endRefreshing]; |
|
[self.mainTableView xtfei_showEmptyView]; |
|
return; |
|
} |
|
|
|
NSString *url = @""; |
|
switch (self.productionType) { |
|
case TFProductionTypeNovel: |
|
url = Book_Comments_List; |
|
break; |
|
case TFProductionTypeComic: |
|
url = Comic_Comments_List; |
|
break; |
|
case TFProductionTypeAudio: |
|
url = Audio_Comments_List; |
|
break; |
|
|
|
default: |
|
break; |
|
} |
|
|
|
WS(weakSelf) |
|
[TFNetworkTools POST:url parameters:@{@"page_num":[TFUtilsHelper formatStringWithInteger:self.currentPageNumber]} model:TFCommentsModel.class success:^(BOOL isSuccess, TFCommentsModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) { |
|
|
|
[weakSelf.mainTableView endRefreshing]; |
|
|
|
if (isSuccess) { |
|
if (weakSelf.currentPageNumber == 1) { |
|
[weakSelf.mainTableView showRefreshFooter]; |
|
[weakSelf.dataSourceArray removeAllObjects]; |
|
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.list]; |
|
} else { |
|
[weakSelf.dataSourceArray addObjectsFromArray:t_model.list]; |
|
} |
|
if (t_model.total_page <= t_model.current_page) { |
|
[weakSelf.mainTableView hideRefreshFooter]; |
|
} |
|
} |
|
|
|
[weakSelf.mainTableView reloadData]; |
|
[weakSelf.mainTableView xtfei_endLoading]; |
|
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { |
|
[weakSelf.mainTableView endRefreshing]; |
|
[weakSelf.mainTableView xtfei_endLoading]; |
|
}]; |
|
} |
|
|
|
@end
|
|
|