2025-06-19 19:22:56 +08:00
|
|
|
|
//
|
|
|
|
|
// MedalsWearingControlCollectionViewCell.m
|
|
|
|
|
// YuMi
|
|
|
|
|
//
|
|
|
|
|
// Created by P on 2025/6/19.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "MedalsWearingControlCollectionViewCell.h"
|
2025-06-23 15:55:11 +08:00
|
|
|
|
#import "MedalsModel.h"
|
|
|
|
|
|
|
|
|
|
@interface VipPill : UIView
|
|
|
|
|
|
|
|
|
|
- (void)updateLevel:(NSInteger)level;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation VipPill {
|
|
|
|
|
UILabel *contentLabel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
|
|
|
{
|
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
|
if (self) {
|
|
|
|
|
[self addGradientBackgroundWithColors:@[
|
|
|
|
|
UIColorFromRGB(0xf2e7ff),
|
|
|
|
|
UIColorFromRGB(0xb497f6)
|
|
|
|
|
] startPoint:CGPointMake(0, 0.5) endPoint:CGPointMake(1, 0.5) cornerRadius:6.5];
|
|
|
|
|
[self setAllCornerRadius:6.5 borderWidth:1 borderColor:[UIColor whiteColor]];
|
|
|
|
|
|
|
|
|
|
contentLabel = [UILabel labelInitWithText:@"VIP" font:kFontHeavy(10) textColor:UIColorFromRGB(0x1b0043)];
|
|
|
|
|
[self addSubview:contentLabel];
|
|
|
|
|
[contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.center.mas_equalTo(self);
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)updateLevel:(NSInteger)level {
|
|
|
|
|
contentLabel.text = [NSString stringWithFormat:@"VIP%@", @(level)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
2025-06-19 19:22:56 +08:00
|
|
|
|
|
|
|
|
|
@interface MedalsWearingControlCollectionViewCell ()
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, strong) NetImageView *medalImageView;
|
|
|
|
|
@property (nonatomic, strong) UIImageView *vipImageView;
|
2025-06-23 15:55:11 +08:00
|
|
|
|
@property (nonatomic, strong) VipPill *pill;
|
2025-06-19 19:22:56 +08:00
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation MedalsWearingControlCollectionViewCell
|
|
|
|
|
|
|
|
|
|
+ (NSString *)cellID {
|
|
|
|
|
return NSStringFromClass([MedalsWearingControlCollectionViewCell class]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void)registerTo:(UICollectionView *)collectionView {
|
|
|
|
|
[collectionView registerClass:[self class] forCellWithReuseIdentifier:[self cellID]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (instancetype)cellFor:(UICollectionView *)collectionView atIndexPath:(NSIndexPath *)index {
|
|
|
|
|
MedalsWearingControlCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[self cellID]
|
|
|
|
|
forIndexPath:index];
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)updateVIPLevel:(NSInteger)level {
|
2025-06-23 15:55:11 +08:00
|
|
|
|
if (level <= 0) {
|
|
|
|
|
self.pill.hidden = YES;
|
|
|
|
|
self.vipImageView.hidden = YES;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.vipImageView.hidden = NO;
|
2025-06-19 19:22:56 +08:00
|
|
|
|
NSString *imagePath = [NSString stringWithFormat:@"medals_control_vip%@",
|
|
|
|
|
@(level)];
|
|
|
|
|
self.vipImageView.image = kImage(imagePath);
|
2025-06-23 15:55:11 +08:00
|
|
|
|
|
|
|
|
|
self.pill.hidden = self.vipImageView.hidden;
|
|
|
|
|
[self.pill updateLevel:level];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)updateMedal:(MedalVo *)medalVo {
|
|
|
|
|
if (!medalVo) {
|
|
|
|
|
self.medalImageView.imageUrl = @"";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-06-27 19:56:03 +08:00
|
|
|
|
|
|
|
|
|
// 按照新的显示逻辑处理(该 Cell 只支持图片显示)
|
|
|
|
|
[self handleMedalDisplay:medalVo];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - 新的显示逻辑
|
|
|
|
|
- (void)handleMedalDisplay:(MedalVo *)medalVo {
|
|
|
|
|
if (!medalVo) {
|
|
|
|
|
self.medalImageView.imageUrl = @"";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 1. 优先判断 mp4Url 是否有内容
|
|
|
|
|
if (![NSString isEmpty:medalVo.mp4Url]) {
|
|
|
|
|
// 该 Cell 不支持 mp4,降级使用 picUrl
|
|
|
|
|
if (![NSString isEmpty:medalVo.picUrl] && [NSString isImageFormat:medalVo.picUrl]) {
|
|
|
|
|
self.medalImageView.imageUrl = medalVo.picUrl;
|
|
|
|
|
} else {
|
|
|
|
|
// picUrl 不是图片格式或为空,显示默认占位图
|
|
|
|
|
self.medalImageView.imageUrl = @"";
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. mp4Url 为空,使用 picUrl
|
|
|
|
|
if (![NSString isEmpty:medalVo.picUrl]) {
|
|
|
|
|
// 3. 使用 picUrl 时,判断内容是否为图片
|
|
|
|
|
if ([NSString isImageFormat:medalVo.picUrl]) {
|
|
|
|
|
self.medalImageView.imageUrl = medalVo.picUrl;
|
|
|
|
|
} else {
|
2025-07-03 19:35:17 +08:00
|
|
|
|
[self handleLegacyDisplay:medalVo];
|
2025-06-27 19:56:03 +08:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 4. 都为空,显示默认占位图
|
|
|
|
|
self.medalImageView.imageUrl = @"";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - 旧版显示逻辑(用于 Debug 环境兼容)
|
|
|
|
|
- (void)handleLegacyDisplay:(MedalVo *)medalVo {
|
2025-06-23 15:55:11 +08:00
|
|
|
|
if (![medalVo.picUrl hasSuffix:@"mp4"]) {
|
|
|
|
|
self.medalImageView.imageUrl = medalVo.picUrl;
|
2025-07-03 19:35:17 +08:00
|
|
|
|
} else {
|
|
|
|
|
self.medalImageView.image = [UIImageConstant defaultEmptyPlaceholder];
|
2025-06-23 15:55:11 +08:00
|
|
|
|
}
|
2025-06-19 19:22:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
|
|
|
{
|
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
|
if (self) {
|
|
|
|
|
[self.contentView addSubview:self.medalImageView];
|
|
|
|
|
[self.contentView addSubview:self.vipImageView];
|
2025-06-23 15:55:11 +08:00
|
|
|
|
[self.contentView addSubview:self.pill];
|
2025-06-19 19:22:56 +08:00
|
|
|
|
|
|
|
|
|
[self.medalImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.edges.mas_equalTo(self.contentView);
|
|
|
|
|
}];
|
|
|
|
|
[self.vipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.centerX.mas_equalTo(self.contentView);
|
|
|
|
|
make.centerY.mas_equalTo(self.contentView.mas_bottom);
|
|
|
|
|
make.size.mas_equalTo(CGSizeMake(32, 13));
|
|
|
|
|
}];
|
2025-06-23 15:55:11 +08:00
|
|
|
|
[self.pill mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.edges.mas_equalTo(self.vipImageView);
|
|
|
|
|
}];
|
2025-06-19 19:22:56 +08:00
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
- (NetImageView *)medalImageView {
|
|
|
|
|
if (!_medalImageView) {
|
|
|
|
|
NetImageConfig *config = [[NetImageConfig alloc] init];
|
|
|
|
|
config.placeHolder = kImage(@"medals_control_position");
|
|
|
|
|
_medalImageView = [[NetImageView alloc] initWithConfig:config];
|
2025-06-27 19:56:03 +08:00
|
|
|
|
_medalImageView.contentMode = UIViewContentModeScaleAspectFill;
|
2025-06-19 19:22:56 +08:00
|
|
|
|
}
|
|
|
|
|
return _medalImageView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIImageView *)vipImageView {
|
|
|
|
|
if (!_vipImageView) {
|
|
|
|
|
_vipImageView = [[UIImageView alloc] init];
|
|
|
|
|
}
|
|
|
|
|
return _vipImageView;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 15:55:11 +08:00
|
|
|
|
- (VipPill *)pill {
|
|
|
|
|
if (!_pill) {
|
|
|
|
|
_pill = [[VipPill alloc] initWithFrame:CGRectZero];
|
|
|
|
|
}
|
|
|
|
|
return _pill;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-19 19:22:56 +08:00
|
|
|
|
@end
|