Files
yinmeng-ios/xplan-ios/Main/Message/View/Session/Content/MessageContentApplicationShareView.m
2022-05-13 16:12:18 +08:00

148 lines
4.8 KiB
Objective-C

//
// MessageContentApplicationShareView.m
// xplan-ios
//
// Created by 冯硕 on 2022/4/19.
//
#import "MessageContentApplicationShareView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import "NetImageView.h"
#import "RoomHostDelegate.h"
#import "XCCurrentVCStackManager.h"
#import "NSObject+MJExtension.h"
///Model
#import "ContentApplicationShareModel.h"
///View
#import "XPRoomViewController.h"
#define MESSAGE_PADDING 10
@interface MessageContentApplicationShareView ()
///标题
@property (nonatomic,strong) UILabel *titleLabel;
///头像
@property (nonatomic,strong) NetImageView *avatarImageView;
///分割线
@property (nonatomic,strong) UIView * lineView;
///进入房间
@property (nonatomic,strong) UIButton *enterButton;
///分享信息
@property (nonatomic,strong) ContentApplicationShareModel *shareInfo;
@end
@implementation MessageContentApplicationShareView
+ (CGFloat)measureHeight:(NIMMessage *)message {
return 90 + CONTENT_PADDING_V_TOTAL;
}
- (void)render:(NIMMessage *)message {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
AttachmentModel * attach = obj.attachment;
ContentApplicationShareModel *info = [ContentApplicationShareModel modelWithDictionary:attach.data];
if (info) {
self.shareInfo = info;
self.titleLabel.text = info.title;
self.avatarImageView.imageUrl = info.avatar;
if (self.shareInfo.actionName.length > 0) {
[self.enterButton setTitle:self.shareInfo.actionName forState:UIControlStateNormal];
}
}
}
- (void)initSubViews {
[super initSubViews];
[self addSubview:self.backView];
[self.backView addSubview:self.titleLabel];
[self.backView addSubview:self.avatarImageView];
[self.backView addSubview:self.lineView];
[self.backView addSubview:self.enterButton];
}
- (void)initSubViewConstraints {
[super initSubViewConstraints];
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(KScreenWidth - AVATAR_MARGIN_H * 2 * 2 - AVATAR_SIZE - AVATAR_MARGIN_H, 90));
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.backView).offset(10);
make.right.mas_equalTo(self.avatarImageView.mas_left).offset(-10);
make.top.mas_equalTo(self.backView);
}];
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(50, 50));
make.top.mas_equalTo(self.backView);
make.right.mas_equalTo(self.backView);
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.backView).inset(12);
make.height.mas_equalTo(1);
make.bottom.mas_equalTo(self.enterButton.mas_top);
}];
[self.enterButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(self.backView);
make.height.mas_equalTo(40);
}];
}
#pragma mark - Event Response
- (void)enterButtonAction:(UIButton *)sender {
if (self.shareInfo.routerValue.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.shareInfo.routerValue 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 = UIViewContentModeScaleAspectFit;
}
return _avatarImageView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:14];
_titleLabel.textColor = [ThemeColor mainTextColor];
_titleLabel.numberOfLines = 2;
}
return _titleLabel;
}
- (UIButton *)enterButton {
if (!_enterButton) {
_enterButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_enterButton setTitle:@"立即进入" forState:UIControlStateNormal];
[_enterButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateNormal];
_enterButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_enterButton addTarget:self action:@selector(enterButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _enterButton;
}
@end