Files
yinmeng-ios/xplan-ios/Main/Home/View/Cell/XPHomeCollectRoomTableViewCell.m
2022-03-04 19:54:17 +08:00

368 lines
12 KiB
Objective-C

//
// XPHomeCollectRoomTableViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2022/3/2.
// 收藏房间
#import "XPHomeCollectRoomTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import "NetImageView.h"
#import "UIImage+Utils.h"
///Model
#import "HomeCollectRoomModel.h"
@interface XPHomeCollectRoomTableViewCell ()
///是否在PK中
@property (nonatomic,strong) UIButton *pkButton;
///显示头像
@property (nonatomic,strong) NetImageView *avatarImageView;
///显示背景
@property (nonatomic,strong) UIImageView *backImageView;
///显示名字
@property (nonatomic,strong) UILabel *nickLabel;
///显示tag
@property (nonatomic,strong) NetImageView *tagImageView;
///显示id
@property (nonatomic,strong) UILabel *idLabel;
///容器
@property (nonatomic,strong) UIView * personContainerView;
///显示🔥
@property (nonatomic,strong) UIImageView *hotImageView;
///显示在线人数
@property (nonatomic,strong) UILabel *numberLabel;
///房间在线人数
@property (nonatomic,strong) UIView *micContainerView;
///第一个
@property (nonatomic,strong) NetImageView *firstImageView;
///第二个
@property (nonatomic,strong) NetImageView *secondImageView;
///第三个
@property (nonatomic,strong) NetImageView *thirdImageView;
///第四个
@property (nonatomic,strong) NetImageView *fourImageView;
///第五个
@property (nonatomic,strong) NetImageView *fifImageView;
@end
@implementation XPHomeCollectRoomTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor clearColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.backImageView];
[self.contentView addSubview:self.avatarImageView];
[self.backImageView addSubview:self.nickLabel];
[self.backImageView addSubview:self.tagImageView];
[self.backImageView addSubview:self.idLabel];
[self.backImageView addSubview:self.personContainerView];
[self.backImageView addSubview:self.micContainerView];
[self.personContainerView addSubview:self.hotImageView];
[self.personContainerView addSubview:self.numberLabel];
[self.avatarImageView addSubview:self.pkButton];
[self.micContainerView addSubview:self.firstImageView];
[self.micContainerView addSubview:self.secondImageView];
[self.micContainerView addSubview:self.thirdImageView];
[self.micContainerView addSubview:self.fourImageView];
[self.micContainerView addSubview:self.fifImageView];
}
- (void)initSubViewConstraints {
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(74, 74));
make.left.mas_equalTo(self.contentView).offset(15);
make.top.mas_equalTo(self.contentView);
}];
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.contentView).inset(15);
make.top.mas_equalTo(self.contentView).offset(8);
make.height.mas_equalTo(66);
}];
[self.pkButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(44, 16));
make.left.top.mas_equalTo(self.avatarImageView);
}];
[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.backImageView).offset(82);
make.top.mas_equalTo(self.backImageView).offset(12);
make.right.mas_lessThanOrEqualTo(self.personContainerView.mas_left).offset(-5);
}];
[self.tagImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(38, 14));
make.left.mas_equalTo(self.nickLabel);
make.top.mas_equalTo(self.nickLabel.mas_bottom).offset(13);
}];
[self.idLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.tagImageView);
make.left.mas_equalTo(self.tagImageView.mas_right).offset(8);
}];
[self.personContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.hotImageView.mas_left).offset(-4);
make.height.mas_equalTo(16);
make.top.mas_equalTo(self.backImageView).offset(3);
make.right.mas_equalTo(self.backImageView).offset(-3);
}];
[self.hotImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(13, 13));
make.right.mas_equalTo(self.numberLabel.mas_left).offset(-2);
make.centerY.mas_equalTo(self.personContainerView);
}];
[self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.personContainerView.mas_right).offset(-4);
make.centerY.mas_equalTo(self.personContainerView);
}];
[self.micContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.backImageView).offset(-13);
make.height.mas_equalTo(16);
make.centerY.mas_equalTo(self.tagImageView);
make.left.mas_equalTo(self.fifImageView.mas_left).offset(-5);
}];
[self.firstImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(16, 16));
make.right.mas_equalTo(self.micContainerView);
make.centerY.mas_equalTo(self.micContainerView);
}];
[self.secondImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.centerY.mas_equalTo(self.firstImageView);
make.right.mas_equalTo(self.firstImageView.mas_left).offset(-3);
}];
[self.thirdImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.centerY.mas_equalTo(self.firstImageView);
make.right.mas_equalTo(self.secondImageView.mas_left).offset(-3);
}];
[self.fourImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.centerY.mas_equalTo(self.firstImageView);
make.right.mas_equalTo(self.thirdImageView.mas_left).offset(-3);
}];
[self.fifImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.centerY.mas_equalTo(self.firstImageView);
make.right.mas_equalTo(self.fourImageView.mas_left).offset(-3);
}];
}
#pragma mark - Getters And Setters
- (void)setRoomInfo:(HomeCollectRoomModel *)roomInfo {
_roomInfo = roomInfo;
if (_roomInfo) {
self.avatarImageView.imageUrl = _roomInfo.roomAvatar;
self.nickLabel.text = _roomInfo.roomName;
self.tagImageView.imageUrl = _roomInfo.tagPict;
self.idLabel.text = [NSString stringWithFormat:@"ID:%@", _roomInfo.erbanNo];
self.numberLabel.text = _roomInfo.roomOnlineNum;
self.pkButton.hidden = !_roomInfo.crossPking;
for (int i = 0; i< self.micContainerView.subviews.count; i++) {
NetImageView * imageView = [self.micContainerView.subviews objectAtIndex:i];
if (i< _roomInfo.micUsers.count) {
HomePlayMicUserModel * micUserInfo = [_roomInfo.micUsers objectAtIndex:i];
imageView.imageUrl = micUserInfo.avatar;
imageView.hidden = NO;
} else {
imageView.hidden = YES;
}
}
}
}
- (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.layer.cornerRadius = 8;
_avatarImageView.layer.borderColor = [ThemeColor appMainColor].CGColor;
}
return _avatarImageView;
}
- (UIButton *)pkButton {
if (!_pkButton) {
_pkButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_pkButton setTitle:@"pk中" forState:UIControlStateNormal];
[_pkButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_pkButton.titleLabel.font = [UIFont systemFontOfSize:12];
[_pkButton setBackgroundImage:[UIImage imageNamed:@"home_like_across_pk_bg"] forState:UIControlStateNormal];
_pkButton.layer.masksToBounds = YES;
_pkButton.layer.cornerRadius = 10;
}
return _pkButton;
}
- (UIImageView *)backImageView {
if (!_backImageView) {
_backImageView = [[UIImageView alloc] init];
_backImageView.userInteractionEnabled = YES;
_backImageView.layer.masksToBounds = YES;
_backImageView.layer.shadowColor = UIColorRGBAlpha(0xE5E5F2, 0.34).CGColor;
_backImageView.layer.cornerRadius = 12;
_backImageView.layer.shadowOffset = CGSizeMake(4, 4);
_backImageView.image = [UIImage imageWithColor:[ThemeColor appCellBackgroundColor]];
}
return _backImageView;
}
- (UILabel *)nickLabel {
if (!_nickLabel) {
_nickLabel = [[UILabel alloc] init];
_nickLabel.font = [UIFont systemFontOfSize:14];
_nickLabel.textColor = [ThemeColor mainTextColor];
}
return _nickLabel;
}
- (NetImageView *)tagImageView {
if (!_tagImageView) {
_tagImageView = [[NetImageView alloc] init];
}
return _tagImageView;
}
- (UILabel *)idLabel {
if (!_idLabel) {
_idLabel = [[UILabel alloc] init];
_idLabel.font = [UIFont systemFontOfSize:12];
_idLabel.textColor = [ThemeColor secondTextColor];
}
return _idLabel;
}
- (UIView *)personContainerView {
if (!_personContainerView) {
_personContainerView = [[UIView alloc] init];
_personContainerView.backgroundColor = [UIColor clearColor];
_personContainerView.layer.masksToBounds = YES;
_personContainerView.layer.cornerRadius = 8;
}
return _personContainerView;
}
- (UIImageView *)hotImageView {
if (!_hotImageView) {
_hotImageView = [[UIImageView alloc] init];
_hotImageView.userInteractionEnabled = YES;
_hotImageView.image = [UIImage imageNamed:@"room_like_collect_room_hot"];
}
return _hotImageView;
}
- (UILabel *)numberLabel {
if (!_numberLabel) {
_numberLabel = [[UILabel alloc] init];
_numberLabel.font = [UIFont boldSystemFontOfSize:12];
_numberLabel.textColor = [ThemeColor mainTextColor];
}
return _numberLabel;
}
- (UIView *)micContainerView {
if (!_micContainerView) {
_micContainerView = [[UIView alloc] init];
_micContainerView.backgroundColor = [UIColor clearColor];
}
return _micContainerView;
}
- (NetImageView *)firstImageView {
if (!_firstImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_firstImageView = [[NetImageView alloc] initWithConfig:config];
_firstImageView.layer.masksToBounds = YES;
_firstImageView.layer.cornerRadius = 8;
_firstImageView.layer.borderColor = [UIColor whiteColor].CGColor;
_firstImageView.layer.borderWidth = 1;
}
return _firstImageView;
}
- (NetImageView *)secondImageView {
if (!_secondImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_secondImageView = [[NetImageView alloc] initWithConfig:config];
_secondImageView.layer.masksToBounds = YES;
_secondImageView.layer.cornerRadius = 8;
_secondImageView.layer.borderColor = [UIColor whiteColor].CGColor;
_secondImageView.layer.borderWidth = 1;
}
return _secondImageView;
}
- (NetImageView *)thirdImageView {
if (!_thirdImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_thirdImageView = [[NetImageView alloc] initWithConfig:config];
_thirdImageView.layer.masksToBounds = YES;
_thirdImageView.layer.cornerRadius = 8;
_thirdImageView.layer.borderColor = [UIColor whiteColor].CGColor;
_thirdImageView.layer.borderWidth = 1;
}
return _thirdImageView;
}
- (NetImageView *)fourImageView {
if (!_fourImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_fourImageView = [[NetImageView alloc] initWithConfig:config];
_fourImageView.layer.masksToBounds = YES;
_fourImageView.layer.cornerRadius = 8;
_fourImageView.layer.borderColor = [UIColor whiteColor].CGColor;
_fourImageView.layer.borderWidth = 1;
}
return _fourImageView;
}
- (NetImageView *)fifImageView {
if (!_fifImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_fifImageView = [[NetImageView alloc] initWithConfig:config];
_fifImageView.layer.masksToBounds = YES;
_fifImageView.layer.cornerRadius = 8;
_fifImageView.layer.borderColor = [UIColor whiteColor].CGColor;
_fifImageView.layer.borderWidth = 1;
}
return _fifImageView;
}
@end