Files
yinmeng-ios/xplan-ios/Main/Home/View/Mew/MewHomeView/MewMainHomeMakeFriendVC.m
2023-12-26 14:29:53 +08:00

502 lines
21 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// MewMainHomeMakeFriendVC.m
// xplan-ios
//
// Created by duoban on 2023/12/20.
//
#import "MewMainHomeMakeFriendVC.h"
#import "XPHomeListEmptyCollectionViewCell.h"
#import "MewMainHomeMakeFriendHeadView.h"
#import "MewHomeManager.h"
#import "MewMainHomeProtocol.h"
#import "MewMainHomeMenuInfoModel.h"
#import "MewMainHomeMakeFriendCell.h"
#import "XPWebViewController.h"
#import "Api+MewHomeApi.h"
#import "MewMainHomeMenuDataModel.h"
#import "XPRoomViewController.h"
#import "RoomInfoModel.h"
#import "Api+Room.h"
#import "XPLittleGameRoomOpenView.h"
#import "XPHomeRecommendOtherRoomView.h"
#import "SessionViewController.h"
#import "XPNewHomeFilterView.h"
#import "CountDownHelper.h"
#import "XPSkillCardPlayerManager.h"
#import "UploadFile.h"
#import "XPMineUserInfoViewController.h"
#import "MewMainHomeMakeFriendEmptyCell.h"
@interface MewMainHomeMakeFriendVC ()<MewMainHomeMakeFriendHeadViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,XPHomeRecommendOtherRoomViewDelegate,MewMainHomeMakeFriendCellDelegate,CountDownHelperDelegate>
@property(nonatomic,strong) UICollectionView *mewCollectionView;
@property(nonatomic,strong) NSMutableArray *mewFriendList;
@property(nonatomic,strong) NSMutableArray *mewRecommendList;
@property(nonatomic,strong) NSMutableArray *mewTabList;
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
@property(nonatomic,strong) MewMainHomeMenuInfoModel *mewMenuInfo;
@property(nonatomic,strong) MewMainHomeMakeFriendCell *mewPlayCell;
@property(nonatomic,copy) NSString *gameId;
///筛选下标
@property (nonatomic, assign) NSInteger mewIndex;
@property(nonatomic,assign) BOOL isNoChooseSex;
///性别
@property (nonatomic,strong) NSString *mewSex;
@property(nonatomic,strong) CountDownHelper *mewDownHelper;
@end
@implementation MewMainHomeMakeFriendVC
@synthesize parentMode = _parentMode;
- (MewHomeManager *)createPresenter {
return [[MewHomeManager alloc] init];
}
- (BOOL)isHiddenNavBar {
return YES;
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidAppear:animated];
[self.mewDownHelper stopCountDown];
[[XPSkillCardPlayerManager shareInstance] stopMusic];
if(self.mewPlayCell != nil){
[self.mewPlayCell mew_setPlayVoiceStatus:NO];
self.mewPlayCell = nil;
}
}
- (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;
if(self.mewPlayCell != nil){
if(self.delegate && [self.delegate respondsToSelector:@selector(mew_RefreshDataSucceed:)]){
[self.delegate mew_RefreshDataSucceed:self];
}
return;
}
[self.presenter mew_requestMainHomeTopDataList];
[self.presenter mew_requsetMainHomeGameTabList];
[self.presenter mew_requestMainHomeNewFriendListWithGender:self.mewSex gameId:self.gameId];
[self.presenter mew_RequestMainHomeFriendMahoganyList];
}
/// 刷新数据,可见时才调用
- (void)mew_RefreshFriendListData {
if (self.isViewLoaded && self.view.window) {
[self.presenter mew_requestMainHomeNewFriendListWithGender:self.mewSex gameId:self.gameId];
}
}
#pragma mark- MewMainHomeProtocol
///获取首页轮播图列表成功
-(void)mew_getHomeTopDataSuccess:(NSArray *)menuList{
for (MewMainHomeMenuInfoModel *obj in menuList) {
if(obj.posSeq == 5){
self.mewMenuInfo = obj;
break;
}
}
if(self.mewMenuInfo == nil)return;
if(self.mewPlayCell == nil){
[self.mewCollectionView reloadData];
}
}
///获取首页轮播图列表失败
-(void)mew_getHomeTopDataFail{
}
/// 发现新朋友成功
-(void)mew_getNewFriendListSuccess:(NSArray *)list gameId:(nullable NSString *)gameId{
[self hideHUD];
self.mewFriendList = [[NSMutableArray alloc]initWithArray:list];
if(self.mewPlayCell == nil){
[self.mewCollectionView reloadData];
}
if(self.delegate && [self.delegate respondsToSelector:@selector(mew_RefreshDataSucceed:)]){
[self.delegate mew_RefreshDataSucceed:self];
}
}
/// 发现新朋友失败
-(void)mew_getNewFriendListFailWithGameId:(nullable NSString *)gameId{
[self hideHUD];
if(self.delegate && [self.delegate respondsToSelector:@selector(mew_RefreshDataSucceed:)]){
[self.delegate mew_RefreshDataSucceed:self];
}
}
///大神推荐
-(void)mew_RequestMainHomeFriendMahoganyListSuccess:(NSArray *)list{
self.mewRecommendList = [NSMutableArray arrayWithArray:list];
}
///首页游戏点单分类
-(void)mew_getMainHomeGameTabList:(NSArray *)list{
if(self.mewTabList.count == 0){
self.mewTabList = [NSMutableArray arrayWithArray:list];
}else{
MewMainHomeGameTabModel *tabModel;
for (MewMainHomeGameTabModel *obj in self.mewTabList) {
if(obj.isOnClick == YES){
tabModel = obj;
break;
}
}
if(tabModel){
for (MewMainHomeGameTabModel *obj in list) {
if([obj.gameId isEqualToString:tabModel.gameId]){
obj.isOnClick = tabModel.isOnClick;
break;
}
}
}
self.mewTabList = [NSMutableArray arrayWithArray:list];
}
if(self.mewPlayCell == nil){
[self.mewCollectionView reloadData];
}
}
////// 一键匹配成功
-(void)mew_getMainHomeFriendChatPickDataSuccess:(NSString *)uid{
/// 跳聊天
NSString *sessionId = uid;
NIMSession *session = [NIMSession session:sessionId type:NIMSessionTypeP2P];
SessionViewController *sessionVC = [[SessionViewController alloc] initWithSession:session];
sessionVC.isNOAstrictChat = YES;
[self.navigationController pushViewController:sessionVC animated:YES];
}
////// 一键匹配失败
-(void)mew_getMainHomeFriendChatPickDataFail:(NSString *)msg{
}
#pragma mark - MewMainHomeMakeFriendHeadViewDelegate
///大神带飞
-(void)mew_selectGodFlightAction:(MewMainHomeMenuInfoModel *_Nullable)menuInfo{
if (menuInfo.resourceType == MewMainHomeMenuInfoModelType_H5) {
XPWebViewController * webVC = [[ XPWebViewController alloc] init];
webVC.url = menuInfo.resourceContent;
[self.navigationController pushViewController:webVC animated:YES];
}else {
NSString * uid = [AccountInfoStorage instance].getUid;
if (menuInfo.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.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 {
[XCHUDTool showErrorWithMessage:msg];
}
} uid:uid rid:menuInfo.hid type:@"0"];
}
}
}
///一键匹配
-(void)mew_selectOneClickMatchingAction:(MewMainHomeMenuInfoModel *_Nullable)menuInfo{
[self.presenter mew_getMainHomeFriendChatPickData];
}
///选择游戏
-(void)mew_selectGameFriendAction:(MewMainHomeGameTabModel *_Nullable)gameInfo type:(MewMainHomeMakeFriendHeadViewType)type sender:(UILabel *_Nullable)sender{
if(type == MewMainHomeMakeFriendHeadViewTyep_Change){
[self mew_RefreshFriendListData];
}else if (type == MewMainHomeMakeFriendHeadViewTyep_Sex){
XPNewHomeFilterView *filterView = [[XPNewHomeFilterView alloc] init];
@kWeakify(self);
@kWeakify(sender);
filterView.selectBlock = ^(NSString *gender, NSString *title, NSInteger index) {
@kStrongify(self);
@kStrongify(sender);
if(index == 404){
self.isNoChooseSex = YES;
if(self.mewPlayCell == nil){
[self.mewCollectionView reloadData];
}
return;
}
sender.text = title;
// 刷新列表
self.mewSex = gender;
self.mewIndex = index;
[self mew_RefreshFriendListData];
};
[filterView addToVCView:self.view targetView:sender selectedIndex:self.mewIndex];
}else if (type == MewMainHomeMakeFriendHeadViewTyep_Game_Select){
[self showLoading];
self.gameId = gameInfo.gameId;
[self.presenter mew_requestMainHomeNewFriendListWithGender:self.mewSex gameId:gameInfo.gameId];
}else{
[self showLoading];
self.gameId = nil;
[self.presenter mew_requestMainHomeNewFriendListWithGender:self.mewSex gameId:self.gameId];
}
}
///点击了我的房间
- (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.mewPlayCell != nil){
BOOL isVisible = YES;
CGRect cellR = [self.mewCollectionView convertRect:self.mewPlayCell.frame toView:self.mewCollectionView];
if((self.mewCollectionView.contentOffset.y - (cellR.origin.y)) > cellR.size.height){
isVisible = NO;
}
if (cellR.origin.y - self.mewCollectionView.contentOffset.y > self.mewCollectionView.frame.size.height) {//下滑的情况
isVisible = NO;
}
if(!isVisible && [self.mewPlayCell isKindOfClass:[MewMainHomeMakeFriendCell class]]) {
[self.mewDownHelper stopCountDown];
[[XPSkillCardPlayerManager shareInstance] stopMusic];
[self.mewPlayCell mew_setPlayVoiceStatus:NO];
self.mewPlayCell = nil;
}
}
if(self.scrollCallback){
self.scrollCallback(scrollView);
}
}
#pragma mark - MewMainHomeMakeFriendCellDelegate
///点击播放声音
-(void)mew_clickPlayVoiceActionWithCell:(MewMainHomeMakeFriendCell *)cell model:(MewMainHomeMakeFriendModel *)model isPlay:(BOOL)isPlay{
if(isPlay == YES){
if(self.mewPlayCell != nil){
[self.mewDownHelper stopCountDown];
[self.mewPlayCell mew_setPlayVoiceStatus:NO];
[[XPSkillCardPlayerManager shareInstance] stopMusic];
self.mewPlayCell = nil;
}
self.mewPlayCell = cell;
NSString *fileName = [[model.playUrl componentsSeparatedByString:@"/"] lastObject];
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) safeObjectAtIndex1:0] stringByAppendingPathComponent:@"kMewMainHomeVoiceCard"];
NSString *fullPath = [filePath stringByAppendingPathComponent:fileName];
if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
[self mew_setplayAudioWithUrl:fullPath ];
}else{
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSFileManager *fileMgr = [[NSFileManager alloc] init];
[fileMgr createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
}
[UploadFile mew_downloadAudioWithFileName:fileName musicUrl:model.playUrl mainFileName:@"kMewMainHomeVoiceCard" completion:^(BOOL isSuccess, NSString *editAudioPath) {
if(isSuccess){
[self mew_setplayAudioWithUrl:editAudioPath];
}else{
[self.mewPlayCell mew_setPlayVoiceStatus:NO];
[[XPSkillCardPlayerManager shareInstance] stopMusic];
self.mewPlayCell = nil;
}
}];
}
}else{
[self.mewDownHelper stopCountDown];
[self.mewPlayCell mew_setPlayVoiceStatus:NO];
[[XPSkillCardPlayerManager shareInstance] stopMusic];
self.mewPlayCell = nil;
}
}
/// 播放录音
/// - Parameters:
/// - url: 录音链接
/// - isDelay: 是否延时0.5秒播放录音因为如果在麦上的话需要先关麦再播放所以要延时0.5秒来关麦后再播放,不然会没声音
-(void)mew_setplayAudioWithUrl:(NSString*)url {
NSInteger getCurrentTime = ceil([self.mewPlayCell.friendModel.playTime integerValue]);
[self.mewDownHelper openCountdownWithTime:(int)getCurrentTime];
[[XPSkillCardPlayerManager shareInstance] playerVoiceWithPath:url completionBlock:^{
[[XPSkillCardPlayerManager shareInstance] stopMusic];
}];
}
///点击房间
-(void)mew_clickRoomBtnActionWithModel:(MewMainHomeMakeFriendModel *)model{
if(model.lock == 1)return;
if (model.inRoomUid.length > 0) {
if (model.inMic) {
[XPRoomViewController openRoom:model.inRoomUid fromNick:model.nick fromType:UserEnterRoomFromType_Follow_User fromUid:[NSString stringWithFormat:@"%@",model.uid] viewController:self];
}else{
[XPRoomViewController openRoom:model.inRoomUid fromNick:nil fromType:UserEnterRoomFromType_Home_Recommend fromUid:nil viewController:self];
}
}
}
///点击头像
-(void)mew_clickAvatarBtnActionWithModel:(MewMainHomeMakeFriendModel *)model{
XPMineUserInfoViewController *userInfoVC = [XPMineUserInfoViewController new];
userInfoVC.uid = [model.uid integerValue];
[self.navigationController pushViewController:userInfoVC animated:YES];
}
#pragma mark- UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if(self.gameId != nil && self.mewFriendList.count == 0){
return self.mewRecommendList.count + 1;
}
return self.mewFriendList.count > 0 ? self.mewFriendList.count : 1;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
return CGSizeMake(0, kGetScaleWidth(206));
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if(self.gameId != nil && self.mewFriendList.count == 0){
return indexPath.row == 0 ? CGSizeMake(KScreenWidth, 255):CGSizeMake(kGetScaleWidth(168), kGetScaleWidth(184));
}
return self.mewFriendList.count == 0 ? CGSizeMake(KScreenWidth, 150):CGSizeMake(kGetScaleWidth(168), kGetScaleWidth(184));
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
if(kind == UICollectionElementKindSectionHeader){
MewMainHomeMakeFriendHeadView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:NSStringFromClass([MewMainHomeMakeFriendHeadView class]) forIndexPath:indexPath];
headView.mewMeunInfo = self.mewMenuInfo;
headView.mewGameList = self.mewTabList;
headView.delegate = self;
return headView;
}
return nil;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if(self.gameId != nil && self.mewFriendList.count == 0){
if(indexPath.row == 0){
MewMainHomeMakeFriendEmptyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MewMainHomeMakeFriendEmptyCell class]) forIndexPath:indexPath];
return cell;
}
MewMainHomeMakeFriendCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MewMainHomeMakeFriendCell class]) forIndexPath:indexPath];
cell.friendModel = [self.mewRecommendList safeObjectAtIndex1:indexPath.row];
cell.delegate = self;
return cell;
}
if(self.mewFriendList.count == 0){
XPHomeListEmptyCollectionViewCell * emptyCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPHomeListEmptyCollectionViewCell class]) forIndexPath:indexPath];
return emptyCell;
}
MewMainHomeMakeFriendCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([MewMainHomeMakeFriendCell class]) forIndexPath:indexPath];
cell.friendModel = [self.mewFriendList safeObjectAtIndex1:indexPath.row];
cell.delegate = self;
return cell;
}
#pragma mark - CountDownHelperDelegate
///倒计时结束
- (void)onCountdownFinish{
if(self.mewPlayCell != nil){
[self.mewPlayCell mew_setPlayVoiceTime:0];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self.mewPlayCell mew_setPlayVoiceStatus:NO];
self.mewPlayCell = nil;
});
}
}
///倒计时进行
- (void)onCountdownOpen:(int)time{
if(self.mewPlayCell != nil){
[self.mewPlayCell mew_setPlayVoiceTime:(int)time + 1];
}
}
#pragma mark - 懒加载
- (UICollectionView *)mewCollectionView{
if(!_mewCollectionView){
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
layout.sectionInset = UIEdgeInsetsMake(0, 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:[XPHomeListEmptyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPHomeListEmptyCollectionViewCell class])];
[_mewCollectionView registerClass:[MewMainHomeMakeFriendHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([MewMainHomeMakeFriendHeadView class])];
[_mewCollectionView registerClass:[MewMainHomeMakeFriendCell class] forCellWithReuseIdentifier:NSStringFromClass([MewMainHomeMakeFriendCell class])];
[_mewCollectionView registerClass:[MewMainHomeMakeFriendEmptyCell class] forCellWithReuseIdentifier:NSStringFromClass([MewMainHomeMakeFriendEmptyCell class])];
}
return _mewCollectionView;
}
- (CountDownHelper *)mewDownHelper{
if(!_mewDownHelper){
_mewDownHelper = [[CountDownHelper alloc]init];
_mewDownHelper.delegate = self;
}
return _mewDownHelper;
}
@end