Files
peko-ios/YuMi/Modules/YMNewHome/View/XPHomePartyViewController.m

222 lines
7.2 KiB
Mathematica
Raw Normal View History

2023-07-14 18:50:55 +08:00
//
// 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
2023-09-05 11:45:21 +08:00
#import "XPNewHomePartyCollectionViewCell.h"
#import "XPGuildEmptyCollectionViewCell.h"
#import "XPWeakTimer.h"
2023-07-14 18:50:55 +08:00
///P
#import "XPHomePresenter.h"
#import "XPHomeProtocol.h"
///VC
#import "XPRoomViewController.h"
2023-09-05 11:45:21 +08:00
@interface XPHomePartyViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, XPHomeProtocol>
2023-07-14 18:50:55 +08:00
///
@property (nonatomic,strong) NSMutableArray *datasource;
///
2023-09-05 11:45:21 +08:00
@property (nonatomic,strong) UICollectionView *collectionView;
2023-07-14 18:50:55 +08:00
///
@property (nonatomic,assign) int page;
///
@property (nonatomic,assign) BOOL hasNoMoreData;
2023-09-07 19:01:31 +08:00
2023-07-14 18:50:55 +08:00
@end
@implementation XPHomePartyViewController
- (BOOL)isHiddenNavBar {
return YES;
}
- (XPHomePresenter *)createPresenter {
return [[XPHomePresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
2023-09-05 11:45:21 +08:00
[self initSubViews];
[self initSubViewConstraints];
2023-09-07 19:01:31 +08:00
2023-09-05 11:45:21 +08:00
2023-07-14 18:50:55 +08:00
}
2024-02-22 15:58:48 +08:00
2023-07-14 18:50:55 +08:00
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor clearColor];
2023-09-05 11:45:21 +08:00
[self.view addSubview:self.collectionView];
2023-07-14 18:50:55 +08:00
}
- (void)initSubViewConstraints {
2023-09-05 11:45:21 +08:00
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
2023-07-14 18:50:55 +08:00
make.edges.mas_equalTo(self.view);
}];
2024-02-22 15:58:48 +08:00
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;
2023-07-14 18:50:55 +08:00
}
2023-09-07 19:01:31 +08:00
2023-07-14 18:50:55 +08:00
#pragma mark - fangfa
- (void)headerRefresh {
2024-02-22 15:58:48 +08:00
if([self.tagModel.id isEqualToString:@"-1"]){
[self.presenter getHomePersonalRoomList];
}else{
self.page = 1;
[self.presenter getRecommendRoomList:self.tagModel.id page:self.page pageSize:20];
}
2023-07-14 18:50:55 +08:00
}
2024-02-22 15:58:48 +08:00
-(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];
}
}
2023-07-14 18:50:55 +08:00
2023-09-05 11:45:21 +08:00
#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;
2023-07-14 18:50:55 +08:00
}
2023-09-05 11:45:21 +08:00
- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if(self.datasource.count == 0)return 1;
return self.datasource.count;
2023-07-14 18:50:55 +08:00
}
2023-09-05 11:45:21 +08:00
- (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));
2023-07-14 18:50:55 +08:00
}
2023-09-05 11:45:21 +08:00
-(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];
}
2023-07-14 18:50:55 +08:00
}
2023-09-05 11:45:21 +08:00
#pragma mark - XPHomeProtocol
- (void)getHomePersonalRoomListSuccess:(NSArray *)list{
2024-02-22 15:58:48 +08:00
[[NSNotificationCenter defaultCenter]postNotificationName:@"khomeVCRefreshComplete" object:nil];
2023-09-05 11:45:21 +08:00
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];
2023-07-14 18:50:55 +08:00
}
2023-09-05 15:37:02 +08:00
- (void)getHomePersonalRoomListFail{
2024-02-22 15:58:48 +08:00
[[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;
2023-09-05 15:37:02 +08:00
}
2024-02-22 15:58:48 +08:00
if(self.page == 1){
self.datasource = [NSMutableArray arrayWithArray:list];
}else{
[self.datasource addObjectsFromArray:list];
}
[self.collectionView reloadData];
[[NSNotificationCenter defaultCenter]postNotificationName:@"khomeVCRefreshComplete" object:nil];
2023-09-05 15:37:02 +08:00
}
2023-07-14 18:50:55 +08:00
2024-02-22 15:58:48 +08:00
- (void)getHomeRecommendRoomListFail:(NSString *)message{
[self.collectionView.mj_footer endRefreshing];
[[NSNotificationCenter defaultCenter]postNotificationName:@"khomeVCRefreshComplete" object:nil];
}
2023-09-01 18:58:41 +08:00
#pragma mark - JXPagingViewListViewDelegate
- (UIScrollView *)listScrollView {
2023-09-05 11:45:21 +08:00
return self.collectionView;
2023-09-01 18:58:41 +08:00
}
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
self.scrollCallback = callback;
}
2023-07-14 18:50:55 +08:00
- (UIView *)listView {
2023-09-01 18:58:41 +08:00
return self.view;
2023-07-14 18:50:55 +08:00
}
2023-09-01 18:58:41 +08:00
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if(self.scrollCallback){
self.scrollCallback(scrollView);
}
}
2023-07-14 18:50:55 +08:00
#pragma mark - Getters And Setters
2024-02-22 15:58:48 +08:00
-(void)setTagModel:(PIHomeCategoryTitleModel *)tagModel{
_tagModel = tagModel;
2023-08-16 21:30:09 +08:00
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self headerRefresh];
});
2023-07-14 18:50:55 +08:00
}
2023-08-16 21:30:09 +08:00
2023-07-14 18:50:55 +08:00
2024-02-22 15:58:48 +08:00
2023-09-05 11:45:21 +08:00
- (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;
2024-02-22 15:58:48 +08:00
_collectionView.tag = 78574;
2023-09-05 11:45:21 +08:00
[_collectionView registerClass:[XPNewHomePartyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPNewHomePartyCollectionViewCell class])];
[_collectionView registerClass:[XPGuildEmptyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGuildEmptyCollectionViewCell class])];
}
return _collectionView;
}
2023-07-14 18:50:55 +08:00
- (NSMutableArray *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
@end