Files
yinmeng-ios/xplan-ios/Main/Home/View/XPHomeHappyViewController.m
2023-03-16 22:16:53 +08:00

218 lines
6.6 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// XPHomeHappyViewController.m
// xplan-ios
//
// Created by 冯硕 on 2022/2/25.
// 开黑畅聊 热门房间
#import "XPHomeHappyViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <MJRefresh/MJRefresh.h>
///Tool
#import "ThemeColor.h"
#import "NSArray+Safe.h"
///View
#import "XPHomeHapppyRoomTableViewCell.h"
#import "XPHomeBannerTableViewCell.h"
#import "XPHomeListEmptyTableViewCell.h"
///Model
#import "HomePlayRoomModel.h"
///VC
#import "XPWebViewController.h"
#import "XPRoomViewController.h"
///P
#import "XPHomeRecommendPresenter.h"
#import "XPHomeRecommendProtocol.h"
@interface XPHomeHappyViewController ()<UITableViewDelegate, UITableViewDataSource, XPHomeBannerTableViewCellDelegate, XPHomeRecommendProtocol>
///列表
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
/// 数据源
@property (nonatomic, strong) NSMutableArray *dataSource;
@end
@implementation XPHomeHappyViewController
- (XPHomeRecommendPresenter *)createPresenter {
return [[XPHomeRecommendPresenter alloc] init];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
[self requestData];
}
#pragma mark - InitHttp
- (void)requestData {
[self.presenter getPlayGameWithTeam:1];
}
/// 刷新数据,可见时才调用
- (void)refreshData {
if (self.isViewLoaded && self.view.window) {
[self requestData];
}
}
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.tableView];
}
- (void)initSubViewConstraints {
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
#pragma mark - XPHomeRecommendProtocol
- (void)getPlayGameWithTeamSuccess:(NSArray *)list{
/// 移除banner放到派对顶部去
NSMutableArray *tempArr = list.mutableCopy;
for (HomePlayRoomModel *model in list) {
if (model.isBanner) {
[tempArr removeObject:model];
break;
}
}
[self.dataSource removeAllObjects];
[self.dataSource addObjectsFromArray:tempArr];
[self.tableView reloadData];
}
- (void)getHomeRecommendDataFail {
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSource.count > 0 ? self.dataSource.count : 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.dataSource.count > 0) {
HomePlayRoomModel * model = [self.dataSource safeObjectAtIndex1:indexPath.row];
if (model.isBanner) {
return 80;
}
return 94;
}
return 300;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.dataSource.count > 0) {
HomePlayRoomModel * model = [self.dataSource safeObjectAtIndex1:indexPath.row];
if (model.isBanner) {
XPHomeBannerTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPHomeBannerTableViewCell class])];
if (cell == nil) {
cell = [[XPHomeBannerTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPHomeBannerTableViewCell class])];
}
cell.delegate = self;
cell.bannerList = model.bannerVoList;
return cell;
}
XPHomeHapppyRoomTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPHomeHapppyRoomTableViewCell class])];
if (cell == nil) {
cell = [[XPHomeHapppyRoomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPHomeHapppyRoomTableViewCell class])];
}
cell.roomInfo = model;
return cell;
}
XPHomeListEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
if (cell == nil) {
cell = [[XPHomeListEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.dataSource.count > 0) {
HomePlayRoomModel * model = [self.dataSource safeObjectAtIndex1:indexPath.row];
if (!model.isBanner && model.uid.integerValue > 0) {
[XPRoomViewController openRoom:model.uid fromNick:nil fromType:UserEnterRoomFromType_Home_Recommend fromUid:nil viewController:self];
}
}
}
#pragma mark - XPHomeBannerTableViewCellDelegate
- (void)xPHomeBannerTableViewCell:(XPHomeBannerTableViewCell *)view didClickBanner:(HomeBannerInfoModel *)info {
switch (info.skipType) {
case HomeBannerInfoSkipType_Room:
{
if (info.skipUri.length > 0) {
[XPRoomViewController openRoom:info.skipUri viewController:self];
}
}
break;
case HomeBannerInfoSkipType_Web:
{
XPWebViewController *vc = [[XPWebViewController alloc]init];
vc.url = info.skipUri;
[self.navigationController pushViewController:vc animated:YES];
}
break;
default:
break;
}
}
#pragma mark - JXPagingViewListViewDelegate
- (UIView *)listView {
return self.view;
}
- (UIScrollView *)listScrollView {
return self.tableView;
}
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
self.scrollCallback = callback;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
self.scrollCallback(scrollView);
}
#pragma mark - Getters And Setters
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.tableFooterView = [UIView new];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor clearColor];
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[XPHomeHapppyRoomTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPHomeHapppyRoomTableViewCell class])];
[_tableView registerClass:[XPHomeBannerTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPHomeBannerTableViewCell class])];
[_tableView registerClass:[XPHomeListEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
}
return _tableView;
}
- (NSMutableArray *)dataSource {
if (!_dataSource) {
_dataSource = [NSMutableArray array];
}
return _dataSource;
}
@end