首页新的UI以及数据

This commit is contained in:
fengshuo
2022-02-21 20:06:09 +08:00
parent 5cb54a7f3f
commit 63763776a9
55 changed files with 2237 additions and 272 deletions

View File

@@ -2,36 +2,32 @@
// XPHomeViewController.m
// xplan-ios
//
// Created by on 2021/11/29.
// Created by on 2022/2/21.
//
#import "XPHomeViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <MJRefresh/MJRefresh.h>
#import <JXCategoryView/JXCategoryListContainerView.h>
///Tool
#import "ThemeColor+Home.h"
#import "XPMacro.h"
#import "ThemeColor.h"
///Model
#import "HomeRecommendRoomModel.h"
#import "XPHtmlURL.h"
///View
#import "XPHomeListCollectionViewCell.h"
#import "XPHomeListEmptyCollectionViewCell.h"
///P
#import "XPHomePresenter.h"
#import "XPHomeProtocol.h"
///VC
#import "XPRoomViewController.h"
#import "XPHomeNavView.h"
#import "XPHomeRecommendViewController.h"
#import "XPRoomSearchContainerViewController.h"
#import "XPHomePartyContainerViewController.h"
#import "XPWebViewController.h"
@interface XPHomeViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, XPHomeProtocol>
///
@property (nonatomic,strong) NSMutableArray *datasource;
///
@property (nonatomic,strong) UICollectionView *collectionView;
///
@property (nonatomic,assign) int page;
///
@property (nonatomic,assign) BOOL hasNoMoreData;
@interface XPHomeViewController ()<XPHomeNavViewDelegate, JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>
///
@property (nonatomic,strong) NSArray<NSString *> *titles;
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
///
@property (nonatomic,strong) UIImageView *topBackImageView;
///
@property (nonatomic,strong) XPHomeNavView *homeNavView;
@end
@implementation XPHomeViewController
@@ -40,141 +36,101 @@
return YES;
}
- (XPHomePresenter *)createPresenter {
return [[XPHomePresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initHeaderAndFooterRrfresh];
[self initSubViews];
[self initSubViewConstraints];
}
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.collectionView];
[self.view addSubview:self.topBackImageView];
[self.view addSubview:self.homeNavView];
[self.view addSubview:self.listContainerView];
self.homeNavView.titleView.titles = self.titles;
self.homeNavView.titleView.delegate = self;
self.homeNavView.titleView.listContainer = self.listContainerView;
[self.homeNavView.titleView reloadData];
}
- (void)initSubViewConstraints {
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
[self.topBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.right.mas_equalTo(self.view);
make.height.mas_equalTo(336);
}];
[self.homeNavView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self.view);
make.height.mas_equalTo(kNavigationHeight);
}];
[self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(self.view);
make.top.mas_equalTo(self.homeNavView.mas_bottom);
}];
}
- (void)initHeaderAndFooterRrfresh {
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
header.stateLabel.font = [UIFont systemFontOfSize:10.0];
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:10.0];
header.stateLabel.textColor = [ThemeColor secondTextColor];
header.lastUpdatedTimeLabel.textColor = [ThemeColor secondTextColor];
self.collectionView.mj_header = header;
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;
#pragma mark - JXCategoryListContainerViewDelegate
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
return self.titles.count;
}
#pragma mark - fangfa
- (void)headerRefresh {
self.page = 1;
[self.presenter getRecommendRoomList:self.tabId page:self.page pageSize:20 state:NO];
// index `JXCategoryListContentViewDelegate`
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
if (index == 0) {
return [[XPHomeRecommendViewController alloc] init];
}else if (index == 1) {
return [[XPHomePartyContainerViewController alloc] init];
}
return nil;
}
- (void)footerRefresh {
if (self.hasNoMoreData) {
[self showErrorToast:@"没有更多房间了"];
return;
}
self.page++;
[self.presenter getRecommendRoomList:self.tabId page:self.page pageSize:20 state:YES];
#pragma mark - XPHoneNavViewDelegate
- (void)xPHomeNavViewDidClickSearch:(XPHomeNavView *)view {
XPRoomSearchContainerViewController * searchVC = [[XPRoomSearchContainerViewController alloc] init];
searchVC.modalPresentationStyle = UIModalPresentationFullScreen;
[self.navigationController presentViewController:searchVC animated:YES completion:nil];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.datasource.count > 0 ? self.datasource.count : 1;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
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];
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 {
if (state == 0) {
[self.datasource removeAllObjects];
[self.collectionView.mj_header endRefreshing];
} else {
[self.collectionView.mj_footer endRefreshing];
}
if (list.count > 0) {
self.hasNoMoreData = NO;
[self.datasource addObjectsFromArray:list];
} else {
self.hasNoMoreData = YES;
[self.collectionView.mj_footer endRefreshingWithNoMoreData];
}
[self.collectionView reloadData];
}
#pragma mark - JXCategoryListContentViewDelegate
- (UIView *)listView {
return self.view;
- (void)xPHomeNavView:(XPHomeNavView *)view didClickRank:(UIButton *)sender {
XPWebViewController * webVC =[[XPWebViewController alloc] init];
webVC.url = URLWithType(kHomeRankURL);
[self.navigationController pushViewController:webVC animated:YES];
}
#pragma mark - Getters And Setters
- (void)setTabId:(NSString *)tabId {
_tabId = tabId;
[self headerRefresh];
}
- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 0;
layout.minimumInteritemSpacing = 15;
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.backgroundColor = [UIColor clearColor];
[_collectionView registerClass:[XPHomeListCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPHomeListCollectionViewCell class])];
[_collectionView registerClass:[XPHomeListEmptyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPHomeListEmptyCollectionViewCell class])];
- (JXCategoryListContainerView *)listContainerView {
if (!_listContainerView) {
_listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
}
return _collectionView;
return _listContainerView;
}
- (NSMutableArray *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
- (XPHomeNavView *)homeNavView {
if (!_homeNavView) {
_homeNavView = [[XPHomeNavView alloc] init];
_homeNavView.delegate = self;
}
return _datasource;
return _homeNavView;
}
- (UIImageView *)topBackImageView {
if (!_topBackImageView) {
_topBackImageView = [[UIImageView alloc] init];
_topBackImageView.userInteractionEnabled = YES;
_topBackImageView.image = [UIImage imageNamed:@"home_nav_background"];
}
return _topBackImageView;
}
- (NSArray<NSString *> *)titles {
if (!_titles) {
_titles = @[@"推荐",@"派对"];
}
return _titles;
}
@end