146 lines
4.8 KiB
Objective-C
146 lines
4.8 KiB
Objective-C
//
|
|
// MessageContentOnlineView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/4/19.
|
|
//
|
|
|
|
#import "MessageContentOpenLiveView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "NetImageView.h"
|
|
#import "ThemeColor.h"
|
|
#import "XCCurrentVCStackManager.h"
|
|
#import "RoomHostDelegate.h"
|
|
///Model
|
|
#import "ContentOpenLiveInfoModel.h"
|
|
///View
|
|
#import "XPRoomViewController.h"
|
|
|
|
|
|
@interface MessageContentOpenLiveView ()
|
|
///头像
|
|
@property (nonatomic,strong) NetImageView *avatarImageView;
|
|
///显示标题
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
///显示id
|
|
@property (nonatomic,strong) UILabel *idLabel;
|
|
@property (nonatomic,strong) ContentOpenLiveInfoModel *userInfo;
|
|
@end
|
|
|
|
@implementation MessageContentOpenLiveView
|
|
|
|
+ (CGFloat)measureHeight:(NIMMessage *)message {
|
|
return (50 + CONTENT_PADDING_V_TOTAL + MESSAGE_PADDING * 2);
|
|
}
|
|
|
|
- (void)render:(NIMMessage *)message {
|
|
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
|
AttachmentModel * attach = obj.attachment;
|
|
ContentOpenLiveInfoModel *info = [ContentOpenLiveInfoModel modelWithDictionary:attach.data];
|
|
self.userInfo = info;
|
|
if (info.userVo.avatar.length > 0 && info.userVo.nick.length > 0) {
|
|
self.avatarImageView.imageUrl = info.userVo.avatar;
|
|
self.idLabel.text = [NSString stringWithFormat:@"%@ 上线了", info.userVo.nick];
|
|
} else {
|
|
|
|
NSArray *uids = @[info.uid];
|
|
[[NIMSDK sharedSDK].userManager fetchUserInfos:uids completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
|
|
if (error == nil) {
|
|
NIMUser *user = users[0];
|
|
self.avatarImageView.imageUrl = user.userInfo.avatarUrl;
|
|
self.idLabel.text = [NSString stringWithFormat:@"%@ 上线了", user.userInfo.nickName];
|
|
}
|
|
}];
|
|
}
|
|
}
|
|
|
|
- (void)initSubViews {
|
|
[super initSubViews];
|
|
[self addSubview:self.backView];
|
|
|
|
[self.backView addSubview:self.avatarImageView];
|
|
[self.backView addSubview:self.titleLabel];
|
|
[self.backView addSubview:self.idLabel];
|
|
UITapGestureRecognizer * tap= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backViewTapRecognozer)];
|
|
[self.backView addGestureRecognizer:tap];
|
|
}
|
|
|
|
|
|
- (void)initSubViewConstraints {
|
|
[super initSubViewConstraints];
|
|
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self).insets(UIEdgeInsetsMake(MESSAGE_PADDING, MESSAGE_PADDING, MESSAGE_PADDING, MESSAGE_PADDING));
|
|
make.size.mas_equalTo(CGSizeMake(200, 50));
|
|
}];
|
|
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(47, 47));
|
|
make.centerY.mas_equalTo(self.backView);
|
|
make.left.mas_equalTo(self.backView).offset(10);
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.avatarImageView.mas_right).offset(10);
|
|
make.bottom.mas_equalTo(self.avatarImageView.mas_centerY).offset(-2);
|
|
make.right.mas_lessThanOrEqualTo(self.backView);
|
|
}];
|
|
|
|
[self.idLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.titleLabel);
|
|
make.top.mas_equalTo(self.avatarImageView.mas_centerY).offset(2);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)backViewTapRecognozer {
|
|
if (self.userInfo.uid.length > 0) {
|
|
UIViewController * controllerView = [XCCurrentVCStackManager shareManager].getCurrentVC;
|
|
//退出原来的房间 如果有的话 TODO 总感觉这种处理不太优雅 进房入口多了 怎么办 进房需要整合
|
|
[controllerView.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if ([obj isKindOfClass:[XPRoomViewController class]]) {
|
|
[controllerView.navigationController popToRootViewControllerAnimated:NO];
|
|
XPRoomViewController<RoomHostDelegate> * rooomVC = obj;
|
|
[rooomVC exitRoom];
|
|
*stop = YES;
|
|
}
|
|
}];
|
|
[XPRoomViewController openRoom:self.userInfo.uid viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (NetImageView *)avatarImageView {
|
|
if (!_avatarImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.imageType = ImageTypeUserIcon;
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_avatarImageView.layer.masksToBounds = YES;
|
|
_avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
}
|
|
return _avatarImageView;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.font = [UIFont systemFontOfSize:17];
|
|
_titleLabel.text = @"你关注的TA";
|
|
_titleLabel.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UILabel *)idLabel {
|
|
if (!_idLabel) {
|
|
_idLabel = [[UILabel alloc] init];
|
|
_idLabel.font = [UIFont systemFontOfSize:13];
|
|
_idLabel.textColor = [ThemeColor secondTextColor];
|
|
}
|
|
return _idLabel;
|
|
}
|
|
|
|
@end
|