105 lines
3.6 KiB
Mathematica
105 lines
3.6 KiB
Mathematica
|
|
//
|
||
|
|
// QXRoomEmojiContentView.m
|
||
|
|
// QXLive
|
||
|
|
//
|
||
|
|
// Created by 启星 on 2025/10/22.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import "QXRoomEmojiContentView.h"
|
||
|
|
#import "QXEmojiCell.h"
|
||
|
|
#import "QXMineNetwork.h"
|
||
|
|
@interface QXRoomEmojiContentView()<UICollectionViewDelegate,UICollectionViewDataSource>
|
||
|
|
@property (nonatomic,strong)UICollectionView *collectionView;
|
||
|
|
@property (nonatomic,strong)NSMutableArray *dataArray;
|
||
|
|
@end
|
||
|
|
|
||
|
|
@implementation QXRoomEmojiContentView
|
||
|
|
|
||
|
|
-(UIView *)listView{
|
||
|
|
return self;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
||
|
|
{
|
||
|
|
self = [super initWithFrame:frame];
|
||
|
|
if (self) {
|
||
|
|
[self initSubviews];
|
||
|
|
}
|
||
|
|
return self;
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)initSubviews{
|
||
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||
|
|
layout.itemSize = CGSizeMake((int)(SCREEN_WIDTH-16*2-12*3)/4, ScaleWidth(75));
|
||
|
|
layout.minimumLineSpacing = 12;
|
||
|
|
layout.minimumInteritemSpacing = 12;
|
||
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);
|
||
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
||
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
||
|
|
[self.collectionView registerNib:[UINib nibWithNibName:@"QXEmojiCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXEmojiCell"];
|
||
|
|
self.collectionView.delegate = self;
|
||
|
|
self.collectionView.dataSource = self;
|
||
|
|
self.collectionView.showsHorizontalScrollIndicator = NO;
|
||
|
|
self.collectionView.bounces = NO;
|
||
|
|
self.collectionView.pagingEnabled = NO;
|
||
|
|
self.collectionView.backgroundColor = [UIColor clearColor];
|
||
|
|
[self addSubview:self.collectionView];
|
||
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
|
make.left.mas_equalTo(0);
|
||
|
|
make.top.mas_equalTo(12);
|
||
|
|
make.bottom.equalTo(self);
|
||
|
|
make.right.mas_equalTo(0);
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)setModel:(QXEmojiTypeModel *)model{
|
||
|
|
_model = model;
|
||
|
|
@weakify(self)
|
||
|
|
[QXMineNetwork roomEmojiListWithTypeId:model.id pid:@"" successBlock:^(NSArray<QXEmojiModel *> * _Nonnull list) {
|
||
|
|
@strongify(self);
|
||
|
|
[self.dataArray removeAllObjects];
|
||
|
|
[self.dataArray addObjectsFromArray:list];
|
||
|
|
[self.collectionView reloadData];
|
||
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
||
|
|
return self.dataArray.count;
|
||
|
|
}
|
||
|
|
|
||
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
|
QXEmojiCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXEmojiCell" forIndexPath:indexPath];
|
||
|
|
cell.model = self.dataArray[indexPath.row];
|
||
|
|
return cell;
|
||
|
|
}
|
||
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
|
QXEmojiModel *md = self.dataArray[indexPath.row];
|
||
|
|
QXEmojiModel *result = [self randomResultWithEmoji:md];
|
||
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectedEmoji:)]) {
|
||
|
|
[self.delegate didSelectedEmoji:result];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
-(QXEmojiModel*)randomResultWithEmoji:(QXEmojiModel*)emoji{
|
||
|
|
QXEmojiModel *result;
|
||
|
|
if (emoji.children.count>0) {
|
||
|
|
NSUInteger randomIndex = arc4random() % emoji.children.count;
|
||
|
|
QXEmojiChirldModel *md = emoji.children[randomIndex];
|
||
|
|
result = [[QXEmojiModel alloc] init];
|
||
|
|
result.image = md.image;
|
||
|
|
result.animate_image = emoji.animate_image;
|
||
|
|
}else{
|
||
|
|
result = emoji;
|
||
|
|
}
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
-(NSMutableArray *)dataArray{
|
||
|
|
if (!_dataArray) {
|
||
|
|
_dataArray = [NSMutableArray array];
|
||
|
|
}
|
||
|
|
return _dataArray;
|
||
|
|
}
|
||
|
|
@end
|