208 lines
8.0 KiB
Objective-C
208 lines
8.0 KiB
Objective-C
//
|
|
// TTRoomAnchorInfoCardView.m
|
|
// PlanetStar
|
|
//
|
|
// Created by GreenLand on 2021/6/28.
|
|
// Copyright © 2021 WUJIE INTERACTIVE. All rights reserved.
|
|
//
|
|
|
|
#import "XPRoomAnchorInfoCardView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import "TTPopup.h"
|
|
///Tool
|
|
#import "XCHUDTool.h"
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
|
#import "XPMacro.h"
|
|
#import "ThemeColor.h"
|
|
#import "UIImage+Utils.h"
|
|
#import "Api+UserCard.h"
|
|
#import "AccountInfoStorage.h"
|
|
///View
|
|
#import "NetImageView.h"
|
|
///Model
|
|
#import "UserInfoModel.h"
|
|
#import "XPAnchorAttentSendInfo.h"
|
|
#import "AttachmentModel.h"
|
|
|
|
@interface XPRoomAnchorInfoCardView()
|
|
|
|
@property (nonatomic, strong) UIButton *closeBtn;//关闭按钮
|
|
@property (nonatomic, strong) NetImageView *avatarImageView;//头像
|
|
@property (nonatomic, strong) UILabel *nameLabel;//昵称
|
|
@property (nonatomic, strong) UILabel *descLabel;//描述
|
|
@property (nonatomic, strong) UIButton *followBtn;//关注按钮
|
|
|
|
@end
|
|
|
|
@implementation XPRoomAnchorInfoCardView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
if (self = [super initWithFrame:frame]) {
|
|
[self initView];
|
|
[self initConstraint];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)initView {
|
|
self.backgroundColor = [UIColor whiteColor];
|
|
[self addSubview:self.closeBtn];
|
|
[self addSubview:self.avatarImageView];
|
|
[self addSubview:self.nameLabel];
|
|
[self addSubview:self.descLabel];
|
|
[self addSubview:self.followBtn];
|
|
}
|
|
|
|
- (void)initConstraint {
|
|
CGFloat margin = 16;
|
|
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(margin);
|
|
make.top.mas_equalTo(margin);
|
|
make.width.height.mas_equalTo(30);
|
|
}];
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.mas_centerX);
|
|
make.width.height.mas_equalTo(80);
|
|
make.top.mas_equalTo(55);
|
|
}];
|
|
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.avatarImageView.mas_bottom).mas_offset(10);
|
|
make.centerX.mas_equalTo(self.mas_centerX);
|
|
make.left.mas_equalTo(margin);
|
|
}];
|
|
[self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.nameLabel.mas_bottom).mas_offset(30);
|
|
make.centerX.mas_equalTo(self.mas_centerX);
|
|
}];
|
|
[self.followBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(kSafeAreaBottomHeight > 0 ? -kSafeAreaBottomHeight : -20);
|
|
make.centerX.mas_equalTo(self.mas_centerX);
|
|
make.width.mas_equalTo(225);
|
|
make.height.mas_equalTo(30);
|
|
}];
|
|
}
|
|
|
|
- (void)setUserInfo:(UserInfoModel *)userInfo {
|
|
_userInfo = userInfo;
|
|
}
|
|
|
|
- (void)setTargetUserInfo:(UserInfoModel *)targetUserInfo {
|
|
_targetUserInfo = targetUserInfo;
|
|
self.avatarImageView.imageUrl = targetUserInfo.avatar;
|
|
self.nameLabel.text = targetUserInfo.nick;
|
|
}
|
|
|
|
- (void)drawRect:(CGRect)rect {
|
|
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15, 15)];
|
|
CAShapeLayer *maskLayer = [CAShapeLayer layer];
|
|
maskLayer.path = path.CGPath;
|
|
self.layer.mask = maskLayer;
|
|
}
|
|
|
|
- (void)layoutSubviews {
|
|
[super layoutSubviews];
|
|
CGFloat imageWidth = _followBtn.imageView.frame.size.width;
|
|
CGFloat space = 5.f; //定义两个元素交换后的间距
|
|
_followBtn.titleEdgeInsets = UIEdgeInsetsMake(0, imageWidth + space,0,imageWidth + space);
|
|
}
|
|
|
|
- (void)followBtnClick:(UIButton *)btn {
|
|
NSString * uid = [[AccountInfoStorage instance] getUid];
|
|
NSString * ticket = [[AccountInfoStorage instance] getTicket];
|
|
NSString * type = @"1";
|
|
[Api attentionCompletion:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
if (code == 200) {
|
|
[self.followBtn setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor cancelButtonGradientStartColor], [ThemeColor cancelButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
|
|
[self.followBtn setTitle:@"已关注" forState:UIControlStateNormal];
|
|
[self.followBtn setTitleColor:[ThemeColor cancelButtonTextColor] forState:UIControlStateNormal];
|
|
|
|
XPAnchorAttentSendInfo *info = [[XPAnchorAttentSendInfo alloc] init];
|
|
info.uid = self.userInfo.uid;
|
|
info.targetNick = self.targetUserInfo.nick;
|
|
info.targetUid = self.targetUserInfo.uid;
|
|
info.nick = self.userInfo.nick;
|
|
|
|
AttachmentModel *attachment = [[AttachmentModel alloc]init];
|
|
attachment.first = CustomMessageType_Room_Tip;
|
|
attachment.second = Custom_Message_Sub_Room_Tip_Attention_Owner;
|
|
attachment.data = info.encodeAttachemt;
|
|
|
|
NIMMessage *message = [[NIMMessage alloc]init];
|
|
NIMCustomObject *object = [[NIMCustomObject alloc] init];
|
|
object.attachment = attachment;
|
|
message.messageObject = object;
|
|
//构造会话
|
|
NIMSession *session = [NIMSession session:[NSString stringWithFormat:@"%zd", self.roomId] type:NIMSessionTypeChatroom];
|
|
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
[TTPopup dismiss];
|
|
});
|
|
}
|
|
} uid:uid likedUid:[NSString stringWithFormat:@"%zd", self.targetUserInfo.uid] ticket:ticket type:type];
|
|
}
|
|
|
|
- (void)close:(UIButton *)btn {
|
|
[TTPopup dismiss];
|
|
}
|
|
|
|
#pragma mark - lazy
|
|
- (UIButton *)closeBtn {
|
|
if (!_closeBtn) {
|
|
_closeBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
|
|
[_closeBtn setImage:[UIImage imageNamed:@"messageChat_popup_game_close_slices"] forState:UIControlStateNormal];
|
|
[_closeBtn addTarget:self action:@selector(close:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _closeBtn;
|
|
}
|
|
|
|
- (NetImageView *)avatarImageView {
|
|
if (!_avatarImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc] init];
|
|
config.imageType = ImageTypeUserIcon;
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_avatarImageView.layer.cornerRadius = 40;
|
|
_avatarImageView.layer.masksToBounds = YES;
|
|
}
|
|
return _avatarImageView;
|
|
}
|
|
|
|
- (UILabel *)nameLabel {
|
|
if (!_nameLabel) {
|
|
_nameLabel = [[UILabel alloc] init];
|
|
_nameLabel.font = [UIFont boldSystemFontOfSize:14];
|
|
_nameLabel.textColor = [ThemeColor mainTextColor];
|
|
_nameLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _nameLabel;
|
|
}
|
|
|
|
- (UILabel *)descLabel {
|
|
if (!_descLabel) {
|
|
_descLabel = [[UILabel alloc] init];
|
|
_descLabel.font = [UIFont boldSystemFontOfSize:14];
|
|
_descLabel.textColor = [ThemeColor textThirdColor];
|
|
_descLabel.textAlignment = NSTextAlignmentCenter;
|
|
_descLabel.text = @"点击加关注,下次直播不迷路~";
|
|
}
|
|
return _descLabel;
|
|
}
|
|
|
|
- (UIButton *)followBtn {
|
|
if (!_followBtn) {
|
|
_followBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_followBtn setImage:[UIImage imageNamed:@"personalAnchor_add"] forState:UIControlStateNormal];
|
|
[_followBtn setTitle:@"关注" forState:UIControlStateNormal];
|
|
[_followBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:15]];
|
|
[_followBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
_followBtn.layer.cornerRadius = 15;
|
|
_followBtn.layer.masksToBounds = YES;
|
|
[_followBtn addTarget:self action:@selector(followBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
|
[_followBtn setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor], [ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
|
|
}
|
|
return _followBtn;
|
|
}
|
|
|
|
@end
|