Files
yinmeng-ios/xplan-ios/Main/Room/View/BaseUIContainerView/XPRoomFunctionContainerView.m

339 lines
14 KiB
Mathematica
Raw Normal View History

2021-12-15 18:12:55 +08:00
//
// XPRoomFunctionContainerView.m
// xplan-ios
//
// Created by on 2021/12/15.
//
#import "XPRoomFunctionContainerView.h"
2022-01-06 11:12:32 +08:00
///Third
#import <Masonry/Masonry.h>
#import <ReactiveObjC/ReactiveObjC.h>
#import <NIMSDK/NIMSDK.h>
2021-12-15 18:12:55 +08:00
///Tool
#import "XPMacro.h"
2022-01-06 11:12:32 +08:00
#import "AccountInfoStorage.h"
#import "UIImage+Utils.h"
#import "ThemeColor.h"
2022-01-14 11:38:09 +08:00
#import "TTPopup.h"
2022-01-06 11:12:32 +08:00
#import "Api+Room.h"
#import "XCHudTool.h"
#import "XPHtmlUrl.h"
#import "Api+Mine.h"
2021-12-15 18:12:55 +08:00
///Model
#import "RoomInfoModel.h"
2022-01-06 11:12:32 +08:00
#import "MicroQueueModel.h"
#import "UserInfoModel.h"
#import "AttachmentModel.h"
2022-02-16 15:59:25 +08:00
#import "GiftValueInfoModel.h"
2021-12-15 18:12:55 +08:00
///View
2022-01-14 11:38:09 +08:00
#import "XPRoomHalfWebView.h"
#import "XPAnchorAudienceUpMicView.h"
#import "XPRoomAnchorInfoCardView.h"
2022-02-16 15:59:25 +08:00
#import "AnchorGiftValueView.h"
2021-12-15 18:12:55 +08:00
@interface XPRoomFunctionContainerView ()
///host
@property (nonatomic,weak) id<RoomHostDelegate>delegate;
///
@property (nonatomic,strong) UIButton *contributionButton;
2022-01-06 11:12:32 +08:00
///
@property (nonatomic,strong) UIButton *datingProgresButton;
///
@property (nonatomic, strong) dispatch_source_t followAnchorTimer;
2022-02-16 15:59:25 +08:00
///
@property (nonatomic, strong) AnchorGiftValueView *anchorGiftValueView;
2021-12-15 18:12:55 +08:00
@end
@implementation XPRoomFunctionContainerView
- (instancetype)initWithdelegate:(id<RoomHostDelegate>)delegate {
self = [super init];
if (self) {
self.delegate = delegate;
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.contributionButton];
2022-02-16 15:59:25 +08:00
[self addSubview:self.anchorGiftValueView];
2021-12-15 18:12:55 +08:00
}
- (void)initSubViewConstraints {
[self.contributionButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(-12);
make.top.mas_equalTo(statusbarHeight+57);
make.width.mas_equalTo(90);
make.height.mas_equalTo(26);
}];
2022-02-16 15:59:25 +08:00
[self.anchorGiftValueView mas_makeConstraints:^(MASConstraintMaker *make) {
2022-03-04 17:37:39 +08:00
make.left.mas_equalTo(self.contributionButton.mas_right).mas_offset(8);
2022-02-16 15:59:25 +08:00
make.centerY.mas_equalTo(self.contributionButton);
make.height.mas_equalTo(26);
}];
2021-12-15 18:12:55 +08:00
}
2022-01-06 11:12:32 +08:00
#pragma mark - RoomGuestDelegate
- (void)onRoomUpdate {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
MicroQueueModel * model = [self.delegate.getMicroQueue objectForKey:@"-1"];
if (roomInfo.roomModeType == RoomModeType_Open_Blind && model.userInfo && model.userInfo.uid == [AccountInfoStorage instance].getUid.integerValue) {
if (!self.datingProgresButton.superview) {
[self addSubview:self.datingProgresButton];
[self.datingProgresButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(70, 30));
make.centerX.mas_equalTo(self);
make.top.mas_equalTo(self).offset(354 + kSafeAreaTopHeight);
}];
}
switch (roomInfo.blindDateState) {
case RoomPlayDateingType_Talk:
[self.datingProgresButton setTitle:@"开始选择>" forState:UIControlStateNormal];
break;
case RoomPlayDateingType_Pick:
[self.datingProgresButton setTitle:@"公布心动>" forState:UIControlStateNormal];
break;
case RoomPlayDateingType_Result:
[self.datingProgresButton setTitle:@"结束本轮>" forState:UIControlStateNormal];
break;
case RoomPlayDateingType_Finish:
[self.datingProgresButton setTitle:@"嘉宾交流>" forState:UIControlStateNormal];
break;
default:
break;
}
} else {
if (self.datingProgresButton.superview) {
[self.datingProgresButton removeFromSuperview];
}
}
2022-02-16 15:59:25 +08:00
if (roomInfo.type == RoomType_Anchor) {
[self.contributionButton setTitle:@"主播榜" forState:UIControlStateNormal];
self.anchorGiftValueView.hidden = !roomInfo.showGiftValue;
if (!roomInfo.showGiftValue) {
self.anchorGiftValueView.giftValue = 0;
}
2022-03-04 17:37:39 +08:00
[self.contributionButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(statusbarHeight+49);
}];
2022-02-16 15:59:25 +08:00
} else {
[self.contributionButton setTitle:@"房间榜" forState:UIControlStateNormal];
self.anchorGiftValueView.hidden = YES;
2022-03-04 17:37:39 +08:00
[self.contributionButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(statusbarHeight+57);
}];
2022-02-16 15:59:25 +08:00
}
2022-01-06 11:12:32 +08:00
}
- (void)onRoomEntered {
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
NSString * roomUid = [NSString stringWithFormat:@"%ld", roomInfo.uid];
2022-02-16 15:59:25 +08:00
if (roomInfo.type == RoomType_Anchor) {//
if (![[AccountInfoStorage instance].getUid isEqualToString:roomUid]) {//
NSString * uid = [[AccountInfoStorage instance] getUid];
[Api attentionStatusCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {//
BOOL isLike = ((NSNumber *)data.data).boolValue;
if (!isLike) {
[self setFollowAnchorTimer];
}
} uid:uid isLikeUid:roomUid];
}
}
}
- (void)onMicroGiftValueUpdate:(NSDictionary *)data {
[self handleAnchorGiftValue:data];
}
- (void)handleNIMCustomMessage:(NIMMessage *)message {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
if (attachment.first == CustomMessageType_AnchorRoom_AudienceUpMic) {
[self showAskForUpMic:attachment.data];
2022-02-16 15:59:25 +08:00
} else if(attachment.first == CustomMessageType_Room_GiftValue && attachment.second == Custom_Message_Sub_Room_GiftValue_Sync) {
[self handleAnchorGiftValue:attachment.data];
} else if(attachment.first == CustomMessageType_Gift && (attachment.second == Custom_Message_Sub_Gift_Send || attachment.second == Custom_Message_Sub_Gift_LuckySend || attachment.second == Custom_Message_Sub_Gift_ChannelNotify)) {
[self handleAnchorGiftValue:attachment.data];
}else if(attachment.first == CustomMessageType_AllMicroSend && (attachment.second == Custom_Message_Sub_AllMicroSend || attachment.second == Custom_Message_Sub_AllBatchSend || attachment.second == Custom_Message_Sub_AllMicroLuckySend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend)) {
[self handleAnchorGiftValue:attachment.data];
}
}
}
2021-12-15 18:12:55 +08:00
#pragma mark - Event Response
- (void)contributionButtonAction:(UIButton *)sender {
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
2022-01-14 11:38:09 +08:00
XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init];
webView.url = [NSString stringWithFormat:@"%@?roomUid=%@", URLWithType(kRoomRankURL), roomUid];
[TTPopup popupView:webView style:TTPopupStyleActionSheet];
2021-12-15 18:12:55 +08:00
}
2022-01-06 11:12:32 +08:00
- (void)datingProgresButtonAction:(UIButton *)sender {
[TTPopup dismiss];
RoomInfoModel * roomInfo = self.delegate.getRoomInfo;
NSString * message = @"";
if (roomInfo.blindDateState == RoomPlayDateingType_Talk) {
message = @"进入心动选人环节?";
} else if(roomInfo.blindDateState == RoomPlayDateingType_Pick) {
message = @"进入心动公布环节?";
} else if(roomInfo.blindDateState == RoomPlayDateingType_Result) {
message = @"结束本轮,同时清空魅力值?";
} else if (roomInfo.blindDateState == RoomPlayDateingType_Finish) {
message = @"进入嘉宾交流环节?";
}
TTAlertConfig * config = [[TTAlertConfig alloc] init];
config.message = message;
[TTPopup alertWithConfig:config confirmHandler:^{
NSString * roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
NSString * roundId = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.blindDateState];
[Api changeRoomDatingState:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
} else {
[XCHUDTool showErrorWithMessage:msg];
}
} roomUserId:roomUid roundId:roundId];
} cancelHandler:^{
}];}
2022-02-16 15:59:25 +08:00
- (void)tapGiftValueRecognizer {
if (self.anchorGiftValueView.hidden) return;
if (self.delegate.getUserInfo && self.delegate.getUserInfo.uid > 0) {
XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init];
webView.roomUid = [NSString stringWithFormat:@"%ld", self.delegate.getRoomInfo.uid];
webView.url = [NSString stringWithFormat:@"%@?uid=%ld", URLWithType(kRoomCharmRankURL), self.delegate.getRoomInfo.uid];
[TTPopup popupView:webView style:TTPopupStyleActionSheet];
}
}
#pragma mark -
- (void)setFollowAnchorTimer {
if (self.followAnchorTimer != nil) {
dispatch_source_cancel(self.followAnchorTimer);
}
#ifdef DEBUG
NSInteger totalTime = 5;
#else
NSInteger totalTime = 420;
#endif
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
self.followAnchorTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(self.followAnchorTimer,dispatch_walltime(NULL, totalTime*NSEC_PER_SEC), totalTime*NSEC_PER_SEC, 0); //
@weakify(self);
dispatch_source_set_event_handler(self.followAnchorTimer, ^{
dispatch_async(dispatch_get_main_queue(), ^{
@strongify(self);
dispatch_source_cancel(self.followAnchorTimer);
RoomInfoModel* roomInfo = self.delegate.getRoomInfo;
NSString *roomUid = [NSString stringWithFormat:@"%zd", roomInfo.uid];
NSString * uid = [[AccountInfoStorage instance] getUid];
[Api attentionStatusCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
BOOL isLike = ((NSNumber *)data.data).boolValue;
if (!isLike) { //
if (self.window) {
[self showFollowAnchorView];
}
}
} uid:uid isLikeUid:roomUid];
});
});
dispatch_resume(self.followAnchorTimer);
}
//
- (void)showFollowAnchorView {
RoomInfoModel* roomInfo = self.delegate.getRoomInfo;
NSString *roomUid = [NSString stringWithFormat:@"%zd", roomInfo.uid];
[Api getUserInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
UserInfoModel *userInfo = [UserInfoModel modelWithDictionary:data.data];
XPRoomAnchorInfoCardView *view = [[XPRoomAnchorInfoCardView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 300)];
view.userInfo = self.delegate.getUserInfo;
view.targetUserInfo = userInfo;
view.roomId =roomInfo.roomId;
[TTPopup popupView:view style:TTPopupStyleActionSheet];
} uid:roomUid];
}
///
- (void)showAskForUpMic:(NSDictionary *)dict {
NSString *roomUid = [NSString stringWithFormat:@"%zd", self.delegate.getRoomInfo.uid];
if (![roomUid isEqualToString:[AccountInfoStorage instance].getUid]) {
return;
}
UserInfoModel *model = [UserInfoModel modelWithJSON:dict];
XPAnchorAudienceUpMicView *upMicView = [[XPAnchorAudienceUpMicView alloc] initWithFrame:CGRectMake(0, 0, 300, 226) delegate:self.delegate];
upMicView.info = model;
TTPopupConfig *config = [[TTPopupConfig alloc] init];
config.filterIdentifier = @"audienceRequestUpMic";
config.shouldFilterPopup = YES;
config.contentView = upMicView;
config.style = TTPopupStyleAlert;
[TTPopup popupWithConfig:config];
}
2022-02-16 15:59:25 +08:00
- (void)handleAnchorGiftValue:(NSDictionary *)dict {
if (self.delegate.getRoomInfo.type != RoomType_Anchor) {//
return;
}
GiftValueInfoModel * model = [GiftValueInfoModel modelWithDictionary:dict];
for (int i = 0; i < model.giftValueVos.count; i++) {
GiftValueDetailModel * giftValueModel = [model.giftValueVos objectAtIndex:i];
if (![giftValueModel.uid isEqualToString:[NSString stringWithFormat:@"%zd", self.delegate.getRoomInfo.uid]]) {
continue;
}
self.anchorGiftValueView.giftValue = giftValueModel.giftValue;
}
}
2021-12-15 18:12:55 +08:00
#pragma mark - Getters And Setters
- (UIButton *)contributionButton {
if (!_contributionButton) {
_contributionButton = [[UIButton alloc]init];
[_contributionButton addTarget:self action:@selector(contributionButtonAction:) forControlEvents:UIControlEventTouchUpInside];
2022-03-04 17:37:39 +08:00
_contributionButton.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];
2021-12-15 18:12:55 +08:00
[_contributionButton setTitle:@"房间榜" forState:UIControlStateNormal];
[_contributionButton setImage:[UIImage imageNamed:@"room_rank_enter_icon"] forState:UIControlStateNormal];
[_contributionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_contributionButton.titleLabel.font = [UIFont systemFontOfSize:12];
_contributionButton.layer.cornerRadius = 13;
_contributionButton.layer.masksToBounds = YES;
_contributionButton.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
_contributionButton.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
}
return _contributionButton;
}
2022-01-06 11:12:32 +08:00
- (UIButton *)datingProgresButton {
if (!_datingProgresButton) {
_datingProgresButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_datingProgresButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xFA7186), UIColorFromRGB(0xFA4972)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(65, 30)] forState:UIControlStateNormal];
[_datingProgresButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_datingProgresButton.titleLabel.font = [UIFont systemFontOfSize:13];
[_datingProgresButton setTitle:@"开始选择>" forState:UIControlStateNormal];
[_datingProgresButton addTarget:self action:@selector(datingProgresButtonAction:) forControlEvents:UIControlEventTouchUpInside];
_datingProgresButton.layer.masksToBounds = YES;
_datingProgresButton.layer.cornerRadius = 15;
}
return _datingProgresButton;
}
2022-02-16 15:59:25 +08:00
- (AnchorGiftValueView *)anchorGiftValueView {
if (!_anchorGiftValueView) {
_anchorGiftValueView = [[AnchorGiftValueView alloc] init];
_anchorGiftValueView.hidden = YES;
_anchorGiftValueView.layer.cornerRadius = 13;
_anchorGiftValueView.layer.masksToBounds = YES;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGiftValueRecognizer)];
[_anchorGiftValueView addGestureRecognizer:tap];
}
return _anchorGiftValueView;
}
2021-12-15 18:12:55 +08:00
@end