// // XPHomeListCollectionViewCell.m // xplan-ios // // Created by 冯硕 on 2021/11/29. // #import "XPHomeListCollectionViewCell.h" ///Third #import ///Tool #import "ThemeColor.h" #import "UIImage+Utils.h" #import ///Model #import "HomeRecommendRoomModel.h" ///View #import "NetImageView.h" #import "XPNoteView.h" @interface XPHomeListCollectionViewCell () ///头像 @property (nonatomic,strong) NetImageView *avatarImageView; ///底部的view @property (nonatomic,strong) UIView * bottomView; ///名字 @property (nonatomic,strong) UILabel *nickLabel; ///类型 @property (nonatomic,strong) NetImageView *tagImageView; ///背景图 @property (nonatomic,strong) UIImageView *shadowImageView; ///在线人数的容器 @property (nonatomic,strong) UIImageView * noteContainImageView; ///音符 @property (nonatomic,strong) XPNoteView *noteView; ///在线人数的 @property (nonatomic,strong) UILabel *numberLabel; ///动画管理类 @property (strong, nonatomic) SVGAParser *parser; ///PK中动图 @property (nonatomic, strong) SVGAImageView *svgDisplayView; @end @implementation XPHomeListCollectionViewCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Private Method - (void)initSubViews { [self.contentView addSubview:self.avatarImageView]; [self.contentView addSubview:self.tagImageView]; [self.contentView addSubview:self.svgDisplayView]; [self.contentView addSubview:self.shadowImageView]; [self.contentView addSubview:self.noteContainImageView]; [self.contentView addSubview:self.bottomView]; [self.bottomView addSubview:self.nickLabel]; [self.noteContainImageView addSubview:self.noteView]; [self.noteContainImageView addSubview:self.numberLabel]; } - (void)initSubViewConstraints { [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.mas_equalTo(self.contentView); make.height.mas_equalTo(157); }]; [self.tagImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(43, 18)); make.left.top.mas_equalTo(self.contentView); }]; [self.svgDisplayView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.mas_equalTo(self.contentView); make.size.mas_equalTo(CGSizeMake(40, 20)); }]; [self.noteContainImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(self.avatarImageView).offset(-5); make.left.mas_equalTo(self.noteView).offset(-3); make.right.mas_equalTo(self.avatarImageView).offset(-5); make.height.mas_equalTo(16); }]; [self.shadowImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.mas_equalTo(self.avatarImageView); make.height.mas_equalTo(50); }]; [self.noteView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(10); make.height.mas_equalTo(10); make.centerY.mas_equalTo(self.noteContainImageView); make.right.mas_equalTo(self.numberLabel.mas_left).offset(-2); }]; [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.noteContainImageView.mas_right).offset(-2); make.centerY.mas_equalTo(self.noteContainImageView); }]; [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.mas_equalTo(self.contentView); make.top.mas_equalTo(self.avatarImageView.mas_bottom); }]; [self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.centerY.mas_equalTo(self.bottomView); }]; } #pragma mark - Getters And Setters - (void)setRoomModel:(HomeRecommendRoomModel *)roomModel { _roomModel = roomModel; if (_roomModel) { self.avatarImageView.imageUrl = _roomModel.avatar; self.nickLabel.text = _roomModel.title.length > 0 ? _roomModel.title : @""; self.numberLabel.text = [NSString stringWithFormat:@"%ld", _roomModel.onlineNum]; self.tagImageView.imageUrl = _roomModel.tagPict; if (roomModel.crossPking) { self.tagImageView.hidden = YES; self.svgDisplayView.hidden = NO; [self.parser parseWithNamed:@"anchorPk_crossPking" inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { self.svgDisplayView.loops = INT_MAX; self.svgDisplayView.clearsAfterStop = NO; self.svgDisplayView.videoItem = videoItem; [self.svgDisplayView startAnimation]; } failureBlock:^(NSError * _Nonnull error) { }]; } else { self.tagImageView.hidden = NO; [self.svgDisplayView stopAnimation]; self.svgDisplayView.hidden = YES; } } } - (NetImageView *)avatarImageView { if (!_avatarImageView) { _avatarImageView = [[NetImageView alloc] init]; _avatarImageView.layer.masksToBounds = YES; _avatarImageView.layer.cornerRadius = 12; _avatarImageView.image = [UIImageConstant defaultAvatarPlaceholder]; _avatarImageView.contentMode = UIViewContentModeScaleAspectFill; } return _avatarImageView;; } - (NetImageView *)tagImageView { if (!_tagImageView) { _tagImageView = [[NetImageView alloc] init]; } return _tagImageView;; } - (UIView *)bottomView { if (!_bottomView) { _bottomView = [[UIView alloc] init]; _bottomView.backgroundColor = [UIColor clearColor]; } return _bottomView; } - (UILabel *)nickLabel { if (!_nickLabel) { _nickLabel = [[UILabel alloc] init]; _nickLabel.font = [UIFont systemFontOfSize:12]; _nickLabel.textColor = [ThemeColor secondTextColor]; } return _nickLabel; } - (UIImageView *)shadowImageView { if (!_shadowImageView) { _shadowImageView = [[UIImageView alloc] init]; _shadowImageView.userInteractionEnabled = YES; _shadowImageView.image = [UIImage imageNamed:@"home_room_list_shadow_bg"]; } return _shadowImageView; } - (UIImageView *)noteContainImageView { if (!_noteContainImageView) { _noteContainImageView = [[UIImageView alloc] init]; _noteContainImageView.userInteractionEnabled = YES; _noteContainImageView.image = [[UIImage imageNamed:@"home_room_list_note_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 20, 15, 40) resizingMode:UIImageResizingModeStretch]; } return _noteContainImageView; } - (UILabel *)numberLabel { if (!_numberLabel) { _numberLabel = [[UILabel alloc] init]; _numberLabel.font = [UIFont systemFontOfSize:10]; _numberLabel.textColor = [UIColor whiteColor]; } return _numberLabel; } - (XPNoteView *)noteView { if (!_noteView) { _noteView = [[XPNoteView alloc] init]; _noteView.pillarColor = [UIColor whiteColor]; _noteView.pillarWidth = 1.5; [_noteView startAnimation]; } return _noteView; } - (SVGAImageView *)svgDisplayView { if (_svgDisplayView == nil) { _svgDisplayView = [[SVGAImageView alloc]init]; _svgDisplayView.contentMode = UIViewContentModeScaleToFill; _svgDisplayView.userInteractionEnabled = NO; _svgDisplayView.backgroundColor = [UIColor clearColor]; } return _svgDisplayView; } - (SVGAParser *)parser { if (!_parser) { _parser = [[SVGAParser alloc]init]; } return _parser; } @end