137 lines
4.9 KiB
Objective-C
137 lines
4.9 KiB
Objective-C
//
|
|
// QXHomeSubViewController.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/5/7.
|
|
//
|
|
|
|
#import "QXHomeSubViewController.h"
|
|
#import "QXHomeRoomCell.h"
|
|
#import "QXHomePageNetwork.h"
|
|
|
|
@interface QXHomeSubViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
|
|
@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)viewWillAppear:(BOOL)animated{
|
|
[super viewWillAppear:animated];
|
|
QXLOG(@"========首页子控制器即将展示========");
|
|
}
|
|
-(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;
|
|
@weakify(self)
|
|
[QXHomePageNetwork homeRoomListWithPage:self.page is_top:NO label_id:self.roomType.id successBlock:^(NSArray<QXRoomListModel *> * _Nonnull list, BOOL isAppStore) {
|
|
@strongify(self)
|
|
if (self.page == 1) {
|
|
[self.dataArray removeAllObjects];
|
|
}
|
|
[self.dataArray addObjectsFromArray:list];
|
|
[self.collectionView reloadData];
|
|
if (list.count == 0) {
|
|
self.collectionView.mj_footer.state = MJRefreshStateNoMoreData;
|
|
}else{
|
|
[self.collectionView.mj_footer endRefreshing];
|
|
}
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
@strongify(self)
|
|
[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
|
|
@weakify(self)
|
|
_collectionView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
|
|
@strongify(self)
|
|
self.page++;
|
|
[self getRoomList];
|
|
}];
|
|
}
|
|
return _collectionView;
|
|
}
|
|
|
|
|
|
@end
|