Files
yinmeng-ios/xplan-ios/Main/Home/View/Mew/MewHomeView/MewMainHomeMoreGameVC.m

238 lines
11 KiB
Mathematica
Raw Normal View History

2023-12-26 14:29:53 +08:00
//
// MewMainHomeMoreGameVC.m
// xplan-ios
//
// Created by duoban on 2023/12/25.
//
#import "MewMainHomeMoreGameVC.h"
#import "MewMainHomeMoreGameCell.h"
2023-12-27 18:06:18 +08:00
#import "MewMainHomeEmptyCell.h"
2023-12-26 14:29:53 +08:00
#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];
2024-01-02 10:19:12 +08:00
[self initHeaderAndFooterRrfresh];
2023-12-26 14:29:53 +08:00
}
-(void)installUI{
[self.view addSubview:self.mewBgImageView];
[self.view addSubview:self.mewBackBtn];
[self.view addSubview:self.mewCollectionView];
}
2024-01-02 10:19:12 +08:00
- (void)initHeaderAndFooterRrfresh {
MewRefreshSvgaHeader *header = [MewRefreshSvgaHeader headerWithRefreshingTarget:self refreshingAction:@selector(mew_headerRefresh)];
self.mewCollectionView.mj_header = header;
[self.mewCollectionView.mj_header beginRefreshing];
2023-12-26 14:29:53 +08:00
2024-01-02 10:19:12 +08:00
}
2023-12-26 14:29:53 +08:00
-(void)mew_headerRefresh{
[self.presenter mew_getMainHomeLittleGameList];
[self.presenter mew_getMainHomeGameFriendList];
}
-(void)installConstraints{
[self.mewBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
2023-12-28 17:23:49 +08:00
make.left.right.top.equalTo(self.view);
2023-12-26 14:29:53 +08:00
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";
2023-12-27 18:06:18 +08:00
gameInfo.name = @"扩列交友";
2023-12-26 14:29:53 +08:00
[self.mewGameList addObject:gameInfo];
[self.mewCollectionView reloadData];
}
///
-(void)mew_getMainHomeGameFriendListSuccess:(NSArray *)list{
2024-01-02 10:19:12 +08:00
[self.mewCollectionView.mj_header endRefreshing];
2023-12-26 14:29:53 +08:00
self.mewRoomList = [NSMutableArray arrayWithArray:list];
[self.mewCollectionView reloadData];
}
2024-01-02 10:19:12 +08:00
-(void)mew_getMainHomeGameFriendListFail{
[self.mewCollectionView.mj_header endRefreshing];
}
2023-12-26 14:29:53 +08:00
#pragma mark - MewMainHomeMoreGameHeadViewDelegate
- (void)mew_selectGameAction:(MewMainHomeLittleGameInfoModel *)gameInfo{
2023-12-27 18:06:18 +08:00
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_homepage_moregame_tab_click eventAttributes:@{@"name":gameInfo.name}];
2023-12-26 14:29:53 +08:00
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];
2023-12-27 16:13:11 +08:00
if(sourceModel.needOpenSelfRoom == YES){
[self mew_clickMyRoom:[AccountInfoStorage instance].getUid];
return;
}
2023-12-26 14:29:53 +08:00
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 {
2023-12-27 18:46:45 +08:00
if(code == 10108){
2024-01-30 16:46:31 +08:00
[self showRealNameAuthenticationTipsAlertView:@"为了营造更安全的网络环境\n在 开通个人房间前\n需要先进行实名认证" isShowRoom:YES];
2023-12-27 18:46:45 +08:00
return;
}
2023-12-26 14:29:53 +08:00
[XCHUDTool showErrorWithMessage:msg];
}
2023-12-28 17:23:49 +08:00
} uid:uid rid:gameInfo.mgId type:[gameInfo.mgId isEqualToString:@"-9999"] ? @"2":@"1"] ;
2023-12-26 14:29:53 +08:00
}
}
#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){
2023-12-27 18:06:18 +08:00
MewMainHomeEmptyCell * emptyCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MewMainHomeEmptyCell class]) forIndexPath:indexPath];
2023-12-26 14:29:53 +08:00
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;
2023-12-27 18:06:18 +08:00
[_mewCollectionView registerClass:[MewMainHomeEmptyCell class] forCellWithReuseIdentifier:NSStringFromClass([MewMainHomeEmptyCell class])];
2023-12-26 14:29:53 +08:00
[_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