// // QXDirectListView.m // IsLandVoice // // Created by 启星 on 2025/3/6. // #import "QXDirectListView.h" #import "QXDirectListCell.h" #import "QXAddDirectView.h" #import "QXMineNetwork.h" #import "QXAlertView.h" @interface QXDirectListView() @property (nonatomic,strong)UIView *bgView; @property (nonatomic,strong)UILabel *titleLabel; @property (nonatomic,strong)UIButton *addBtn; @property (nonatomic,strong)UITableView*tableView; @property (nonatomic,strong)NSMutableArray*dataArray; @property (nonatomic,strong)QXAlertView *alertView; @end @implementation QXDirectListView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); [self createViews]; } return self; } -(void)createViews{ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)]; tap.delegate = self; [self addGestureRecognizer:tap]; self.backgroundColor = [UIColor clearColor]; self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, ScaleWidth(429))]; self.bgView.backgroundColor = [UIColor whiteColor]; [self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)]; [self addSubview:self.bgView]; self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 16, 300, 24)]; self.titleLabel.text = @"主持人"; self.titleLabel.font = [UIFont boldSystemFontOfSize:16]; self.titleLabel.textColor = [UIColor colorWithHexString:@"#333333"]; [self.bgView addSubview:self.titleLabel]; self.addBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.width-75, 5, 60, 40)]; [self.addBtn setTitle:@"添加主持" forState:(UIControlStateNormal)]; [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:(UIControlStateNormal)]; self.addBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.addBtn addTarget:self action:@selector(addAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.bgView addSubview:self.addBtn]; self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom+6, self.width, self.bgView.height-6-self.titleLabel.bottom) style:(UITableViewStylePlain)]; if (@available(iOS 15.0, *)) { self.tableView.sectionHeaderTopPadding = 0; } else { // Fallback on earlier versions } self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.tableFooterView = [UIView new]; self.tableView.delegate = self; self.tableView.dataSource = self; [self.bgView addSubview:self.tableView]; } -(void)setRoomId:(NSString *)roomId{ _roomId = roomId; [self getDirectList]; } -(void)getDirectList{ MJWeakSelf [QXMineNetwork roomManagerListWithRoomId:self.roomId type:1 successBlock:^(NSArray * _Nonnull list) { [weakSelf.dataArray removeAllObjects]; [weakSelf.dataArray addObjectsFromArray:list]; [weakSelf.tableView reloadData]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)addAction{ [self hide]; QXAddDirectView *v = [[QXAddDirectView alloc] init]; v.roomId = self.roomId; for (UIWindow *w in [UIApplication sharedApplication].windows) { if ([w isKeyWindow]) { [v showInView:w]; break; } } } -(void)setDirectRatioSuccess{ [self getDirectList]; } -(void)removeDirectSuccess{ [self getDirectList]; } -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ return touch.view == self; } -(void)showInView:(UIView *)view{ [view addSubview:self]; [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = SCREEN_HEIGHT-ScaleWidth(429); }]; } -(void)hide{ [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = SCREEN_HEIGHT; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } //-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // [self hide]; //} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ QXDirectListCell *cell = [QXDirectListCell cellWithTableView:tableView]; QXRoomOnlineList *model = self.dataArray[indexPath.row]; cell.delegate = self; cell.roomId = self.roomId; cell.model = model; return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 126; } -(NSMutableArray *)dataArray{ if (!_dataArray) { _dataArray = [NSMutableArray array]; } return _dataArray; } -(QXAlertView *)alertView{ if (!_alertView) { _alertView = [[QXAlertView alloc] initWithFrame:CGRectMake(0, 0, ScaleWidth(300), ScaleWidth(175))]; MJWeakSelf _alertView.commitBlock = ^{ }; } return _alertView; } @end