343 lines
12 KiB
Objective-C
343 lines
12 KiB
Objective-C
//
|
|
// XPBlankCollectionViewCell.m
|
|
// YuMi
|
|
//
|
|
// Created by Linus on 2024/12/19.
|
|
//
|
|
|
|
#import "XPPartyRoomItemCollectionViewCell.h"
|
|
|
|
@interface XPPartyRoomItemCollectionViewCell ()
|
|
|
|
@property(nonatomic,strong) NetImageView *avatarView;
|
|
@property(nonatomic,strong) NetImageView *rankImageView;
|
|
@property(nonatomic,strong) NetImageView *tagImageView;
|
|
@property (nonatomic, strong) NetImageView *flagImage;
|
|
@property (nonatomic,strong) NetImageView *boomImageView;
|
|
@property(nonatomic,strong) UILabel *nameLabel;
|
|
@property(nonatomic,strong) MarqueeLabel *subLabel;
|
|
@property(nonatomic,strong) UIImageView *heatIcon;
|
|
@property(nonatomic,strong) UILabel *heatNumLable;
|
|
@property (nonatomic, strong) UIImageView *bottomShadow;
|
|
@property (nonatomic, strong) NetImageView *levelImageView;
|
|
@end
|
|
|
|
@implementation XPPartyRoomItemCollectionViewCell
|
|
|
|
+ (NSString *)blankCellID {
|
|
return @"blankCellID";
|
|
}
|
|
|
|
+ (NSString *)itemCellID {
|
|
return NSStringFromClass([self class]);
|
|
}
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
self.contentView.backgroundColor = [UIColor clearColor];
|
|
self.clipsToBounds = NO;
|
|
self.contentView.clipsToBounds = NO;
|
|
|
|
[self installUI];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)installUI {
|
|
[self.contentView addSubview:self.avatarView];
|
|
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.contentView).offset(14);
|
|
make.leading.trailing.mas_equalTo(self.contentView).inset(8);
|
|
make.height.mas_equalTo(self.avatarView.mas_width) ;
|
|
}];
|
|
|
|
[self.contentView addSubview:self.rankImageView];
|
|
[self.rankImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.contentView);
|
|
make.leading.trailing.mas_equalTo(self.contentView);
|
|
make.height.mas_equalTo(self.rankImageView.mas_width) ;
|
|
}];
|
|
|
|
[self.contentView addSubview:self.tagImageView];
|
|
[self.tagImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.avatarView).offset(8);
|
|
make.trailing.mas_equalTo(self.avatarView).offset(-8);
|
|
make.height.mas_equalTo(20);
|
|
make.width.mas_equalTo(60);
|
|
}];
|
|
|
|
[self.contentView addSubview:self.flagImage];
|
|
[self.flagImage mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.avatarView.mas_leading);
|
|
make.top.mas_equalTo(self.avatarView.mas_bottom).offset(8);
|
|
make.size.mas_equalTo(CGSizeMake(18, 14));
|
|
}];
|
|
|
|
[self.contentView addSubview:self.nameLabel];
|
|
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.flagImage);
|
|
make.leading.mas_equalTo(self.flagImage.mas_trailing).offset(4);
|
|
make.trailing.mas_equalTo(self.avatarView.mas_trailing);
|
|
}];
|
|
|
|
[self.contentView addSubview:self.subLabel];
|
|
[self.contentView addSubview:self.heatNumLable];
|
|
[self.heatNumLable mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.trailing.mas_equalTo(self.avatarView).offset(-10);
|
|
make.centerY.mas_equalTo(self.subLabel);
|
|
}];
|
|
|
|
[self.contentView addSubview:self.heatIcon];
|
|
[self.heatIcon mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.subLabel);
|
|
make.trailing.mas_equalTo(self.heatNumLable.mas_leading).offset(2);
|
|
make.size.mas_equalTo(CGSizeMake(15, 15));
|
|
}];
|
|
|
|
|
|
[self.subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.avatarView).offset(10);
|
|
make.trailing.mas_equalTo(self.heatIcon.mas_leading).offset(-4);
|
|
make.bottom.mas_equalTo(self.avatarView).offset(-8);
|
|
}];
|
|
|
|
[self.contentView addSubview:self.boomImageView];
|
|
[self.boomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.trailing.mas_equalTo(self.heatNumLable);
|
|
make.bottom.mas_equalTo(self.heatNumLable.mas_top).offset(-8);
|
|
make.size.mas_equalTo(CGSizeMake(25, 37));
|
|
}];
|
|
|
|
[self.contentView insertSubview:self.bottomShadow belowSubview:self.rankImageView];
|
|
[self.bottomShadow mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.leading.trailing.mas_equalTo(self.avatarView);
|
|
make.height.mas_equalTo(kGetScaleWidth(34));
|
|
}];
|
|
|
|
[self.contentView addSubview:self.levelImageView];
|
|
[self.levelImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.avatarView).offset(2);
|
|
make.top.mas_equalTo(self.tagImageView);
|
|
make.size.mas_equalTo(CGSizeMake(38, 15));
|
|
}];
|
|
}
|
|
|
|
- (void)prepareForReuse {
|
|
[super prepareForReuse];
|
|
// 重置图像,释放引用,避免复用持有
|
|
[self.avatarView cancelLoadImage];
|
|
self.avatarView.imageUrl = nil;
|
|
self.rankImageView.image = nil;
|
|
[self.tagImageView cancelLoadImage];
|
|
self.tagImageView.image = nil;
|
|
[self.levelImageView cancelLoadImage];
|
|
self.levelImageView.imageUrl = nil;
|
|
[self.boomImageView cancelLoadImage];
|
|
self.boomImageView.imageUrl = nil;
|
|
[self.flagImage cancelLoadImage];
|
|
self.flagImage.imageUrl = nil;
|
|
|
|
// 重置文本
|
|
self.nameLabel.attributedText = nil;
|
|
self.nameLabel.text = @"";
|
|
self.subLabel.text = @"";
|
|
self.heatNumLable.text = @"0";
|
|
}
|
|
|
|
- (void)setRoomInfo:(HomePlayRoomModel *)roomInfo {
|
|
_roomInfo = roomInfo;
|
|
self.avatarView.imageUrl = roomInfo.avatar;
|
|
self.levelImageView.imageUrl = roomInfo.roomLevelIcon;
|
|
if (roomInfo.hourTop > 0) {
|
|
NSString *name = [NSString stringWithFormat:@"room_level_top_%ld", (long)roomInfo.hourTop];
|
|
self.rankImageView.image = [UIImage getLanguageImage:name];
|
|
} else {
|
|
self.rankImageView.image = nil;
|
|
}
|
|
|
|
if (roomInfo.roomBoom) {
|
|
self.boomImageView.hidden = NO;
|
|
self.boomImageView.imageUrl = [roomInfo roomBoomPic];
|
|
} else {
|
|
self.boomImageView.hidden = YES;
|
|
}
|
|
|
|
self.flagImage.imageUrl = roomInfo.regionFlag;
|
|
self.flagImage.hidden = [NSString isEmpty:roomInfo.regionFlag];
|
|
self.heatNumLable.text = [NSString isEmpty:roomInfo.hotValue.stringValue] ? @"0" : @(roomInfo.hotValue.integerValue).stringValue;
|
|
|
|
[self updateRoomName];
|
|
[self updateSubTitleAndTag];
|
|
|
|
}
|
|
|
|
- (void)updateRoomName {
|
|
NSString *title = self.roomInfo.title;
|
|
switch (self.roomInfo.homeRoomType) {
|
|
case 1:{
|
|
NSTextAttachment *attach = [[NSTextAttachment alloc] init];
|
|
attach.image = kImage(@"room_type_rd");
|
|
attach.bounds = CGRectMake(0, 2, 14, 14);
|
|
NSAttributedString *attachString = [NSAttributedString attributedStringWithAttachment:attach];
|
|
NSAttributedString *titleString = [[NSAttributedString alloc] initWithString:title
|
|
attributes:@{
|
|
NSFontAttributeName: kFontSemibold(15),
|
|
NSForegroundColorAttributeName: UIColorFromRGB(0x313131)
|
|
}];
|
|
NSMutableAttributedString *ms = [[NSMutableAttributedString alloc] initWithAttributedString:titleString];
|
|
[ms insertAttributedString:attachString atIndex:0];
|
|
self.nameLabel.attributedText = ms;
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
NSTextAttachment *attach = [[NSTextAttachment alloc] init];
|
|
attach.image = kImage(@"room_type_cs");
|
|
attach.bounds = CGRectMake(0, 2, 14, 14);
|
|
NSAttributedString *attachString = [NSAttributedString attributedStringWithAttachment:attach];
|
|
NSAttributedString *titleString = [[NSAttributedString alloc] initWithString:title
|
|
attributes:@{
|
|
NSFontAttributeName: kFontSemibold(15),
|
|
NSForegroundColorAttributeName: UIColorFromRGB(0x313131)
|
|
}];
|
|
NSMutableAttributedString *ms = [[NSMutableAttributedString alloc] initWithAttributedString:titleString];
|
|
[ms insertAttributedString:attachString atIndex:0];
|
|
_nameLabel.attributedText = ms;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
_nameLabel.text = _roomInfo.title;
|
|
break;
|
|
}
|
|
}
|
|
|
|
- (void)updateSubTitleAndTag {
|
|
if ([NSString isEmpty:self.roomInfo.tagPict]) {
|
|
self.subLabel.text = self.roomInfo.roomDesc.length > 0 ? self.roomInfo.roomDesc : YMLocalizedString(@"XPHomeMineViewController3");
|
|
self.tagImageView.hidden = YES;
|
|
} else {
|
|
@kWeakify(self);
|
|
[self.tagImageView loadImageWithUrl:self.roomInfo.tagPict
|
|
completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) {
|
|
@kStrongify(self);
|
|
if (image) {
|
|
self.tagImageView.hidden = NO;
|
|
self.tagImageView.image = image;
|
|
CGFloat width = kGetScaleWidth(62);
|
|
if (image.size.height > 0){
|
|
width = image.size.width * kGetScaleWidth(19) / image.size.height;
|
|
}
|
|
[self.tagImageView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(width);
|
|
}];
|
|
[self layoutIfNeeded];
|
|
} else {
|
|
self.tagImageView.hidden = YES;
|
|
}
|
|
self.subLabel.text = [NSString stringWithFormat:@" %@", self.roomInfo.roomDesc.length > 0 ? self.roomInfo.roomDesc : YMLocalizedString(@"XPHomeMineViewController3")];
|
|
}];
|
|
}
|
|
}
|
|
|
|
#pragma mark -
|
|
|
|
- (NetImageView *)avatarView{
|
|
if(!_avatarView){
|
|
NetImageConfig *config = [[NetImageConfig alloc]init];
|
|
config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder];
|
|
_avatarView = [[NetImageView alloc]initWithConfig:config];
|
|
_avatarView.contentMode = UIViewContentModeScaleAspectFill;
|
|
[_avatarView setCornerRadius:12];
|
|
}
|
|
return _avatarView;
|
|
}
|
|
|
|
- (NetImageView *)rankImageView{
|
|
if(!_rankImageView){
|
|
_rankImageView = [NetImageView new];
|
|
}
|
|
return _rankImageView;
|
|
}
|
|
|
|
- (NetImageView *)tagImageView{
|
|
if(!_tagImageView){
|
|
_tagImageView = [NetImageView new];
|
|
}
|
|
return _tagImageView;
|
|
}
|
|
|
|
- (NetImageView *)boomImageView{
|
|
if(!_boomImageView){
|
|
_boomImageView = [NetImageView new];
|
|
_boomImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
}
|
|
return _boomImageView;
|
|
}
|
|
|
|
- (NetImageView *)flagImage{
|
|
if(!_flagImage){
|
|
_flagImage = [NetImageView new];
|
|
_flagImage.contentMode = UIViewContentModeScaleAspectFit;
|
|
}
|
|
return _flagImage;
|
|
}
|
|
|
|
- (UILabel *)nameLabel{
|
|
if(!_nameLabel){
|
|
_nameLabel = [UILabel labelInitWithText:@""
|
|
font:kFontMedium(15)
|
|
textColor:UIColorFromRGB(0x1E1E1F)];
|
|
_nameLabel.adjustsFontSizeToFitWidth = YES;
|
|
_nameLabel.minimumScaleFactor = 0.5;
|
|
}
|
|
return _nameLabel;
|
|
}
|
|
|
|
- (MarqueeLabel *)subLabel{
|
|
if(!_subLabel){
|
|
_subLabel = [[MarqueeLabel alloc] init];
|
|
_subLabel.text = @"";
|
|
_subLabel.font = kFontRegular(13);
|
|
_subLabel.textColor = [UIColor whiteColor];
|
|
_subLabel.textAlignment = NSTextAlignmentLeft;
|
|
_subLabel.scrollDuration = 3.0;
|
|
_subLabel.fadeLength = 8.0f;
|
|
_subLabel.animationDelay = 1.0;
|
|
}
|
|
return _subLabel;
|
|
}
|
|
|
|
- (UIImageView *)heatIcon{
|
|
if(!_heatIcon){
|
|
_heatIcon = [UIImageView new];
|
|
_heatIcon.image = kImage(@"ms_home_heat_icon");
|
|
}
|
|
return _heatIcon;
|
|
}
|
|
|
|
-(UILabel *)heatNumLable{
|
|
if(!_heatNumLable){
|
|
_heatNumLable = [UILabel labelInitWithText:@"0" font:kFontMedium(12) textColor:[UIColor whiteColor]];
|
|
_heatNumLable.textAlignment = NSTextAlignmentRight;
|
|
}
|
|
return _heatNumLable;
|
|
}
|
|
|
|
- (UIImageView *)bottomShadow {
|
|
if (!_bottomShadow) {
|
|
_bottomShadow = [[UIImageView alloc] initWithImage:kImage(@"room_bottom_shadow")];
|
|
}
|
|
return _bottomShadow;
|
|
}
|
|
|
|
- (NetImageView *)levelImageView{
|
|
if(!_levelImageView){
|
|
_levelImageView = [[NetImageView alloc]init];
|
|
}
|
|
return _levelImageView;
|
|
}
|
|
|
|
@end
|