Files
midi_ios/QXLive/HomePage(声播)/View/房间/QXRoomOnlineUserListView.m
2025-09-08 08:49:04 +08:00

189 lines
6.9 KiB
Objective-C

//
// QXRoomOnlineUserListView.m
// QXLive
//
// Created by 启星 on 2025/6/9.
//
#import "QXRoomOnlineUserListView.h"
#import "QXBlackListCell.h"
#import "QXMineNetwork.h"
@interface QXRoomOnlineUserListView()<UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate,QXBlackListCellDelegate>
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,strong)NSMutableArray *allUsers;;
@end
@implementation QXRoomOnlineUserListView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(void)initSubviews{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
tap.delegate = self;
[self addGestureRecognizer:tap];
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, ScaleWidth(144), 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 = [NSString localizedStringWithFormat:QXText(@"在线用户(%@人)"),@"0"];
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 = 60;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
MJWeakSelf
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[weakSelf getOnlineList];
}];
[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)didHugSeatWithModel:(QXRoomUserInfoModel *)model isUpSeat:(BOOL)isUpSeat{
if (isUpSeat) {
return;
}
MJWeakSelf
[QXMineNetwork roomCompereApplyPitWithRoomId:self.roomId pit_number:self.pitNumber user_id:model.user_id type:@"1" successBlock:^(NSDictionary * _Nonnull dict) {
[weakSelf hide];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
showToast(msg);
}];
}
-(void)getOnlineList{
MJWeakSelf
[QXMineNetwork roomOnlineListWithRoomId:self.roomId page:0 successBlock:^(NSArray<QXRoomUserInfoModel *> * _Nonnull onPitList, NSArray<QXRoomUserInfoModel *> * _Nonnull offPitList) {
[weakSelf.dataArray removeAllObjects];
[weakSelf.allUsers removeAllObjects];
[weakSelf.dataArray addObject:onPitList];
[weakSelf.dataArray addObject:offPitList];
[weakSelf.allUsers addObjectsFromArray:onPitList];
[weakSelf.allUsers addObjectsFromArray:offPitList];
weakSelf.titleLabel.text = [NSString localizedStringWithFormat:QXText(@"在线用户(%@人)"),[NSString stringWithFormat:@"%ld",onPitList.count+offPitList.count]];
[weakSelf.tableView.mj_header endRefreshing];
[weakSelf.tableView reloadData];
if (weakSelf.onlineListBlock) {
weakSelf.onlineListBlock(weakSelf.allUsers);
}
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
[weakSelf.tableView.mj_header endRefreshing];
}];
}
-(void)setRoomId:(NSString *)roomId{
_roomId = roomId;
[self getOnlineList];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return self.dataArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSMutableArray *arr = self.dataArray[section];
return arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
QXBlackListCell *cell = [QXBlackListCell cellWithTableView:tableView];
if (self.isHugSeat) {
cell.cellType = QXBlackListCellTypeHugSeat;
}else{
cell.cellType = QXBlackListCellTypeOnline;
}
if (indexPath.section == 0) {
cell.isUpSeat = YES;
}else{
cell.isUpSeat = NO;
}
NSMutableArray *arr = self.dataArray[indexPath.section];
cell.onlineUser = arr[indexPath.row];
cell.delegate = self;
return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
header.backgroundColor = [UIColor whiteColor];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 0, SCREEN_WIDTH-32, 30)];
titleLabel.font = [UIFont systemFontOfSize:14];
titleLabel.textColor = RGB16(0x666666);
[header addSubview:titleLabel];
if (section == 0) {
titleLabel.text = @"麦上用户";
}else{
titleLabel.text = @"麦下用户";
}
return header;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 30;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSMutableArray *arr = self.dataArray[indexPath.section];
QXRoomUserInfoModel*user = arr[indexPath.row];
if (self.delegate && [self.delegate respondsToSelector:@selector(previewUserInfoWithUserId:)]) {
[self.delegate previewUserInfoWithUserId:user.user_id];
}
}
-(void)showInView:(UIView *)view{
self.bgView.y = SCREEN_HEIGHT;
[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;
}
-(NSMutableArray *)allUsers{
if (!_allUsers) {
_allUsers = [NSMutableArray array];
}
return _allUsers;
}
@end