144 lines
4.7 KiB
Objective-C
144 lines
4.7 KiB
Objective-C
//
|
|
// MessageContentApplicationShareView.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2022/4/19.
|
|
//
|
|
|
|
#import "MessageContentApplicationShareView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "NetImageView.h"
|
|
#import "RoomHostDelegate.h"
|
|
#import "XCCurrentVCStackManager.h"
|
|
///Model
|
|
#import "ContentApplicationShareModel.h"
|
|
#import "MessageApplicationShareModel.h"
|
|
///View
|
|
#import "XPRoomViewController.h"
|
|
|
|
@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
|
|
|
|
|
|
- (void)render:(MessageBaseModel *)message {
|
|
MessageApplicationShareModel * model = (MessageApplicationShareModel *)message;
|
|
ContentApplicationShareModel *info = model.shareInfo;
|
|
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.leading.mas_equalTo(self.backView).offset(10);
|
|
make.trailing.mas_equalTo(self.avatarImageView.mas_leading).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.trailing.mas_equalTo(self.backView);
|
|
}];
|
|
|
|
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.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.leading.trailing.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 = [DJDKMIMOMColor mainTextColor];
|
|
_titleLabel.numberOfLines = 2;
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UIButton *)enterButton {
|
|
if (!_enterButton) {
|
|
_enterButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_enterButton setTitle:YMLocalizedString(@"MessageContentApplicationShareView0") forState:UIControlStateNormal];
|
|
[_enterButton setTitleColor:[DJDKMIMOMColor mainTextColor] forState:UIControlStateNormal];
|
|
_enterButton.titleLabel.font = [UIFont systemFontOfSize:16];
|
|
[_enterButton addTarget:self action:@selector(enterButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _enterButton;
|
|
}
|
|
|
|
|
|
@end
|