Files
yinmeng-ios/xplan-ios/Main/Home/View/XPHomeHappyViewController.m
2022-03-04 19:54:17 +08:00

215 lines
6.7 KiB
Objective-C

//
// 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"
///View
#import "XPHomeHapppyRoomTableViewCell.h"
#import "XPHomeBannerTableViewCell.h"
#import "XPHomeListEmptyTableViewCell.h"
///P
#import "XPHomeRecommendPresenter.h"
#import "XPHomeRecommendProtocol.h"
///Model
#import "HomePlayRoomModel.h"
///VC
#import "XPWebViewController.h"
#import "XPRoomViewController.h"
@interface XPHomeHappyViewController ()<UITableViewDelegate, UITableViewDataSource, XPHomeBannerTableViewCellDelegate, XPHomeRecommendProtocol>
///列表
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
///房间列表
@property (nonatomic,strong) NSMutableArray *roomList;
///当前的页数
@property (nonatomic,assign) int page;
@end
@implementation XPHomeHappyViewController
- (XPHomeRecommendPresenter *)createPresenter {
return [[XPHomeRecommendPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initHeaderAndFooterRrfresh];
[self initSubViews];
[self initSubViewConstraints];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)configPlayGameRoomList:(NSArray *)list {
self.page = 1;
[self.roomList removeAllObjects];
[self.roomList addObjectsFromArray:list];;
[self.tableView reloadData];
}
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.tableView];
}
- (void)initHeaderAndFooterRrfresh {
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
footer.stateLabel.textColor = [ThemeColor secondTextColor];
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
self.tableView.mj_footer = footer;
}
- (void)initSubViewConstraints {
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
- (void)footerRefresh {
self.page ++;
[self.presenter getPlayGameWithTeam:self.page];
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.roomList.count > 0 ? self.roomList.count : 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.roomList.count > 0) {
HomePlayRoomModel * model = [self.roomList objectAtIndex:indexPath.row];
if (model.isBanner) {
return 80;
}
return 94;
}
return 300;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.roomList.count > 0) {
HomePlayRoomModel * model = [self.roomList objectAtIndex: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.roomList.count > 0) {
HomePlayRoomModel * model = [self.roomList objectAtIndex:indexPath.row];
if (!model.isBanner && model.uid.integerValue > 0) {
[XPRoomViewController openRoom:model.uid 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 - XPHomeRecommendProtocol
- (void)getPlayGameWithTeamSuccess:(NSArray *)list {
[self.tableView.mj_footer endRefreshing];
if (list.count <=0) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
}
[self.roomList addObjectsFromArray:list];
[self.tableView reloadData];
}
#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 *)roomList {
if (!_roomList) {
_roomList = [NSMutableArray array];
}
return _roomList;
}
@end