298 lines
12 KiB
Objective-C
298 lines
12 KiB
Objective-C
//
|
|
// QXMyRoomSubViewController.m
|
|
// IsLandVoice
|
|
//
|
|
// Created by 启星 on 2025/3/5.
|
|
//
|
|
|
|
#import "QXMyRoomSubViewController.h"
|
|
#import "QXHomeRoomCell.h"
|
|
#import "QXMyRoomListCell.h"
|
|
#import "QXMyHistoryHeaderView.h"
|
|
#import "QXMineNetwork.h"
|
|
#import "QXMyRoomViewController.h"
|
|
#import "QXMyCpRoomListCell.h"
|
|
|
|
@interface QXMyRoomSubViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,QXMyHistoryHeaderViewDelegate>
|
|
@property (nonatomic,strong)UICollectionView *collectionView;
|
|
@property (nonatomic,strong)NSMutableArray *dataArray;
|
|
@property (nonatomic,strong)NSMutableArray *historyArray;
|
|
@property (nonatomic,strong)NSMutableArray *cpRoomArray;
|
|
|
|
|
|
@property (nonatomic,strong) QXMyHistoryHeaderView *headerView;
|
|
@property (nonatomic,assign)NSInteger page;
|
|
|
|
|
|
@end
|
|
|
|
@implementation QXMyRoomSubViewController
|
|
-(UIView *)listView{
|
|
return self.view;
|
|
}
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
[self initSubview];
|
|
}
|
|
-(void)initSubview{
|
|
self.page = 1;
|
|
[self.view addSubview:self.collectionView];
|
|
[self getRoomList];
|
|
}
|
|
-(void)refreshRoom{
|
|
self.page = 1;
|
|
[self getRoomList];
|
|
}
|
|
-(void) getRoomList{
|
|
MJWeakSelf
|
|
[QXMineNetwork myRoomListWithType:[NSString stringWithFormat:@"%ld",self.type] page:self.page successBlock:^(NSArray<QXRoomListModel *> * _Nonnull list) {
|
|
|
|
if (self.page == 1) {
|
|
[weakSelf.dataArray removeAllObjects];
|
|
}
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
|
if (list.count == 0) {
|
|
if (weakSelf.type == 0) {
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}else{
|
|
weakSelf.collectionView.mj_footer.state = MJRefreshStateNoMoreData;
|
|
}
|
|
}else{
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}
|
|
[weakSelf.collectionView.mj_header endRefreshing];
|
|
[weakSelf.collectionView reloadData];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
[weakSelf.collectionView.mj_header endRefreshing];
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}];
|
|
if (self.type == 0) {
|
|
[QXMineNetwork myHistoryRoomWithPage:self.page successBlock:^(NSArray<QXMyRoomHistory *> * _Nonnull list) {
|
|
if (weakSelf.page == 1) {
|
|
[weakSelf.historyArray removeAllObjects];
|
|
}
|
|
[weakSelf.historyArray addObjectsFromArray:list];
|
|
if (list.count == 0) {
|
|
weakSelf.collectionView.mj_footer.state = MJRefreshStateNoMoreData;
|
|
}else{
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}
|
|
[weakSelf.collectionView.mj_header endRefreshing];
|
|
[weakSelf.collectionView reloadData];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
[weakSelf.collectionView.mj_header endRefreshing];
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}];
|
|
|
|
[QXMineNetwork getMyCpRoomListSuccessBlock:^(NSArray<QXRoomListCpModel *> * _Nonnull list) {
|
|
[weakSelf.cpRoomArray removeAllObjects];
|
|
[weakSelf.cpRoomArray addObjectsFromArray:list];
|
|
[weakSelf.collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
}];
|
|
}
|
|
// [self.dataArray addObject:@""];
|
|
// [self.dataArray addObject:@""];
|
|
// [self.dataArray addObject:@""];
|
|
// [self.dataArray addObject:@""];
|
|
// [self.historyArray addObject:@""];
|
|
}
|
|
#pragma mark - QXMyHistoryHeaderViewDelegate
|
|
-(void)didClickClearBtn{
|
|
MJWeakSelf
|
|
[QXMineNetwork clearRoomHistorySuccessBlock:^(NSArray<QXRoomListCpModel *> * _Nonnull list) {
|
|
[self.historyArray removeAllObjects];
|
|
[self.collectionView reloadData];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
showToast(msg);
|
|
}];
|
|
}
|
|
- (void)requestDeleteAllFootprintData {
|
|
|
|
}
|
|
#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
|
|
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
|
|
if (self.type == 0) {
|
|
return 3;
|
|
}
|
|
return 1;
|
|
}
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
if (self.type == 0) {
|
|
if (section == 0) {
|
|
return self.dataArray.count;;
|
|
}else if (section == 1) {
|
|
return self.cpRoomArray.count;;
|
|
}else{
|
|
return self.historyArray.count;
|
|
}
|
|
}
|
|
return self.dataArray.count;
|
|
}
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
if (self.type == 0) {
|
|
if (indexPath.section == 0) {
|
|
QXMyRoomListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXMyRoomListCell" forIndexPath:indexPath];
|
|
cell.type = self.type;
|
|
cell.model = self.dataArray[indexPath.row];
|
|
return cell;
|
|
}else if (indexPath.section == 1) {
|
|
QXMyCpRoomListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXMyCpRoomListCell" forIndexPath:indexPath];
|
|
cell.type = self.type;
|
|
cell.cpModel = self.cpRoomArray[indexPath.row];
|
|
return cell;
|
|
}else{
|
|
QXHomeRoomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXHomeRoomCell" forIndexPath:indexPath];
|
|
cell.historyModel = self.historyArray[indexPath.row];
|
|
return cell;
|
|
}
|
|
}else if (self.type == 1){
|
|
QXMyRoomListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXMyRoomListCell" forIndexPath:indexPath];
|
|
cell.type = self.type;
|
|
cell.model = self.dataArray[indexPath.row];
|
|
return cell;
|
|
}else{
|
|
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{
|
|
if ([cell isKindOfClass:[QXHomeRoomCell class]]) {
|
|
QXHomeRoomCell *rCell = (QXHomeRoomCell *)cell;
|
|
[rCell startAnimating];
|
|
}
|
|
}
|
|
-(void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
if ([cell isKindOfClass:[QXHomeRoomCell class]]) {
|
|
QXHomeRoomCell *rCell = (QXHomeRoomCell *)cell;
|
|
[rCell endAnimating];
|
|
}
|
|
}
|
|
|
|
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
if (self.type == 0) {
|
|
if (indexPath.section == 0 || indexPath.section == 1) {
|
|
return CGSizeMake(SCREEN_WIDTH, 143);
|
|
}else{
|
|
return CGSizeMake((SCREEN_WIDTH-15*3-1)/2.0, (SCREEN_WIDTH-15*3-1)/2.0);
|
|
}
|
|
}else if (self.type == 1){
|
|
return CGSizeMake(SCREEN_WIDTH, 143);
|
|
}else{
|
|
return CGSizeMake((SCREEN_WIDTH-15*3-1)/2.0, (SCREEN_WIDTH-15*3-1)/2.0);
|
|
}
|
|
}
|
|
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
|
|
if (self.type == 0) {
|
|
if (indexPath.section == 2) {
|
|
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
|
|
UICollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"QXMyHistoryHeaderView" forIndexPath:indexPath];
|
|
[header addSubview:self.headerView];
|
|
return header;
|
|
}else{
|
|
return nil;
|
|
}
|
|
}else{
|
|
return nil;
|
|
}
|
|
}
|
|
return nil;
|
|
}
|
|
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
|
|
if (self.type == 0) {
|
|
if (section == 2) {
|
|
return CGSizeMake(SCREEN_WIDTH, 46);
|
|
}else{
|
|
return CGSizeZero;
|
|
}
|
|
}else{
|
|
return CGSizeZero;
|
|
}
|
|
}
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
if (self.type == 0) {
|
|
if (indexPath.section == 0) {
|
|
QXRoomListModel *model = self.dataArray[indexPath.row];
|
|
[[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_id isRejoin:NO navagationController:self.navigationController];
|
|
}else if (indexPath.section == 1) {
|
|
QXRoomListCpModel *cpRoom = self.cpRoomArray[indexPath.row];
|
|
[[QXGlobal shareGlobal] joinRoomWithRoomId:cpRoom.room_id isRejoin:NO navagationController:self.navigationController];
|
|
}else{
|
|
QXMyRoomHistory *model = self.historyArray[indexPath.row];
|
|
[[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_id isRejoin:NO navagationController:self.navigationController];
|
|
}
|
|
}else if (self.type == 1){
|
|
QXRoomListModel *model = self.dataArray[indexPath.row];
|
|
[[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_id isRejoin:NO navagationController:self.navigationController];
|
|
}else{
|
|
QXRoomListModel *model = self.dataArray[indexPath.row];
|
|
[[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_id isRejoin:NO navagationController:self.navigationController];
|
|
}
|
|
}
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
}
|
|
|
|
-(UICollectionView *)collectionView{
|
|
if (!_collectionView) {
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.minimumLineSpacing = 15;
|
|
layout.minimumInteritemSpacing = 15;
|
|
layout.sectionInset = UIEdgeInsetsMake(8, 15, 8, 15);
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-kSafeAreaTop-kSafeAreaBottom-44*2) collectionViewLayout:layout];
|
|
_collectionView.delegate = self;
|
|
_collectionView.dataSource = self;
|
|
_collectionView.backgroundColor = [UIColor clearColor];
|
|
[_collectionView registerNib:[UINib nibWithNibName:@"QXHomeRoomCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXHomeRoomCell"];
|
|
[_collectionView registerNib:[UINib nibWithNibName:@"QXMyRoomListCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXMyRoomListCell"];
|
|
[_collectionView registerNib:[UINib nibWithNibName:@"QXMyCpRoomListCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXMyCpRoomListCell"];
|
|
[_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"QXMyHistoryHeaderView"];
|
|
MJWeakSelf
|
|
_collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
[weakSelf getRoomList];
|
|
}];
|
|
}
|
|
return _collectionView;
|
|
}
|
|
-(NSMutableArray *)dataArray{
|
|
if (!_dataArray) {
|
|
_dataArray = [NSMutableArray array];
|
|
}
|
|
return _dataArray;
|
|
}
|
|
-(NSMutableArray *)historyArray{
|
|
if (!_historyArray) {
|
|
_historyArray = [NSMutableArray array];
|
|
}
|
|
return _historyArray;
|
|
}
|
|
-(NSMutableArray *)cpRoomArray{
|
|
if (!_cpRoomArray) {
|
|
_cpRoomArray = [NSMutableArray array];
|
|
}
|
|
return _cpRoomArray;
|
|
}
|
|
|
|
-(QXMyHistoryHeaderView *)headerView{
|
|
if (!_headerView) {
|
|
_headerView = [[QXMyHistoryHeaderView alloc] init];
|
|
_headerView.delegate = self;
|
|
}
|
|
return _headerView;
|
|
}
|
|
/*
|
|
#pragma mark - Navigation
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
// Get the new view controller using [segue destinationViewController].
|
|
// Pass the selected object to the new view controller.
|
|
}
|
|
*/
|
|
|
|
@end
|