Files
yinmeng-ios/xplan-ios/Main/Home/View/Mew/MewHomeView/MewMainHomePartyVC.m
liyuhua 64e3eafaa8 埋点
2023-12-27 18:06:18 +08:00

300 lines
12 KiB
Objective-C

//
// MewMainHomePartyVC.m
// xplan-ios
//
// Created by duoban on 2023/12/20.
//
#import "MewMainHomePartyVC.h"
#import "MewMainHomePartyHeadView.h"
#import "MewMainHomePartyCell.h"
#import "MewMainHomeEmptyCell.h"
#import "MewHomeManager.h"
#import "MewMainHomeProtocol.h"
#import "XPWebViewController.h"
#import "XPRoomViewController.h"
#import "Api+MewHomeApi.h"
#import "MewMainHomeMenuDataModel.h"
#import "XPHomeRecommendOtherRoomView.h"
#import "Api+Room.h"
#import "XPLittleGameRoomOpenView.h"
#import "MewMainHomeMoreGameVC.h"
@interface MewMainHomePartyVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,MewMainHomePartyHeadViewDelegate,XPHomeRecommendOtherRoomViewDelegate>
@property(nonatomic,strong) UICollectionView *mewCollectionView;
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
@property(nonatomic,strong) NSArray *mewDataList;
@property(nonatomic,copy) NSArray *mewMenuList;
@property (nonatomic, copy) NSArray*mewBannerArray;
@property(nonatomic,copy) NSArray *mewGiftRecordList;
@end
@implementation MewMainHomePartyVC
@synthesize parentMode = _parentMode;
- (BOOL)isHiddenNavBar {
return YES;
}
- (MewHomeManager *)createPresenter {
return [[MewHomeManager alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[self installUI];
[self installConstraints];
[self headerRefresh];
}
-(void)installUI{
[self.view addSubview:self.mewCollectionView];
}
-(void)installConstraints{
[self.mewCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
}
- (void)headerRefresh {
if (_parentMode) return;
[self.presenter mew_requestMainHomeTopDataList];
[self.presenter mew_requestMainHomeGiftRecordList];
[self.presenter mew_getMainHomeBannerList];
[self.presenter mew_requestMainHomePersonalRoomList:[AccountInfoStorage instance].getUid];
}
#pragma mark- MewMainHomeProtocol
///获取首页轮播图列表成功
-(void)mew_getHomeTopDataSuccess:(NSArray *)menuList{
self.mewMenuList = menuList;
[self.mewCollectionView reloadData];
}
///获取首页轮播图列表失败
-(void)mew_getHomeTopDataFail{
}
/// 获取全服礼物记录列表
-(void)mew_getHomeGiftRecordListSuccess:(NSArray *)list{
self.mewGiftRecordList = list;
[self.mewCollectionView reloadData];
}
/// 获取全服礼物记录列表失败
-(void)mew_getHomeGiftRecordListFail{
}
-(void)mew_getMainHomeBannerListSuccess:(NSArray *)list{
self.mewBannerArray = list;
[self.mewCollectionView reloadData];
}
//获取热门房间
-(void)mew_getHomePersonalRoomListSuccess:(NSArray *)list{
self.mewDataList = list;
if(self.delegate && [self.delegate respondsToSelector:@selector(mew_RefreshSucceed:)]){
[self.delegate mew_RefreshSucceed:self];
}
[self.mewCollectionView reloadData];
}
-(void)mew_getHomePersonalRoomListFail{
if(self.delegate && [self.delegate respondsToSelector:@selector(mew_RefreshSucceed:)]){
[self.delegate mew_RefreshSucceed:self];
}
}
#pragma mark - MewMainHomePartyHeadViewDelegate
/// 点击banner
- (void)mewClickBannerAction:(MewMainHomeBannerInfoModel *_Nullable)info{
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_homepage_banner_click];
switch (info.skipType) {
case MewMainHomeBannerInfoModelSkipType_Room:
{
if (info.skipUri.length > 0) {
[XPRoomViewController openRoom:info.skipUri viewController:self];
}
}
break;
case MewMainHomeBannerInfoModelSkipType_Web:
{
XPWebViewController *vc = [[XPWebViewController alloc]init];
vc.url = info.skipUri;
[self.navigationController pushViewController:vc animated:YES];
}
break;
default:
break;
}
}
///点击热说item
- (void)mew_clickMainHomeHeadScrollView:(MewMainHomeGiftRecordModel *_Nullable)model{
if(model.roomUid.length > 0){
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_homepage_inform_click eventAttributes:@{@"roomUid":model.roomUid}];
}
if (model.roomUid.length > 0 && model.lock == NO) {
[XPRoomViewController openRoom:model.roomUid fromNick:nil fromType:UserEnterRoomFromType_Home_Recommend fromUid:nil viewController:self];
}
}
///点击顶部菜单
- (void)mew_clickMainHomeHeadViewMenu:(MewMainHomeMenuInfoModel *_Nullable)info{
if(info.isMorn == YES){
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_homepage_top_moregame_click];
MewMainHomeMoreGameVC *moreGameVC = [MewMainHomeMoreGameVC new];
[self.navigationController pushViewController:moreGameVC animated:YES];
return;
}
if (info.resourceType == MewMainHomeMenuInfoModelType_H5) {
XPWebViewController * webVC = [[ XPWebViewController alloc] init];
webVC.url = info.resourceContent;
[self.navigationController pushViewController:webVC animated:YES];
}else {
NSDictionary *typeDic = @{@"1":@"A",@"2":@"B",@"3":@"C",@"4":@"D"};
if(typeDic[info.hid]){
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_homepage_top_resource_click eventAttributes:@{@"type":typeDic[info.hid]}];
}
NSString * uid = [AccountInfoStorage instance].getUid;
if (info.hid.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 == YES ) {
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 {
[XCHUDTool showErrorWithMessage:msg];
}
} uid:uid rid:info.hid type:@"0"];
}
}
}
///点击了我的房间
- (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 - 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];
}
}
#pragma mark - JXPagingViewListViewDelegate
- (UIView *)listView {
return self.view;
}
- (UIScrollView *)listScrollView {
return self.mewCollectionView;
}
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
self.scrollCallback = callback;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if(self.scrollCallback){
self.scrollCallback(scrollView);
}
}
#pragma mark- UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.mewDataList.count > 0 ? self.mewDataList.count : 1;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
return CGSizeMake(0, kGetScaleWidth(341));
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return self.mewDataList.count == 0 ? CGSizeMake(KScreenWidth, 150):CGSizeMake(kGetScaleWidth(172), kGetScaleWidth(174));
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
if(kind == UICollectionElementKindSectionHeader){
MewMainHomePartyHeadView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:NSStringFromClass([MewMainHomePartyHeadView class]) forIndexPath:indexPath];
headView.mewMenuList = self.mewMenuList;
headView.mewBannerArray = self.mewBannerArray;
headView.mewGiftRecordList = self.mewGiftRecordList;
headView.delegate = self;
return headView;
}
return nil;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if(self.mewDataList.count == 0){
MewMainHomeEmptyCell * emptyCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MewMainHomeEmptyCell class]) forIndexPath:indexPath];
return emptyCell;
}
MewMainHomePartyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MewMainHomePartyCell class]) forIndexPath:indexPath];
cell.roomModel = [self.mewDataList safeObjectAtIndex1:indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if(self.mewDataList.count == 0)return;
MewMainHomeHotRoomModel *roomModel = [self.mewDataList safeObjectAtIndex1:indexPath.row];
[XPRoomViewController openRoom:roomModel.uid viewController:self];
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_homepage_room_click eventAttributes:@{@"erbanNo":roomModel.erbanNo}];
}
#pragma mark - 懒加载
- (UICollectionView *)mewCollectionView{
if(!_mewCollectionView){
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
layout.sectionInset = UIEdgeInsetsMake(0, kGetScaleWidth(11), kGetScaleWidth(15), kGetScaleWidth(11));
layout.minimumLineSpacing = kGetScaleWidth(8);
layout.minimumInteritemSpacing = kGetScaleWidth(4);
_mewCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
_mewCollectionView.backgroundColor = [UIColor clearColor];
_mewCollectionView.delegate = self;
_mewCollectionView.dataSource = self;
[_mewCollectionView registerClass:[MewMainHomePartyHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([MewMainHomePartyHeadView class])];
[_mewCollectionView registerClass:[MewMainHomePartyCell class] forCellWithReuseIdentifier:NSStringFromClass([MewMainHomePartyCell class])];
[_mewCollectionView registerClass:[MewMainHomeEmptyCell class] forCellWithReuseIdentifier:NSStringFromClass([MewMainHomeEmptyCell class])];
}
return _mewCollectionView;
}
@end