diff --git a/YuMi/Modules/YMMessage/Model/AttachmentModel.h b/YuMi/Modules/YMMessage/Model/AttachmentModel.h index 5b526c5d..0b6e518e 100644 --- a/YuMi/Modules/YMMessage/Model/AttachmentModel.h +++ b/YuMi/Modules/YMMessage/Model/AttachmentModel.h @@ -729,10 +729,12 @@ typedef NS_ENUM(NSUInteger, CustomMessageTypeCPGift) { }; @interface AttachmentModel : PIBaseModel + +@property (nonatomic, strong) id data; @property (nonatomic,assign) int first; @property (nonatomic,assign) int second; -@property (nonatomic, strong) id data; @property(nonatomic,assign) BOOL isBroadcast; + @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMMessage/Tool/CustomAttachmentDecoder.m b/YuMi/Modules/YMMessage/Tool/CustomAttachmentDecoder.m index 0114b31f..663ef062 100644 --- a/YuMi/Modules/YMMessage/Tool/CustomAttachmentDecoder.m +++ b/YuMi/Modules/YMMessage/Tool/CustomAttachmentDecoder.m @@ -15,55 +15,48 @@ id attachment; NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding]; if (data) { - NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; + NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data + options:0 + error:nil]; if ([dict isKindOfClass:[NSDictionary class]]) { int first = [dict[@"first"] intValue]; int second = [dict[@"second"] intValue]; - NSDictionary *data = dict[@"data"]; - if ([data isKindOfClass:[NSString class]]) { - data = [self dictionaryWithJsonString:(NSString *)data]; - } - if ([data isKindOfClass:[NSDictionary class]]) { - AttachmentModel *attachment = [[AttachmentModel alloc]init]; - attachment.first = (short)first; - attachment.second = (short)second; - attachment.data = data; - return attachment; - } - + id originalData = dict[@"data"]; + + AttachmentModel *model = [[AttachmentModel alloc]init]; + model.first = (short)first; + model.second = (short)second; + + if ([originalData isKindOfClass:[NSArray class]]) { + model.data = originalData; + } else if ([originalData isKindOfClass:[NSDictionary class]]) { + model.data = originalData; + } else if ([originalData isKindOfClass:[NSString class]]) { + NSDictionary *jsonDict = [self dictionaryWithJsonString:(NSString *)originalData]; + if ([jsonDict isKindOfClass:[NSDictionary class]]) { + model.data = jsonDict; + } + } + attachment = model; } } return attachment; } //json格式字符串转字典: - (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString { - - if (jsonString == nil) { - + if (jsonString == nil || jsonString.length == 0) { return nil; - } - NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; - NSError *err; - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData - options:NSJSONReadingMutableContainers - error:&err]; - if(err) { - NSLog(@"json解析失败:%@",err); - return nil; - } - return dic; - } @end diff --git a/YuMi/Modules/YMRoom/Features/Boom/RoomBoomEntryView.m b/YuMi/Modules/YMRoom/Features/Boom/RoomBoomEntryView.m index 29d169da..d2467759 100644 --- a/YuMi/Modules/YMRoom/Features/Boom/RoomBoomEntryView.m +++ b/YuMi/Modules/YMRoom/Features/Boom/RoomBoomEntryView.m @@ -25,19 +25,18 @@ dispatch_async(dispatch_get_main_queue(), ^{ @kStrongify(self); self.icon.imageUrl = boomModel.pic; - CGFloat progress = boomModel.speed * 1.0 / 100.0; - if (progress == 0) { - self.progress.hidden = YES; - } else { - self.progress.hidden = NO; - [UIView animateWithDuration:0.3 animations:^{ - [self.progress mas_updateConstraints:^(MASConstraintMaker *make) { - make.width.mas_equalTo(kGetScaleWidth(32) * progress); - }]; - // 强制布局更新以确保约束生效,并在动画期间平滑变化 - [self layoutIfNeeded]; - }]; - } +// CGFloat progress = boomModel.speed * 1.0 / 100.0; +// if (progress == 0) { +// self.progress.hidden = YES; +// } else { +// self.progress.hidden = NO; +// [UIView animateWithDuration:0.3 animations:^{ +// [self.progress mas_updateConstraints:^(MASConstraintMaker *make) { +// make.width.mas_equalTo(kGetScaleWidth(32) * progress); +// }]; +// [self layoutIfNeeded]; +// }]; +// } }); } @@ -60,8 +59,8 @@ [self addSubview:self.progress]; [self.progress mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.progressBG); - make.leading.mas_equalTo(self.icon).offset(4); - make.width.mas_equalTo(0); + make.leading.mas_equalTo(self.icon).offset(4.5); + make.width.mas_equalTo(kGetScaleWidth(32)); make.height.mas_equalTo(5); }]; } diff --git a/YuMi/Modules/YMRoom/Features/Boom/RoomBoomManager.m b/YuMi/Modules/YMRoom/Features/Boom/RoomBoomManager.m index a1690397..23a347da 100644 --- a/YuMi/Modules/YMRoom/Features/Boom/RoomBoomManager.m +++ b/YuMi/Modules/YMRoom/Features/Boom/RoomBoomManager.m @@ -49,7 +49,7 @@ instance.giftEventsQueue = @[].mutableCopy; instance.bannerEventsQueue = @[].mutableCopy; -// [[NIMSDK sharedSDK].chatManager addDelegate:instance]; + [[NIMSDK sharedSDK].chatManager addDelegate:instance]; [[NIMSDK sharedSDK].broadcastManager addDelegate:instance]; }); return instance; @@ -141,6 +141,17 @@ } } +- (void)explosionEnd { + self.isBooming = NO; + if (self.giftEventsQueue.count > 0) { + id obj = self.giftEventsQueue.firstObject; + [self handleBoomGiftUpdate:obj]; + [self.giftEventsQueue removeObjectAtIndex:0]; + } else { + [self checkAndStartBoomEvent]; + } +} + - (void)checkAndStartBannerEvent { if (self.isBannering) { return; @@ -153,17 +164,6 @@ } } -- (void)explosionEnd { - self.isBooming = NO; - if (self.giftEventsQueue.count > 0) { - id obj = self.giftEventsQueue.firstObject; - [self handleBoomGiftUpdate:obj]; - [self.giftEventsQueue removeObjectAtIndex:0]; - } else { - [self checkAndStartBoomEvent]; - } -} - - (void)giftDisplayEnd { [self checkAndStartBoomEvent]; } @@ -239,7 +239,7 @@ // TODO: 增加隊列處理 switch (attachment.second) { case Custom_Message_Room_Boom_EXP: { - NSLog(@" -------- 631 : %@", attachment.data); + NSLog(@" 火箭 -------- 631 : %@", attachment.data); BoomDetailModel *boomDetail = [BoomDetailModel modelWithJSON:attachment.data]; [self handleProgressUpdate:boomDetail]; } @@ -314,17 +314,17 @@ #pragma mark - - (void)onRecvMessages:(NSArray *)messages { -// for (NIMMessage * message in messages) { -// if (message.messageType == NIMMessageTypeCustom) { -// NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; -// if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) { -// AttachmentModel * attachment = (AttachmentModel *)obj.attachment; -// if (attachment.first == CustomMessageType_RoomBoom) { -// [self receiveNIMResponse:attachment]; -// } -// } -// } -// } + for (NIMMessage * message in messages) { + if (message.messageType == NIMMessageTypeCustom) { + NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; + if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) { + AttachmentModel * attachment = (AttachmentModel *)obj.attachment; + if (attachment.first == CustomMessageType_RoomBoom) { + [self receiveNIMResponse:attachment]; + } + } + } + } } - (void)onReceiveBroadcastMessage:(NIMBroadcastMessage *)broadcastMessage { diff --git a/YuMi/Modules/YMRoom/Features/Boom/RoomBoomResultView.h b/YuMi/Modules/YMRoom/Features/Boom/RoomBoomResultView.h index 896e44b1..9d55e910 100644 --- a/YuMi/Modules/YMRoom/Features/Boom/RoomBoomResultView.h +++ b/YuMi/Modules/YMRoom/Features/Boom/RoomBoomResultView.h @@ -7,13 +7,13 @@ #import +@class AttachmentModel; + NS_ASSUME_NONNULL_BEGIN @interface RoomBoomResultView : UIView -+ (void)displayEmptyView:(UIView *)superView; - -+ (void)display:(UIView *)superView gifts:(NSArray *)giftsArray; ++ (void)display:(UIView *)superView attachment:(AttachmentModel *)attachment; @end diff --git a/YuMi/Modules/YMRoom/Features/Boom/RoomBoomResultView.m b/YuMi/Modules/YMRoom/Features/Boom/RoomBoomResultView.m index 4cb18550..586794dd 100644 --- a/YuMi/Modules/YMRoom/Features/Boom/RoomBoomResultView.m +++ b/YuMi/Modules/YMRoom/Features/Boom/RoomBoomResultView.m @@ -7,9 +7,14 @@ #import "RoomBoomResultView.h" +#import "BoomInfoModel.h" +#import "RoomBoomManager.h" +#import "AttachmentModel.h" + @interface RoomBoomResultCollectionViewCell : UICollectionViewCell @property (nonatomic, strong) NetImageView *giftPic; +@property (nonatomic, strong) BoomGiftModel *model; @end @@ -34,6 +39,11 @@ return self; } +- (void)setModel:(BoomGiftModel *)model { + _model = model; + self.giftPic.imageUrl = model.awardPic; +} + - (UIImageView *)bgView { UIImageView *bg = [[UIImageView alloc] initWithImage:kImage(@"room_boom_result_gift_cell_bg")]; return bg; @@ -54,6 +64,7 @@ @property (nonatomic, strong) UILabel *contentLabel; @property (nonatomic, strong) UIButton *bottomButton; @property (nonatomic, strong) UICollectionView *giftsCollectionView; +@property (nonatomic, copy) NSArray * dataSource; @end @@ -77,7 +88,7 @@ }]; } -+ (void)display:(UIView *)superView gifts:(NSArray *)giftsArray { ++ (void)display:(UIView *)superView gifts:(NSArray *)giftsArray { RoomBoomResultView *resultView = [[RoomBoomResultView alloc] init]; resultView.alpha = 0; [superView addSubview:resultView]; @@ -88,18 +99,46 @@ make.height.mas_equalTo(kGetScaleWidth(394)); }]; - [resultView setupFroGifts:giftsArray.count]; + [resultView setupFroGifts]; + resultView.dataSource = giftsArray; [UIView animateWithDuration:0.2 animations:^{ resultView.alpha = 1; }]; } ++ (void)display:(UIView *)superView attachment:(AttachmentModel *)attachment { + if (!attachment || + ![attachment.data isKindOfClass:[NSArray class]] || + [attachment.data count] == 0) { + return; + } + + NSMutableArray *myGifts = @[].mutableCopy; + NSArray *gifts = [BoomGiftModel modelsWithArray:attachment.data]; + for (BoomGiftModel *model in gifts) { + if (model.uid == [[AccountInfoStorage instance].getUid integerValue]) { + [myGifts addObject:model]; + } + } + + if (myGifts.count == 0) { + [RoomBoomResultView displayEmptyView:superView]; + } else { + [RoomBoomResultView display:superView gifts:myGifts]; + } +} + - (instancetype)init { if (self = [super init]) {} return self; } +- (void)setDataSource:(NSArray *)dataSource { + _dataSource = dataSource; + [self.giftsCollectionView reloadData]; +} + - (void)setupForEmpty { self.backgroundImageView.image = kImage(@"room_boom_empty_result_bg"); [self addSubview:self.backgroundImageView]; @@ -125,7 +164,7 @@ }]; } -- (void)setupFroGifts:(NSInteger)giftsCount { +- (void)setupFroGifts { self.backgroundImageView.image = kImage(@"room_boom_gifts_result_bg"); [self addSubview:self.backgroundImageView]; [self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) { @@ -174,12 +213,13 @@ } - (void)didTapBottomButton { + [[RoomBoomManager sharedManager] giftDisplayEnd]; [self removeFromSuperview]; } #pragma mark - UICollectionView delegate & datasource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { - return arc4random()%30; + return self.dataSource.count; } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { diff --git a/YuMi/Modules/YMRoom/Model/BoomInfoModel.h b/YuMi/Modules/YMRoom/Model/BoomInfoModel.h index 2004d146..92cdba73 100644 --- a/YuMi/Modules/YMRoom/Model/BoomInfoModel.h +++ b/YuMi/Modules/YMRoom/Model/BoomInfoModel.h @@ -93,4 +93,17 @@ NS_ASSUME_NONNULL_BEGIN @end +@interface BoomGiftModel : PIBaseModel + +@property (nonatomic, copy) NSString *nick; +@property (nonatomic, copy) NSString *awardName; +@property (nonatomic, copy) NSString *awardPic; + +@property (nonatomic, assign) NSInteger uid; +@property (nonatomic, assign) NSInteger roomUid; +@property (nonatomic, assign) NSInteger level; +@property (nonatomic, assign) NSInteger roleType; + +@end + NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/Model/BoomInfoModel.m b/YuMi/Modules/YMRoom/Model/BoomInfoModel.m index eb33f343..2ec6bf3d 100644 --- a/YuMi/Modules/YMRoom/Model/BoomInfoModel.m +++ b/YuMi/Modules/YMRoom/Model/BoomInfoModel.m @@ -45,5 +45,9 @@ @implementation Boom632Model +@end + +@implementation BoomGiftModel + @end diff --git a/YuMi/Modules/YMRoom/View/XPRoomViewController.m b/YuMi/Modules/YMRoom/View/XPRoomViewController.m index d5c54d62..05c7ab4a 100644 --- a/YuMi/Modules/YMRoom/View/XPRoomViewController.m +++ b/YuMi/Modules/YMRoom/View/XPRoomViewController.m @@ -342,6 +342,9 @@ XPCandyTreeInsufficientBalanceViewDelegate> // [b addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside]; //#endif } +//- (void)test { +// +//} - (void)setupFroBoom { @kWeakify(self); @@ -357,7 +360,7 @@ XPCandyTreeInsufficientBalanceViewDelegate> [[RoomBoomManager sharedManager] registerBoomGiftDisplay:^(id _Nonnull sth) { @kStrongify(self); dispatch_async(dispatch_get_main_queue(), ^{ - [RoomBoomResultView displayEmptyView:self.view]; + [RoomBoomResultView display:self.view attachment:sth]; }); } target:self]; @@ -371,19 +374,11 @@ XPCandyTreeInsufficientBalanceViewDelegate> } target:self]; } -//- (void)test { -// -//} - - (void)loadRoomDataAndUsers { [XNDJTDDLoadingTool showAnchorLoading:self.navigationController.view]; [self.presenter initEnterRoom:self.roomUid user:[AccountInfoStorage instance].getUid]; } -- (void)loadRoomBoom { -// [self.presenter getBoomInfo:s]; -} - - (void)setupNotifications { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myGiftEffectUpdate:) name:kRoomGiftEffectUpdateNotificationKey object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showRoomFirstChargeWindowFormNot:) name:kShowFirstRechargeView object:nil]; @@ -1820,9 +1815,6 @@ XPCandyTreeInsufficientBalanceViewDelegate> [self.littleGameView handleNIMNotificationMessage:message]; } else if (message.messageType == NIMMessageTypeCustom) { NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; - -633 attachment 為 nil ,確認 data 內的數據格式是否符合? - if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) { AttachmentModel * attachment = (AttachmentModel *)obj.attachment; [self.stageView handleNIMCustomMessage:message]; @@ -1935,13 +1927,14 @@ XPCandyTreeInsufficientBalanceViewDelegate> [self.presenter getFreeGiftData]; [[NSNotificationCenter defaultCenter]postNotificationName:kFreeGiftCountdownNotification object:nil userInfo:@{@"updateGiftInfo":attachment.data ?: @""}]; } - } else if (attachment.first == CustomMessageType_RoomBoom) { - if (attachment.second == 631) { - [[RoomBoomManager sharedManager] receiveNIMResponse:attachment]; - } else if (attachment.second == 633) { - [[RoomBoomManager sharedManager] receiveNIMResponse:attachment]; - } } +// else if (attachment.first == CustomMessageType_RoomBoom) { +// if (attachment.second == 631) { +// [[RoomBoomManager sharedManager] receiveNIMResponse:attachment]; +// } else if (attachment.second == 633) { +// [[RoomBoomManager sharedManager] receiveNIMResponse:attachment]; +// } +// } [self.messageContainerView handleNIMCustomMessage:message]; }