新的首页

This commit is contained in:
fengshuo
2021-12-02 14:00:05 +08:00
committed by zu
parent 863f870206
commit c746e7dcae
20 changed files with 499 additions and 59 deletions

View File

@@ -16,20 +16,16 @@
#import "HomeRecommendRoomModel.h"
///View
#import "XPHomeListCollectionViewCell.h"
#import "XPHoneNavView.h"
#import "XPHomeListEmptyCollectionViewCell.h"
///P
#import "XPHomePresenter.h"
#import "XPHomeProtocol.h"
///VC
#import "XPRoomViewController.h"
#import "XPHomeSearchViewController.h"
@interface XPHomeViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, XPHomeProtocol, XPHoneNavViewDelegate>
///
@property (nonatomic,strong) XPHoneNavView *navView;
@interface XPHomeViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, XPHomeProtocol>
///
@property (nonatomic,strong) NSMutableArray *datasource;
///
@property (nonatomic,strong) UIView * backView;
///
@property (nonatomic,strong) UICollectionView *collectionView;
///
@@ -57,25 +53,12 @@
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.navView];
[self.view addSubview:self.backView];
[self.backView addSubview:self.collectionView];
[self.view addSubview:self.collectionView];
}
- (void)initSubViewConstraints {
[self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self.view);
make.height.mas_equalTo(kNavigationHeight + 10);
}];
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(self.view);
make.top.mas_equalTo(self.navView.mas_bottom).offset(-10);
}];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(self.backView);
make.top.mas_equalTo(self.backView).offset(15);
make.edges.mas_equalTo(self.view);
}];
}
@@ -92,14 +75,12 @@
footer.stateLabel.textColor = [ThemeColor secondTextColor];
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
self.collectionView.mj_footer = footer;
///
[self headerRefresh];
}
#pragma mark - fangfa
- (void)headerRefresh {
self.page = 1;
[self.presenter getRecommendRoomList:@"1" page:self.page pageSize:20 state:NO];
[self.presenter getRecommendRoomList:self.tabId page:self.page pageSize:20 state:NO];
}
- (void)footerRefresh {
@@ -108,25 +89,40 @@
return;
}
self.page++;
[self.presenter getRecommendRoomList:@"1" page:self.page pageSize:20 state:YES];
[self.presenter getRecommendRoomList:self.tabId page:self.page pageSize:20 state:YES];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.datasource.count;
return self.datasource.count > 0 ? self.datasource.count : 1;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
XPHomeListCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPHomeListCollectionViewCell class]) forIndexPath:indexPath];
HomeRecommendRoomModel * model = [self.datasource objectAtIndex:indexPath.item];
cell.roomModel = model;
return cell;
if (self.datasource.count > 0) {
XPHomeListCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPHomeListCollectionViewCell class]) forIndexPath:indexPath];
HomeRecommendRoomModel * model = [self.datasource objectAtIndex:indexPath.item];
cell.roomModel = model;
return cell;
}
XPHomeListEmptyCollectionViewCell * emptyCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPHomeListEmptyCollectionViewCell class]) forIndexPath:indexPath];
return emptyCell;
}
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
HomeRecommendRoomModel * model = [self.datasource objectAtIndex:indexPath.item];
[XPRoomViewController openRoom:model.roomUid viewController:self];
if (self.datasource.count > 0) {
HomeRecommendRoomModel * model = [self.datasource objectAtIndex:indexPath.item];
[XPRoomViewController openRoom:model.roomUid viewController:self];
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if (self.datasource.count <= 0) {
return CGSizeMake(KScreenWidth, KScreenHeight- kNavigationHeight - 49 - 20);
}
return CGSizeMake((KScreenWidth - 15 * 3) / 2, 157 + 36);
}
#pragma mark - XPHomeProtocol
- (void)getHomeRecommendRoomListSuccess:(NSArray *)list state:(BOOL)state {
@@ -145,33 +141,21 @@
}
[self.collectionView reloadData];
}
#pragma mark - XPHoneNavViewDelegate
- (void)xPHoneNavView:(XPHoneNavView *)view didClickSearch:(UIButton *)sender {
XPHomeSearchViewController * searchVC = [[XPHomeSearchViewController alloc] init];
[self.navigationController presentViewController:searchVC animated:YES completion:nil];
#pragma mark - JXCategoryListContentViewDelegate
- (UIView *)listView {
return self.view;
}
#pragma mark - Getters And Setters
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.backgroundColor = [ThemeColor appBackgroundColor];
_backView.layer.masksToBounds = YES;
_backView.layer.cornerRadius = 15;
}
return _backView;
}
- (XPHoneNavView *)navView {
if (!_navView) {
_navView = [[XPHoneNavView alloc] init];
_navView.delegat = self;
}
return _navView;
- (void)setTabId:(NSString *)tabId {
_tabId = tabId;
[self headerRefresh];
}
- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake((KScreenWidth - 15 * 3) / 2, 157 + 36);
layout.minimumLineSpacing = 0;
layout.minimumInteritemSpacing = 15;
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
@@ -180,6 +164,7 @@
_collectionView.delegate = self;
_collectionView.backgroundColor = [UIColor clearColor];
[_collectionView registerClass:[XPHomeListCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPHomeListCollectionViewCell class])];
[_collectionView registerClass:[XPHomeListEmptyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPHomeListEmptyCollectionViewCell class])];
}
return _collectionView;
}