1263 lines
48 KiB
Objective-C
1263 lines
48 KiB
Objective-C
//
|
||
// YMSendGiftView.m
|
||
// YUMI
|
||
//
|
||
// Created by YUMI on 2021/11/9.
|
||
//
|
||
|
||
#import "XPSendGiftView.h"
|
||
///Third
|
||
#import <Masonry/Masonry.h>
|
||
#import <NIMSDK/NIMSDK.h>
|
||
#import <UIImageView+WebCache.h>
|
||
///Tool
|
||
#import "YUMIMacroUitls.h"
|
||
#import "XPGiftPresenter.h"
|
||
#import "TTPopup.h"
|
||
#import "ThemeColor+SendGift.h"
|
||
#import "YUMIHtmlUrl.h"
|
||
#import "AccountInfoStorage.h"
|
||
#import "NSArray+Safe.h"
|
||
#import "ClientConfig.h"
|
||
#import "XCCurrentVCStackManager.h"
|
||
///Model
|
||
#import "GiftInfoModel.h"
|
||
#import "XPGiftCountModel.h"
|
||
#import "GiftReceiveInfoModel.h"
|
||
#import "AttachmentModel.h"
|
||
#import "RoomInfoModel.h"
|
||
#import "UserInfoModel.h"
|
||
#import "WalletInfoModel.h"
|
||
#import "XPMessageRemoteExtModel.h"
|
||
///View
|
||
#import "XPGiftUsersView.h"
|
||
#import "PIGiftInfoSegmentedView.h"
|
||
#import "XPGiftBarView.h"
|
||
#import "XPRoomHalfWebView.h"
|
||
#import "XPGraffitiGiftView.h"
|
||
#import "XPGiftHeadTypeView.h"
|
||
#import "XPGiftLuckyGiftBroadcastView.h"
|
||
#import "XPGiftTwelveStarBroadcastView.h"
|
||
#import "VIPCenterViewController.h"
|
||
#import "PIGiftBravoGiftBroadcastView.h"
|
||
///P
|
||
#import "XPGiftProtocol.h"
|
||
///VC
|
||
|
||
#import "XPIAPRechargeViewController.h"
|
||
#import "XPWebViewController.h"
|
||
#import "PIGiftSuperGiftBroadcastView.h"
|
||
|
||
#import "GiftComboManager.h"
|
||
|
||
static NSString * const kTargetUidKey = @"targetUid";
|
||
|
||
UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification;
|
||
UIKIT_EXTERN NSString * kShowFirstRechargeView;
|
||
|
||
@interface XPSendGiftView ()< XPGiftBarViewDelegate, XPGiftProtocol, XPGraffitiGiftViewDelegate, XPGiftUsersViewDelegate, XPGiftHeadTypeViewDelegate, XPGiftLuckyGiftBroadcastViewDelegate, XPGiftTwelveStarBroadcastViewDelegate,PIGiftInfoSegmentedViewDelegate,PIGiftSuperGiftBroadcastViewDelegate>
|
||
///顶部的区域
|
||
@property (nonatomic,strong) UIView * topView;
|
||
///内容区域
|
||
@property (nonatomic,strong) UIView *contentView;
|
||
///模糊背景
|
||
@property (nonatomic, strong) UIVisualEffectView *effectView;
|
||
///
|
||
@property (nonatomic,strong) UIStackView *stackView;
|
||
///幸运礼物广播
|
||
@property (nonatomic, strong) XPGiftLuckyGiftBroadcastView *luckyBroadcastView;
|
||
///星座礼物广播
|
||
@property (nonatomic, strong) XPGiftTwelveStarBroadcastView *constellationBanner;
|
||
|
||
@property (nonatomic, strong) PIGiftBravoGiftBroadcastView *bravoGiftView;
|
||
///超级礼物
|
||
//@property(nonatomic,strong) PIGiftSuperGiftBroadcastView *superGiftView;
|
||
///礼物类型(普通/互动)
|
||
@property (nonatomic, strong) XPGiftHeadTypeView *headTypeView;
|
||
///送礼物的人
|
||
@property (nonatomic,strong) XPGiftUsersView *userView;
|
||
///送的什么礼物
|
||
@property (nonatomic,strong) PIGiftInfoSegmentedView *giftInfoView;
|
||
///送多少礼物
|
||
@property (nonatomic,strong) XPGiftBarView *giftBarView;
|
||
///底部的View
|
||
@property (nonatomic,strong) UIView * bottomView;
|
||
///涂鸦礼物
|
||
@property (nonatomic,strong) XPGraffitiGiftView *graffitiView;
|
||
///房主的uid/私聊的话 就是用户的uid
|
||
@property (nonatomic,copy) NSString *roomUid;
|
||
///使用的地方
|
||
@property (nonatomic,assign) SendGiftType usingplaceType;
|
||
///普通礼物的重试次数
|
||
@property (nonatomic,assign) int normalGiftRetryCount;
|
||
///背包礼物的重试次数
|
||
@property (nonatomic,assign) int packGiftRetryCount;
|
||
@property (nonatomic,strong) NSArray<XPGiftUserInfoModel *> *userArray;
|
||
///涂鸦礼物的坐标
|
||
@property (nonatomic,strong) NSArray *graffitiPoint;
|
||
///选择了滑块的类型
|
||
@property (nonatomic,assign) GiftSegmentType segmentType;
|
||
///福袋礼物全服记录
|
||
@property (nonatomic,strong) NSArray *records;
|
||
///背包礼物数据
|
||
@property (nonatomic,copy) NSArray<GiftInfoModel *> * packGiftList;
|
||
|
||
@property (nonatomic, assign) bool didLoadPackGiftList;
|
||
|
||
@property (nonatomic, strong) NSMutableArray *sendGiftMessageArray;
|
||
|
||
@property (nonatomic, strong) GiftComboView *comboView;
|
||
|
||
@property (strong, nonatomic) NSOperationQueue *messageQueue;
|
||
|
||
@end
|
||
|
||
@implementation XPSendGiftView
|
||
|
||
- (XPGiftPresenter *)createPresenter {
|
||
return [[XPGiftPresenter alloc] init];
|
||
}
|
||
|
||
-(void)dealloc{
|
||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||
|
||
[[GiftComboManager sharedManager] registerActions:nil];
|
||
|
||
if (_bravoGiftView) {
|
||
[self.bravoGiftView endloop];
|
||
}
|
||
}
|
||
|
||
- (instancetype)initWithType:(SendGiftType)type uid:(NSString * __nullable)uid{
|
||
if (self = [super init]) {
|
||
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
||
self.roomUid = uid;
|
||
self.usingplaceType = type;
|
||
}
|
||
return self;
|
||
}
|
||
|
||
- (void)viewDidLoad {
|
||
|
||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getFreeGiftCountdownNotification:) name:kFreeGiftCountdownNotification object:nil];
|
||
|
||
[self initSubViews];
|
||
[self initSubViewConstraints];
|
||
[self initHttpRequest];
|
||
|
||
if (self.usingplaceType == SendGiftType_User) {
|
||
return;
|
||
}
|
||
@kWeakify(self);
|
||
[[GiftComboManager sharedManager] registerActions:^(ComboActionType type) {
|
||
@kStrongify(self);
|
||
if (!self) {
|
||
return;
|
||
}
|
||
switch (type) {
|
||
case ComboAction_ShowPanel: {
|
||
self.contentView.hidden = YES;
|
||
// if (self->_superGiftView) {
|
||
// self.superGiftView.hidden = YES;
|
||
// }
|
||
if (self->_constellationBanner) {
|
||
self.constellationBanner.hidden = YES;
|
||
}
|
||
if (self->_luckyBroadcastView) {
|
||
self.luckyBroadcastView.hidden = YES;
|
||
}
|
||
if (self->_bravoGiftView) {
|
||
self.bravoGiftView.hidden = YES;
|
||
}
|
||
[self.view addSubview:self.comboView];
|
||
[self.comboView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.edges.mas_equalTo(self.view);
|
||
}];
|
||
}
|
||
break;
|
||
case ComboAction_RemovePanel:{
|
||
self.contentView.hidden = NO;
|
||
// if (self->_superGiftView) {
|
||
// self.superGiftView.hidden = NO;
|
||
// }
|
||
if (self->_constellationBanner) {
|
||
self.constellationBanner.hidden = NO;
|
||
}
|
||
if (self->_luckyBroadcastView) {
|
||
self.luckyBroadcastView.hidden = NO;
|
||
}
|
||
if (self->_bravoGiftView) {
|
||
self.bravoGiftView.hidden = NO;
|
||
}
|
||
[self.presenter getUserWalletInfo];
|
||
|
||
[self.comboView stopTimer];
|
||
[self.comboView endCombo];
|
||
[self.comboView removeFromSuperview];
|
||
self.comboView = nil;
|
||
}
|
||
break;
|
||
case ComboAction_Combo_Count_Update: {
|
||
[self.comboView updateCount];
|
||
}
|
||
break;
|
||
case ComboAction_Error: {
|
||
NSString *message = [[GiftComboManager sharedManager] loadErrorMessage];
|
||
if (![NSString isEmpty:message]) {
|
||
[self showErrorToast:message];
|
||
}
|
||
}
|
||
break;
|
||
case ComboAction_Update_After_Send_Success: {
|
||
GiftReceiveInfoModel *receiveInfo = [GiftComboManager sharedManager].sendGiftReceiveInfo;
|
||
if (receiveInfo.sourceType == GiftSourceType_Pack) {
|
||
///更新个数
|
||
[self.giftInfoView updatePackSource:receiveInfo numberUser:receiveInfo.receiveGiftNumberUser];
|
||
} else {
|
||
self.giftBarView.walletInfoModel = receiveInfo.userPurse;
|
||
}
|
||
}
|
||
break;
|
||
case ComboAction_SendGift_Gold_Update: {
|
||
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}];
|
||
}
|
||
|
||
- (void)setupMessageQueue {
|
||
if (!_messageQueue) {
|
||
_messageQueue = [[NSOperationQueue alloc] init];
|
||
_messageQueue.maxConcurrentOperationCount = 1; // 串行队列
|
||
}
|
||
}
|
||
|
||
- (GiftComboView *)comboView {
|
||
if (!_comboView) {
|
||
_comboView = [[GiftComboView alloc] init];
|
||
}
|
||
return _comboView;
|
||
}
|
||
|
||
|
||
#pragma mark - Private Method
|
||
- (void)initSubViews {
|
||
[self.view addSubview:self.topView];
|
||
[self.view addSubview:self.contentView];
|
||
[self.contentView addSubview:self.effectView];
|
||
[self.contentView addSubview:self.stackView];
|
||
[self.stackView addArrangedSubview:self.graffitiView];
|
||
[self.stackView addArrangedSubview:self.headTypeView];
|
||
[self.stackView addArrangedSubview:self.userView];
|
||
[self.stackView addArrangedSubview:self.giftInfoView];
|
||
[self.stackView addArrangedSubview:self.giftBarView];
|
||
[self.stackView addArrangedSubview:self.bottomView];
|
||
}
|
||
-(void)getFreeGiftCountdownNotification:(NSNotification *)not{
|
||
NSDictionary *freeDic = not.userInfo;
|
||
BOOL isReset = [freeDic[@"isReset"] boolValue];///礼物清零
|
||
|
||
if(isReset == YES){
|
||
[self.presenter getPackGiftList];
|
||
self.giftInfoView.isDelFreeGift = NO;
|
||
}
|
||
}
|
||
- (void)initSubViewConstraints {
|
||
[self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.leading.trailing.top.mas_equalTo(self.view);
|
||
make.bottom.mas_equalTo(self.contentView.mas_top);
|
||
}];
|
||
|
||
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.mas_equalTo(self.stackView.mas_top);
|
||
make.leading.trailing.bottom.mas_equalTo(self.view);
|
||
}];
|
||
|
||
[self.effectView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.edges.mas_equalTo(self.contentView);
|
||
}];
|
||
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.leading.trailing.bottom.mas_equalTo(self.contentView);
|
||
}];
|
||
|
||
[self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.height.mas_equalTo(kSafeAreaBottomHeight);
|
||
}];
|
||
}
|
||
|
||
- (void)initHttpRequest {
|
||
// [self.presenter getNormalGiftList:self.roomUid];
|
||
[self.presenter getTagsAndGifts:self.roomUid];
|
||
[self.presenter getUserInfo:[AccountInfoStorage instance].getUid];
|
||
[self.presenter getUserWalletInfo];
|
||
|
||
[self.presenter luckyGiftBroadcastRecord];
|
||
if (self.didLoadPackGiftList) {
|
||
return;
|
||
}
|
||
self.didLoadPackGiftList = YES;
|
||
[self.presenter getPackGiftList];
|
||
}
|
||
|
||
#pragma mark - Send Custom Message
|
||
- (void)sendGraffitiGiftMessage {
|
||
if (self.segmentType == GiftSegmentType_Graffiti && self.graffitiPoint.count > 0) {
|
||
AttachmentModel * attachment = [[AttachmentModel alloc] init];
|
||
attachment.first = CustomMessageType_Graffiti_Gift;
|
||
attachment.second = Custom_Message_Sub_Graffiti_Gift;
|
||
NSMutableDictionary * dic = [NSMutableDictionary dictionary];
|
||
[dic setValue:@(self.giftInfoView.lastSelectGift.giftId) forKey:@"giftId"];
|
||
[dic setValue:self.graffitiPoint forKey:@"drawFixedArray"];
|
||
attachment.data = dic;
|
||
[self sendCustomMessage:attachment];
|
||
}
|
||
|
||
if (self.segmentType == GiftSegmentType_Graffiti) {
|
||
NSString * title = [NSString stringWithFormat:YMLocalizedString(@"XPSendGiftView3"),self.giftInfoView.lastSelectGift.giftName];
|
||
[self showSuccessToast:title];
|
||
[self dismissViewControllerAnimated:YES completion:nil];
|
||
}
|
||
}
|
||
|
||
- (void)sendCustomMessage:(GiftReceiveInfoModel *)receiveModel
|
||
oringinDic:(NSDictionary *)originDic {
|
||
NSDictionary * dict = originDic;
|
||
NSMutableDictionary *data = [NSMutableDictionary dictionary];
|
||
[data addEntriesFromDictionary:dict];
|
||
|
||
if (receiveModel.roomSendGiftType == RoomSendGiftType_AllMic) { // 全麦
|
||
if (receiveModel.gift.giftType == GiftType_Lucky) { // 如果是福袋 需要分开发送消息
|
||
[self sendLuckyBagGifts:receiveModel
|
||
data:data
|
||
firstType:CustomMessageType_AllMicroSend
|
||
secondType:Custom_Message_Sub_AllMicroLuckySend
|
||
isToOne:NO];
|
||
}else { // 全麦赠送普通礼物 包含背包礼物
|
||
if (receiveModel.gift.showAvatarType > 0) {
|
||
[self handleEmbeddedValueGiftsMessage:receiveModel
|
||
oringinDic:data
|
||
isToOne:NO];
|
||
} else {
|
||
[self sendGiftToMultipleMessage:data isAll:YES];
|
||
}
|
||
}
|
||
} else if (receiveModel.roomSendGiftType == RoomSendGiftType_MutableOnMic) { // 多人非全麦
|
||
if (receiveModel.gift.giftType == GiftType_Lucky) { // 多人非全麦 福袋礼物
|
||
[self sendLuckyBagGifts:receiveModel
|
||
data:data
|
||
firstType:CustomMessageType_AllMicroSend
|
||
secondType:Custom_Message_Sub_AllBatchMicroLuckySend
|
||
isToOne:NO];
|
||
} else { // 多人非全麦 普通礼物
|
||
if (receiveModel.gift.showAvatarType > 0) {
|
||
[self handleEmbeddedValueGiftsMessage:receiveModel
|
||
oringinDic:data
|
||
isToOne:NO];
|
||
} else {
|
||
[self sendGiftToMultipleMessage:data isAll:NO];
|
||
}
|
||
}
|
||
} else if (receiveModel.roomSendGiftType == RoomSendGiftType_ToOne) { // 单人
|
||
if (receiveModel.gift.giftType == GiftType_Lucky) { // 一对一 福袋礼物
|
||
[self sendLuckyBagGifts:receiveModel
|
||
data:data
|
||
firstType:CustomMessageType_Gift
|
||
secondType:Custom_Message_Sub_Gift_LuckySend
|
||
isToOne:NO];
|
||
}else { // 一对一 普通礼物
|
||
if (receiveModel.gift.showAvatarType > 0) {
|
||
[self handleEmbeddedValueGiftsMessage:receiveModel
|
||
oringinDic:data
|
||
isToOne:YES];
|
||
} else {
|
||
[self sendGiftToOneMessage:data];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
- (void)handleEmbeddedValueGiftsMessage:(GiftReceiveInfoModel *)receiveModel
|
||
oringinDic:(NSMutableDictionary *)data
|
||
isToOne:(BOOL)isToOne {
|
||
// 需要显示嵌入内容的动画,都发 second = 31,如果是送多人,则遍历发送
|
||
[self setupMessageQueue];
|
||
@kWeakify(self);
|
||
NSArray *targetUsers = [data objectForKey:@"targetUsers"];
|
||
for (NSDictionary *obj in targetUsers) {
|
||
AttachmentModel *attachment = [[AttachmentModel alloc] init];
|
||
attachment.first = CustomMessageType_Gift;
|
||
attachment.second = Custom_Message_Sub_Gift_Send;
|
||
[data setObject:[[obj objectForKey:@"uid"] stringValue] forKey:kTargetUidKey];
|
||
[data setObject:[obj objectForKey:@"nick"] forKey:@"targetNick"];
|
||
[data setObject:[obj objectForKey:@"avatar"] forKey:@"targetAvatar"];
|
||
attachment.data = data;
|
||
NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
|
||
@kStrongify(self);
|
||
[self sendCustomMessage:attachment];
|
||
}];
|
||
[self.messageQueue addOperation:operation];
|
||
}
|
||
}
|
||
|
||
- (void)sendGiftToOneMessage:(NSMutableDictionary *)data {
|
||
AttachmentModel *attachment = [[AttachmentModel alloc] init];
|
||
attachment.first = CustomMessageType_Gift;
|
||
attachment.second = Custom_Message_Sub_Gift_Send;
|
||
NSDictionary *targetUsers = ((NSArray *)[data objectForKey:@"targetUsers"]).firstObject;
|
||
if (targetUsers.count == 0) {
|
||
return;
|
||
}
|
||
[data setObject:[targetUsers valueForKeyPath:@"uid"] forKey:kTargetUidKey];
|
||
[data setObject:[targetUsers valueForKeyPath:@"nick"] forKey:@"targetNick"];
|
||
[data setObject:[targetUsers valueForKeyPath:@"avatar"] forKey:@"targetAvatar"];
|
||
attachment.data = data;
|
||
[self sendCustomMessage:attachment];
|
||
}
|
||
|
||
- (void)sendGiftToMultipleMessage:(NSMutableDictionary *)data isAll:(BOOL)isALl{
|
||
AttachmentModel *attachment = [[AttachmentModel alloc] init];
|
||
attachment.first = CustomMessageType_AllMicroSend;
|
||
attachment.second = isALl ? Custom_Message_Sub_AllMicroSend : Custom_Message_Sub_AllBatchSend;
|
||
[data setObject:[data valueForKeyPath:@"targetUsers.uid"] forKey:@"targetUids"];
|
||
attachment.data = data;
|
||
[self sendCustomMessage:attachment];
|
||
}
|
||
|
||
- (void)sendLuckyBagGifts:(GiftReceiveInfoModel *)receiveModel
|
||
data:(NSMutableDictionary *)data
|
||
firstType:(NSUInteger)first
|
||
secondType:(NSUInteger)second
|
||
isToOne:(BOOL)isToOne {
|
||
@kWeakify(self);
|
||
NSArray *luckyBagGifts = (NSArray *)[data objectForKey:@"luckyBagGifts"];
|
||
[luckyBagGifts enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||
@kStrongify(self);
|
||
NSMutableDictionary *tempData = [NSMutableDictionary dictionaryWithDictionary:data.copy];
|
||
|
||
AttachmentModel * attachment = [[AttachmentModel alloc] init];
|
||
attachment.first = (int)first;
|
||
attachment.second = (int)second;
|
||
|
||
[tempData setObject:idx == 0 ? @(YES):@(NO) forKey:@"isShowAnimation"];
|
||
[tempData setObject:obj forKey:@"luckyGiftList"];
|
||
[tempData setObject:receiveModel.gift.giftName forKey:@"giftName"];
|
||
[tempData setObject:[obj valueForKeyPath:@"user.uid"] forKey:kTargetUidKey];
|
||
if (isToOne) {
|
||
[tempData setObject:[obj valueForKeyPath:@"user.nick"] forKey:@"targetNick"];
|
||
}
|
||
[tempData setObject:[data valueForKeyPath:@"targetUsers.uid"] forKey:@"targetUids"];
|
||
if ([tempData valueForKeyPath:@"gift.luckyGiftSvgaUrl"]) {
|
||
[tempData setObject:[data valueForKeyPath:@"gift.luckyGiftSvgaUrl"] forKey:@"luckyGiftSvgaUrl"];
|
||
}
|
||
|
||
attachment.data = tempData;
|
||
[self sendCustomMessage:attachment];
|
||
}];
|
||
}
|
||
|
||
- (void)sendCustomMessage:(AttachmentModel *)attachment {
|
||
NSString *sessionID = self.usingplaceType == SendGiftType_User ? [NSString stringWithFormat:@"%ld", self.userArray.firstObject.uid] : [NSString stringWithFormat:@"%ld", [self.delegate getRoomInfo].roomId];
|
||
NIMMessage *message = [[NIMMessage alloc]init];
|
||
NIMCustomObject *object = [[NIMCustomObject alloc] init];
|
||
|
||
[attachment.data setObject:@([[GiftComboManager sharedManager] loadComboCountFromSendGiftView]) forKey:@"comboCount"];
|
||
|
||
attachment.data = [self removeNSNullValuesAndEmptyStringsRecursively:attachment.data];
|
||
|
||
object.attachment = attachment;
|
||
message.messageObject = object;
|
||
|
||
UserInfoModel *userInfo = [self.delegate getUserInfo];
|
||
XPMessageRemoteExtModel *extModel = [[XPMessageRemoteExtModel alloc] init];
|
||
extModel.androidBubbleUrl = userInfo.androidBubbleUrl;
|
||
extModel.iosBubbleUrl = userInfo.iosBubbleUrl;
|
||
extModel.fromSayHelloChannel = userInfo.fromSayHelloChannel;
|
||
extModel.platformRole = userInfo.platformRole;
|
||
NSMutableDictionary *remoteExt = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[NSString stringWithFormat:@"%ld", userInfo.uid]];
|
||
message.remoteExt = remoteExt;
|
||
NIMSessionType sessionType = self.usingplaceType == SendGiftType_Room ? NIMSessionTypeChatroom : NIMSessionTypeP2P;
|
||
//构造会话
|
||
NIMSession *session = [NIMSession session:sessionID type:sessionType];
|
||
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session completion:^(NSError * _Nullable error) {
|
||
if (error) {
|
||
NSLog(@"%@",error);
|
||
}
|
||
}];
|
||
}
|
||
|
||
- (id)removeNSNullValuesAndEmptyStringsRecursively:(id)object {
|
||
// 处理字典
|
||
if ([object isKindOfClass:[NSDictionary class]]) {
|
||
NSMutableDictionary *cleanedDictionary = [NSMutableDictionary dictionary];
|
||
[(NSDictionary *)object enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||
// 检查是否需要跳过特定键
|
||
if ([key isKindOfClass:[NSString class]] &&
|
||
([key isEqualToString:@"userPurse"] || [key isEqualToString:@"hasSvga"])) {
|
||
return; // 跳过这些键
|
||
}
|
||
|
||
// 递归清理子对象
|
||
id cleanedValue = [self removeNSNullValuesAndEmptyStringsRecursively:obj];
|
||
if (cleanedValue) {
|
||
cleanedDictionary[key] = cleanedValue;
|
||
}
|
||
}];
|
||
return [cleanedDictionary copy];
|
||
}
|
||
|
||
// 处理数组
|
||
else if ([object isKindOfClass:[NSArray class]]) {
|
||
NSMutableArray *cleanedArray = [NSMutableArray array];
|
||
for (id obj in (NSArray *)object) {
|
||
id cleanedValue = [self removeNSNullValuesAndEmptyStringsRecursively:obj];
|
||
if (cleanedValue) {
|
||
[cleanedArray addObject:cleanedValue];
|
||
}
|
||
}
|
||
return [cleanedArray copy];
|
||
}
|
||
|
||
// 检查是否是 NSNull 或空字符串
|
||
else if ([object isKindOfClass:[NSNull class]] ||
|
||
([object isKindOfClass:[NSString class]] && [(NSString *)object length] == 0)) {
|
||
return nil;
|
||
}
|
||
|
||
// 保留其他类型
|
||
return object;
|
||
}
|
||
|
||
#pragma mark - Deal Send Gift Data
|
||
- (NSString *)dealSendGiftCount:(XPGiftCountModel *)model gift:(GiftInfoModel *)gift {
|
||
NSString * count = @"1";
|
||
if (model.isTotal) {
|
||
count = [NSString stringWithFormat:@"%ld", gift.count];
|
||
} else {
|
||
count = model.giftNumber;
|
||
}
|
||
|
||
if (self.segmentType == GiftSegmentType_Graffiti) {
|
||
count = [NSString stringWithFormat:@"%ld", self.graffitiPoint.count];
|
||
}
|
||
return count;
|
||
}
|
||
|
||
- (NSString *)dealSendGiftUids:(NSArray<NSString *> *)uids {
|
||
NSString *uidString = [[NSString alloc] init];
|
||
for (NSString *item in uids) {
|
||
if (uidString.length > 0) {
|
||
uidString = [uidString stringByAppendingString:@","];
|
||
}
|
||
uidString = [uidString stringByAppendingString:item];
|
||
}
|
||
return uidString;
|
||
}
|
||
|
||
- (RoomSendGiftType)dealRoomSendGiftType:(GiftInfoModel *)giftInfo giftCount:(XPGiftCountModel *)giftCount {
|
||
NSArray * uids = [self.userView getSelectUserList];
|
||
RoomSendGiftType roomSendGiftType;
|
||
if (self.userView.isSelectAll) {
|
||
if (giftInfo.sourceType == GiftSourceType_Pack && giftCount.isTotal && giftInfo && uids.count > 1) {
|
||
[self showErrorToast:YMLocalizedString(@"XPSendGiftView0")];
|
||
roomSendGiftType = -1;
|
||
} else {
|
||
// if (uids.count == 1) {
|
||
// roomSendGiftType = RoomSendGiftType_ToOne;
|
||
// } else {
|
||
roomSendGiftType = RoomSendGiftType_AllMic;
|
||
// }
|
||
}
|
||
} else if(uids.count > 1) {
|
||
if (giftInfo.sourceType == GiftSourceType_Pack && giftCount.isTotal) {
|
||
[self showErrorToast:YMLocalizedString(@"XPSendGiftView1")];
|
||
roomSendGiftType = -1;
|
||
} else {
|
||
roomSendGiftType = RoomSendGiftType_MutableOnMic;
|
||
}
|
||
} else if(uids.count == 1) {
|
||
roomSendGiftType = RoomSendGiftType_ToOne;
|
||
} else {
|
||
roomSendGiftType = -1;
|
||
}
|
||
return roomSendGiftType;
|
||
}
|
||
|
||
#pragma mark - Public Method
|
||
- (void)configGiftUsers:(NSArray<XPGiftUserInfoModel *> *)users {
|
||
self.userArray = users;
|
||
[self.userView configGiftUsers:users];
|
||
if (users.count <= 0 || self.usingplaceType == SendGiftType_User) {
|
||
self.userView.hidden = YES;
|
||
} else {
|
||
self.userView.hidden = NO;
|
||
}
|
||
}
|
||
|
||
/// 初始化/重置 连击礼物功能状态
|
||
- (void)readyForCombo:(XPGiftCountModel *)giftCount
|
||
gift:(GiftInfoModel *)giftInfo {
|
||
if (self.segmentType == GiftSegmentType_Pack) {
|
||
[[GiftComboManager sharedManager] enableToCombo:NO];
|
||
return;
|
||
}
|
||
|
||
if (giftInfo.giftType != GiftType_Game &&
|
||
giftInfo.giftType != GiftType_super &&
|
||
giftInfo.giftType != GiftType_Lucky24 &&
|
||
giftInfo.giftType != GiftType_Lucky25 &&
|
||
giftInfo.giftType != GiftType_Bravo) {
|
||
[[GiftComboManager sharedManager] enableToCombo:NO];
|
||
return;
|
||
}
|
||
|
||
[[GiftComboManager sharedManager] enableToCombo:YES];
|
||
|
||
NSString *sessionID = self.usingplaceType == SendGiftType_User ? [NSString stringWithFormat:@"%ld", self.userArray.firstObject.uid] : [NSString stringWithFormat:@"%ld", [self.delegate getRoomInfo].roomId];
|
||
[[GiftComboManager sharedManager] saveSendGiftTo:[self.userView getSelectUserList]];
|
||
[[GiftComboManager sharedManager] saveGiftSourceType:giftInfo.sourceType];
|
||
[[GiftComboManager sharedManager] saveSendGiftInfo:giftInfo];
|
||
[[GiftComboManager sharedManager] saveSendGiftType:[self dealRoomSendGiftType:giftInfo giftCount:giftCount]];
|
||
[[GiftComboManager sharedManager] saveSendGiftNum:[self dealSendGiftCount:giftCount gift:giftInfo]];
|
||
[[GiftComboManager sharedManager] saveRoomUID:self.roomUid];
|
||
[[GiftComboManager sharedManager] saveUserInfo:self.delegate.getUserInfo];
|
||
[[GiftComboManager sharedManager] saveSessionID:sessionID];
|
||
[[GiftComboManager sharedManager] saveGiftCountModel:giftCount];
|
||
}
|
||
|
||
#pragma mark - XPGiftBarViewDelegate
|
||
- (void)xPGiftBarView:(XPGiftBarView *)view didClickSendGift:(XPGiftCountModel *)giftCount {
|
||
///总礼物 三要素 送礼物的人 送的什么礼物 送多少个礼物
|
||
NSArray * uids = [self.userView getSelectUserList];
|
||
GiftInfoModel *giftInfo = self.giftInfoView.lastSelectGift;
|
||
if (self.usingplaceType == SendGiftType_Room) {
|
||
if (uids.count > 0) {
|
||
[self readyForCombo:giftCount
|
||
gift:giftInfo];
|
||
|
||
///送礼物的人
|
||
NSString * uidString = [self dealSendGiftUids:uids];
|
||
///送礼物的个数
|
||
NSString * giftNumber = [self dealSendGiftCount:giftCount gift:giftInfo];
|
||
///送的什么礼物
|
||
NSString * giftId = [NSString stringWithFormat:@"%ld", giftInfo.giftId];
|
||
///给麦上的人送礼物
|
||
GiftSendType sendType = GiftSendType_OnMic;
|
||
///礼物来源
|
||
GiftSourceType sourceType = giftInfo.sourceType;
|
||
if(sourceType != GiftSourceType_Normal && sourceType != GiftSourceType_Pack){
|
||
sourceType = _segmentType == GiftSegmentType_Pack ? GiftSourceType_Pack : GiftSourceType_Normal;
|
||
}
|
||
///送一个人 还是全麦 还是多人非全麦
|
||
RoomSendGiftType roomSendType = [self dealRoomSendGiftType:giftInfo giftCount:giftCount];
|
||
if (roomSendType == -1) {
|
||
return;
|
||
}
|
||
self.giftBarView.sendButtonIsEnable = NO;
|
||
///发送消息
|
||
[self.presenter sendGift:uidString giftNum:giftNumber sendType:sendType giftId:giftId giftSource:sourceType giftType:giftInfo.giftType roomSendType:roomSendType roomUid:self.roomUid msg:@""];
|
||
} else {
|
||
[self showErrorToast:YMLocalizedString(@"XPSendGiftView2")];
|
||
}
|
||
} else if(self.usingplaceType == SendGiftType_User) {
|
||
///送礼物的人
|
||
NSString * uidString = [self dealSendGiftUids:uids];
|
||
///送礼物的个数
|
||
NSString * giftNumber = [self dealSendGiftCount:giftCount gift:giftInfo];
|
||
///送的什么礼物
|
||
NSString * giftId = [NSString stringWithFormat:@"%ld", giftInfo.giftId];
|
||
///给麦上的人送礼物
|
||
GiftSendType sendType = GiftSendType_Chat;
|
||
///礼物来源
|
||
GiftSourceType sourceType = giftInfo.sourceType;
|
||
if(sourceType != GiftSourceType_Normal && sourceType != GiftSourceType_Pack){
|
||
sourceType = _segmentType == GiftSegmentType_Pack ? GiftSourceType_Pack :GiftSourceType_Normal;
|
||
}
|
||
///送一个人 还是全麦 还是多人非全麦
|
||
RoomSendGiftType roomSendType = RoomSendGiftType_ToOne;
|
||
self.giftBarView.sendButtonIsEnable = NO;
|
||
[self.presenter sendGift:uidString giftNum:giftNumber sendType:sendType giftId:giftId giftSource:sourceType giftType:giftInfo.giftType roomSendType:roomSendType roomUid:self.roomUid msg:@""];
|
||
}
|
||
}
|
||
|
||
///充值
|
||
- (void)xPGiftBarViewDidClickRecharge:(XPGiftBarView *)view {
|
||
// @kWeakify(self);
|
||
[self dismissViewControllerAnimated:NO completion:^{
|
||
// @kStrongify(self);
|
||
XPIAPRechargeViewController * rechargeVC = [[XPIAPRechargeViewController alloc] init];
|
||
rechargeVC.type = @"4";
|
||
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:rechargeVC animated:YES];
|
||
}];
|
||
}
|
||
|
||
- (void)xPGiftBarViewDidClickFirstRecharge:(XPGiftBarView *)view {
|
||
@kWeakify(self);
|
||
[self dismissViewControllerAnimated:NO completion:^{
|
||
@kStrongify(self);
|
||
[[NSNotificationCenter defaultCenter]postNotificationName:kShowFirstRechargeView object:@{@"type":@"1",@"diamonds": self.giftBarView.walletInfoModel.diamonds ?: @"0"}];
|
||
}];
|
||
}
|
||
|
||
#pragma mark - XPGiftLuckyGiftBroadcastViewDelegate
|
||
///点击了玩法说明
|
||
- (void)xPGiftLuckyGiftBroadcastViewPlayDescClick {
|
||
NSString * giftExplainUrl;
|
||
if (self.segmentType == GiftSegmentType_Lucky) {
|
||
giftExplainUrl = [NSString stringWithFormat:URLWithType(kLuckyGiftPlayRuleURL), [NSString stringWithFormat:@"%ld", self.giftInfoView.lastSelectGift.giftId]];
|
||
} else {
|
||
giftExplainUrl = self.giftInfoView.lastSelectGift.giftExplainUrl;
|
||
}
|
||
XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init];
|
||
webView.url = giftExplainUrl;
|
||
[TTPopup popupView:webView style:TTPopupStyleActionSheet];
|
||
}
|
||
#pragma mark - PIGiftSuperGiftBroadcastViewDelegate
|
||
- (void)pIGiftSuperGiftBroadcastViewClickWithModel:(GiftInfoModel *)giftModel{
|
||
if ([NSString isEmpty:giftModel.skipUrl]) {
|
||
return;
|
||
}
|
||
XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init];
|
||
webView.url = giftModel.skipUrl;
|
||
[TTPopup popupView:webView style:TTPopupStyleActionSheet];
|
||
}
|
||
#pragma mark - XPGiftWeekStarBroadcastViewDelegate
|
||
///点击了周星榜入口
|
||
- (void)xPGiftWeekStarBroadcastViewWeekStarClick {
|
||
@kWeakify(self);
|
||
[self dismissViewControllerAnimated:NO completion:^{
|
||
@kStrongify(self);
|
||
XPWebViewController * webVC = [[XPWebViewController alloc] initWithRoomUID:self.roomUid];
|
||
webVC.url = URLWithType(kNewWeekStarURL);
|
||
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES];
|
||
}];
|
||
}
|
||
|
||
#pragma mark - XPGiftHeadTypeViewDelegate
|
||
///点击了VIP
|
||
- (void)xPGiftHeadTypeViewDidClickNoble:(XPGiftHeadTypeView *)view {
|
||
@kWeakify(self);
|
||
[self dismissViewControllerAnimated:NO completion:^{
|
||
@kStrongify(self);
|
||
VIPCenterViewController * nobleVC = [[VIPCenterViewController alloc] initWithRoomUid:self.delegate.getRoomInfo.uid];
|
||
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:nobleVC animated:YES];
|
||
}];
|
||
}
|
||
///点击了首充
|
||
- (void)xPGiftHeadTypeViewDidClickFirstRecharge:(XPGiftHeadTypeView *)view {
|
||
@kWeakify(self);
|
||
[self dismissViewControllerAnimated:NO completion:^{
|
||
@kStrongify(self);
|
||
[[NSNotificationCenter defaultCenter]postNotificationName:kShowFirstRechargeView object:@{@"type":@"1",@"diamonds": self.giftBarView.walletInfoModel.diamonds ?: @"0"}];
|
||
}];
|
||
|
||
}
|
||
///点击了礼物
|
||
- (void)xPGiftHeadTypeViewDidClickGift:(XPGiftHeadTypeView *)view {
|
||
[self.luckyBroadcastView removeFromSuperview];
|
||
// [self.superGiftView removeFromSuperview];
|
||
[self.bravoGiftView removeFromSuperview];
|
||
// [self.giftInfoView giftHeadTypeHadChange:1];
|
||
if (!self.graffitiView.hidden) {//清空涂鸦礼物
|
||
[self.graffitiView clearData];
|
||
[self.graffitiView cratePriceAttribute];
|
||
[UIView animateWithDuration:0.2 animations:^{
|
||
self.graffitiView.hidden = YES;
|
||
self.giftInfoView.hidden = NO;
|
||
}];
|
||
}
|
||
}
|
||
///点击了互动
|
||
- (void)xPGiftHeadTypeViewDidClickInteraction:(XPGiftHeadTypeView *)view {
|
||
[self.luckyBroadcastView removeFromSuperview];
|
||
// [self.superGiftView removeFromSuperview];
|
||
[self.bravoGiftView removeFromSuperview];
|
||
// [self.giftInfoView giftHeadTypeHadChange:2];
|
||
}
|
||
|
||
#pragma mark - PIGiftInfoSegmentedViewDelegate
|
||
///点击了切换不同礼物的tabbar
|
||
- (void)pIGiftInfoSegmentedView:(PIGiftInfoSegmentedView *)view didClickSegment:(GiftSegmentType)type{
|
||
self.segmentType = type;
|
||
self.giftBarView.userInfo = [self.delegate getUserInfo];
|
||
self.giftBarView.type = type;
|
||
self.giftBarView.drawGiftCount = 10;
|
||
// [self.superGiftView removeFromSuperview];
|
||
[self.luckyBroadcastView removeFromSuperview];
|
||
[self.bravoGiftView removeFromSuperview];
|
||
[self.constellationBanner removeFromSuperview];
|
||
|
||
switch (type) {
|
||
case GiftSegmentType_Bravo: {
|
||
if (!self.bravoGiftView.superview) {
|
||
[self.view addSubview:self.bravoGiftView];
|
||
[self.bravoGiftView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.bottom.mas_equalTo(self.contentView.mas_top);
|
||
make.leading.trailing.mas_equalTo(0);
|
||
make.height.mas_equalTo(kGetScaleWidth(80));
|
||
}];
|
||
}
|
||
}
|
||
break;
|
||
case GiftSegmentType_Lucky: {
|
||
if (!self.luckyBroadcastView.superview) {
|
||
[self.view addSubview:self.luckyBroadcastView];
|
||
[self.luckyBroadcastView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||
make.bottom.mas_equalTo(self.contentView.mas_top);
|
||
make.leading.trailing.mas_equalTo(0);
|
||
make.height.mas_equalTo(kGetScaleWidth(56));
|
||
}];
|
||
}
|
||
}
|
||
break;
|
||
case GiftSegmentType_SuperLucky: {
|
||
// if (!self.superGiftView.superview) {
|
||
// self.superGiftView.giftModel = self.giftInfoView.lastSelectGift;
|
||
// [self.view addSubview:self.superGiftView];
|
||
// [self.superGiftView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||
// make.bottom.mas_equalTo(self.contentView.mas_top);
|
||
// make.leading.trailing.mas_equalTo(0);
|
||
// make.height.mas_equalTo(kGetScaleWidth(90));
|
||
// }];
|
||
// }
|
||
}
|
||
break;
|
||
case GiftSegmentType_WeekStar: {
|
||
if (!self.constellationBanner.superview) {
|
||
[self.view addSubview:self.constellationBanner];
|
||
[self.constellationBanner mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||
make.bottom.mas_equalTo(self.contentView.mas_top);
|
||
make.leading.trailing.mas_equalTo(0);
|
||
make.height.mas_equalTo(kGetScaleWidth(56));
|
||
}];
|
||
}
|
||
}
|
||
break;
|
||
case GiftSegmentType_Pack: {
|
||
if (!self.didLoadPackGiftList) {
|
||
self.didLoadPackGiftList = YES;
|
||
[self.giftInfoView showLoading];
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_global_queue(0, 0), ^{
|
||
[self.presenter getPackGiftList];
|
||
});
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
///点击了某个item
|
||
- (void)pIGiftInfoSegmentedView:(PIGiftInfoSegmentedView *)view didClickItem:(GiftInfoModel *)info type:(GiftSegmentType)type{
|
||
switch (type) {
|
||
case GiftSegmentType_Bravo:
|
||
[self.constellationBanner removeFromSuperview];
|
||
// [self.superGiftView removeFromSuperview];
|
||
[self.luckyBroadcastView removeFromSuperview];
|
||
if (!self.bravoGiftView.superview) {
|
||
[self.view addSubview:self.bravoGiftView];
|
||
[self.bravoGiftView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.bottom.mas_equalTo(self.contentView.mas_top);
|
||
make.leading.trailing.mas_equalTo(0);
|
||
make.height.mas_equalTo(kGetScaleWidth(80));
|
||
}];
|
||
}
|
||
break;
|
||
case GiftSegmentType_Lucky:{
|
||
[self.bravoGiftView removeFromSuperview];
|
||
[self.constellationBanner removeFromSuperview];
|
||
// [self.superGiftView removeFromSuperview];
|
||
if (!self.luckyBroadcastView.superview) {
|
||
[self.view addSubview:self.luckyBroadcastView];
|
||
[self.luckyBroadcastView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.bottom.mas_equalTo(self.contentView.mas_top);
|
||
make.leading.trailing.mas_equalTo(0);
|
||
make.height.mas_equalTo(kGetScaleWidth(56));
|
||
}];
|
||
}
|
||
}
|
||
break;
|
||
case GiftSegmentType_SuperLucky: {
|
||
[self.bravoGiftView removeFromSuperview];
|
||
[self.constellationBanner removeFromSuperview];
|
||
[self.luckyBroadcastView removeFromSuperview];
|
||
// self.superGiftView.giftModel = info;
|
||
// if (!self.superGiftView.superview) {
|
||
// [self.view addSubview:self.superGiftView];
|
||
// [self.superGiftView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
// make.bottom.mas_equalTo(self.contentView.mas_top);
|
||
// make.leading.trailing.mas_equalTo(0);
|
||
// make.height.mas_equalTo(kGetScaleWidth(90));
|
||
// }];
|
||
// }
|
||
}
|
||
break;
|
||
case GiftSegmentType_Graffiti: {
|
||
self.giftInfoView.hidden = YES;
|
||
self.graffitiView.hidden = NO;
|
||
self.graffitiView.price = info.goldPrice;
|
||
self.giftBarView.drawGiftCount = 0;
|
||
self.graffitiView.selectUidNumber = [self.userView getSelectUserList].count;
|
||
@kWeakify(self);
|
||
[[SDWebImageManager sharedManager] loadImageWithURL:[NSURL URLWithString:info.giftUrl]
|
||
options:SDWebImageProgressiveLoad
|
||
progress:nil
|
||
completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
|
||
@kStrongify(self);
|
||
if (error == nil && image) {
|
||
self.graffitiView.image = image;
|
||
} else {
|
||
self.giftInfoView.hidden = NO;
|
||
}
|
||
}];
|
||
}
|
||
case GiftSegmentType_WeekStar:
|
||
self.constellationBanner.giftInfo = info;
|
||
break;
|
||
default:
|
||
self.giftBarView.drawGiftCount = 10;
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
#pragma mark - XPGiftUsersViewDelegate
|
||
- (void)xPGiftUsersView:(XPGiftUsersView *)view didSelectUsers:(NSArray *)selectUids {
|
||
self.graffitiView.selectUidNumber = selectUids.count;
|
||
}
|
||
|
||
#pragma mark - XPGraffitiGiftViewDelegate
|
||
- (void)xPGraffitiGiftView:(XPGraffitiGiftView *)view didClickClose:(UIButton *)sender {
|
||
[UIView animateWithDuration:0.2 animations:^{
|
||
self.graffitiView.hidden = YES;
|
||
self.giftInfoView.hidden = NO;
|
||
}];
|
||
}
|
||
|
||
- (void)xPGraffitiGiftView:(XPGraffitiGiftView *)view didClickChange:(UIButton *)sender {
|
||
[UIView animateWithDuration:0.2 animations:^{
|
||
self.graffitiView.hidden = YES;
|
||
self.giftInfoView.hidden = NO;
|
||
}];
|
||
}
|
||
|
||
- (void)xPGraffitiGiftView:(XPGraffitiGiftView *)view didDrawCompletion:(NSArray *)pointArray {
|
||
self.graffitiPoint = pointArray;
|
||
self.giftBarView.drawGiftCount = self.graffitiPoint.count;
|
||
}
|
||
|
||
#pragma mark - XPGiftTwelveStarBroadcastViewDelegate
|
||
- (void)xPGiftTwelveStarBroadcastView:(XPGiftTwelveStarBroadcastView *)view didClickDetail:(UIButton *)sender {
|
||
[self dismissViewControllerAnimated:NO completion:^{
|
||
XPWebViewController * webVC = [[XPWebViewController alloc] initWithRoomUID:self.roomUid];
|
||
webVC.url = URLWithType(kNewWeekStarURL);
|
||
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES];
|
||
}];
|
||
}
|
||
|
||
#pragma mark - XPGiftProtocol
|
||
- (void)onGetUserInfoSuccess:(UserInfoModel *)userInfo {
|
||
self.headTypeView.isShowFirstRecharge = userInfo.isFirstCharge;
|
||
self.giftBarView.isShowFirstRecharge = userInfo.isFirstCharge;
|
||
self.giftInfoView.curUserNobleLevel = userInfo.userVipInfoVO.vipLevel;
|
||
}
|
||
|
||
- (void)getUserWalletInfo:(WalletInfoModel *)balanceInfo {
|
||
self.giftBarView.walletInfoModel = balanceInfo;
|
||
}
|
||
///背包礼物
|
||
- (void)getPacketGiftListSuccess:(NSArray<GiftInfoModel *> *)giftList {
|
||
|
||
[self.giftInfoView hideLoading];
|
||
self.packGiftList = giftList;
|
||
NSMutableArray<GiftInfoModel *> *giftArray = [NSMutableArray arrayWithArray:self.packGiftList];
|
||
BOOL isHaveFreeGift = NO;
|
||
for (int i = 0 ; i < self.packGiftList.count; i++) {
|
||
GiftInfoModel *infoModel = self.packGiftList[i];
|
||
if(infoModel.giftId == self.freeModel.giftId.integerValue){
|
||
[giftArray removeObjectAtIndex:i];
|
||
[giftArray insertObject:infoModel atIndex:0];
|
||
isHaveFreeGift = YES;
|
||
break;
|
||
}
|
||
}
|
||
if(isHaveFreeGift == NO && self.freeModel.curStage != nil && self.freeModel.curStage.integerValue == 0 ){
|
||
GiftInfoModel *infoModel = [GiftInfoModel new];
|
||
infoModel.giftId = self.freeModel.giftId.integerValue;
|
||
infoModel.count = 0;
|
||
infoModel.giftUrl = self.freeModel.giftUrl;
|
||
infoModel.giftName = self.freeModel.giftName;
|
||
[giftArray insertObject:infoModel atIndex:0];
|
||
}
|
||
self.giftInfoView.freeModel = self.freeModel;
|
||
self.giftInfoView.packOriginArray = giftArray;
|
||
}
|
||
|
||
- (void)getPacketGiftListFail:(NSString *)message {
|
||
[self.giftInfoView hideLoading];
|
||
self.packGiftRetryCount ++;
|
||
if (self.packGiftRetryCount <= 10) {
|
||
@kWeakify(self);
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||
@kStrongify(self);
|
||
if (self) {
|
||
[self.presenter getPackGiftList];
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
///普通礼物 /幸运礼物
|
||
- (void)getNormalGiftListSuccess:(NSArray<GiftInfoModel *> *)giftList {
|
||
self.giftInfoView.normalOriginArray = giftList;
|
||
}
|
||
|
||
- (void)getTagsSuccess:(NSArray<GiftPanelTabModel*> *)tags {
|
||
self.giftInfoView.tagsArray = tags;
|
||
}
|
||
|
||
- (void)getNormalGiftListFail:(NSString *)message {
|
||
self.normalGiftRetryCount ++;
|
||
if (self.normalGiftRetryCount <= 10) {
|
||
@kWeakify(self);
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||
@kStrongify(self);
|
||
if (self) {
|
||
[self.presenter getTagsAndGifts:self.roomUid];
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
- (void)sendGiftSuccess:(GiftReceiveInfoModel *)receiveInfo
|
||
originDic:(NSDictionary *)originDic
|
||
uidCount:(NSInteger)uidCount{
|
||
self.giftBarView.sendButtonIsEnable = YES;
|
||
if (receiveInfo.sourceType == GiftSourceType_Pack) {
|
||
///更新个数
|
||
[self.giftInfoView updatePackSource:receiveInfo numberUser:uidCount];
|
||
} else {
|
||
self.giftBarView.walletInfoModel = receiveInfo.userPurse;
|
||
}
|
||
|
||
// @kWeakify(self);
|
||
// dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC));
|
||
// dispatch_after(delayTime, dispatch_get_main_queue(), ^{
|
||
// @kStrongify(self);
|
||
if (self) {
|
||
if ([GiftComboManager sharedManager].enableCombo) {
|
||
[[GiftComboManager sharedManager] resetCombo];
|
||
[self sendCustomMessage:receiveInfo oringinDic:originDic];
|
||
[self.comboView setupCurrentGold:receiveInfo.userPurse.diamonds.doubleValue];
|
||
@kWeakify(self);
|
||
[[GiftComboManager sharedManager] setHandleComboSuccess:^(GiftReceiveInfoModel * _Nonnull receiveModel, NSMutableDictionary * _Nonnull originDic) {
|
||
@kStrongify(self);
|
||
[self sendCustomMessage:receiveInfo oringinDic:originDic.copy];
|
||
}];
|
||
} else {
|
||
[self sendCustomMessage:receiveInfo oringinDic:originDic];
|
||
}
|
||
}
|
||
// });
|
||
|
||
///发送涂鸦礼物消息
|
||
// [self sendGraffitiGiftMessage];
|
||
}
|
||
|
||
///送礼物失败
|
||
- (void)sendGiftFailWithCode:(NSInteger)code msg:(NSString *)msg {
|
||
self.giftBarView.sendButtonIsEnable = YES;
|
||
if (code == 31005) {// 余额不足
|
||
[self showNotSufficientFundsWithToast:msg];
|
||
} else if (code == 8535) {//VIP等级未达到礼物等级
|
||
|
||
GiftInfoModel * giftInfo = self.giftInfoView.lastSelectGift;
|
||
TTAlertConfig *config = [[TTAlertConfig alloc] init];
|
||
config.actionStyle = TTAlertActionConfirmStyle;
|
||
config.message = [NSString stringWithFormat:YMLocalizedString(@"XPSendGiftView4"), giftInfo.giftName, giftInfo.giftVipInfo.vipName];
|
||
[TTPopup alertWithConfig:config confirmHandler:^{
|
||
|
||
} cancelHandler:^{
|
||
|
||
}];
|
||
} else {
|
||
[self showErrorToast:msg];
|
||
}
|
||
}
|
||
|
||
/// 余额不足,是否弹首充弹窗
|
||
- (void)showNotSufficientFundsWithToast:(NSString *)msg {
|
||
if (self.delegate.getUserInfo.isFirstCharge) {
|
||
[self dismissViewControllerAnimated:NO completion:^{
|
||
[[NSNotificationCenter defaultCenter]postNotificationName:kShowFirstRechargeView object:@{@"type":self.delegate != nil ? @"2" : @"9",@"diamonds": self.giftBarView.walletInfoModel.diamonds ?: @"0"}];
|
||
}];
|
||
} else {
|
||
[self showErrorToast:msg];
|
||
}
|
||
}
|
||
|
||
- (void)luckyGiftBroadcastRecordSuccess:(NSArray *)records {
|
||
self.records = records;
|
||
self.luckyBroadcastView.records = records;
|
||
}
|
||
|
||
- (void)getTwelveStarLastRankFirstSuccess:(GiftTwelveStarFirstModel *)model {
|
||
|
||
}
|
||
|
||
#pragma mark - Event Response
|
||
- (void)disMissViewRecognizer:(UITapGestureRecognizer *)tap {
|
||
[self dismissViewControllerAnimated:YES completion:nil];
|
||
}
|
||
|
||
#pragma mark - Getters And Setters
|
||
- (void)setUsingplaceType:(SendGiftType)usingplaceType {
|
||
_usingplaceType = usingplaceType;
|
||
self.giftBarView.userInfo = [self.delegate getUserInfo];
|
||
self.giftBarView.usingplaceType = usingplaceType;
|
||
self.giftInfoView.usingPlaceType = _usingplaceType;
|
||
self.headTypeView.hidden = _usingplaceType == SendGiftType_User;
|
||
self.userView.hidden = _usingplaceType == SendGiftType_User;
|
||
self.effectView.hidden = _usingplaceType == SendGiftType_User;
|
||
if (_usingplaceType == SendGiftType_User) {
|
||
self.contentView.backgroundColor = [UIColor whiteColor];
|
||
}
|
||
}
|
||
|
||
- (void)setSelectGiftId:(NSString *)selectGiftId {
|
||
_selectGiftId = selectGiftId;
|
||
// self.giftInfoView.defaultSelectGiftId = selectGiftId;
|
||
}
|
||
|
||
- (void)setDelegate:(id<RoomHostDelegate>)delegate {
|
||
_delegate = delegate;
|
||
if (_delegate) {
|
||
self.giftInfoView.roomType = _delegate.getRoomInfo.type;
|
||
}
|
||
}
|
||
|
||
- (UIView *)topView {
|
||
if (!_topView) {
|
||
_topView = [[UIView alloc] init];
|
||
_topView.backgroundColor = [UIColor clearColor];
|
||
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disMissViewRecognizer:)];
|
||
[_topView addGestureRecognizer:tap];
|
||
}
|
||
return _topView;
|
||
}
|
||
|
||
- (UIView *)contentView {
|
||
if (!_contentView) {
|
||
_contentView = [[UIView alloc] init];
|
||
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, KScreenWidth, KScreenHeight) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)];
|
||
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
|
||
maskLayer.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
|
||
maskLayer.path = maskPath.CGPath;
|
||
_contentView.layer.mask = maskLayer;
|
||
}
|
||
return _contentView;
|
||
}
|
||
|
||
- (XPGiftUsersView *)userView {
|
||
if (!_userView) {
|
||
_userView = [[XPGiftUsersView alloc] init];
|
||
_userView.delegate = self;
|
||
}
|
||
return _userView;
|
||
}
|
||
|
||
- (PIGiftInfoSegmentedView *)giftInfoView {
|
||
if (!_giftInfoView) {
|
||
_giftInfoView = [[PIGiftInfoSegmentedView alloc] initWithFrame:CGRectZero];
|
||
_giftInfoView.delegate = self;
|
||
}
|
||
return _giftInfoView;
|
||
}
|
||
|
||
- (XPGiftBarView *)giftBarView {
|
||
if (!_giftBarView) {
|
||
_giftBarView = [[XPGiftBarView alloc] init];
|
||
_giftBarView.delegate = self;
|
||
}
|
||
return _giftBarView;
|
||
}
|
||
|
||
- (UIStackView *)stackView {
|
||
if (!_stackView) {
|
||
_stackView = [[UIStackView alloc] init];
|
||
_stackView.axis = UILayoutConstraintAxisVertical;
|
||
_stackView.distribution = UIStackViewDistributionFill;
|
||
_stackView.alignment = UIStackViewAlignmentFill;
|
||
_stackView.spacing = 0;
|
||
_stackView.backgroundColor = [UIColor clearColor];
|
||
}
|
||
return _stackView;
|
||
}
|
||
|
||
- (UIView *)bottomView {
|
||
if (!_bottomView) {
|
||
_bottomView = [[UIView alloc] init];
|
||
_bottomView.backgroundColor = [UIColor clearColor];
|
||
}
|
||
return _bottomView;
|
||
}
|
||
|
||
- (XPGraffitiGiftView *)graffitiView {
|
||
if (!_graffitiView) {
|
||
_graffitiView = [[XPGraffitiGiftView alloc] init];
|
||
_graffitiView.hidden = YES;
|
||
_graffitiView.delegate = self;
|
||
}
|
||
return _graffitiView;
|
||
}
|
||
|
||
- (XPGiftHeadTypeView *)headTypeView {
|
||
if (!_headTypeView) {
|
||
_headTypeView = [[XPGiftHeadTypeView alloc] init];
|
||
_headTypeView.delegate = self;
|
||
}
|
||
return _headTypeView;
|
||
}
|
||
|
||
- (XPGiftLuckyGiftBroadcastView *)luckyBroadcastView {
|
||
if (!_luckyBroadcastView) {
|
||
_luckyBroadcastView = [[XPGiftLuckyGiftBroadcastView alloc] init];
|
||
_luckyBroadcastView.delegate = self;
|
||
}
|
||
return _luckyBroadcastView;
|
||
}
|
||
|
||
- (XPGiftTwelveStarBroadcastView *)constellationBanner {
|
||
if (!_constellationBanner) {
|
||
_constellationBanner = [[XPGiftTwelveStarBroadcastView alloc] initWithFrame:CGRectZero];
|
||
_constellationBanner.delegate = self;
|
||
}
|
||
return _constellationBanner;
|
||
}
|
||
|
||
- (UIVisualEffectView *)effectView {
|
||
if (!_effectView) {
|
||
UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
|
||
_effectView = [[UIVisualEffectView alloc] initWithEffect:beffect];
|
||
}
|
||
return _effectView;
|
||
}
|
||
//- (PIGiftSuperGiftBroadcastView *)superGiftView{
|
||
// if(!_superGiftView){
|
||
// _superGiftView = [[PIGiftSuperGiftBroadcastView alloc]initWithFrame:CGRectZero];
|
||
// _superGiftView.delegate = self;
|
||
// }
|
||
// return _superGiftView;
|
||
//}
|
||
|
||
- (PIGiftBravoGiftBroadcastView *)bravoGiftView {
|
||
if (!_bravoGiftView) {
|
||
_bravoGiftView = [[PIGiftBravoGiftBroadcastView alloc] initWithFrame:CGRectZero];
|
||
}
|
||
return _bravoGiftView;
|
||
}
|
||
@end
|