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.
366 lines
15 KiB
366 lines
15 KiB
// |
|
// TFBookStoreAudioController.m |
|
// TFReader |
|
// |
|
// Created by 谢腾飞 on 2020/12/16. |
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved. |
|
// |
|
|
|
#import "TFBookStoreAudioController.h" |
|
#import "TFLimitFreeViewController.h" |
|
#import "TFBookStoreNovelStyleOneCell.h" |
|
#import "TFBookStoreNovelStyleTwoCell.h" |
|
#import "TFBookStoreNovelStyleThreeCell.h" |
|
#import "TFBookStoreNovelStyleFourCell.h" |
|
#import "TFPublicAdvertisementViewCell.h" |
|
#import "TFBookStoreMenuView.h" |
|
#import "TFBookStoreLabelModel.h" |
|
#import "TFBannerActionManager.h" |
|
// 分类 |
|
#import "TFSortViewController.h" |
|
// 排行榜 |
|
#import "TFPopularityViewController.h" |
|
// 包月 |
|
#import "TFMemberViewController.h" |
|
// 完本 |
|
#import "TFCompleteViewController.h" |
|
// 限免 |
|
#import "TFFreeViewController.h" |
|
|
|
@interface TFBookStoreAudioController ()<UITableViewDelegate, UITableViewDataSource> |
|
|
|
@property (nonatomic ,strong) TFBookStoreMenuView *headerView; |
|
@property (nonatomic ,strong) TFBookStoreModel *audioMallModel; |
|
@property (nonatomic ,assign) BOOL needRefresh; |
|
|
|
@end |
|
|
|
@implementation TFBookStoreAudioController |
|
|
|
- (void)viewDidLoad |
|
{ |
|
[super viewDidLoad]; |
|
|
|
[self initialize]; |
|
[self createSubviews]; |
|
[self netRequest]; |
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Restore_Network object:nil]; |
|
} |
|
|
|
- (void)initialize |
|
{ |
|
self.needRefresh = YES; |
|
[self hiddenNavigationBar:YES]; |
|
|
|
self.hotwordArray = [NSArray array]; |
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Channel_Change object:nil]; |
|
} |
|
|
|
- (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(0); |
|
make.width.mas_equalTo(self.view.mas_width); |
|
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_TABBAR_HEIGHT); |
|
}]; |
|
|
|
WS(weakSelf) |
|
self.headerView = [[TFBookStoreMenuView alloc] init]; |
|
self.headerView.productionType = self.productionType; |
|
self.headerView.bannerrImageClickBlock = ^(TFBannerModel * _Nonnull bannerModel) { |
|
if ([TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeAudio]) { |
|
[weakSelf.navigationController pushViewController:[TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeAudio] animated:YES]; |
|
} |
|
}; |
|
self.headerView.menuButtonClickBlock = ^(TFMenuButtonType menuButtonType, NSString * _Nonnull menuButtonTitle) { |
|
switch (menuButtonType) { |
|
case TFMenuButtonTypeFree: { |
|
TFFreeViewController *free = [[TFFreeViewController alloc] init]; |
|
free.productionType = weakSelf.productionType; |
|
free.navTitle = menuButtonTitle; |
|
[weakSelf.navigationController pushViewController:free animated:YES]; |
|
} |
|
break; |
|
|
|
case TFMenuButtonTypeComplete: { |
|
TFCompleteViewController *complete = [[TFCompleteViewController alloc] init]; |
|
complete.productionType = weakSelf.productionType; |
|
complete.navTitle = menuButtonTitle; |
|
[weakSelf.navigationController pushViewController:complete animated:YES]; |
|
} |
|
break; |
|
|
|
case TFMenuButtonTypeSort: { |
|
TFSortViewController *sort = [[TFSortViewController alloc] init]; |
|
sort.productionType = weakSelf.productionType; |
|
sort.navTitle = menuButtonTitle; |
|
[weakSelf.navigationController pushViewController:sort animated:YES]; |
|
} |
|
break; |
|
|
|
case TFMenuButtonTypePopularity: { |
|
TFPopularityViewController *popularity = [[TFPopularityViewController alloc] init]; |
|
popularity.productionType = weakSelf.productionType; |
|
popularity.navTitle = menuButtonTitle; |
|
[weakSelf.navigationController pushViewController:popularity animated:YES]; |
|
} |
|
break; |
|
|
|
case TFMenuButtonTypeMember: { |
|
TFMemberViewController *member = [[TFMemberViewController alloc] init]; |
|
member.productionType = weakSelf.productionType; |
|
[weakSelf.navigationController pushViewController:member animated:YES]; |
|
} |
|
break; |
|
|
|
default: |
|
break; |
|
} |
|
}; |
|
|
|
self.mainTableViewGroup.tableHeaderView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH); |
|
[self.mainTableViewGroup setTableHeaderView:self.headerView]; |
|
|
|
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{ |
|
[weakSelf netRequest]; |
|
}]; |
|
} |
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView |
|
{ |
|
return self.audioMallModel.label.count; |
|
} |
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section |
|
{ |
|
return 1; |
|
} |
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
TFBookStoreLabelModel *labelModel = [self.audioMallModel.label objectOrNilAtIndex:indexPath.section]; |
|
for (TFProductionModel *t_model in labelModel.list) { |
|
t_model.productionType = self.productionType; |
|
} |
|
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) { |
|
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init]; |
|
vc.audio_id = production_id; |
|
[weakSelf.navigationController pushViewController:vc animated:YES]; |
|
}; |
|
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; |
|
} |
|
|
|
- (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 |
|
{ |
|
TFBookStoreLabelModel *labelModel = [self.audioMallModel.label objectOrNilAtIndex:section]; |
|
if (labelModel.can_more || labelModel.can_refresh) { |
|
return 50; |
|
} |
|
return CGFLOAT_MIN; |
|
} |
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section |
|
{ |
|
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)]; |
|
view.backgroundColor = [UIColor whiteColor]; |
|
|
|
CGFloat buttonX = SCREEN_WIDTH / 4; |
|
CGFloat buttonY = 10; |
|
CGFloat buttonW = SCREEN_WIDTH / 2; |
|
CGFloat buttonH = 30; |
|
|
|
TFBookStoreLabelModel *labelModel = [self.audioMallModel.label objectOrNilAtIndex:section]; |
|
|
|
if (!labelModel.can_more && !labelModel.can_refresh) { |
|
return view; |
|
} |
|
|
|
TFButton *moreButton = [TFButton initWithFrame:CGRectMake(buttonX, buttonY, buttonW, buttonH) btnTitle:TFLocalizedString(@"更多") btnImageName:@"comic_mall_more" backgroundColor:kGrayViewColor btnTintColor:kGrayTextLightColor btnStyle:TFButtonIndicatorTitleLeft cornerRadius:15 target:self action:@selector(moreButtonClick:)]; |
|
moreButton.graphicDistance = 5; |
|
moreButton.tag = section; |
|
[moreButton addTarget:self action:@selector(moreButtonClick:) forControlEvents:UIControlEventTouchUpInside]; |
|
|
|
|
|
TFButton *changeButton = [TFButton initWithFrame:CGRectMake(buttonX, 0, buttonW, buttonH) btnTitle:TFLocalizedString(@"换一换") btnImageName:@"comic_mall_refresh" backgroundColor:kGrayViewColor btnTintColor:kGrayTextLightColor btnStyle:TFButtonIndicatorTitleLeft cornerRadius:15 target:self action:@selector(changeButtonClick:)]; |
|
changeButton.graphicDistance = 5; |
|
changeButton.buttonImageScale = 0.5; |
|
changeButton.tag = section; |
|
[changeButton addTarget:self action:@selector(changeButtonClick:) forControlEvents:UIControlEventTouchUpInside]; |
|
|
|
if (labelModel.can_more && !labelModel.can_refresh) { |
|
[view addSubview:moreButton]; |
|
} |
|
|
|
if (!labelModel.can_more && labelModel.can_refresh) { |
|
[view addSubview:changeButton]; |
|
} |
|
|
|
if (labelModel.can_more && labelModel.can_refresh) { |
|
moreButton.frame = CGRectMake(kMargin, buttonY, (SCREEN_WIDTH - 3 * kMargin) / 2, buttonH); |
|
changeButton.frame = CGRectMake(2 * kMargin + (SCREEN_WIDTH - 3 * kMargin) / 2, buttonY, (SCREEN_WIDTH - 3 * kMargin) / 2, buttonH); |
|
[view addSubview:moreButton]; |
|
[view addSubview:changeButton]; |
|
} |
|
|
|
return view; |
|
} |
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView |
|
{ |
|
CGFloat pointY = scrollView.contentOffset.y; |
|
|
|
self.scrollViewContentOffsetY = pointY; |
|
[UIApplication sharedApplication].statusBarHidden = NO; |
|
} |
|
|
|
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate |
|
{ |
|
CGFloat pointY = scrollView.contentOffset.y; |
|
|
|
self.scrollViewContentOffsetY = pointY; |
|
} |
|
|
|
#pragma mark - 点击事件 |
|
- (void)moreButtonClick:(UIButton *)sender |
|
{ |
|
TFBookStoreLabelModel *t_labelModel = [self.audioMallModel.label objectOrNilAtIndex:sender.tag]; |
|
TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init]; |
|
vc.productionType = self.productionType; |
|
vc.recommend_id = [TFUtilsHelper formatStringWithInteger:t_labelModel.recommend_id]; |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
} |
|
|
|
- (void)changeButtonClick:(UIButton *)sender |
|
{ |
|
TFButton *button = (TFButton *)sender; |
|
[button startSpin]; |
|
[self changeBookRecommendRequestAtIndex:sender.tag complete:^{ |
|
[button stopSpin]; |
|
}]; |
|
} |
|
|
|
- (void)netRequest |
|
{ |
|
WS(weakSelf) |
|
NSMutableDictionary *params = [NSMutableDictionary dictionary]; |
|
params[@"channel_id"] = (self.channel != 0) ? [TFUtilsHelper formatStringWithInteger:self.channel] : @(TFSystemInfoManager.sexChannel); |
|
|
|
[TFNetworkTools POSTQuick:Audio_Mall parameters:params model:TFBookStoreModel.class success:^(BOOL isSuccess, TFBookStoreModel * _Nullable t_model, BOOL isCache, TFNetworkRequestModel * _Nonnull requestModel) { |
|
|
|
if (isSuccess) { |
|
weakSelf.audioMallModel = t_model; |
|
weakSelf.headerView.mallCenterModel = t_model; |
|
weakSelf.hotwordArray = t_model.hot_word; |
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Reload_Mall_Hot_Word object:nil]; |
|
} |
|
[weakSelf.mainTableViewGroup endRefreshing]; |
|
weakSelf.needRefresh = YES; |
|
[weakSelf.mainTableViewGroup reloadData]; |
|
dispatch_async(dispatch_get_main_queue(), ^{ |
|
weakSelf.needRefresh = NO; |
|
}); |
|
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { |
|
[weakSelf.mainTableViewGroup endRefreshing]; |
|
}]; |
|
} |
|
|
|
- (void)changeBookRecommendRequestAtIndex:(NSInteger)index complete:(void(^)(void))complete; |
|
{ |
|
TFBookStoreLabelModel *t_labelModel = [self.audioMallModel.label objectOrNilAtIndex:index]; |
|
NSString *recommend_id = [TFUtilsHelper formatStringWithInteger:t_labelModel.recommend_id]; |
|
|
|
if (recommend_id.length <= 0) return; |
|
|
|
WS(weakSelf) |
|
NSMutableDictionary *params = [NSMutableDictionary dictionary]; |
|
params[@"recommend_id"] = recommend_id; |
|
|
|
[TFNetworkTools POST:Audio_Refresh parameters:params model:TFBookStoreLabelModel.class success:^(BOOL isSuccess, TFBookStoreLabelModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) { |
|
|
|
if (isSuccess) { |
|
for (TFProductionModel *obj in t_model.list) { |
|
obj.productionType = weakSelf.productionType; |
|
} |
|
[weakSelf.audioMallModel.label objectAtIndex:index].list = t_model.list; |
|
|
|
TFBookStoreNovelBasicViewCell *cell = [weakSelf.mainTableViewGroup cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:index]]; |
|
t_model.style = cell.labelModel.style; |
|
cell.labelModel = t_model; |
|
!complete ? : complete(); |
|
} |
|
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { |
|
!complete ?: complete(); |
|
}]; |
|
} |
|
|
|
@end
|
|
|