Files
peko-ios/YuMi/Modules/YMMine/View/Medals/MedalsWearingControlCollectionViewCell.m

188 lines
5.5 KiB
Mathematica
Raw Normal View History

//
// MedalsWearingControlCollectionViewCell.m
// YuMi
//
// Created by P on 2025/6/19.
//
#import "MedalsWearingControlCollectionViewCell.h"
#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
@interface MedalsWearingControlCollectionViewCell ()
@property (nonatomic, strong) NetImageView *medalImageView;
@property (nonatomic, strong) UIImageView *vipImageView;
@property (nonatomic, strong) VipPill *pill;
@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 {
if (level <= 0) {
self.pill.hidden = YES;
self.vipImageView.hidden = YES;
return;
}
self.vipImageView.hidden = NO;
NSString *imagePath = [NSString stringWithFormat:@"medals_control_vip%@",
@(level)];
self.vipImageView.image = kImage(imagePath);
self.pill.hidden = self.vipImageView.hidden;
[self.pill updateLevel:level];
}
- (void)updateMedal:(MedalVo *)medalVo {
if (!medalVo) {
self.medalImageView.imageUrl = @"";
return;
}
// 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 {
[self handleLegacyDisplay:medalVo];
}
return;
}
// 4.
self.medalImageView.imageUrl = @"";
}
#pragma mark - Debug
- (void)handleLegacyDisplay:(MedalVo *)medalVo {
if (![medalVo.picUrl hasSuffix:@"mp4"]) {
self.medalImageView.imageUrl = medalVo.picUrl;
} else {
self.medalImageView.image = [UIImageConstant defaultEmptyPlaceholder];
}
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self.contentView addSubview:self.medalImageView];
[self.contentView addSubview:self.vipImageView];
[self.contentView addSubview:self.pill];
[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));
}];
[self.pill mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.vipImageView);
}];
}
return self;
}
#pragma mark -
- (NetImageView *)medalImageView {
if (!_medalImageView) {
NetImageConfig *config = [[NetImageConfig alloc] init];
config.placeHolder = kImage(@"medals_control_position");
_medalImageView = [[NetImageView alloc] initWithConfig:config];
_medalImageView.contentMode = UIViewContentModeScaleAspectFill;
}
return _medalImageView;
}
- (UIImageView *)vipImageView {
if (!_vipImageView) {
_vipImageView = [[UIImageView alloc] init];
}
return _vipImageView;
}
- (VipPill *)pill {
if (!_pill) {
_pill = [[VipPill alloc] initWithFrame:CGRectZero];
}
return _pill;
}
@end