Files
yinmeng-ios/xplan-ios/Main/Room/View/MoreView/View/XPRoomMoreMenuViewController.m
2022-04-20 15:34:56 +08:00

356 lines
12 KiB
Objective-C

//
// XPRoomMoreMenuViewController.m
// xplan-ios
//
// Created by 冯硕 on 2021/12/11.
//
#import "XPRoomMoreMenuViewController.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "XPMacro.h"
#import "TTPopup.h"
#import "XPConstant.h"
///Model
#import "XPRoomMoreItemModel.h"
#import "RoomInfoModel.h"
#import "AttachmentModel.h"
///View
#import "XPRoomMoreMenuCollectionViewCell.h"
#import "XPRoomInviteFansView.h"
#import "XPAcrossRoomPKViewController.h"
#import "XPAnchorPKViewController.h"
///P
#import "XPMoreMenuPresenter.h"
#import "XPMoreMenuProtocol.h"
UIKIT_EXTERN NSString * const kRoomRoomSettingNotificationKey;
UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
@interface XPRoomMoreMenuViewController ()<UICollectionViewDelegate, UICollectionViewDataSource,XPMoreMenuProtocol>
///顶部的View
@property (nonatomic,strong) UIView * topView;
///列表
@property (nonatomic,strong) UICollectionView *collectionView;
///底部的View
@property (nonatomic,strong) UIView * bottomView;
///数据源
@property (nonatomic,strong) NSArray<XPRoomMoreItemModel *> *datasource;
///房间信息
@property (nonatomic,strong) RoomInfoModel *roomInfo;
///
@property (nonatomic,weak) UINavigationController *currentNav;
@end
@implementation XPRoomMoreMenuViewController
- (instancetype)initRoomInfo:(RoomInfoModel *)roomInfo currentNav:(UINavigationController *)currentNav{
if (self = [super init]) {
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
self.roomInfo = roomInfo;
self.currentNav = currentNav;
}
return self;
}
- (XPMoreMenuPresenter *)createPresenter {
return [[XPMoreMenuPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
[self.presenter getMoreMenuDataSource:self.roomInfo];
}
#pragma mark - Private Method
- (void)initSubViews {
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.topView];
[self.view addSubview:self.collectionView];
[self.view addSubview:self.bottomView];
}
- (void)initSubViewConstraints {
[self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.collectionView.mas_top);
}];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view);
make.height.mas_equalTo(0);
make.bottom.mas_equalTo(self.bottomView.mas_top);
}];
[self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(self.view);
make.height.mas_equalTo(kSafeAreaBottomHeight);
}];
}
#pragma mark - XPMoreMenuProtocol
- (void)getMoreMenuDataSuccess:(NSArray<XPRoomMoreItemModel *> *)list {
self.datasource = list;
[self.collectionView reloadData];
CGFloat contentHeight= 24 + 36;
CGFloat itemHeight = 52;
int page = list.count % 5;
int scale = (int)list.count / (int)5;
if (page == 0) {
contentHeight += (scale *itemHeight);
} else {
contentHeight += ((scale+1) *itemHeight + scale * 10);
}
CAShapeLayer * layer = [CAShapeLayer layer];
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, KScreenWidth, contentHeight) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)];
layer.path = path.CGPath;
self.collectionView.layer.mask = layer;
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(contentHeight);
}];
}
- (void)openRoomGiftValueSuccess {
[self showSuccessToast:@"开启礼物值成功"];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)closeRoomGiftValueSuccess {
[self showSuccessToast:@"关闭礼物值成功"];
[self dismissViewControllerAnimated:YES completion:nil];
}
/// 设置公屏开关
- (void)updateRoomMessageScreenStateSuccess:(RoomInfoModel *)roomInfo {
AttachmentModel *attachement = [[AttachmentModel alloc]init];
attachement.first = CustomMessageType_Update_RoomInfo;
attachement.second = Custom_Message_Sub_Update_RoomInfo_MessageState;
attachement.data = @{@"roomInfo":roomInfo.model2dictionary};
NIMMessage *message = [[NIMMessage alloc]init];
NIMCustomObject *object = [[NIMCustomObject alloc] init];
object.attachment = attachement;
message.messageObject = object;
//构造会话
NSString * roomId = [NSString stringWithFormat:@"%ld", roomInfo.roomId];
NIMSession *session = [NIMSession session:roomId type:NIMSessionTypeChatroom];
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)openRoomDatingSuccess {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)closeRoomDatingSuccess {
[self dismissViewControllerAnimated:YES completion:nil];
}
///发布房间广播
- (void)getReleaseRadioSuccess:(XPReleaseRadioModel *)model {
[self dismissViewControllerAnimated:YES completion:^{
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomReleaseRadioNotificationKey object:model];
}];
}
///获取房间贵族小喇叭
- (void)getTrumpetSuccess:(XPNobleTrumpetModel *)model {
[self dismissViewControllerAnimated:YES completion:^{
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomNobleTrumpetNotificationKey object:model];
}];
}
#pragma mark - UICollectionViewDelegate And UICollectionViewDatasource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.datasource.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
XPRoomMoreMenuCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPRoomMoreMenuCollectionViewCell class]) forIndexPath:indexPath];
cell.itemModel = [self.datasource objectAtIndex:indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
XPRoomMoreItemModel * item = [self.datasource objectAtIndex:indexPath.row];
NSString * roomUid = [NSString stringWithFormat:@"%ld",self.roomInfo.uid];
NSString * roomId = [NSString stringWithFormat:@"%ld", self.roomInfo.roomId];
switch (item.type) {
case RoomMoreMenuType_Gift_Value_Close:
{
if (self.roomInfo.roomModeType == RoomModeType_Open_Blind) {
[self showErrorToast:@"相亲模式中不能关闭房间礼物值"];
return;
}
TTAlertConfig * config = [[TTAlertConfig alloc] init];
config.title = @"";
config.message = @"关闭礼物值将会清除当前麦上所有礼物值数据,确认关闭吗?";
[TTPopup alertWithConfig:config confirmHandler:^{
[self.presenter closeRoomGiftValue:roomUid];
} cancelHandler:^{
}];
}
break;
case RoomMoreMenuType_Gift_Value_Open:
[self.presenter openRoomGiftValue:roomUid];
break;
case RoomMoreMenuType_Message_Screen_Open:
[self.presenter updateRoomMessageScreenState:NO roomId:roomId];
break;
case RoomMoreMenuType_Message_Screen_Close:
[self.presenter updateRoomMessageScreenState:YES roomId:roomId];
break;
case RoomMoreMenuType_Gift_Effect_Open:
{
[self showSuccessToast:@"礼物特效已开启"];
NSDictionary * dic = @{@"hasAnimationEffect": @(1)};
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomGiftEffectUpdateNotificationKey object:dic];
[self dismissViewControllerAnimated:YES completion:nil];
}
break;
case RoomMoreMenuType_Gift_Effect_Close:
{
[self showSuccessToast:@"礼物特效已关闭"];
NSDictionary * dic = @{@"hasAnimationEffect": @(0)};
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomGiftEffectUpdateNotificationKey object:dic];
[self dismissViewControllerAnimated:YES completion:nil];
}
break;
case RoomMoreMenuType_Invite_Fans:
{
[self dismissViewControllerAnimated:YES completion:nil];
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.roomInfo.uid];
XPRoomInviteFansView * inviteFansView = [[XPRoomInviteFansView alloc]initWithRoomUid:roomUid];
[TTPopup popupView:inviteFansView style:TTPopupStyleActionSheet];
}
break;
case RoomMoreMenuType_Room_Setting:
{
[self dismissViewControllerAnimated:YES completion:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomRoomSettingNotificationKey object:nil];
}
break;
case RoomMoreMenuType_Room_Dating_Open:
{
if (self.roomInfo.roomModeType == RoomModeType_Open_AcrossRoomPK_mode) {
[self showErrorToast:@"跨房PK中不可开启相亲模式!"];
[self dismissViewControllerAnimated:NO completion:nil];
return;
}
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.message = @"开启相亲模式?开启同时现有礼物值将被清空";
config.confirmButtonConfig.title = @"开启";
[TTPopup alertWithConfig:config confirmHandler:^{
[self.presenter openRoomDating:roomUid];
} cancelHandler:^{
}];
}
break;
case RoomMoreMenuType_Room_Dating_Close:
{
TTAlertConfig * config = [[TTAlertConfig alloc] init];
config.title = @"提示";
config.message = @"关闭相亲模式?";
config.confirmButtonConfig.title = @"关闭";
[TTPopup alertWithConfig:config confirmHandler:^{
[self.presenter closeRoomDating:roomUid];
} cancelHandler:^{
}];
}
break;
case RoomMoreMenuType_Release_Radio:
{
[self.presenter getRoomRadioMessageListWithType:[NSString stringWithFormat:@"%zd", self.roomInfo.type]];
}
break;
case RoomMoreMenuType_Room_trumpet:
[self.presenter getRoomgetUserVipRoomTrumpet:roomUid];
break;
case RoomMoreMenuType_Room_Across_PK_Open:
{
if (self.roomInfo.roomModeType == RoomModeType_Open_Blind) {
[self showErrorToast:@"相亲中不可开启跨房PK!"];
[self dismissViewControllerAnimated:NO completion:nil];
return;
}
[self dismissViewControllerAnimated:NO completion:nil];
XPAcrossRoomPKViewController * acrossRoomPKVC = [[XPAcrossRoomPKViewController alloc] initWithRoomUid:roomUid];
[self.currentNav presentViewController:acrossRoomPKVC animated:YES completion:nil];
}
break;
case RoomMoreMenuType_Room_Across_PK_Close:
{
[self showErrorToast:@"正在跨房PK中!"];
[self dismissViewControllerAnimated:NO completion:nil];
}
break;
case RoomMoreMenuType_Room_Anchor_PK_Open:
{
[self dismissViewControllerAnimated:NO completion:nil];
XPAnchorPKViewController * acrossRoomPKVC = [[XPAnchorPKViewController alloc] initWithRoomUid:roomUid];
[self.currentNav presentViewController:acrossRoomPKVC animated:YES completion:nil];
}
break;
case RoomMoreMenuType_Room_Anchor_PK_Close:
{
[self showErrorToast:@"主播正在PK中!"];
[self dismissViewControllerAnimated:NO completion:nil];
}
break;
default:
break;
}
}
#pragma mark - Event Response
- (void)disMissRecognizer {
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Getters And Setters
- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.sectionInset = UIEdgeInsetsMake(24, 0, 10, 0);
layout.itemSize = CGSizeMake(KScreenWidth /5, 52);
layout.minimumLineSpacing = 10;
layout.minimumInteritemSpacing = 0;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.backgroundColor = [UIColor blackColor];
_collectionView.alpha = 0.9;
_collectionView.scrollEnabled = NO;
[_collectionView registerClass:[XPRoomMoreMenuCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPRoomMoreMenuCollectionViewCell class])];
}
return _collectionView;
}
- (UIView *)topView {
if (!_topView) {
_topView = [[UIView alloc] init];
_topView.backgroundColor = [UIColor clearColor];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disMissRecognizer)];
[_topView addGestureRecognizer:tap];
}
return _topView;
}
- (UIView *)bottomView {
if (!_bottomView) {
_bottomView = [[UIView alloc] init];
_bottomView.backgroundColor = [UIColor blackColor];
_bottomView.alpha = 0.9;
}
return _bottomView;
}
@end