
refactor(勋章排行): 重构排行榜分页加载和刷新逻辑 fix(会话): 优化官方账号判断逻辑和跳转处理 style(UI): 调整勋章排行榜和游戏菜单UI布局 chore: 更新Podfile配置和bitcode框架列表
374 lines
12 KiB
Objective-C
374 lines
12 KiB
Objective-C
//
|
|
// MedalsDetailView.m
|
|
// YuMi
|
|
//
|
|
// Created by P on 2025/6/18.
|
|
//
|
|
|
|
#import "MedalsDetailView.h"
|
|
#import "MedalsModel.h"
|
|
#import <QGVAPWrapView.h>
|
|
#import "XPRoomGiftAnimationParser.h"
|
|
#import "MedalsLevelIndicatorView.h"
|
|
|
|
@interface MedalsDetailView ()
|
|
|
|
@property (nonatomic, strong) UIImageView *bgLightImageView;
|
|
@property(nonatomic, copy) NSString *imagePath;
|
|
@property(nonatomic, copy) NSString *mp4Path;
|
|
@property(nonatomic, strong) NetImageView *imageView;
|
|
@property(nonatomic, strong) VAPView *mp4View;
|
|
@property(nonatomic, strong) XPRoomGiftAnimationParser *mp4Parser;
|
|
@property (nonatomic, strong) UILabel *titleLabel;
|
|
@property (nonatomic, strong) UILabel *subLabel;
|
|
@property (nonatomic, strong) MedalsLevelIndicatorView *levelIndicatorView;
|
|
|
|
@property (nonatomic, strong) MedalSeriesItemVo *currentSeriesItemVO;
|
|
@property (nonatomic, strong) MedalVo *displayModel;
|
|
|
|
@end
|
|
|
|
@implementation MedalsDetailView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self setupUI];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)setupUI {
|
|
self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.8];
|
|
|
|
[self addSubview:self.bgLightImageView];
|
|
[self.bgLightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.leading.trailing.mas_equalTo(self);
|
|
make.height.mas_equalTo(self.bgLightImageView.mas_width);
|
|
}];
|
|
|
|
self.imageView = [[NetImageView alloc] init];
|
|
self.imageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
[self addSubview:self.imageView];
|
|
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self);
|
|
make.top.mas_equalTo(kGetScaleWidth(135));
|
|
make.size.mas_equalTo(CGSizeMake(228, 228));
|
|
}];
|
|
|
|
[self addSubview:self.mp4View];
|
|
[self.mp4View mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.imageView);
|
|
}];
|
|
|
|
self.titleLabel = [UILabel labelInitWithText:@"" font:kFontSemibold(20) textColor:[UIColor whiteColor]];
|
|
self.subLabel = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:[UIColor colorWithWhite:1 alpha:0.6]];
|
|
self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
self.subLabel.textAlignment = NSTextAlignmentCenter;
|
|
self.subLabel.numberOfLines = 2;
|
|
[self addSubview:self.titleLabel];
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self);
|
|
make.top.mas_equalTo(self.imageView.mas_bottom).offset(8);
|
|
make.leading.trailing.mas_equalTo(self).inset(13);
|
|
make.height.mas_equalTo(28);
|
|
}];
|
|
[self addSubview:self.subLabel];
|
|
[self.subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self);
|
|
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(12);
|
|
make.leading.trailing.mas_equalTo(self).inset(3);
|
|
}];
|
|
|
|
// 添加等级指示器
|
|
self.levelIndicatorView = [[MedalsLevelIndicatorView alloc] init];
|
|
[self addSubview:self.levelIndicatorView];
|
|
[self.levelIndicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self);
|
|
make.top.mas_equalTo(self.subLabel.mas_bottom).offset(33);
|
|
make.leading.trailing.mas_greaterThanOrEqualTo(self).inset(8);
|
|
make.height.mas_equalTo(66);
|
|
}];
|
|
|
|
// 设置等级选择回调
|
|
@kWeakify(self);
|
|
self.levelIndicatorView.levelSelectedBlock = ^(NSInteger level) {
|
|
@kStrongify(self);
|
|
// 处理等级选择事件
|
|
if (self.currentSeriesItemVO && level <= self.currentSeriesItemVO.medalVos.count) {
|
|
MedalVo *selectedMedalVo = [self.currentSeriesItemVO.medalVos xpSafeObjectAtIndex:level - 1];
|
|
if (selectedMedalVo) {
|
|
self.displayModel = selectedMedalVo;
|
|
[self updateDisplayWithCurrentModel];
|
|
}
|
|
}
|
|
};
|
|
|
|
// 在 levelIndicatorView 底部添加一个视图作为关闭按钮区域
|
|
UIView *closeButtonView = [[UIView alloc] init];
|
|
closeButtonView.backgroundColor = [UIColor clearColor];
|
|
[self addSubview:closeButtonView];
|
|
[closeButtonView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.levelIndicatorView.mas_bottom).offset(20);
|
|
make.bottom.leading.trailing.mas_equalTo(self);
|
|
}];
|
|
|
|
// 添加点击手势到关闭按钮区域
|
|
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleBackgroundTap:)];
|
|
[closeButtonView addGestureRecognizer:tapGesture];
|
|
|
|
UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[back setBackgroundImage:kImage(@"common_nav_back_white") forState:UIControlStateNormal];
|
|
[back addTarget:selfWeak action:@selector(handleBackgroundTap:) forControlEvents:UIControlEventTouchUpInside];
|
|
[self addSubview:back];
|
|
[back mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(16);
|
|
make.top.mas_equalTo(kStatusBarHeight);
|
|
make.size.mas_equalTo(CGSizeMake(22, 22));
|
|
}];
|
|
}
|
|
|
|
- (void)setDetailItemVo:(MedalSeriesItemVo *)detailItemVo {
|
|
// _detailItemVo = detailItemVo;
|
|
self.currentSeriesItemVO = detailItemVo;
|
|
self.displayModel = [detailItemVo.medalVos xpSafeObjectAtIndex:0];
|
|
|
|
[self.levelIndicatorView setupWithMaxLevel:self.currentSeriesItemVO.medalLevel];
|
|
for (MedalVo *vo in detailItemVo.medalVos) {
|
|
if (vo.level > self.displayModel.level) {
|
|
self.displayModel = vo;
|
|
}
|
|
}
|
|
[self.levelIndicatorView setSelectedLevel:self.displayModel.level animated:NO];
|
|
[self.levelIndicatorView setSeriesItems:detailItemVo.medalVos];
|
|
|
|
// 设置指示器类型为带图片
|
|
self.levelIndicatorView.indicatorType = MedalsLevelIndicatorTypeWithImage;
|
|
|
|
// 为每个等级设置对应的图片,使用新的 URL 优先级逻辑
|
|
for (MedalVo *medalVo in detailItemVo.medalVos) {
|
|
NSString *imageUrl = [self getImageUrlForMedal:medalVo];
|
|
[self.levelIndicatorView setImageUrl:imageUrl forLevel:medalVo.level];
|
|
}
|
|
|
|
[self updateDisplayWithCurrentModel];
|
|
}
|
|
|
|
- (void)updateDisplayWithCurrentModel {
|
|
if (!self.displayModel) {
|
|
[self showDefaultPlaceholder];
|
|
return;
|
|
}
|
|
|
|
#if 0
|
|
// Debug 环境:如果数据不满足新条件,使用原有逻辑
|
|
if ([NSString isEmpty:self.displayModel.mp4Url] && ![NSString isEmpty:self.displayModel.picUrl]) {
|
|
// 使用原有逻辑:通过 picUrl 后缀判断
|
|
if ([self.displayModel.picUrl hasSuffix:@"mp4"]) {
|
|
[self setMp4Path:self.displayModel.picUrl];
|
|
} else {
|
|
[self setImagePath:self.displayModel.picUrl];
|
|
}
|
|
self.titleLabel.text = self.displayModel.name;
|
|
self.subLabel.text = self.displayModel.medalDesc;
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
// 新逻辑:优先使用 mp4URL
|
|
if (![NSString isEmpty:self.displayModel.mp4Url]) {
|
|
[self setMp4Path:self.displayModel.mp4Url];
|
|
} else if (![NSString isEmpty:self.displayModel.picUrl]) {
|
|
// mp4URL 为空,使用 picURL
|
|
if ([NSString isValidImageURL:self.displayModel.picUrl]) {
|
|
[self setImagePath:self.displayModel.picUrl];
|
|
} else {
|
|
// picURL 不是有效图片,显示默认占位图
|
|
[self showDefaultPlaceholder];
|
|
}
|
|
} else {
|
|
// 都为空,显示默认占位图
|
|
[self showDefaultPlaceholder];
|
|
}
|
|
|
|
self.titleLabel.text = self.displayModel.name;
|
|
self.subLabel.text = self.displayModel.medalDesc;
|
|
}
|
|
|
|
#pragma mark - 私有方法
|
|
|
|
/// 显示默认占位图
|
|
- (void)showDefaultPlaceholder {
|
|
[self stopMP4Playback];
|
|
self.mp4View.hidden = YES;
|
|
self.imageView.hidden = NO;
|
|
|
|
// 设置默认占位图
|
|
self.imageView.imageUrl = @"";
|
|
self.imageView.image = [UIImageConstant defaultEmptyPlaceholder];
|
|
}
|
|
|
|
/// 根据新的优先级逻辑获取勋章的图片URL
|
|
- (NSString *)getImageUrlForMedal:(MedalVo *)medal {
|
|
if (!medal) {
|
|
return @"";
|
|
}
|
|
|
|
#if 0
|
|
// Debug 环境:如果数据不满足新条件,使用原有逻辑
|
|
if ([NSString isEmpty:medal.mp4Url] && ![NSString isEmpty:medal.picUrl]) {
|
|
return medal.picUrl;
|
|
}
|
|
#endif
|
|
|
|
// 新逻辑:优先使用 mp4URL
|
|
if (![NSString isEmpty:medal.mp4Url]) {
|
|
return medal.mp4Url;
|
|
} else if (![NSString isEmpty:medal.picUrl]) {
|
|
// mp4URL 为空,使用 picURL (需要验证是否为有效图片)
|
|
if ([NSString isValidImageURL:medal.picUrl]) {
|
|
return medal.picUrl;
|
|
} else {
|
|
// picURL 不是有效图片,返回空字符串
|
|
return @"";
|
|
}
|
|
} else {
|
|
// 都为空,返回空字符串
|
|
return @"";
|
|
}
|
|
}
|
|
|
|
- (void)setImagePath:(NSString *)imagePath {
|
|
// 停止之前的 mp4 播放
|
|
[self stopMP4Playback];
|
|
|
|
_imagePath = imagePath;
|
|
self.mp4View.hidden = YES;
|
|
self.imageView.hidden = NO;
|
|
self.imageView.imageUrl = imagePath;
|
|
}
|
|
|
|
- (void)setMp4Path:(NSString *)mp4Path {
|
|
// 如果是相同的 mp4 路径,不需要重新加载
|
|
// if ([_mp4Path isEqualToString:mp4Path]) {
|
|
// return;
|
|
// }
|
|
|
|
// 停止之前的 mp4 播放
|
|
[self stopMP4Playback];
|
|
|
|
_mp4Path = mp4Path;
|
|
self.mp4View.hidden = NO;
|
|
self.imageView.hidden = YES;
|
|
|
|
if (!_mp4Parser) {
|
|
self.mp4Parser = [[XPRoomGiftAnimationParser alloc] init];
|
|
}
|
|
|
|
@kWeakify(self);
|
|
[self.mp4Parser parseWithURL:mp4Path
|
|
completionBlock:^(NSString * _Nullable videoUrl) {
|
|
@kStrongify(self);
|
|
if (![NSString isEmpty:videoUrl]) {
|
|
[self.mp4View playHWDMP4:videoUrl repeatCount:-1 delegate:nil];
|
|
}
|
|
} failureBlock:^(NSError * _Nullable error) {
|
|
@kStrongify(self);
|
|
NSLog(@"Failed to parse mp4: %@", error);
|
|
// MP4 解析失败,降级使用 picURL
|
|
[self handleMP4FailureWithFallback];
|
|
}];
|
|
}
|
|
|
|
/// 处理 MP4 播放失败,降级使用 picURL
|
|
- (void)handleMP4FailureWithFallback {
|
|
if (![NSString isEmpty:self.displayModel.picUrl]) {
|
|
if ([NSString isValidImageURL:self.displayModel.picUrl]) {
|
|
[self setImagePath:self.displayModel.picUrl];
|
|
} else {
|
|
[self showDefaultPlaceholder];
|
|
}
|
|
} else {
|
|
[self showDefaultPlaceholder];
|
|
}
|
|
}
|
|
|
|
#pragma mark - MP4 播放控制
|
|
|
|
- (void)stopMP4Playback {
|
|
if (self.mp4View) {
|
|
[self.mp4View stopHWDMP4];
|
|
self.mp4View.tag = 0; // 重置播放状态标记
|
|
}
|
|
}
|
|
|
|
- (void)pauseMP4Playback {
|
|
if (self.mp4View && !self.mp4View.hidden) {
|
|
[self.mp4View pauseHWDMP4];
|
|
}
|
|
}
|
|
|
|
- (void)resumeMP4Playback {
|
|
if (self.mp4View && !self.mp4View.hidden && self.mp4Path) {
|
|
if (self.mp4View.tag == 1) { // 已准备好但尚未播放
|
|
@kWeakify(self);
|
|
[self.mp4Parser parseWithURL:self.mp4Path
|
|
completionBlock:^(NSString * _Nullable videoUrl) {
|
|
@kStrongify(self);
|
|
if (![NSString isEmpty:videoUrl]) {
|
|
[self.mp4View playHWDMP4:videoUrl repeatCount:-1 delegate:nil];
|
|
}
|
|
} failureBlock:^(NSError * _Nullable error) {
|
|
@kStrongify(self);
|
|
// MP4 恢复播放失败,降级使用 picURL
|
|
[self handleMP4FailureWithFallback];
|
|
}];
|
|
} else {
|
|
[self.mp4View resumeHWDMP4];
|
|
}
|
|
}
|
|
}
|
|
|
|
#pragma mark -
|
|
- (UIImageView *)bgLightImageView {
|
|
if (!_bgLightImageView) {
|
|
_bgLightImageView = [[UIImageView alloc] initWithImage:kImage(@"medals_lights")];
|
|
}
|
|
return _bgLightImageView;
|
|
}
|
|
|
|
- (VAPView *)mp4View {
|
|
if (!_mp4View) {
|
|
_mp4View = [[VAPView alloc] init];
|
|
_mp4View.contentMode = UIViewContentModeScaleAspectFit;
|
|
}
|
|
return _mp4View;
|
|
}
|
|
|
|
// 修改处理背景点击的方法名称,使其更符合实际功能
|
|
- (void)handleBackgroundTap:(UITapGestureRecognizer *)gesture {
|
|
[self removeFromSuperview];
|
|
}
|
|
|
|
// 重写 removeFromSuperview 方法,确保在移除前停止 MP4 播放
|
|
- (void)removeFromSuperview {
|
|
// 停止 MP4 播放并释放资源
|
|
[self stopMP4Playback];
|
|
self.mp4Parser = nil;
|
|
|
|
[super removeFromSuperview];
|
|
}
|
|
|
|
// 添加 dealloc 方法确保资源被正确释放
|
|
- (void)dealloc {
|
|
// 停止 MP4 播放
|
|
[self stopMP4Playback];
|
|
|
|
// 清理资源
|
|
self.mp4Parser = nil;
|
|
NSLog(@"MedalsDetailView dealloc");
|
|
}
|
|
|
|
@end
|