Files
peko-ios/YuMi/Modules/YMNewHome/View/Cell/XPNewHomePartyCollectionViewCell.m
2023-09-28 14:07:47 +08:00

226 lines
8.2 KiB
Objective-C

//
// XPNewHomePartyCollectionViewCell.m
// YuMi
//
// Created by duoban on 2023/9/4.
//
#import "XPNewHomePartyCollectionViewCell.h"
#import <SDWebImageFLPlugin/SDWebImageFLPlugin.h>
#import <SVGA.h>
@interface XPNewHomePartyCollectionViewCell()
///背景
@property(nonatomic,strong) NetImageView *bgImageView;
///阴影
@property(nonatomic,strong) UIImageView *shadowBgView;
///榜单
@property(nonatomic,strong) UIImageView *rankImageView;
///类型
@property(nonatomic,strong) NetImageView *tagBgImageView;
///房间名
@property(nonatomic,strong) UILabel *nameView;
///热度
@property(nonatomic,strong) UILabel *heatView;
///热度波浪
@property(nonatomic,strong) FLAnimatedImageView *heatGifView;
///pk
@property(nonatomic,strong) SVGAParser *parser;
@property(nonatomic,strong) SVGAImageView *pkImageView;
@end
@implementation XPNewHomePartyCollectionViewCell
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
for (int i = 0; i < 5; i++) {
NetImageConfig *config = [[NetImageConfig alloc]init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
NetImageView *iconView = [[NetImageView alloc]initWithConfig:config];
iconView.tag = 100 + i;
iconView.layer.cornerRadius = kGetScaleWidth(18)/2;
iconView.layer.masksToBounds = YES;
iconView.layer.borderWidth = 1;
iconView.layer.borderColor = [UIColor whiteColor].CGColor;
iconView.hidden = YES;
[self.bgImageView addSubview:iconView];
CGFloat left = kGetScaleWidth(8) + i * kGetScaleWidth(12);
[iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.nameView.mas_top).mas_offset(-kGetScaleWidth(2));
make.leading.mas_equalTo(left);
make.width.height.mas_equalTo(kGetScaleWidth(18));
}];
}
}
return self;
}
-(void)installUI{
[self.contentView addSubview:self.bgImageView];
[self.bgImageView addSubview:self.shadowBgView];
[self.contentView addSubview:self.rankImageView];
[self.bgImageView addSubview:self.tagBgImageView];
[self.bgImageView addSubview:self.pkImageView];
[self.bgImageView addSubview:self.nameView];
[self.bgImageView addSubview:self.heatGifView];
[self.bgImageView addSubview:self.heatView];
@kWeakify(self);
[self.parser parseWithNamed:@"pi_home_new_pk" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
@kStrongify(self);
self.pkImageView.loops = INT_MAX;
self.pkImageView.clearsAfterStop = NO;
self.pkImageView.videoItem = videoItem;
[self.pkImageView startAnimation];
} failureBlock:^(NSError * _Nullable error) {
}];
}
-(void)installConstraints{
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(170));
make.height.mas_equalTo(kGetScaleWidth(174));
make.center.equalTo(self.contentView);
}];
[self.shadowBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.bgImageView);
}];
[self.rankImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.equalTo(self.contentView);
make.width.mas_equalTo(kGetScaleWidth(174));
make.height.mas_equalTo(kGetScaleWidth(178));
}];
[self.tagBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.mas_equalTo(kGetScaleWidth(6));
make.width.mas_equalTo(kGetScaleWidth(46));
make.height.mas_equalTo(kGetScaleWidth(20));
}];
[self.heatView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-kGetScaleWidth(12));
make.bottom.mas_equalTo(-kGetScaleWidth(12));
make.height.mas_equalTo(kGetScaleWidth(12));
make.width.mas_equalTo(kGetScaleWidth(17));
}];
[self.heatGifView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(10));
make.height.mas_equalTo(kGetScaleWidth(9));
make.trailing.equalTo(self.heatView.mas_leading).mas_offset(-kGetScaleWidth(2));
make.centerY.equalTo(self.heatView);
}];
[self.nameView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(8));
make.bottom.mas_equalTo(-kGetScaleWidth(10));
make.trailing.equalTo(self.heatGifView.mas_leading).mas_equalTo(0);
make.height.mas_equalTo(kGetScaleWidth(20));
}];
[self.pkImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(23));
make.height.mas_equalTo(kGetScaleWidth(22));
make.trailing.mas_equalTo(-kGetScaleWidth(12));
make.bottom.equalTo(self.bgImageView.mas_bottom).mas_offset(-kGetScaleWidth(30));
}];
}
- (void)setRoomInfo:(HomePlayRoomModel *)roomInfo{
_roomInfo = roomInfo;
_nameView.text = _roomInfo.title;
_bgImageView.imageUrl = _roomInfo.avatar;
_tagBgImageView.imageUrl = _roomInfo.tagPict;
_heatView.text = @(_roomInfo.onlineNum).stringValue;
_rankImageView.image = nil;
_pkImageView.hidden = !_roomInfo.crossPking;
if(_roomInfo.isHourTop1 == YES){
_rankImageView.image = kImage(@"home_hour_no_1");
}else{
if(_roomInfo.isWeekTop1 == YES){
_rankImageView.image = kImage(@"home_week_no_1");
}
}
for (int i = 0; i < 5; i++) {
NetImageView *iconView = [self.bgImageView viewWithTag:100 + i];
if(i < _roomInfo.micUsers.count){
iconView.hidden = NO;
HomePlayMicUserModel *playModel = _roomInfo.micUsers[i];
iconView.imageUrl = playModel.avatar;
}else{
iconView.hidden = YES;
}
}
[self.heatView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.roomInfo.width);
}];
}
#pragma mark - 懒加载
- (NetImageView *)bgImageView{
if(!_bgImageView){
NetImageConfig *config = [[NetImageConfig alloc]init];
config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder];
_bgImageView = [[NetImageView alloc]initWithConfig:config];
[_bgImageView setCornerWithLeftTopCorner:kGetScaleWidth(14) rightTopCorner:kGetScaleWidth(14) bottomLeftCorner:kGetScaleWidth(15) bottomRightCorner:kGetScaleWidth(14) size:CGSizeMake(kGetScaleWidth(170), kGetScaleWidth(174))];
}
return _bgImageView;
}
- (UIImageView *)rankImageView{
if(!_rankImageView){
_rankImageView = [UIImageView new];
}
return _rankImageView;
}
- (NetImageView *)tagBgImageView{
if(!_tagBgImageView){
_tagBgImageView = [NetImageView new];
}
return _tagBgImageView;
}
- (UILabel *)nameView{
if(!_nameView){
_nameView = [UILabel labelInitWithText:@"" font:kFontMedium(14) textColor:[UIColor whiteColor]];
}
return _nameView;
}
-(UILabel *)heatView{
if(!_heatView){
_heatView = [UILabel labelInitWithText:@"0" font:kFontBold(10) textColor:[UIColor whiteColor]];
_heatView.textAlignment = NSTextAlignmentRight;
}
return _heatView;
}
- (FLAnimatedImageView *)heatGifView{
if(!_heatGifView){
_heatGifView = [FLAnimatedImageView new];
NSData *localData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"home_heat.gif" ofType:nil]];
FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:localData];
_heatGifView.animatedImage = animatedImage;
}
return _heatGifView;
}
- (UIImageView *)shadowBgView{
if(!_shadowBgView){
_shadowBgView = [UIImageView new];
_shadowBgView.image = kImage(@"home_friend_shadow_bg");
}
return _shadowBgView;
}
- (SVGAParser *)parser{
if(!_parser){
_parser = [SVGAParser new];
}
return _parser;
}
- (SVGAImageView *)pkImageView {
if (_pkImageView == nil) {
_pkImageView = [[SVGAImageView alloc]init];
_pkImageView.contentMode = UIViewContentModeScaleToFill;
_pkImageView.hidden = YES;
_pkImageView.backgroundColor = [UIColor clearColor];
}
return _pkImageView;
}
@end