Files
yinmeng-ios/xplan-ios/Main/Home/View/XPPartyListViewController.m

364 lines
14 KiB
Mathematica
Raw Normal View History

2023-03-07 18:51:04 +08:00
//
// XPPartyListViewController.m
// xplan-ios
//
// Created by XY on 2023/3/7.
//
#import "XPPartyListViewController.h"
///Third
#import <Masonry.h>
#import <MJRefresh.h>
///Tool
#import "XPMacro.h"
#import "XCHUDTool.h"
#import "NSArray+Safe.h"
#import "ThemeColor.h"
///View
#import "XPPartyListCollectionViewCell.h"
2023-07-26 18:44:15 +08:00
#import "XPNewPartyListCollectionViewCell.h"
2023-03-13 19:50:02 +08:00
#import "XPHomeListEmptyCollectionViewCell.h"
2023-03-07 18:51:04 +08:00
///P
#import "XPHomePresenter.h"
#import "XPHomeProtocol.h"
/// VC
#import "XPRoomViewController.h"
/// Model
#import "HomeRecommendRoomModel.h"
2023-07-26 18:44:15 +08:00
@interface XPPartyListViewController ()<UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout, XPHomeProtocol>
2023-03-07 18:51:04 +08:00
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
///
@property (nonatomic, strong) NSMutableArray *dataSource;
2023-07-26 18:44:15 +08:00
@property (nonatomic, strong) NSMutableArray *personList;
2023-03-07 18:51:04 +08:00
///
@property (nonatomic,assign) int page;
///
@property (nonatomic,assign) BOOL hasNoMoreData;
2023-10-10 11:19:56 +08:00
2023-03-07 18:51:04 +08:00
@end
@implementation XPPartyListViewController
- (XPHomePresenter *)createPresenter {
return [[XPHomePresenter alloc] init];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
[self initHeaderAndFooterRrfresh];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
2023-10-10 12:11:37 +08:00
2023-03-07 18:51:04 +08:00
}
- (void)initHeaderAndFooterRrfresh {
2023-10-10 11:19:56 +08:00
2023-03-07 18:51:04 +08:00
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
footer.stateLabel.textColor = [ThemeColor secondTextColor];
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
self.collectionView.mj_footer = footer;
2023-10-10 12:11:37 +08:00
[self headerRefresh];
2023-03-07 18:51:04 +08:00
}
#pragma mark - fangfa
2023-10-10 11:19:56 +08:00
2023-03-07 18:51:04 +08:00
- (void)headerRefresh {
if ([self.tabId isEqualToString:@"recommend"]) {
[self.presenter getPartyRecommendRoomList];
}else{
self.page = 1;
[self.presenter getRecommendRoomList:self.tabId page:self.page pageSize:20 state:0];
}
2023-07-26 18:44:15 +08:00
if ([[AccountInfoStorage instance] getUid].length > 0 && [self.tabId isEqualToString:@"recommend"]) {
[self.presenter getHomePersonalRoomListWithUid:[AccountInfoStorage instance].getUid];
}
2023-03-07 18:51:04 +08:00
}
- (void)footerRefresh {
if (self.hasNoMoreData) {
[self showErrorToast:@"没有更多房间了"];
[self.collectionView.mj_footer endRefreshing];
return;
}
if ([self.tabId isEqualToString:@"recommend"]) {
}else{
self.page++;
[self.presenter getRecommendRoomList:self.tabId page:self.page pageSize:20 state:1];
}
2023-07-26 18:44:15 +08:00
if ([[AccountInfoStorage instance] getUid].length > 0 && [self.tabId isEqualToString:@"recommend"]) {
[self.presenter getHomePersonalRoomListWithUid:[AccountInfoStorage instance].getUid];
}
2023-03-07 18:51:04 +08:00
}
#pragma mark - Private Method
- (void)initSubViews {
2023-03-21 17:59:16 +08:00
self.view.backgroundColor = UIColor.whiteColor;
2023-03-07 18:51:04 +08:00
[self.view addSubview:self.collectionView];
}
- (void)initSubViewConstraints {
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
2023-03-17 20:05:42 +08:00
make.left.right.bottom.mas_equalTo(self.view);
2023-03-21 15:12:49 +08:00
make.top.mas_equalTo(6);
2023-03-07 18:51:04 +08:00
}];
}
#pragma mark - XPHomeProtocol
- (void)getHomeRecommendRoomListSuccess:(NSArray *)list state:(BOOL)state {
if (state == 0) {
self.hasNoMoreData = NO;
[self.dataSource removeAllObjects];
2023-10-10 11:19:56 +08:00
if(self.delegate && [self.delegate respondsToSelector:@selector(headerRefreshComplete)]){
[self.delegate headerRefreshComplete];
}
2023-03-07 18:51:04 +08:00
} else {
[self.collectionView.mj_footer endRefreshing];
}
if (list.count > 0) {
self.hasNoMoreData = NO;
[self.dataSource addObjectsFromArray:list];
} else {
self.hasNoMoreData = YES;
}
[self.collectionView reloadData];
[XCHUDTool hideHUD];
}
2023-07-26 18:44:15 +08:00
- (void)getHomePersonalRoomListSuccess:(NSArray *)list{
self.personList = [[NSMutableArray alloc]initWithArray:list];
2023-08-03 14:25:36 +08:00
[self.collectionView reloadData];
2023-07-26 18:44:15 +08:00
}
2023-03-07 18:51:04 +08:00
- (void)getHomeRecommendRoomListFail:(NSString *)message state:(BOOL)state {
if (state == 0) {
2023-10-10 11:19:56 +08:00
if(self.delegate && [self.delegate respondsToSelector:@selector(headerRefreshComplete)]){
[self.delegate headerRefreshComplete];
}
2023-03-07 18:51:04 +08:00
} else {
[self.collectionView.mj_footer endRefreshing];
}
[XCHUDTool hideHUD];
}
- (void)getPartyRecommendRoomListSuccess:(NSArray *)list {
self.hasNoMoreData = YES;
[self.dataSource removeAllObjects];
[self.dataSource addObjectsFromArray:list];
[self.collectionView reloadData];
2023-10-10 11:19:56 +08:00
if(self.delegate && [self.delegate respondsToSelector:@selector(headerRefreshComplete)]){
[self.delegate headerRefreshComplete];
}
2023-03-07 18:51:04 +08:00
[self.collectionView.mj_footer endRefreshing];
[XCHUDTool hideHUD];
}
- (void)getPartyRecommendDataFail {
[self.collectionView.mj_footer endRefreshing];
[XCHUDTool hideHUD];
}
#pragma mark - UICollectionViewDelegate
2023-07-26 18:44:15 +08:00
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
if([self.tabId isEqualToString:@"recommend"]){
return 2;
}
return 1;
}
2023-03-07 18:51:04 +08:00
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
2023-07-26 18:44:15 +08:00
if([self.tabId isEqualToString:@"recommend"]){
if(section == 1)return self.personList.count;
return self.dataSource.count;
}
2023-03-13 19:50:02 +08:00
return self.dataSource.count > 0 ? self.dataSource.count : 1;
2023-03-07 18:51:04 +08:00
}
2023-07-26 18:44:15 +08:00
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if([self.tabId isEqualToString:@"recommend"]){
return indexPath.section == 0 ? CGSizeMake(kGetScaleWidth(168), kGetScaleWidth(148)) : CGSizeMake(KScreenWidth, 102);
}
return CGSizeMake(KScreenWidth, 102);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
if([self.tabId isEqualToString:@"recommend"]){
2023-08-04 10:20:09 +08:00
return section == 0 ? UIEdgeInsetsMake(kGetScaleWidth(8), kGetScaleWidth(15), 0, kGetScaleWidth(15)):UIEdgeInsetsMake(0, 0, 0, 0);
2023-07-26 18:44:15 +08:00
}
return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
if([self.tabId isEqualToString:@"recommend"]){
return section == 0 ? kGetScaleWidth(7) : 12;
}
return 12 ;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
if([self.tabId isEqualToString:@"recommend"]){
return section == 0 ? kGetScaleWidth(7) : 12;
}
return 12 ;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
if([self.tabId isEqualToString:@"recommend"]){
return section == 0 ? CGSizeMake(0, 0): CGSizeMake(KScreenWidth, kGetScaleWidth(40));
}
return CGSizeMake(0, 0);
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
if([self.tabId isEqualToString:@"recommend"] && [kind isEqualToString:UICollectionElementKindSectionHeader]){
UICollectionReusableView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:NSStringFromClass([UICollectionReusableView class]) forIndexPath:indexPath];
if(headView.subviews.count == 0){
UILabel *titelView = [UILabel labelInitWithText:@"更多房间" font:kFontMedium(16) textColor:UIColorFromRGB(0x2B2D33)];
[headView addSubview:titelView];
[titelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(28));
make.centerY.equalTo(headView);
}];
}
return headView;
}
return nil;
}
2023-03-07 18:51:04 +08:00
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
2023-07-26 18:44:15 +08:00
if([self.tabId isEqualToString:@"recommend"]){
if(indexPath.section == 0){
XPNewPartyListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPNewPartyListCollectionViewCell class]) forIndexPath:indexPath];
HomeRecommendRoomModel *model = [self.dataSource safeObjectAtIndex1:indexPath.row];
cell.roomModel = model;
return cell;
}
XPPartyListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPPartyListCollectionViewCell class]) forIndexPath:indexPath];
HomeRecommendRoomModel *model = [self.personList safeObjectAtIndex1:indexPath.row];
cell.roomModel = model;
NSInteger index = (indexPath.row+1) % 3;
if (index == 1) {
cell.backView.image = [UIImage imageNamed:@"home_party_bg_1"];
}else if (index == 2) {
cell.backView.image = [UIImage imageNamed:@"home_party_bg_2"];
}else{
cell.backView.image = [UIImage imageNamed:@"home_party_bg_3"];
}
return cell;
}
2023-03-13 19:50:02 +08:00
if (self.dataSource.count > 0) {
XPPartyListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPPartyListCollectionViewCell class]) forIndexPath:indexPath];
HomeRecommendRoomModel *model = [self.dataSource safeObjectAtIndex1:indexPath.row];
2023-07-26 18:44:15 +08:00
cell.roomModel = model;
2023-03-17 18:53:46 +08:00
NSInteger index = (indexPath.row+1) % 3;
if (index == 1) {
cell.backView.image = [UIImage imageNamed:@"home_party_bg_1"];
}else if (index == 2) {
cell.backView.image = [UIImage imageNamed:@"home_party_bg_2"];
}else{
cell.backView.image = [UIImage imageNamed:@"home_party_bg_3"];
}
2023-03-13 19:50:02 +08:00
return cell;
}
XPHomeListEmptyCollectionViewCell * emptyCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPHomeListEmptyCollectionViewCell class]) forIndexPath:indexPath];
return emptyCell;
2023-03-07 18:51:04 +08:00
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
2023-07-26 18:44:15 +08:00
if([self.tabId isEqualToString:@"recommend"]){
NSString *roomUid = @"";
if(indexPath.section == 0){
if (self.dataSource.count > 0) {
HomeRecommendRoomModel * model = [self.dataSource safeObjectAtIndex1:indexPath.item];
roomUid = model.roomUid;
}
}else{
if (self.personList.count > 0) {
HomeRecommendRoomModel * model = [self.personList safeObjectAtIndex1:indexPath.item];
2023-08-03 17:21:51 +08:00
roomUid = model.uid;
2023-07-26 18:44:15 +08:00
}
}
2023-03-07 18:51:04 +08:00
if (roomUid.length > 0) {
[XPRoomViewController openRoom:roomUid viewController:self];
}
2023-07-26 18:44:15 +08:00
return;
}
NSString *roomUid = @"";
if (self.dataSource.count > 0) {
HomeRecommendRoomModel * model = [self.dataSource safeObjectAtIndex1:indexPath.item];
roomUid = model.roomUid;
}
if (roomUid.length > 0) {
[XPRoomViewController openRoom:roomUid viewController:self];
2023-03-07 18:51:04 +08:00
}
}
#pragma mark - JXCategoryListContentViewDelegate
- (UIView *)listView {
return self.view;
}
- (UIScrollView *)listScrollView {
return self.collectionView;
}
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
self.scrollCallback = callback;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
self.scrollCallback(scrollView);
}
#pragma mark - Getters And Setters
- (UICollectionView *)collectionView {
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
2023-07-26 18:44:15 +08:00
2023-03-07 18:51:04 +08:00
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.backgroundColor = UIColor.clearColor;
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerClass:[XPPartyListCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPPartyListCollectionViewCell class])];
2023-03-13 19:50:02 +08:00
[_collectionView registerClass:[XPHomeListEmptyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPHomeListEmptyCollectionViewCell class])];
2023-07-26 18:44:15 +08:00
[_collectionView registerClass:[XPNewPartyListCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPNewPartyListCollectionViewCell class])];
[_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([UICollectionReusableView class])];
2023-03-07 18:51:04 +08:00
}
return _collectionView;
}
- (NSMutableArray *)dataSource {
if (!_dataSource) {
_dataSource = [NSMutableArray array];
}
return _dataSource;
}
@end