// // QXHomeSubViewController.m // QXLive // // Created by 启星 on 2025/5/7. // #import "QXHomeSubViewController.h" #import "QXHomeRoomCell.h" #import "QXHomePageNetwork.h" @interface QXHomeSubViewController () @property (nonatomic,strong)UICollectionView *collectionView; @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView); @end @implementation QXHomeSubViewController -(UIView *)listView{ return self.view; } -(void)listWillAppear{ self.page = 1; [self getRoomList]; } -(UIScrollView *)listScrollView{ return self.collectionView; } - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback { self.scrollCallback = callback; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (self.scrollCallback != nil) { self.scrollCallback(scrollView); } } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } -(void)initSubViews{ self.page = 1; [self.view addSubview:self.collectionView]; // [self getRoomList]; self.bgImageHidden = YES; } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; [self.collectionView reloadData]; } -(void)setRoomType:(QXMyRoomType *)roomType{ _roomType = roomType; [self getRoomList]; } - (void)getRoomList { __weak typeof(self)weakSelf = self; [QXHomePageNetwork homeRoomListWithPage:self.page is_top:NO label_id:self.roomType.id successBlock:^(NSArray * _Nonnull list, BOOL isAppStore) { if (weakSelf.page == 1) { [weakSelf.dataArray removeAllObjects]; } [weakSelf.dataArray addObjectsFromArray:list]; [weakSelf.collectionView reloadData]; if (list.count == 0) { weakSelf.collectionView.mj_footer.state = MJRefreshStateNoMoreData; }else{ [weakSelf.collectionView.mj_footer endRefreshing]; } } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { [self.collectionView.mj_footer endRefreshing]; }]; } #pragma mark - UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.dataArray.count; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ QXHomeRoomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXHomeRoomCell" forIndexPath:indexPath]; cell.model = self.dataArray[indexPath.row]; return cell; } -(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{ QXHomeRoomCell *rCell = (QXHomeRoomCell *)cell; [rCell startAnimating]; } -(void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{ QXHomeRoomCell *rCell = (QXHomeRoomCell *)cell; [rCell endAnimating]; } -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ return CGSizeMake((SCREEN_WIDTH-15*3-1)/2.0, (SCREEN_WIDTH-15*3-1)/2.0); } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ QXRoomListModel *model = self.dataArray[indexPath.row]; [[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_id isRejoin:NO navagationController:self.navigationController]; } -(UICollectionView *)collectionView{ if (!_collectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 15; layout.minimumInteritemSpacing = 15; layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15); _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(NavContentHeight+TabbarContentHeight)) collectionViewLayout:layout]; _collectionView.delegate = self; _collectionView.dataSource = self; _collectionView.backgroundColor = [UIColor clearColor]; [_collectionView registerNib:[UINib nibWithNibName:@"QXHomeRoomCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXHomeRoomCell"]; MJWeakSelf _collectionView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{ weakSelf.page++; [weakSelf getRoomList]; }]; } return _collectionView; } @end