Files
featherVoice/QXLive/Room(房间)/View/QXRoomOnlineUserListView.m
2025-12-10 10:01:27 +08:00

224 lines
7.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 *onPitListArray;
@property (nonatomic,strong)NSMutableArray *offPitListArray;
@property (nonatomic,strong)NSMutableArray *allUsers;;
@property (nonatomic,assign) NSInteger page;
@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.page = 1;
[weakSelf getOnlineList];
}];
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
weakSelf.page++;
[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:self.page successBlock:^(NSArray<QXRoomUserInfoModel *> * _Nonnull onPitList, NSArray<QXRoomUserInfoModel *> * _Nonnull offPitList, NSString * _Nonnull count) {
if (weakSelf.page == 1) {
[weakSelf.onPitListArray removeAllObjects];
[weakSelf.offPitListArray removeAllObjects];
[weakSelf.allUsers removeAllObjects];
}
[weakSelf.onPitListArray addObjectsFromArray:onPitList];
[weakSelf.offPitListArray addObjectsFromArray:offPitList];
[weakSelf.allUsers addObjectsFromArray:onPitList];
[weakSelf.allUsers addObjectsFromArray:offPitList];
weakSelf.titleLabel.text = [NSString localizedStringWithFormat:QXText(@"用户列表(%@人)"),[NSString stringWithFormat:@"%@",count]];
[weakSelf.tableView.mj_header endRefreshing];
[weakSelf.tableView.mj_footer endRefreshing];
[weakSelf.tableView reloadData];
if (weakSelf.onlineListBlock) {
weakSelf.onlineListBlock(weakSelf.allUsers);
}
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
[weakSelf.tableView.mj_header endRefreshing];
[weakSelf.tableView.mj_footer endRefreshing];
}];
}
-(void)setRoomId:(NSString *)roomId{
_roomId = roomId;
self.page = 1;
[self getOnlineList];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 0) {
return self.onPitListArray.count;
}else{
return self.offPitListArray.count;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
QXBlackListCell *cell = [QXBlackListCell cellWithTableView:tableView];
if (self.isHugSeat) {
cell.cellType = QXBlackListCellTypeHugSeat;
}else{
cell.cellType = QXBlackListCellTypeOnline;
}
QXRoomUserInfoModel *model;
if (indexPath.section == 0) {
cell.isUpSeat = YES;
model = self.onPitListArray[indexPath.row];
}else{
cell.isUpSeat = NO;
model = self.offPitListArray[indexPath.row];
}
cell.onlineUser = model;
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];
QXRoomUserInfoModel *user;
if (indexPath.section == 0) {
user = self.onPitListArray[indexPath.row];
}else{
user = self.offPitListArray[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 *)onPitListArray{
if (!_onPitListArray) {
_onPitListArray = [NSMutableArray array];
}
return _onPitListArray;
}
-(NSMutableArray *)offPitListArray{
if (!_offPitListArray) {
_offPitListArray = [NSMutableArray array];
}
return _offPitListArray;
}
-(NSMutableArray *)allUsers{
if (!_allUsers) {
_allUsers = [NSMutableArray array];
}
return _allUsers;
}
@end