284 lines
10 KiB
Objective-C
284 lines
10 KiB
Objective-C
//
|
|
// RoomBoomResultView.m
|
|
// YuMi
|
|
//
|
|
// Created by P on 2024/9/27.
|
|
//
|
|
|
|
#import "RoomBoomResultView.h"
|
|
|
|
#import "BoomInfoModel.h"
|
|
#import "RoomBoomManager.h"
|
|
#import "AttachmentModel.h"
|
|
|
|
@interface RoomBoomResultCollectionViewCell : UICollectionViewCell
|
|
|
|
@property (nonatomic, strong) NetImageView *giftPic;
|
|
@property (nonatomic, strong) BoomGiftModel *model;
|
|
|
|
@end
|
|
|
|
@implementation RoomBoomResultCollectionViewCell
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
if (self = [super initWithFrame:frame]) {
|
|
self.backgroundColor = [UIColor clearColor];
|
|
self.contentView.backgroundColor = [UIColor clearColor];
|
|
|
|
UIImageView *bg = [self bgView];
|
|
[self.contentView addSubview:bg];
|
|
[bg mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.contentView);
|
|
}];
|
|
|
|
[self.contentView addSubview:self.giftPic];
|
|
[self.giftPic mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(bg).insets(UIEdgeInsetsMake(10, 10, 10, 10));
|
|
}];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)setModel:(BoomGiftModel *)model {
|
|
_model = model;
|
|
self.giftPic.imageUrl = [model.awardPic stringByRemovingPercentEncoding];
|
|
}
|
|
|
|
- (UIImageView *)bgView {
|
|
UIImageView *bg = [[UIImageView alloc] initWithImage:kImage(@"room_boom_result_gift_cell_bg")];
|
|
return bg;
|
|
}
|
|
|
|
- (NetImageView *)giftPic {
|
|
if (!_giftPic) {
|
|
_giftPic = [[NetImageView alloc] init];
|
|
_giftPic.contentMode = UIViewContentModeScaleAspectFit;
|
|
}
|
|
return _giftPic;
|
|
}
|
|
|
|
@end
|
|
|
|
@interface RoomBoomResultView() <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
|
|
|
|
@property (nonatomic, strong) UIImageView *backgroundImageView;
|
|
@property (nonatomic, strong) UILabel *contentLabel;
|
|
@property (nonatomic, strong) UIButton *bottomButton;
|
|
@property (nonatomic, strong) UICollectionView *giftsCollectionView;
|
|
@property (nonatomic, copy) NSArray <BoomGiftModel *> * dataSource;
|
|
|
|
@end
|
|
|
|
@implementation RoomBoomResultView
|
|
|
|
+ (void)displayEmptyView:(UIView *)superView {
|
|
RoomBoomResultView *resultView = [[RoomBoomResultView alloc] init];
|
|
resultView.alpha = 0;
|
|
[superView addSubview:resultView];
|
|
[resultView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kGetScaleWidth(190));
|
|
make.leading.mas_equalTo(10);
|
|
make.trailing.mas_equalTo(-10);
|
|
make.height.mas_equalTo(kGetScaleWidth(198));
|
|
}];
|
|
|
|
[resultView setupForEmpty];
|
|
|
|
[UIView animateWithDuration:0.2 animations:^{
|
|
resultView.alpha = 1;
|
|
}];
|
|
}
|
|
|
|
+ (void)display:(UIView *)superView gifts:(NSArray <BoomGiftModel *> *)giftsArray {
|
|
RoomBoomResultView *resultView = [[RoomBoomResultView alloc] init];
|
|
resultView.alpha = 0;
|
|
[superView addSubview:resultView];
|
|
[resultView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kGetScaleWidth(190));
|
|
make.leading.mas_equalTo(10);
|
|
make.trailing.mas_equalTo(-10);
|
|
make.height.mas_equalTo(kGetScaleWidth(394));
|
|
}];
|
|
|
|
[resultView setupFroGifts];
|
|
resultView.dataSource = giftsArray;
|
|
|
|
[UIView animateWithDuration:0.2 animations:^{
|
|
resultView.alpha = 1;
|
|
}];
|
|
}
|
|
|
|
+ (void)display:(UIView *)superView attachment:(AttachmentModel *)attachment {
|
|
if (!attachment ||
|
|
![attachment.data isKindOfClass:[NSArray class]] ||
|
|
[attachment.data count] == 0) {
|
|
[[RoomBoomManager sharedManager] giftDisplayEnd];
|
|
return;
|
|
}
|
|
|
|
NSMutableArray *myGifts = @[].mutableCopy;
|
|
NSArray *gifts = [BoomGiftModel modelsWithArray:attachment.data];
|
|
for (BoomGiftModel *model in gifts) {
|
|
if (model.uid == [[AccountInfoStorage instance].getUid integerValue]) {
|
|
[myGifts addObject:model];
|
|
}
|
|
}
|
|
|
|
if (myGifts.count > 0) {
|
|
[RoomBoomResultView display:superView gifts:myGifts];
|
|
}
|
|
}
|
|
|
|
- (instancetype)init {
|
|
if (self = [super init]) {}
|
|
return self;
|
|
}
|
|
|
|
- (void)setDataSource:(NSArray<BoomGiftModel *> *)dataSource {
|
|
_dataSource = dataSource;
|
|
[self.giftsCollectionView reloadData];
|
|
}
|
|
|
|
- (void)setupForEmpty {
|
|
self.backgroundImageView.image = kImage(@"room_boom_empty_result_bg");
|
|
[self addSubview:self.backgroundImageView];
|
|
[self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self);
|
|
}];
|
|
|
|
self.contentLabel.text = YMLocalizedString(@"RoomBoom_0");
|
|
[self addSubview:self.contentLabel];
|
|
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self).offset(kGetScaleWidth(68));
|
|
make.leading.mas_equalTo(24);
|
|
make.trailing.mas_equalTo(-24);
|
|
}];
|
|
|
|
[self.bottomButton setTitle:@"OK" forState:UIControlStateNormal];
|
|
[self.bottomButton setBackgroundImage:kImage(@"room_boom_result_button_bg_1") forState:UIControlStateNormal];
|
|
[self addSubview:self.bottomButton];
|
|
[self.bottomButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(self).offset(kGetScaleWidth(-24));
|
|
make.centerX.mas_equalTo(self);
|
|
make.size.mas_equalTo(CGSizeMake(176, 44));
|
|
}];
|
|
}
|
|
|
|
- (void)setupFroGifts {
|
|
self.backgroundImageView.image = kImage(@"room_boom_gifts_result_bg");
|
|
[self addSubview:self.backgroundImageView];
|
|
[self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self);
|
|
}];
|
|
|
|
UIImageView *topContentImageView = [[UIImageView alloc] initWithImage:kImage(@"room_boom_result_top_bg")];
|
|
[self addSubview:topContentImageView];
|
|
[topContentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.backgroundImageView.mas_top);
|
|
make.centerX.mas_equalTo(self.backgroundImageView);
|
|
make.size.mas_equalTo(CGSizeMake(kGetScaleWidth(214.5), kGetScaleWidth(52.5)));
|
|
}];
|
|
|
|
UILabel *topContentLabel = [UILabel labelInitWithText:YMLocalizedString(@"Combo_6") font:kFontMedium(17.5) textColor:UIColorFromRGB(0xF0E7BA)];
|
|
[self addSubview:topContentLabel];
|
|
[topContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.center.mas_equalTo(topContentImageView);
|
|
}];
|
|
|
|
self.contentLabel.text = YMLocalizedString(@"RoomBoom_1");
|
|
self.contentLabel.font = kFontRegular(10);
|
|
[self addSubview:self.contentLabel];
|
|
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(topContentImageView.mas_bottom).offset(kGetScaleWidth(14));
|
|
make.leading.mas_equalTo(50);
|
|
make.trailing.mas_equalTo(-50);
|
|
}];
|
|
|
|
[self.bottomButton setTitle:@"GREAT" forState:UIControlStateNormal];
|
|
[self.bottomButton setBackgroundImage:kImage(@"room_boom_result_button_bg_1") forState:UIControlStateNormal];
|
|
[self addSubview:self.bottomButton];
|
|
[self.bottomButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(self).offset(kGetScaleWidth(-26));
|
|
make.centerX.mas_equalTo(self);
|
|
make.size.mas_equalTo(CGSizeMake(176, 44));
|
|
}];
|
|
|
|
[self addSubview:self.giftsCollectionView];
|
|
[self.giftsCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(16);
|
|
make.leading.mas_equalTo(kGetScaleWidth(35));
|
|
make.trailing.mas_equalTo(kGetScaleWidth(-35));
|
|
make.bottom.mas_equalTo(self.bottomButton.mas_top).offset(kGetScaleWidth(-30));
|
|
}];
|
|
}
|
|
|
|
- (void)didTapBottomButton {
|
|
[[RoomBoomManager sharedManager] giftDisplayEnd];
|
|
[self removeFromSuperview];
|
|
}
|
|
|
|
#pragma mark - UICollectionView delegate & datasource
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
return self.dataSource.count;
|
|
}
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
RoomBoomResultCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GiftCell" forIndexPath:indexPath];
|
|
cell.model = [self.dataSource xpSafeObjectAtIndex:indexPath.row];
|
|
return cell;
|
|
}
|
|
|
|
#pragma mark -
|
|
- (UIImageView *)backgroundImageView {
|
|
if (!_backgroundImageView) {
|
|
_backgroundImageView = [[UIImageView alloc] init];
|
|
_backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
}
|
|
return _backgroundImageView;
|
|
}
|
|
|
|
- (UILabel *)contentLabel {
|
|
if (!_contentLabel) {
|
|
_contentLabel = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:UIColorFromRGB(0xCBA1FF)];
|
|
_contentLabel.textAlignment = NSTextAlignmentCenter;
|
|
_contentLabel.numberOfLines = 0;
|
|
}
|
|
return _contentLabel;
|
|
}
|
|
|
|
- (UIButton *)bottomButton {
|
|
if (!_bottomButton) {
|
|
_bottomButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_bottomButton.titleLabel setFont:kFontMedium(15)];
|
|
[_bottomButton addTarget:self action:@selector(didTapBottomButton) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _bottomButton;
|
|
}
|
|
|
|
- (UICollectionView *)giftsCollectionView {
|
|
if (!_giftsCollectionView) {
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.itemSize = CGSizeMake(kGetScaleWidth(88), kGetScaleWidth(88)); // 设置每个item的大小
|
|
layout.minimumLineSpacing = 20; // 行间距
|
|
if (iPhoneXSeries) {
|
|
layout.minimumInteritemSpacing = 10; // 列间距
|
|
} else {
|
|
layout.minimumInteritemSpacing = 4;
|
|
}
|
|
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical; // 垂直滚动
|
|
|
|
_giftsCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero
|
|
collectionViewLayout:layout];
|
|
_giftsCollectionView.dataSource = self;
|
|
_giftsCollectionView.delegate = self;
|
|
_giftsCollectionView.showsVerticalScrollIndicator = NO;
|
|
_giftsCollectionView.backgroundColor = [UIColor clearColor];
|
|
[_giftsCollectionView registerClass:[RoomBoomResultCollectionViewCell class] forCellWithReuseIdentifier:@"GiftCell"];
|
|
}
|
|
return _giftsCollectionView;
|
|
}
|
|
|
|
|
|
@end
|