Files
peko-ios/YuMi/Modules/YMMine/View/Cell/MineInfo/XPMineMedalsTableViewCell.m
2024-09-04 16:11:11 +08:00

165 lines
5.9 KiB
Objective-C

//
// XPMineMedalsTableViewCell.m
// YuMi
//
// Created by P on 2024/6/25.
//
#import "XPMineMedalsTableViewCell.h"
#import "MedalModel.h"
#import <QGVAPWrapView.h>
#import "XPRoomGiftAnimationParser.h"
@interface XPMineMedalCell : UICollectionViewCell
@property (nonatomic, strong) NetImageView *imageView;
@property (nonatomic, strong) VAPView *vapView;
@property (nonatomic, strong) XPRoomGiftAnimationParser *vapParser;
@end
@implementation XPMineMedalCell
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_imageView = [[NetImageView alloc] initWithConfig:config];
_imageView.layer.masksToBounds = YES;
_imageView.layer.cornerRadius = 12;
[self.contentView addSubview:_imageView];
[_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
[self.contentView addSubview:self.vapView];
[self.vapView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
}
return self;
}
- (VAPView *)vapView {
if (!_vapView) {
_vapView = [[VAPView alloc] init];
_vapView.contentMode = UIViewContentModeScaleAspectFill;
}
return _vapView;
}
- (XPRoomGiftAnimationParser *)vapParser {
if (!_vapParser) {
_vapParser = [[XPRoomGiftAnimationParser alloc] init];
}
return _vapParser;
}
@end
@interface XPMineMedalsTableViewCell() <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *medalsCollectionView;
@property (nonatomic, strong) UILabel *noDataLabel;
@end
@implementation XPMineMedalsTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.contentView.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:self.medalsCollectionView];
[self.medalsCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.contentView).offset(8);
make.edges.mas_equalTo(self.contentView);
}];
[self.contentView addSubview:self.noDataLabel];
[self.noDataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.contentView);
}];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
- (void)setMedalsDataSource:(NSArray *)medalsDataSource {
_medalsDataSource = medalsDataSource;
self.noDataLabel.hidden = medalsDataSource.count > 0;
[self.medalsCollectionView reloadData];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.medalsDataSource.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
XPMineMedalCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Medal Cell"
forIndexPath:indexPath];
UserMedalModel *userMedal = [self.medalsDataSource xpSafeObjectAtIndex:indexPath.row];
if (userMedal) {
cell.imageView.imageUrl = userMedal.picUrl;
NSString *resourcePath = [userMedal.picUrl stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (resourcePath.length > 0) {
NSString *encodingUrl = [resourcePath stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:@"`#%^{}\"[]|\\<> "].invertedSet];
@kWeakify(cell);
[cell.vapParser parseWithURL:encodingUrl completionBlock:^(NSString * _Nullable videoUrl) {
@kStrongify(cell);
if (videoUrl.length) {
[cell.vapView setMute:YES];
[cell.vapView playHWDMP4:videoUrl repeatCount:-1 delegate:nil];
}
} failureBlock:^(NSError * _Nullable error) {
}];
}
}
return cell;
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(140, 140);
}
#pragma mark -
- (UICollectionView *)medalsCollectionView {
if (!_medalsCollectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.minimumInteritemSpacing = 10;
layout.minimumLineSpacing = 10;
_medalsCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero
collectionViewLayout:layout];
_medalsCollectionView.backgroundColor = [UIColor clearColor];
_medalsCollectionView.delegate = self;
_medalsCollectionView.dataSource = self;
[_medalsCollectionView registerClass:[XPMineMedalCell class]
forCellWithReuseIdentifier:@"Medal Cell"];
}
return _medalsCollectionView;
}
- (UILabel *)noDataLabel {
if (!_noDataLabel) {
_noDataLabel = [UILabel labelInitWithText:YMLocalizedString(@"XPMineDataGiftTableViewCell2") font:[UIFont systemFontOfSize:14 weight:UIFontWeightMedium] textColor:UIColorFromRGB(0x191919)];
_noDataLabel.textAlignment = NSTextAlignmentCenter;
_noDataLabel.alpha = 0.5;
_noDataLabel.hidden = YES;
}
return _noDataLabel;
}
@end