369 lines
12 KiB
Objective-C
369 lines
12 KiB
Objective-C
//
|
||
// XPHomeRecommendViewController.m
|
||
// YuMi
|
||
//
|
||
// Created by YuMi on 2022/2/21.
|
||
//
|
||
|
||
#import "XPHomeRecommendViewController.h"
|
||
///Third
|
||
#import <Masonry/Masonry.h>
|
||
#import <JXCategoryView/JXCategoryView.h>
|
||
#import <MJRefresh/MJRefresh.h>
|
||
#import <ReactiveObjC/ReactiveObjC.h>
|
||
///Tool
|
||
#import "YUMIMacroUitls.h"
|
||
#import "DJDKMIMOMColor.h"
|
||
#import "XPWeakTimer.h"
|
||
#import "ClientConfig.h"
|
||
#import "UIImage+Utils.h"
|
||
#import "Api+Room.h"
|
||
#import "Api+RoomSetting.h"
|
||
#import "AccountInfoStorage.h"
|
||
#import "TTPopup.h"
|
||
#import "NSArray+Safe.h"
|
||
///View
|
||
#import "XPNewHomePlayTableViewCell.h"
|
||
#import "XPNewHomeRecommendTableViewCell.h"
|
||
#import "XPNewHomePlayEmptyTableViewCell.h"
|
||
#import "XPHomeBannerTableViewCell.h"
|
||
#import "XPNewHomePartyTableViewCell.h"
|
||
#import "XPRoomViewController.h"
|
||
#import "XPWebViewController.h"
|
||
|
||
///Model
|
||
#import "HomePlayRoomModel.h"
|
||
#import "HomeBannerInfoModel.h"
|
||
#import "HomeRecommendRoomModel.h"
|
||
#import "ClanDetailInfoModel.h"
|
||
///P
|
||
#import "XPNewHomeRecommendPresenter.h"
|
||
#import "XPNewHomeRecommendProtocol.h"
|
||
UIKIT_EXTERN NSString * const kShieldingNotification;
|
||
@interface XPHomeRecommendViewController ()<UITableViewDelegate, UITableViewDataSource, XPNewHomePlayTableViewCellDelegate, XPHomeBannerTableViewCellDelegate,XPNewHomeRecommendTableViewCellDelegate,XPNewHomeRecommendProtocol>
|
||
{
|
||
NSTimer * timer;
|
||
}
|
||
///列表
|
||
@property (nonatomic,strong) UITableView *tableView;
|
||
|
||
|
||
///组队开黑
|
||
@property (nonatomic,strong) NSArray<HomePlayRoomModel *> *playTeamList;
|
||
///个人房列表数据
|
||
@property (nonatomic,strong) NSArray<HomePlayRoomModel *> *personalRoomList;
|
||
///房间信息
|
||
@property (nonatomic,strong) RoomInfoModel * roomInfo;
|
||
///是否正在请示数据,防止过多请求
|
||
@property (nonatomic,assign) BOOL isRequestData;
|
||
|
||
|
||
@end
|
||
|
||
@implementation XPHomeRecommendViewController
|
||
- (XPNewHomeRecommendPresenter *)createPresenter {
|
||
return [[XPNewHomeRecommendPresenter alloc] init];
|
||
}
|
||
- (BOOL)isHiddenNavBar {
|
||
return YES;
|
||
}
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
[self initSubViews];
|
||
[self initHeaderAndFooterRrfresh];
|
||
[self addTimer];
|
||
|
||
}
|
||
|
||
- (void)viewWillAppear:(BOOL)animated {
|
||
[super viewWillAppear:animated];
|
||
if (timer) {
|
||
[timer setFireDate:[NSDate distantPast]]; //很远的过去
|
||
}
|
||
}
|
||
|
||
- (void)viewWillDisappear:(BOOL)animated {
|
||
[super viewWillDisappear:animated];
|
||
if (timer) {
|
||
//关闭定时器
|
||
[timer setFireDate:[NSDate distantFuture]]; //很远的将来
|
||
}
|
||
}
|
||
-(void)dealloc{
|
||
[[NSNotificationCenter defaultCenter]removeObserver:self];
|
||
}
|
||
#pragma mark - InitHttp
|
||
- (void)addTimer {
|
||
timer = [XPWeakTimer scheduledTimerWithTimeInterval:15 block:^(id userInfo) {
|
||
[self requestData];
|
||
} userInfo:nil repeats:YES];
|
||
}
|
||
-(void)requestData{
|
||
///加锁,防止测试发现偶尔会出现闪退bug
|
||
@synchronized (self.presenter) {
|
||
if(self.isRequestData == YES)return;
|
||
self.isRequestData = YES;
|
||
|
||
///网络请求异步加载
|
||
dispatch_group_t group =dispatch_group_create();
|
||
// 并行队列
|
||
dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
|
||
|
||
|
||
dispatch_group_enter(group);
|
||
dispatch_group_async(group, queue, ^{
|
||
|
||
[self.presenter getPlayGameWithTeam:1 withGroup:group];
|
||
|
||
});
|
||
dispatch_group_enter(group);
|
||
dispatch_group_async(group, queue, ^{
|
||
|
||
[self.presenter getHomePersonalRoomListWithGroup:group];
|
||
|
||
});
|
||
|
||
|
||
|
||
|
||
dispatch_group_notify(group,dispatch_get_main_queue(), ^{
|
||
self.isRequestData = NO;
|
||
[self.tableView.mj_header endRefreshing];
|
||
[self.tableView reloadData];
|
||
});
|
||
|
||
}
|
||
}
|
||
- (void)headerRefresh {
|
||
self.isRequestData = NO;
|
||
[self requestData];
|
||
}
|
||
|
||
- (void)initHeaderAndFooterRrfresh {
|
||
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
|
||
header.stateLabel.font = [UIFont systemFontOfSize:10.0];
|
||
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:10.0];
|
||
header.stateLabel.textColor = [DJDKMIMOMColor secondTextColor];
|
||
header.lastUpdatedTimeLabel.textColor = [DJDKMIMOMColor secondTextColor];
|
||
self.tableView.mj_header = header;
|
||
[self.tableView.mj_header beginRefreshing];
|
||
}
|
||
|
||
#pragma mark - Private Method
|
||
- (void)initSubViews {
|
||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shieldingNotification) name:kShieldingNotification object:nil];
|
||
self.view.backgroundColor = [UIColor clearColor];
|
||
[self.view addSubview:self.tableView];
|
||
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.edges.mas_equalTo(self.view);
|
||
}];
|
||
|
||
}
|
||
-(void)shieldingNotification{
|
||
[self requestData];
|
||
}
|
||
#pragma mark - UITableViewDelegate And UITableViewDataSource
|
||
|
||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
||
return 2;
|
||
}
|
||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||
if(section == 0)return self.playTeamList.count > 0 ? 1 : 0;
|
||
return self.personalRoomList.count > 0 ? self.personalRoomList.count : 1;
|
||
|
||
}
|
||
|
||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||
if (indexPath.section == 0) {
|
||
return kGetScaleWidth(102);
|
||
}
|
||
return self.personalRoomList.count > 0 ? kGetScaleWidth(104) : 300;
|
||
|
||
}
|
||
|
||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||
if(indexPath.section == 0) {
|
||
XPNewHomePlayTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
|
||
if (cell == nil) {
|
||
cell = [[XPNewHomePlayTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
|
||
}
|
||
|
||
|
||
cell.playRoomList = self.playTeamList;
|
||
|
||
cell.delegate = self;
|
||
return cell;
|
||
|
||
}
|
||
|
||
if(self.personalRoomList.count == 0){
|
||
XPNewHomePlayEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomePlayEmptyTableViewCell class])];
|
||
if (cell == nil) {
|
||
cell = [[XPNewHomePlayEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPNewHomePlayEmptyTableViewCell class])];
|
||
}
|
||
|
||
[cell setConstraints];
|
||
[cell setTitle:YMLocalizedString(@"XPGuildEmptyCollectionViewCell0")];
|
||
return cell;
|
||
}
|
||
|
||
XPNewHomePartyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomePartyTableViewCell class])];
|
||
if (cell == nil) {
|
||
cell = [[XPNewHomePartyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPNewHomePartyTableViewCell class])];
|
||
}
|
||
cell.roomInfo = [self.personalRoomList safeObjectAtIndex1:indexPath.row];
|
||
return cell;
|
||
|
||
}
|
||
|
||
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
|
||
|
||
return 0.01;
|
||
|
||
}
|
||
|
||
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
|
||
return 0.01;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||
if(indexPath.section == 3) {
|
||
if (self.personalRoomList.count > 0) {
|
||
HomePlayRoomModel * roomInfo1 = [self.personalRoomList safeObjectAtIndex1:indexPath.row];
|
||
if (roomInfo1.uid.length > 0) {
|
||
[XPRoomViewController openRoom:roomInfo1.uid viewController:self];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
#pragma mark - XPNewHomeRecommendTableViewCellDelegate
|
||
- (void)xPNewHomeRecommendTableViewCell:(XPNewHomeRecommendTableViewCell *)view didSelectItem:(HomeRecommendRoomModel *)info {
|
||
if (info.roomUid.length > 0) {
|
||
[XPRoomViewController openRoom:info.roomUid viewController:self];
|
||
}
|
||
}
|
||
|
||
#pragma mark - XPNewHomePlayTableViewCellDelegate
|
||
- (void)xPNewHomePlayTableViewCell:(XPNewHomePlayTableViewCell *)cell didSelectItem:(HomePlayRoomModel *)info {
|
||
if (info.uid.length > 0) {
|
||
[XPRoomViewController openRoom:info.uid viewController:self];
|
||
}
|
||
}
|
||
- (void)chooseGameAction{
|
||
// XPHomeGameView *gameView = [XPHomeGameView new];
|
||
// gameView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
|
||
// gameView.playGameList = self.littleGameArray;
|
||
// gameView.delegate = self;
|
||
// [kWindow addSubview:gameView];
|
||
}
|
||
#pragma mark - XPNewHomePlayEmptyTableViewCellDelegate
|
||
- (void)emptyCellChooseGameAction{
|
||
// XPHomeGameView *gameView = [XPHomeGameView new];
|
||
// gameView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
|
||
// gameView.playGameList = self.littleGameArray;
|
||
// gameView.delegate = self;
|
||
// [kWindow addSubview:gameView];
|
||
}
|
||
#pragma mark - XPHomeBannerTableViewCell
|
||
- (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)getHomeRecommendRoomListSuccess:(NSArray *)list withGroup:(nonnull dispatch_group_t)group{
|
||
|
||
}
|
||
///房间派对
|
||
- (void)getHomePersonalRoomListSuccess:(NSArray *)list withGroup:(nonnull dispatch_group_t)group {
|
||
NSMutableArray * array = [NSMutableArray array];
|
||
for (HomePlayRoomModel * info in list) {
|
||
|
||
[array addObject:info];
|
||
|
||
}
|
||
self.personalRoomList = array;
|
||
dispatch_group_leave(group);
|
||
}
|
||
///扩列交友
|
||
- (void)getPlayGameWithTeamSuccess:(NSArray *)list withGroup:(nonnull dispatch_group_t)group{
|
||
NSMutableArray * array = [NSMutableArray array];
|
||
for (HomePlayRoomModel * info in list) {
|
||
|
||
[array addObject:info];
|
||
|
||
}
|
||
self.playTeamList = array;
|
||
dispatch_group_leave(group);
|
||
}
|
||
|
||
- (void)getHomeRecommendDataFailWithGroup:(dispatch_group_t)group {
|
||
dispatch_group_leave(group);
|
||
|
||
}
|
||
#pragma mark - JXPagingViewListViewDelegate
|
||
- (UIScrollView *)listScrollView {
|
||
return self.tableView;
|
||
}
|
||
|
||
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
|
||
self.scrollCallback = callback;
|
||
}
|
||
|
||
- (UIView *)listView {
|
||
return self.view;
|
||
}
|
||
|
||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||
if(self.scrollCallback){
|
||
self.scrollCallback(scrollView);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
- (UITableView *)tableView {
|
||
if (!_tableView) {
|
||
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
||
_tableView.delegate = self;
|
||
_tableView.dataSource = self;
|
||
_tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
|
||
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||
_tableView.backgroundColor = [UIColor clearColor];
|
||
if (@available(iOS 11.0, *)) {
|
||
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||
}
|
||
[_tableView registerClass:[XPNewHomePlayTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
|
||
[_tableView registerClass:[XPNewHomePlayEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPNewHomePlayEmptyTableViewCell class])];
|
||
[_tableView registerClass:[XPNewHomePartyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPNewHomePartyTableViewCell class])];
|
||
}
|
||
return _tableView;
|
||
}
|
||
@end
|