Files
yinmeng-ios/xplan-ios/Main/Home/View/Cell/XPHomeHapppyRoomTableViewCell.m
2022-11-11 17:46:37 +08:00

405 lines
14 KiB
Objective-C

//
// XPHomeHapppyRoomTableViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2022/2/25.
//
#import "XPHomeHapppyRoomTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import "NetImageView.h"
#import "XPHomeGradientLabel.h"
#import "NSArray+Safe.h"
///Model
#import "HomePlayRoomModel.h"
@interface XPHomeHapppyRoomTableViewCell ()
///头像
@property (nonatomic,strong) NetImageView *avatarImageView;
///pk标签
@property (nonatomic,strong) UIButton *acrossPkButton;
///背景
@property (nonatomic,strong) UIImageView *backView;
///房间标题
@property (nonatomic,strong) UILabel *roomTitleLabel;
///房间广播
@property (nonatomic, strong) UILabel *broadCastLabel;
///房间的标签
@property (nonatomic,strong) NetImageView *roomTagImageView;
///房间榜单的用户
@property (nonatomic,strong) UIStackView *stackView;
///第一个人的头像
@property (nonatomic,strong) NetImageView *firstImageView;
///第二个人的头像
@property (nonatomic,strong) NetImageView *secondImageView;
///第三个人的头像
@property (nonatomic,strong) NetImageView *thirdImageView;
///第四个人的头像
@property (nonatomic,strong) NetImageView *fourthImageView;
///第五个人的头像
@property (nonatomic,strong) NetImageView *fifImageView;
///个数的logo
@property (nonatomic,strong) UIImageView *logoImageView;
///房间的人的个数
@property (nonatomic,strong) UILabel *numberLabel;
///分割线
@property (nonatomic, strong) UIView *devideView;
///游戏名称
@property (nonatomic, strong) XPHomeGradientLabel *gamenameLabel;
@end
@implementation XPHomeHapppyRoomTableViewCell
- (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.backView];
[self.contentView addSubview:self.avatarImageView];
[self.backView addSubview:self.roomTitleLabel];
[self.backView addSubview:self.devideView];
[self.backView addSubview:self.gamenameLabel];
[self.backView addSubview:self.broadCastLabel];
[self.backView addSubview:self.roomTagImageView];
[self.backView addSubview:self.stackView];
[self.backView addSubview:self.logoImageView];
[self.backView addSubview:self.numberLabel];
[self.avatarImageView addSubview:self.acrossPkButton];
[self.stackView addArrangedSubview:self.firstImageView];
[self.stackView addArrangedSubview:self.secondImageView];
[self.stackView addArrangedSubview:self.thirdImageView];
[self.stackView addArrangedSubview:self.fourthImageView];
[self.stackView addArrangedSubview:self.fifImageView];
}
- (void)initSubViewConstraints {
[self.backView 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(86);
}];
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(70, 70));
make.right.mas_equalTo(self.contentView).offset(-15);
make.top.mas_equalTo(self.contentView);
}];
[self.acrossPkButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(43, 18));
make.bottom.centerX.mas_equalTo(self.avatarImageView);
}];
[self.roomTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.backView).offset(34);
make.top.mas_equalTo(self.backView).offset(8);
make.right.mas_lessThanOrEqualTo(self.avatarImageView);
make.height.mas_equalTo(17);
}];
[self.devideView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.roomTitleLabel.mas_right).mas_offset(5);
make.centerY.mas_equalTo(self.roomTitleLabel);
make.width.mas_equalTo(1);
make.height.mas_equalTo(12);
}];
[self.gamenameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.devideView.mas_right).mas_offset(5);
make.centerY.mas_equalTo(self.roomTitleLabel);
make.right.mas_lessThanOrEqualTo(self.backView.mas_right).offset(-75);
}];
[self.gamenameLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
[self.roomTitleLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
[self.broadCastLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.roomTitleLabel);
make.top.mas_equalTo(self.roomTitleLabel.mas_bottom).offset(6);
make.right.mas_lessThanOrEqualTo(self.avatarImageView);
make.height.mas_equalTo(13);
}];
[self.roomTagImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(38, 16));
make.left.mas_equalTo(self.roomTitleLabel);
make.top.mas_equalTo(self.broadCastLabel.mas_bottom).offset(6);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.roomTagImageView.mas_right).offset(8);
make.height.mas_equalTo(20);
make.centerY.mas_equalTo(self.roomTagImageView);
}];
[self.firstImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(20);
}];
[self.secondImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(20);
}];
[self.thirdImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(20);
}];
[self.fourthImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(20);
}];
[self.fifImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(20);
}];
[self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(12, 13));
make.centerY.mas_equalTo(self.roomTagImageView);
make.left.mas_equalTo(self.stackView.mas_right).offset(11);
}];
[self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.roomTagImageView);
make.left.mas_equalTo(self.logoImageView.mas_right).offset(2);
}];
}
#pragma mark - Getters And Setters
- (void)setRoomInfo:(HomePlayRoomModel *)roomInfo {
_roomInfo = roomInfo;
if (_roomInfo) {
self.roomTitleLabel.text = _roomInfo.title;
if (roomInfo.mgName.length) {
self.gamenameLabel.text = roomInfo.mgName;
_gamenameLabel.gradientColor = @[(id)UIColorFromRGB(0x61C4FE).CGColor, (id)UIColorFromRGB(0xA979FF).CGColor];
} else {
self.gamenameLabel.text = @"扩列交友";
_gamenameLabel.gradientColor = @[(id)UIColorFromRGB(0xFF969B).CGColor, (id)UIColorFromRGB(0x8C5FFF).CGColor];
}
self.roomTagImageView.imageUrl = _roomInfo.tagPict;
self.numberLabel.text = [NSString stringWithFormat:@"%ld", _roomInfo.onlineNum];
self.avatarImageView.imageUrl = _roomInfo.avatar;
if (_roomInfo.micUsers.count > 5) {
_roomInfo.micUsers = [_roomInfo.micUsers subarrayWithRange:NSMakeRange(0, 5)];
}
for (int i = 0; i < self.stackView.subviews.count; i++) {
NetImageView * imageView = [self.stackView.subviews safeObjectAtIndex1:i];
if (i < _roomInfo.micUsers.count) {
HomePlayMicUserModel * userInfo = [_roomInfo.micUsers safeObjectAtIndex1:i];
imageView.imageUrl = userInfo.avatar;
imageView.hidden = NO;
} else {
imageView.hidden = YES;
}
}
self.broadCastLabel.text = roomInfo.broadMsg ? roomInfo.broadMsg : @"";
if (roomInfo.broadMsg.length) {
[self.roomTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.backView).mas_offset(8);
}];
[self.roomTagImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.broadCastLabel.mas_bottom).mas_offset(6);
}];
} else {
[self.roomTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.backView).mas_offset(10);
}];
[self.roomTagImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.roomTitleLabel.mas_bottom).mas_offset(8);
}];
}
self.acrossPkButton.hidden = !_roomInfo.crossPking;
}
}
- (UIImageView *)backView {
if (!_backView) {
_backView = [[UIImageView alloc] init];
_backView.contentMode = UIViewContentModeScaleAspectFill;
_backView.image = [UIImage imageNamed:@"home_recommend_play_list_bg"];
}
return _backView;
}
- (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 = 20;
_avatarImageView.layer.borderWidth = 1.5;
_avatarImageView.layer.borderColor = UIColorFromRGB(0xCCD7FF).CGColor;
}
return _avatarImageView;
}
- (UIButton *)acrossPkButton {
if (!_acrossPkButton) {
_acrossPkButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_acrossPkButton setTitle:@"PK中" forState:UIControlStateNormal];
[_acrossPkButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_acrossPkButton.titleLabel.font = [UIFont systemFontOfSize:12];
[_acrossPkButton setBackgroundImage:[UIImage imageNamed:@"home_recommend_across_pk_bg"] forState:UIControlStateNormal];
}
return _acrossPkButton;
}
- (UILabel *)roomTitleLabel {
if (!_roomTitleLabel) {
_roomTitleLabel = [[UILabel alloc] init];
_roomTitleLabel.font = [UIFont systemFontOfSize:14];
_roomTitleLabel.textColor = [ThemeColor mainTextColor];
}
return _roomTitleLabel;
}
- (UILabel *)broadCastLabel {
if (!_broadCastLabel) {
_broadCastLabel = [[UILabel alloc] init];
_broadCastLabel.font = [UIFont systemFontOfSize:13];
_broadCastLabel.textColor = [ThemeColor appEmphasizeColor];
}
return _broadCastLabel;
}
- (NetImageView *)roomTagImageView {
if (!_roomTagImageView) {
_roomTagImageView = [[NetImageView alloc] init];
_roomTagImageView.userInteractionEnabled = YES;
}
return _roomTagImageView;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = 2;
}
return _stackView;
}
- (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 = 10;
_firstImageView.layer.borderWidth = 1;
_firstImageView.layer.borderColor = [UIColor whiteColor].CGColor;
}
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 = 10;
_secondImageView.layer.borderWidth = 1;
_secondImageView.layer.borderColor = [UIColor whiteColor].CGColor;
}
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 = 10;
_thirdImageView.layer.borderWidth = 1;
_thirdImageView.layer.borderColor = [UIColor whiteColor].CGColor;
}
return _thirdImageView;
}
- (NetImageView *)fourthImageView {
if (!_fourthImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_fourthImageView = [[NetImageView alloc] initWithConfig:config];
_fourthImageView.layer.masksToBounds = YES;
_fourthImageView.layer.cornerRadius = 10;
_fourthImageView.layer.borderWidth = 1;
_fourthImageView.layer.borderColor = [UIColor whiteColor].CGColor;
}
return _fourthImageView;
}
- (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 = 10;
_fifImageView.layer.borderWidth = 1;
_fifImageView.layer.borderColor = [UIColor whiteColor].CGColor;
}
return _fifImageView;
}
- (UIImageView *)logoImageView {
if (!_logoImageView) {
_logoImageView = [[UIImageView alloc] init];
_logoImageView.userInteractionEnabled = YES;
_logoImageView.image = [UIImage imageNamed:@"home_recommend_play_person_logo"];
}
return _logoImageView;
}
- (UILabel *)numberLabel {
if (!_numberLabel) {
_numberLabel = [[UILabel alloc] init];
_numberLabel.font = [UIFont systemFontOfSize:12];
_numberLabel.textColor = [ThemeColor secondTextColor];
}
return _numberLabel;
}
- (UIView *)devideView {
if (!_devideView) {
_devideView = [[UIView alloc] init];
_devideView.backgroundColor = UIColorFromRGB(0xD2D5D7);
}
return _devideView;
}
- (XPHomeGradientLabel *)gamenameLabel {
if (!_gamenameLabel) {
_gamenameLabel = [[XPHomeGradientLabel alloc] init];
_gamenameLabel.font = [UIFont systemFontOfSize:10];
_gamenameLabel.gradientColor = @[(id)UIColorFromRGB(0x61C4FE).CGColor, (id)UIColorFromRGB(0xA979FF).CGColor];
_gamenameLabel.text = @"扩列交友";
}
return _gamenameLabel;
}
@end