272 lines
9.6 KiB
Objective-C
272 lines
9.6 KiB
Objective-C
//
|
|
// XPRoomBottomMenuView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/10/11.
|
|
//
|
|
|
|
#import "XPRoomMenuContainerView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "AccountInfoStorage.h"
|
|
#import "TTPopup.h"
|
|
#import "RtcManager.h"
|
|
///Model
|
|
#import "XPRoomMenuItem.h"
|
|
#import "MicroQueueModel.h"
|
|
#import "UserInfoModel.h"
|
|
#import "MicroStateModel.h"
|
|
#import "RoomInfoModel.h"
|
|
///View
|
|
#import "XPRoomSendTextView.h"
|
|
#import "XPSendGiftView.h"
|
|
#import "SessionListViewController.h"
|
|
|
|
|
|
|
|
@interface XPRoomMenuContainerView ()
|
|
///
|
|
@property (nonatomic,strong) UIStackView *stackView;
|
|
///输入框
|
|
@property (nonatomic,strong) UIButton *inputButton;
|
|
///麦
|
|
@property (nonatomic,strong) UIButton *micButton;
|
|
///声音
|
|
@property (nonatomic,strong) UIButton *voiceButton;
|
|
///表情
|
|
@property (nonatomic,strong) UIButton *faceButton;
|
|
///私聊
|
|
@property (nonatomic,strong) UIButton *messageButton;
|
|
///更多
|
|
@property (nonatomic,strong) UIButton *moreButton;
|
|
///礼物
|
|
@property (nonatomic,strong) UIButton *giftButton;
|
|
///占位的
|
|
@property (nonatomic,strong) UIView * placeHolderView;
|
|
///代理
|
|
@property (nonatomic,weak) id<RoomHostDelegate> delegate;
|
|
@end
|
|
|
|
|
|
@implementation XPRoomMenuContainerView
|
|
|
|
|
|
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate {
|
|
self = [super init];
|
|
if (self) {
|
|
self.delegate = delegate;
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
#pragma mark - Response
|
|
- (void)menuButtonAction:(UIButton *)sender {
|
|
XPRoomMenuItemType type = sender.tag;
|
|
switch (type) {
|
|
case XPRoomMenuItemType_Input:
|
|
[XPRoomSendTextView showTextView:self.superview delegate:self.delegate];
|
|
break;
|
|
|
|
case XPRoomMenuItemType_Mic: {
|
|
[RtcManager instance].localMuted = !self.micButton.isSelected;
|
|
self.micButton.selected = [RtcManager instance].isLocalMuted;
|
|
}
|
|
break;
|
|
|
|
case XPRoomMenuItemType_Voice: {
|
|
[RtcManager instance].remoteMuted = !self.voiceButton.isSelected;
|
|
self.voiceButton.selected = [RtcManager instance].isRemoteMuted;
|
|
}
|
|
break;
|
|
case XPRoomMenuItemType_Gift: {
|
|
NSString * roomUid = [NSString stringWithFormat:@"%ld", [self.delegate getRoomInfo].uid];
|
|
XPSendGiftView * giftView = [[XPSendGiftView alloc] initWithType:SendGiftType_Room uid:roomUid];
|
|
giftView.delegate = self.delegate;
|
|
NSArray * giftUses = [self configGiftUsers:[self.delegate getMicroQueue]];
|
|
[giftView configGiftUsers:giftUses];
|
|
[TTPopup popupView:giftView style:TTPopupStyleActionSheet];
|
|
}
|
|
break;
|
|
case XPRoomMenuItemType_Message: {
|
|
SessionListViewController * sessionList = [[SessionListViewController alloc] initWithType:SessionListOpenTypeRoom];
|
|
[self.delegate.getCurrentNav pushViewController:sessionList animated:YES];
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self addSubview:self.stackView];
|
|
[self.stackView addArrangedSubview:self.inputButton];
|
|
[self.stackView addArrangedSubview:self.micButton];
|
|
[self.stackView addArrangedSubview:self.voiceButton];
|
|
[self.stackView addArrangedSubview:self.faceButton];
|
|
[self.stackView addArrangedSubview:self.messageButton];
|
|
[self.stackView addArrangedSubview:self.moreButton];
|
|
[self.stackView addArrangedSubview:self.placeHolderView];
|
|
[self.stackView addArrangedSubview:self.giftButton];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self).inset(15);
|
|
make.top.bottom.mas_equalTo(self);
|
|
}];
|
|
|
|
[self.inputButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(100, 30));
|
|
}];
|
|
|
|
[self.giftButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(38, 38));
|
|
}];
|
|
}
|
|
|
|
- (NSArray<XPGiftUserInfoModel *> *)configGiftUsers:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
|
|
NSMutableArray * array = [NSMutableArray array];
|
|
for (MicroQueueModel * microModel in queue.allValues) {
|
|
if (microModel.userInfo && microModel.userInfo.uid >0) {
|
|
UserInfoModel * userInfo = microModel.userInfo;
|
|
XPGiftUserInfoModel * userModel = [[XPGiftUserInfoModel alloc] init];
|
|
userModel.avatar = userInfo.avatar;
|
|
userModel.position = [NSString stringWithFormat:@"%d", microModel.microState.position];
|
|
userModel.uid = userInfo.uid;
|
|
[array addObject:userModel];
|
|
}
|
|
}
|
|
return array;
|
|
}
|
|
|
|
- (MicroQueueModel *)findMySelfMicro:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
for (MicroQueueModel * microModel in queue.allValues) {
|
|
if (microModel.userInfo && microModel.userInfo.uid == uid.integerValue) {
|
|
return microModel;
|
|
}
|
|
}
|
|
return nil;
|
|
}
|
|
|
|
#pragma mark - RoomGuestDelegate
|
|
- (void)onMicroQueueUpdate:(NSMutableDictionary<NSString *,MicroQueueModel *> *)queue {
|
|
MicroQueueModel * model = [self findMySelfMicro:queue];
|
|
if (model) {
|
|
self.micButton.hidden = NO;
|
|
self.micButton.selected = model.microState.micState == MicroMicStateType_Close ? YES : [RtcManager instance].isLocalMuted;
|
|
self.micButton.enabled = model.microState.micState == MicroMicStateType_Open;
|
|
} else {
|
|
self.micButton.hidden = YES;
|
|
}
|
|
}
|
|
#pragma mark - Getters And Setters
|
|
- (UIButton *)inputButton {
|
|
if (!_inputButton) {
|
|
_inputButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_inputButton setTitle:@"说点什么..." forState:UIControlStateNormal];
|
|
[_inputButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
_inputButton.titleLabel.font = [UIFont systemFontOfSize:15];
|
|
_inputButton.layer.masksToBounds = YES;
|
|
_inputButton.layer.cornerRadius = 15;
|
|
[_inputButton setBackgroundImage:[UIImage imageNamed:@"room_menu_input_bg"] forState:UIControlStateNormal];
|
|
_inputButton.tag = XPRoomMenuItemType_Input;
|
|
[_inputButton addTarget:self action:@selector(menuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _inputButton;
|
|
}
|
|
|
|
- (UIButton *)micButton {
|
|
if (!_micButton) {
|
|
_micButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_micButton setImage:[UIImage imageNamed:@"room_menu_mic_open"] forState:UIControlStateNormal];
|
|
[_micButton setImage:[UIImage imageNamed:@"room_menu_mic_close"] forState:UIControlStateSelected];
|
|
[_micButton setImage:[UIImage imageNamed:@"room_menu_mic_close"] forState:UIControlStateDisabled | UIControlStateSelected];
|
|
_micButton.tag = XPRoomMenuItemType_Mic;
|
|
[_micButton addTarget:self action:@selector(menuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
_micButton.hidden = YES;
|
|
}
|
|
return _micButton;
|
|
}
|
|
|
|
- (UIButton *)voiceButton {
|
|
if (!_voiceButton) {
|
|
_voiceButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_voiceButton setImage:[UIImage imageNamed:@"room_menu_voice_open"] forState:UIControlStateNormal];
|
|
[_voiceButton setImage:[UIImage imageNamed:@"room_menu_voice_close"] forState:UIControlStateSelected];
|
|
_voiceButton.tag = XPRoomMenuItemType_Voice;
|
|
[_voiceButton addTarget:self action:@selector(menuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _voiceButton;
|
|
}
|
|
|
|
- (UIButton *)faceButton {
|
|
if (!_faceButton) {
|
|
_faceButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_faceButton setImage:[UIImage imageNamed:@"room_menu_face"] forState:UIControlStateNormal];
|
|
[_faceButton setImage:[UIImage imageNamed:@"room_menu_face"] forState:UIControlStateSelected];
|
|
_faceButton.tag = XPRoomMenuItemType_Face;
|
|
[_faceButton addTarget:self action:@selector(menuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
_faceButton.hidden = YES;
|
|
}
|
|
return _faceButton;
|
|
}
|
|
|
|
- (UIButton *)messageButton {
|
|
if (!_messageButton) {
|
|
_messageButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_messageButton setImage:[UIImage imageNamed:@"room_menu_message"] forState:UIControlStateNormal];
|
|
[_messageButton setImage:[UIImage imageNamed:@"room_menu_new_message"] forState:UIControlStateSelected];
|
|
_messageButton.tag = XPRoomMenuItemType_Message;
|
|
[_messageButton addTarget:self action:@selector(menuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _messageButton;
|
|
}
|
|
|
|
- (UIButton *)moreButton {
|
|
if (!_moreButton) {
|
|
_moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_moreButton setImage:[UIImage imageNamed:@"room_menu_more"] forState:UIControlStateNormal];
|
|
[_moreButton setImage:[UIImage imageNamed:@"room_menu_more"] forState:UIControlStateSelected];
|
|
_moreButton.tag = XPRoomMenuItemType_More;
|
|
[_moreButton addTarget:self action:@selector(menuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
_moreButton.hidden = YES;
|
|
}
|
|
return _moreButton;
|
|
}
|
|
|
|
- (UIButton *)giftButton {
|
|
if (!_giftButton) {
|
|
_giftButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_giftButton setImage:[UIImage imageNamed:@"room_menu_gift"] forState:UIControlStateNormal];
|
|
[_giftButton setImage:[UIImage imageNamed:@"room_menu_gift"] forState:UIControlStateSelected];
|
|
_giftButton.tag = XPRoomMenuItemType_Gift;
|
|
[_giftButton addTarget:self action:@selector(menuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _giftButton;
|
|
}
|
|
|
|
- (UIView *)placeHolderView {
|
|
if (!_placeHolderView) {
|
|
_placeHolderView = [[UIView alloc] init];
|
|
_placeHolderView.backgroundColor = [UIColor clearColor];
|
|
[_placeHolderView setContentHuggingPriority:UILayoutPriorityDragThatCanResizeScene forAxis:UILayoutConstraintAxisHorizontal];
|
|
}
|
|
return _placeHolderView;
|
|
}
|
|
|
|
- (UIStackView *)stackView {
|
|
if (!_stackView) {
|
|
_stackView = [[UIStackView alloc] init];
|
|
_stackView.axis = UILayoutConstraintAxisHorizontal;
|
|
_stackView.distribution = UIStackViewDistributionFill;
|
|
_stackView.alignment = UIStackViewAlignmentCenter;
|
|
_stackView.spacing = 8;
|
|
}
|
|
return _stackView;
|
|
}
|
|
|
|
@end
|