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.

226 lines
7.4 KiB

//
// TFPopularityDetailViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/17.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFPopularityDetailViewController.h"
#import "TFProductionListViewCell.h"
#import "TFPublicAdvertisementViewCell.h"
@interface TFPopularityDetailViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFPopularityDetailViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
self.needRefresh = YES;
[self setNavigationBarTitle:self.navTitle];
}
- (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(PUB_NAVBAR_HEIGHT);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT);
}];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无数据") tapBlock:^{
}];
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];
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
if (t_model.ad_type == 0) {
TFProductionListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFProductionListViewCell"];
if (!cell) {
cell = [[TFProductionListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFProductionListViewCell"];
}
cell.isRankList = YES;
cell.productionType = self.productionType;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.productionModel = t_model;
cell.hiddenEndLine = (indexPath.row == self.dataSourceArray.count - 1);
return cell;
} else {
TFPublicAdvertisementViewCell *cell = [self.advertDict objectForKey:[TFUtilsHelper formatStringWithInteger:indexPath.row]];
if (!cell) {
static NSString *cellName = @"TFPublicAdvertisementViewCell";
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
[cell setAdModel:t_model refresh:self.needRefresh];
cell.mainTableView = tableView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[self.advertDict setObject:cell forKey:[TFUtilsHelper formatStringWithInteger:indexPath.row]];
}
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
switch (self.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel: {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic: {
TFComicDetailViewController *comicDetail = [[TFComicDetailViewController alloc] init];
comicDetail.comic_id = t_model.production_id;
[self.navigationController pushViewController:comicDetail animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio: {
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init];
vc.audio_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
default:
break;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
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)netRequest
{
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Rank_Detail_List;
break;
case TFProductionTypeComic:
url = Comic_Rank_Detail_List;
break;
case TFProductionTypeAudio:
url = Audio_Rank_Detail_List;
break;
default:
break;
}
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"channel_id"] = self.channel;
params[@"rank_type"] = self.rank_type;
params[@"page_num"] = [TFUtilsHelper formatStringWithInteger:weakSelf.currentPageNumber];
[TFNetworkTools POST:url parameters:params model:TFProductionListModel.class success:^(BOOL isSuccess, TFProductionListModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
[weakSelf.mainTableView endRefreshing];
if (isSuccess) {
if (weakSelf.currentPageNumber == 1) {
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.list];
} else {
[weakSelf.dataSourceArray addObjectsFromArray:t_model.list];
}
weakSelf.needRefresh = YES;
[weakSelf.mainTableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
if (t_model.total_page <= t_model.current_page) {
[weakSelf.mainTableView hideRefreshFooter];
}
}
[weakSelf.mainTableView xtfei_endLoading];
if (weakSelf.dataSourceArray.count == 0) {
[weakSelf.mainTableView xtfei_showEmptyView];
} else {
[weakSelf.mainTableView xtfei_hideEmptyView];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView endRefreshing];
[weakSelf.mainTableView xtfei_endLoading];
}];
}
@end