238 lines
11 KiB
Objective-C
238 lines
11 KiB
Objective-C
//
|
|
// MewMainHomeMoreGameVC.m
|
|
// xplan-ios
|
|
//
|
|
// Created by duoban on 2023/12/25.
|
|
//
|
|
|
|
#import "MewMainHomeMoreGameVC.h"
|
|
#import "MewMainHomeMoreGameCell.h"
|
|
#import "MewMainHomeEmptyCell.h"
|
|
#import "MewMainHomeMoreGameHeadView.h"
|
|
#import "MewHomeManager.h"
|
|
#import "Api+Room.h"
|
|
#import "Api+MewHomeApi.h"
|
|
#import "MewMainHomeMenuDataModel.h"
|
|
#import "XPRoomViewController.h"
|
|
#import "XPLittleGameRoomOpenView.h"
|
|
#import "XPHomeRecommendOtherRoomView.h"
|
|
@interface MewMainHomeMoreGameVC ()<MewMainHomeMoreGameHeadViewDelegate,XPHomeRecommendOtherRoomViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
|
|
@property(nonatomic,strong) UIButton *mewBackBtn;
|
|
@property(nonatomic,strong) UIImageView *mewBgImageView;
|
|
@property(nonatomic,strong) UICollectionView *mewCollectionView;
|
|
@property(nonatomic,strong) NSMutableArray *mewGameList;
|
|
@property(nonatomic,strong) NSMutableArray *mewRoomList;
|
|
@end
|
|
|
|
@implementation MewMainHomeMoreGameVC
|
|
- (MewHomeManager *)createPresenter {
|
|
return [[MewHomeManager alloc] init];
|
|
}
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
-(void)mew_dissViewAction{
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self installUI];
|
|
[self installConstraints];
|
|
[self initHeaderAndFooterRrfresh];
|
|
}
|
|
-(void)installUI{
|
|
[self.view addSubview:self.mewBgImageView];
|
|
[self.view addSubview:self.mewBackBtn];
|
|
[self.view addSubview:self.mewCollectionView];
|
|
}
|
|
- (void)initHeaderAndFooterRrfresh {
|
|
MewRefreshSvgaHeader *header = [MewRefreshSvgaHeader headerWithRefreshingTarget:self refreshingAction:@selector(mew_headerRefresh)];
|
|
self.mewCollectionView.mj_header = header;
|
|
[self.mewCollectionView.mj_header beginRefreshing];
|
|
|
|
}
|
|
-(void)mew_headerRefresh{
|
|
[self.presenter mew_getMainHomeLittleGameList];
|
|
[self.presenter mew_getMainHomeGameFriendList];
|
|
}
|
|
-(void)installConstraints{
|
|
[self.mewBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.top.equalTo(self.view);
|
|
make.height.mas_equalTo(kGetScaleWidth(250));
|
|
}];
|
|
[self.mewBackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(kGetScaleWidth(16));
|
|
make.width.height.mas_equalTo(18);
|
|
make.top.mas_equalTo(kStatusBarHeight+13);
|
|
}];
|
|
[self.mewCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.bottom.equalTo(self.view);
|
|
make.top.mas_equalTo(kNavigationHeight);
|
|
}];
|
|
}
|
|
///得到小游戏列表成功
|
|
-(void)mew_getMainHomeLittleGameListSuccess:(NSArray *)list{
|
|
self.mewGameList = [NSMutableArray arrayWithArray:list];
|
|
MewMainHomeLittleGameInfoModel *gameInfo = [MewMainHomeLittleGameInfoModel new];
|
|
gameInfo.mgId = @"-9999";
|
|
gameInfo.name = @"扩列交友";
|
|
[self.mewGameList addObject:gameInfo];
|
|
[self.mewCollectionView reloadData];
|
|
}
|
|
///获取游戏列表用户成功
|
|
-(void)mew_getMainHomeGameFriendListSuccess:(NSArray *)list{
|
|
[self.mewCollectionView.mj_header endRefreshing];
|
|
self.mewRoomList = [NSMutableArray arrayWithArray:list];
|
|
[self.mewCollectionView reloadData];
|
|
}
|
|
-(void)mew_getMainHomeGameFriendListFail{
|
|
[self.mewCollectionView.mj_header endRefreshing];
|
|
}
|
|
#pragma mark - MewMainHomeMoreGameHeadViewDelegate
|
|
- (void)mew_selectGameAction:(MewMainHomeLittleGameInfoModel *)gameInfo{
|
|
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_homepage_moregame_tab_click eventAttributes:@{@"name":gameInfo.name}];
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
if (gameInfo.mgId.length > 0 && uid.length > 0) {
|
|
[Api mew_RequestMainHomePickResource:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
if (code == 200) {
|
|
MewMainHomeMenuDataModel * sourceModel = [MewMainHomeMenuDataModel modelWithDictionary:data.data];
|
|
if(sourceModel.needOpenSelfRoom == YES){
|
|
[self mew_clickMyRoom:[AccountInfoStorage instance].getUid];
|
|
return;
|
|
}
|
|
if (sourceModel.isPick) {
|
|
if([sourceModel.uid isEqualToString:[AccountInfoStorage instance].getUid]){
|
|
[self mew_clickMyRoom:sourceModel.uid];
|
|
return;
|
|
}
|
|
if (sourceModel.uid.integerValue > 0) {
|
|
[XPRoomViewController openRoom:sourceModel.uid fromNick:nil fromType:UserEnterRoomFromType_Home_Recommend fromUid:nil viewController:self];
|
|
}
|
|
} else {
|
|
XPHomeRecommendOtherRoomView * recommendView = [[XPHomeRecommendOtherRoomView alloc] init];
|
|
recommendView.delegate = self;
|
|
recommendView.roomInfo = sourceModel;
|
|
[TTPopup popupView:recommendView style:TTPopupStyleAlert];
|
|
}
|
|
} else {
|
|
if(code == 10108){
|
|
[self showRealNameAuthenticationTipsAlertView:@"为了营造更安全的网络环境\n在 开通个人房间前\n需要先进行实名认证" isShowRoom:YES];
|
|
return;
|
|
}
|
|
[XCHUDTool showErrorWithMessage:msg];
|
|
}
|
|
} uid:uid rid:gameInfo.mgId type:[gameInfo.mgId isEqualToString:@"-9999"] ? @"2":@"1"] ;
|
|
}
|
|
}
|
|
#pragma mark - XPHomeRecommendOtherRoomViewDelegate
|
|
- (void)xPHomeRecommendOtherRoomView:(XPHomeRecommendOtherRoomView *)view didClickEnterRoom:(MewMainHomeMenuDataModel *)model {
|
|
if (model.uid.integerValue > 0) {
|
|
if([model.uid isEqualToString:[AccountInfoStorage instance].getUid]){
|
|
[self mew_clickMyRoom:model.uid];
|
|
return;
|
|
}
|
|
[XPRoomViewController openRoom:model.uid fromNick:nil fromType:UserEnterRoomFromType_Home_Recommend fromUid:nil viewController:self];
|
|
}
|
|
}
|
|
///点击了我的房间
|
|
- (void)mew_clickMyRoom:(NSString *)roomUid{
|
|
|
|
[Api getRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
if (code == 200) {
|
|
RoomInfoModel * roomInfo = [RoomInfoModel modelWithJSON:data.data];
|
|
if (roomInfo.isReselect) {
|
|
XPLittleGameRoomOpenView * roomOpenView = [[XPLittleGameRoomOpenView alloc] init];
|
|
roomOpenView.roomInfo = roomInfo;
|
|
roomOpenView.currentVC = self;
|
|
[TTPopup popupView:roomOpenView style:TTPopupStyleActionSheet];
|
|
} else {
|
|
[XPRoomViewController openRoom:roomUid viewController:self];
|
|
}
|
|
} else {
|
|
[self showErrorToast:msg];
|
|
}
|
|
} uid:roomUid intoUid:roomUid];
|
|
}
|
|
#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
return self.mewRoomList.count > 0 ? self.mewRoomList.count : 1;
|
|
}
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
|
|
|
|
return CGSizeMake(0, kGetScaleWidth(67));
|
|
}
|
|
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
return self.mewRoomList.count == 0 ? CGSizeMake(KScreenWidth, 150):CGSizeMake(kGetScaleWidth(168), kGetScaleWidth(148));
|
|
}
|
|
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
if(kind == UICollectionElementKindSectionHeader){
|
|
MewMainHomeMoreGameHeadView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
|
|
withReuseIdentifier:NSStringFromClass([MewMainHomeMoreGameHeadView class]) forIndexPath:indexPath];
|
|
|
|
headView.mewGameList = self.mewGameList;
|
|
headView.delegate = self;
|
|
|
|
return headView;
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
}
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
if(self.mewRoomList.count == 0){
|
|
MewMainHomeEmptyCell * emptyCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MewMainHomeEmptyCell class]) forIndexPath:indexPath];
|
|
return emptyCell;
|
|
}
|
|
MewMainHomeMoreGameCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MewMainHomeMoreGameCell class]) forIndexPath:indexPath];
|
|
cell.moreGameModel = [self.mewRoomList safeObjectAtIndex1:indexPath.row];
|
|
return cell;
|
|
}
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
if(self.mewRoomList.count == 0)return;
|
|
MewMainHomeHotRoomModel *roomModel = [self.mewRoomList safeObjectAtIndex1:indexPath.row];
|
|
[XPRoomViewController openRoom:roomModel.uid viewController:self];
|
|
|
|
|
|
}
|
|
#pragma mark - 懒加载
|
|
- (UIButton *)mewBackBtn{
|
|
if(!_mewBackBtn){
|
|
_mewBackBtn = [UIButton new];
|
|
[_mewBackBtn setImage:kImage(@"mew_mainHome_more_game_back") forState:UIControlStateNormal];
|
|
[_mewBackBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
|
|
[_mewBackBtn addTarget:self action:@selector(mew_dissViewAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _mewBackBtn;
|
|
}
|
|
- (UICollectionView *)mewCollectionView{
|
|
if(!_mewCollectionView){
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
|
|
|
|
layout.sectionInset = UIEdgeInsetsMake(kGetScaleWidth(16), kGetScaleWidth(15), kGetScaleWidth(15), kGetScaleWidth(15));
|
|
layout.minimumLineSpacing = kGetScaleWidth(8);
|
|
layout.minimumInteritemSpacing = kGetScaleWidth(8);
|
|
_mewCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
_mewCollectionView.backgroundColor = [UIColor clearColor];
|
|
_mewCollectionView.delegate = self;
|
|
_mewCollectionView.dataSource = self;
|
|
|
|
[_mewCollectionView registerClass:[MewMainHomeEmptyCell class] forCellWithReuseIdentifier:NSStringFromClass([MewMainHomeEmptyCell class])];
|
|
[_mewCollectionView registerClass:[MewMainHomeMoreGameHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([MewMainHomeMoreGameHeadView class])];
|
|
[_mewCollectionView registerClass:[MewMainHomeMoreGameCell class] forCellWithReuseIdentifier:NSStringFromClass([MewMainHomeMoreGameCell class])];
|
|
|
|
|
|
}
|
|
return _mewCollectionView;
|
|
}
|
|
- (UIImageView *)mewBgImageView{
|
|
if(!_mewBgImageView){
|
|
_mewBgImageView = [UIImageView new];
|
|
_mewBgImageView.image = kImage(@"mew_home_top_bg_image");
|
|
}
|
|
return _mewBgImageView;
|
|
}
|
|
@end
|