
refactor(勋章排行): 重构排行榜分页加载和刷新逻辑 fix(会话): 优化官方账号判断逻辑和跳转处理 style(UI): 调整勋章排行榜和游戏菜单UI布局 chore: 更新Podfile配置和bitcode框架列表
188 lines
5.5 KiB
Objective-C
188 lines
5.5 KiB
Objective-C
//
|
||
// 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
|