233 lines
9.1 KiB
Objective-C
233 lines
9.1 KiB
Objective-C
//
|
|
// QXRoomUserCharmView.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/9/8.
|
|
//
|
|
|
|
#import "QXRoomUserCharmView.h"
|
|
#import "QXMineNetwork.h"
|
|
#import "NSString+QX.h"
|
|
|
|
@interface QXRoomUserCharmView()<UIGestureRecognizerDelegate,UITableViewDelegate,UITableViewDataSource>
|
|
@property (nonatomic,strong)UILabel *titleLabel;
|
|
@property (nonatomic,strong)UITableView *tableView;
|
|
@property (nonatomic,strong)UIView *bgView;
|
|
@property (nonatomic,strong)NSMutableArray *dataArray;
|
|
@end
|
|
@implementation QXRoomUserCharmView
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubviews];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
-(void)initSubviews{
|
|
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
|
|
tap.delegate = self;
|
|
[self addGestureRecognizer:tap];
|
|
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, ScaleWidth(429)+kSafeAreaBottom)];
|
|
self.bgView.backgroundColor = [UIColor whiteColor];
|
|
[self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
|
|
[self addSubview:self.bgView];
|
|
|
|
self.titleLabel = [[UILabel alloc] init];
|
|
self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
self.titleLabel.text = @"魅力值详情";
|
|
self.titleLabel.textColor = QXConfig.textColor;
|
|
self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
|
|
[self.bgView addSubview:self.titleLabel];
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(27);
|
|
make.left.right.equalTo(self.bgView);
|
|
make.height.mas_equalTo(24);
|
|
}];
|
|
|
|
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
|
|
self.tableView.delegate = self;
|
|
self.tableView.dataSource = self;
|
|
self.tableView.rowHeight = 55;
|
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
MJWeakSelf
|
|
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
[weakSelf getCharmList];
|
|
}];
|
|
[self.bgView addSubview:self.tableView];
|
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.titleLabel.mas_bottom).offset(12);
|
|
make.bottom.equalTo(self.bgView);
|
|
make.left.right.equalTo(self.bgView);
|
|
}];
|
|
}
|
|
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
|
|
return touch.view == self;
|
|
}
|
|
-(void)setRoomId:(NSString *)roomId{
|
|
_roomId = roomId;
|
|
}
|
|
-(void)setUserId:(NSString *)userId{
|
|
_userId = userId;
|
|
[self getCharmList];
|
|
}
|
|
|
|
-(void)getCharmList{
|
|
MJWeakSelf
|
|
[QXMineNetwork getRoomUserCharmListWithRoomId:self.roomId userId:self.userId successBlock:^(NSArray * _Nonnull list) {
|
|
[weakSelf.dataArray removeAllObjects];
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
|
[weakSelf.tableView reloadData];
|
|
[weakSelf.tableView.mj_header endRefreshing];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
[weakSelf.tableView.mj_header endRefreshing];
|
|
}];
|
|
}
|
|
|
|
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
|
return self.dataArray.count;
|
|
}
|
|
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXRoomUserCharmCell *cell = [QXRoomUserCharmCell cellWithTableView:tableView];
|
|
cell.model = self.dataArray[indexPath.row];
|
|
return cell;
|
|
}
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXRoomUserCharmModel *model = self.dataArray[indexPath.row];
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(previewUserInfoWithUserId:)]) {
|
|
[self.delegate previewUserInfoWithUserId:model.user_id];
|
|
}
|
|
}
|
|
|
|
-(void)showInView:(UIView *)view{
|
|
[view addSubview:self];
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
self.bgView.y = SCREEN_HEIGHT-ScaleWidth(429)-kSafeAreaBottom;
|
|
}];
|
|
}
|
|
-(void)hide{
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
self.bgView.y = SCREEN_HEIGHT;
|
|
} completion:^(BOOL finished) {
|
|
[self removeFromSuperview];
|
|
}];
|
|
}
|
|
-(NSMutableArray *)dataArray{
|
|
if (!_dataArray) {
|
|
_dataArray = [NSMutableArray array];
|
|
}
|
|
return _dataArray;
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
@implementation QXRoomUserCharmCell
|
|
|
|
+(instancetype)cellWithTableView:(UITableView*)tableView{
|
|
static NSString *cellId = @"QXRoomUserCharmCell";
|
|
QXRoomUserCharmCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
|
|
if (!cell) {
|
|
cell = [[QXRoomUserCharmCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId];
|
|
cell.backgroundColor = [UIColor clearColor];
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
}
|
|
return cell;
|
|
}
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
[self initSubviews];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)setModel:(QXRoomUserCharmModel *)model{
|
|
_model = model;
|
|
self.nameLabel.text = model.nickname;
|
|
self.IdLabel.text= [NSString stringWithFormat:@"ID:%@",model.user_code];
|
|
[self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]];
|
|
self.charmLabel.text = [NSString qx_showHotCountNumDouble:model.charm.longLongValue];
|
|
[self.collectionView reloadData];
|
|
}
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
return self.model.icon.count;
|
|
}
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXTagImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXTagImageCell" forIndexPath:indexPath];
|
|
cell.imageUrl = self.model.icon[indexPath.row];
|
|
return cell;
|
|
}
|
|
-(void)initSubviews{
|
|
self.headImageView = [[UIImageView alloc] init];
|
|
self.headImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
self.headImageView.clipsToBounds = YES;
|
|
[self.headImageView addRoundedCornersWithRadius:ScaleWidth(21.5)];
|
|
[self.contentView addSubview:self.headImageView];
|
|
[self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(16);
|
|
make.width.height.mas_equalTo(43);
|
|
make.centerY.equalTo(self.contentView);
|
|
}];
|
|
|
|
self.nameLabel = [[UILabel alloc] init];
|
|
self.nameLabel.textColor = RGB16(0x333333);
|
|
self.nameLabel.font = [UIFont systemFontOfSize:14];
|
|
[self.contentView addSubview:self.nameLabel];
|
|
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self.headImageView.mas_right).offset(8);
|
|
make.top.equalTo(self.headImageView);
|
|
make.height.mas_equalTo(21);
|
|
}];
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.itemSize = CGSizeMake(42, 16);
|
|
layout.minimumLineSpacing = 7;
|
|
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
self.collectionView.delegate = self;
|
|
self.collectionView.dataSource = self;
|
|
self.collectionView.backgroundColor = UIColor.clearColor;
|
|
[self.collectionView registerClass:[QXTagImageCell class] forCellWithReuseIdentifier:@"QXTagImageCell"];
|
|
[self addSubview:self.collectionView];
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self.nameLabel.mas_right).offset(8);
|
|
make.height.mas_equalTo(21);
|
|
make.centerY.equalTo(self.nameLabel);
|
|
make.width.mas_equalTo(126);
|
|
}];
|
|
|
|
self.IdLabel = [[UILabel alloc] init];
|
|
self.IdLabel.textColor = RGB16(0x999999);
|
|
self.IdLabel.font = [UIFont systemFontOfSize:12];
|
|
[self.contentView addSubview:self.IdLabel];
|
|
[self.IdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self.headImageView.mas_right).offset(8);
|
|
make.bottom.equalTo(self.headImageView);
|
|
make.height.mas_equalTo(18);
|
|
}];
|
|
|
|
self.charmLabel = [[UILabel alloc] init];
|
|
self.charmLabel.textColor = RGB16(0x333333);
|
|
self.charmLabel.font = [UIFont systemFontOfSize:14];
|
|
[self.contentView addSubview:self.charmLabel];
|
|
[self.charmLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(-16);
|
|
make.centerY.equalTo(self.contentView);
|
|
make.height.mas_equalTo(21);
|
|
}];
|
|
|
|
self.charmIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_user_charm_icon"]];
|
|
self.charmIconView.contentMode = UIViewContentModeScaleAspectFill;
|
|
[self.contentView addSubview:self.charmIconView];
|
|
[self.charmIconView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.equalTo(self.charmLabel.mas_left).offset(-6);
|
|
make.width.height.mas_equalTo(18);
|
|
make.centerY.equalTo(self.contentView);
|
|
}];
|
|
}
|
|
@end
|