更换项目

This commit is contained in:
liyuhua
2023-07-14 18:50:55 +08:00
parent fff67e0aee
commit fc0480ea2c
9340 changed files with 236665 additions and 221827 deletions

View File

@@ -0,0 +1,443 @@
//
// 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, XPNewHomePlayEmptyTableViewCellDelegate,XPNewHomeRecommendTableViewCellDelegate,XPNewHomeRecommendProtocol>
{
NSTimer * timer;
}
///
@property (nonatomic,strong) UITableView *tableView;
///
@property (nonatomic,strong) NSArray<HomeBannerInfoModel *> *bannerList;
///
@property (nonatomic,strong) NSArray<HomeRecommendRoomModel *> *recommendList;
///
@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 getHomeRecommendRoomListWithGroup:group];
});
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_enter(group);
dispatch_group_async(group, queue, ^{
[self.presenter getHomeTopBannerListWithGroup:group];
});
dispatch_group_enter(group);
dispatch_group_async(group, queue, ^{
[self getRoomInfoWithGroup: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)getRoomInfoWithGroup:(dispatch_group_t)group{
NSString* roomUid = [AccountInfoStorage instance].getUid;
[Api getRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
RoomInfoModel * roomInfo = [RoomInfoModel modelWithJSON:data.data];
self.roomInfo = roomInfo;
}
dispatch_group_leave(group);
} uid:roomUid intoUid:roomUid];
}
- (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 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return self.recommendList.count > 0 ? 1 : 0;
} else if(section == 1) {
return self.bannerList.count > 0 ? 1 : 0;
} else if(section == 2) {
return self.recommendList != nil ? 1 : 0;
} else {
return self.personalRoomList.count > 0 ? self.personalRoomList.count : 0;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
return 160 * kScreenScale;
} else if(indexPath.section == 1) {
return 96;
} else if(indexPath.section == 2) {
return 65;
} else {
return 94;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
XPNewHomeRecommendTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomeRecommendTableViewCell class])];
if (cell == nil) {
cell = [[XPNewHomeRecommendTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPNewHomeRecommendTableViewCell class])];
}
[cell setRecommendsList:self.recommendList];
cell.delegate = self;
return cell;
} else if(indexPath.section == 1) {
XPHomeBannerTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPHomeBannerTableViewCell class])];
if (cell == nil) {
cell = [[XPHomeBannerTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPHomeBannerTableViewCell class])];
}
cell.bannerList = self.bannerList;
cell.delegate = self;
return cell;
} else if(indexPath.section == 2) {
if (self.playTeamList.count > 0) {
XPNewHomePlayTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
if (cell == nil) {
cell = [[XPNewHomePlayTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
}
// cell.isClan = self.roomInfo.isPermitRoom == PermitRoomType_Licnese;
cell.isClan = YES;
cell.playRoomList = self.playTeamList;
cell.delegate = self;
return cell;
} else {
XPNewHomePlayEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPNewHomePlayEmptyTableViewCell class])];
if (cell == nil) {
cell = [[XPNewHomePlayEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPNewHomePlayEmptyTableViewCell class])];
}
// cell.isClan = self.roomInfo.isPermitRoom == PermitRoomType_Licnese;
cell.isClan = YES;
cell.delegate = self;
return cell;
}
} else {
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 {
if(section == 0){return 5;}
if (section == 2) {
return 50;
}else if (section == 3){
return 50;
}
return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView * view = [[UIView alloc] init];
if(self.recommendList == nil && section == 2)return view;
if(self.personalRoomList == nil && section == 3)return view;
if (section == 2 || section == 3) {
view.frame = CGRectMake(0,0, KScreenWidth, 50);
UILabel * label = [[UILabel alloc] init];
label.textColor = [DJDKMIMOMColor mainTextColor];
label.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
if (section == 2) {
label.text = YMLocalizedString(@"XPHomeRecommendViewController0");
} else {
label.text = YMLocalizedString(@"XPHomeRecommendViewController1");
}
[view addSubview:label];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(16);
make.left.mas_equalTo(view).offset(15);
make.height.mas_equalTo(22);
}];
}
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [UIView new];
}
- (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)getHomeTopBannerListSuccess:(NSArray *)list menuList:(NSArray *)memuList withGroup:(nonnull dispatch_group_t)group{
self.bannerList = list;
dispatch_group_leave(group);
}
///
- (void)getHomeRecommendRoomListSuccess:(NSArray *)list withGroup:(nonnull dispatch_group_t)group{
self.recommendList= list;
dispatch_group_leave(group);
}
///
- (void)getHomePersonalRoomListSuccess:(NSArray *)list withGroup:(nonnull dispatch_group_t)group {
NSMutableArray * array = [NSMutableArray array];
for (HomePlayRoomModel * info in list) {
if(info.isBanner) {
self.bannerList = info.bannerVoList;
} else {
[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) {
if(info.isBanner) {
self.bannerList = info.bannerVoList;
} else {
[array addObject:info];
}
}
self.playTeamList = array;
dispatch_group_leave(group);
}
- (void)getHomeRecommendDataFailWithGroup:(dispatch_group_t)group {
dispatch_group_leave(group);
}
#pragma mark - JXCategoryListContentViewDelegate
- (UIView *)listView {
return self.view;
}
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
_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:[XPNewHomeRecommendTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPNewHomeRecommendTableViewCell class])];
[_tableView registerClass:[XPNewHomePlayTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPNewHomePlayTableViewCell class])];
[_tableView registerClass:[XPNewHomePlayEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPNewHomePlayEmptyTableViewCell class])];
[_tableView registerClass:[XPHomeBannerTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPHomeBannerTableViewCell class])];
[_tableView registerClass:[XPNewHomePartyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPNewHomePartyTableViewCell class])];
}
return _tableView;
}
@end