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.
154 lines
5.1 KiB
154 lines
5.1 KiB
// |
|
// TFAudioRecommendedViewController.m |
|
// TFReader |
|
// |
|
// Created by 谢腾飞 on 2020/12/25. |
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved. |
|
// |
|
|
|
#import "TFAudioRecommendedViewController.h" |
|
#import "TFAudioRecommendedViewCell.h" |
|
#import "TFAudioRecommendedModel.h" |
|
|
|
@interface TFAudioRecommendedViewController ()<UITableViewDelegate, UITableViewDataSource> |
|
|
|
@end |
|
|
|
@implementation TFAudioRecommendedViewController |
|
|
|
- (void)viewDidLoad |
|
{ |
|
[super viewDidLoad]; |
|
|
|
[self initialize]; |
|
[self createSubviews]; |
|
[self netRequest]; |
|
} |
|
|
|
- (void)initialize |
|
{ |
|
[self hiddenNavigationBar:YES]; |
|
} |
|
|
|
- (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.edges.mas_equalTo(self.view); |
|
}]; |
|
|
|
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无数据") buttonTitle:nil tapBlock:^{ |
|
}]; |
|
|
|
WS(weakSelf) |
|
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{ |
|
weakSelf.currentPageNumber = 1; |
|
[weakSelf netRequest]; |
|
}]; |
|
|
|
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 |
|
{ |
|
static NSString *cellName = @"TFAudioRecommendedViewCell"; |
|
TFAudioRecommendedViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName]; |
|
if (!cell) { |
|
cell = [[TFAudioRecommendedViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName]; |
|
} |
|
cell.productionType = self.productionType; |
|
[cell setListModel:[self.dataSourceArray objectOrNilAtIndex:indexPath.row]]; |
|
cell.hiddenEndLine = (indexPath.row == self.dataSourceArray.count - 1); |
|
WS(weakSelf) |
|
cell.clickBlock = ^(NSInteger production_id) { |
|
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init]; |
|
vc.audio_id = production_id; |
|
[weakSelf.navigationController pushViewController:vc animated:YES]; |
|
}; |
|
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
|
return cell; |
|
} |
|
|
|
- (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 |
|
{ |
|
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row]; |
|
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init]; |
|
vc.audio_id = t_model.production_id; |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
} |
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView |
|
{ |
|
if ([scrollView isEqual:self.mainTableView]) { |
|
if (!self.canScroll) { |
|
scrollView.contentOffset = CGPointZero; |
|
} |
|
|
|
if (scrollView.contentOffset.y > 0) { |
|
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Audio_Can_Leave_Top object:@NO]; |
|
} |
|
} |
|
} |
|
|
|
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView |
|
{ |
|
if (scrollView.contentOffset.y <= 0) { |
|
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Audio_Can_Leave_Top object:@YES]; |
|
} |
|
} |
|
|
|
- (void)netRequest |
|
{ |
|
WS(weakSelf) |
|
[TFNetworkTools POST:Audio_Info_Recommend parameters:@{@"page_num":[TFUtilsHelper formatStringWithInteger:self.currentPageNumber]} model:TFAudioRecommendedModel.class success:^(BOOL isSuccess, TFAudioRecommendedModel * _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 reloadData]; |
|
[weakSelf.mainTableView xtfei_endLoading]; |
|
}]; |
|
} |
|
|
|
@end
|
|
|