Files
peko-ios/YuMi/Modules/YMNewHome/View/XPHomePartyViewController.m
2024-02-22 15:58:48 +08:00

222 lines
7.2 KiB
Objective-C

//
// XPHomeViewController.m
// YuMi
//
// Created by YuMi on 2021/11/29.
//
#import "XPHomePartyViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <MJRefresh/MJRefresh.h>
///Tool
#import "YUMIMacroUitls.h"
#import "DJDKMIMOMColor.h"
#import "NSArray+Safe.h"
///Model
#import "HomeRecommendRoomModel.h"
///View
#import "XPNewHomePartyCollectionViewCell.h"
#import "XPGuildEmptyCollectionViewCell.h"
#import "XPWeakTimer.h"
///P
#import "XPHomePresenter.h"
#import "XPHomeProtocol.h"
///VC
#import "XPRoomViewController.h"
@interface XPHomePartyViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, XPHomeProtocol>
///数据源
@property (nonatomic,strong) NSMutableArray *datasource;
///列表
@property (nonatomic,strong) UICollectionView *collectionView;
///当前的页数
@property (nonatomic,assign) int page;
///没有新的数据了
@property (nonatomic,assign) BOOL hasNoMoreData;
@end
@implementation XPHomePartyViewController
- (BOOL)isHiddenNavBar {
return YES;
}
- (XPHomePresenter *)createPresenter {
return [[XPHomePresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
}
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.collectionView];
}
- (void)initSubViewConstraints {
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(fooderRefresh)];
footer.stateLabel.textColor = [DJDKMIMOMColor secondTextColor];
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
self.collectionView.mj_footer = footer;
}
#pragma mark - 刷新的fangfa
- (void)headerRefresh {
if([self.tagModel.id isEqualToString:@"-1"]){
[self.presenter getHomePersonalRoomList];
}else{
self.page = 1;
[self.presenter getRecommendRoomList:self.tagModel.id page:self.page pageSize:20];
}
}
-(void)fooderRefresh{
if([self.tagModel.id isEqualToString:@"-1"]){
[self.collectionView.mj_footer endRefreshing];
}else{
self.page++;
[self.presenter getRecommendRoomList:self.tagModel.id page:self.page pageSize:20];
}
}
#pragma mark - UICollectionViewDelegate And UICollectionViewDataSource
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
if(self.datasource.count == 0){
XPGuildEmptyCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPGuildEmptyCollectionViewCell class]) forIndexPath:indexPath];
[cell setConstraints];
[cell setTitle:YMLocalizedString(@"XPGuildEmptyCollectionViewCell0")];
return cell;
}
XPNewHomePartyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPNewHomePartyCollectionViewCell class]) forIndexPath:indexPath];
cell.roomInfo = [self.datasource safeObjectAtIndex1:indexPath.row];
return cell;
}
- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if(self.datasource.count == 0)return 1;
return self.datasource.count;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if(self.datasource.count == 0)return self.collectionView.frame.size;
return CGSizeMake(kGetScaleWidth(174), kGetScaleWidth(178));
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
HomePlayRoomModel * roomInfo = [self.datasource safeObjectAtIndex1:indexPath.row];
if (roomInfo.uid.length > 0) {
[XPRoomViewController openRoom:roomInfo.uid viewController:self];
}
}
#pragma mark - XPHomeProtocol
- (void)getHomePersonalRoomListSuccess:(NSArray *)list{
[[NSNotificationCenter defaultCenter]postNotificationName:@"khomeVCRefreshComplete" object:nil];
for (HomePlayRoomModel *model in list) {
model.width = [UILabel getWidthWithText:@(model.onlineNum).stringValue height:kGetScaleWidth(12) font:kFontBold(10)]+1;
}
self.datasource = [NSMutableArray arrayWithArray:list];
[self.collectionView reloadData];
}
- (void)getHomePersonalRoomListFail{
[[NSNotificationCenter defaultCenter]postNotificationName:@"khomeVCRefreshComplete" object:nil];
}
- (void)getHomeRecommendRoomListSuccess:(NSArray *)list{
[self.collectionView.mj_footer endRefreshing];
for (HomePlayRoomModel *model in list) {
model.width = [UILabel getWidthWithText:@(model.onlineNum).stringValue height:kGetScaleWidth(12) font:kFontBold(10)]+1;
}
if(self.page == 1){
self.datasource = [NSMutableArray arrayWithArray:list];
}else{
[self.datasource addObjectsFromArray:list];
}
[self.collectionView reloadData];
[[NSNotificationCenter defaultCenter]postNotificationName:@"khomeVCRefreshComplete" object:nil];
}
- (void)getHomeRecommendRoomListFail:(NSString *)message{
[self.collectionView.mj_footer endRefreshing];
[[NSNotificationCenter defaultCenter]postNotificationName:@"khomeVCRefreshComplete" object:nil];
}
#pragma mark - JXPagingViewListViewDelegate
- (UIScrollView *)listScrollView {
return self.collectionView;
}
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
self.scrollCallback = callback;
}
- (UIView *)listView {
return self.view;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if(self.scrollCallback){
self.scrollCallback(scrollView);
}
}
#pragma mark - Getters And Setters
-(void)setTagModel:(PIHomeCategoryTitleModel *)tagModel{
_tagModel = tagModel;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self headerRefresh];
});
}
- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumInteritemSpacing = kGetScaleWidth(6);
layout.minimumLineSpacing = kGetScaleWidth(6);
layout.sectionInset = UIEdgeInsetsMake(0, kGetScaleWidth(10), 0, kGetScaleWidth(10));
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor clearColor];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.tag = 78574;
[_collectionView registerClass:[XPNewHomePartyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPNewHomePartyCollectionViewCell class])];
[_collectionView registerClass:[XPGuildEmptyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGuildEmptyCollectionViewCell class])];
}
return _collectionView;
}
- (NSMutableArray *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
@end