202 lines
6.2 KiB
Objective-C
202 lines
6.2 KiB
Objective-C
//
|
|
// XPHomeContainerViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/12/2.
|
|
//
|
|
|
|
#import "XPHomeContainerViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <JXCategoryView/JXCategoryView.h>
|
|
#import <JXCategoryView/JXCategoryListContainerView.h>
|
|
///Tool
|
|
#import "XPMacro.h"
|
|
#import "ThemeColor.h"
|
|
///Model
|
|
#import "HomeTagModel.h"
|
|
///View
|
|
#import "XPHomeNavView.h"
|
|
#import "XPRoomSearchContainerViewController.h"
|
|
#import "XPHomeViewController.h"
|
|
///P
|
|
#import "XPHomeContainerPresenter.h"
|
|
#import "XPHomeContainerProtocol.h"
|
|
|
|
|
|
@interface XPHomeContainerViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate, XPHomeContainerProtocol,XPHomeNavViewDelegate>
|
|
///背景
|
|
@property (nonatomic,strong) UIImageView *backImageView;
|
|
///导航栏
|
|
@property (nonatomic,strong) XPHomeNavView *navView;
|
|
///背景图
|
|
@property (nonatomic,strong) UIView * backView;
|
|
///分页标题
|
|
@property (nonatomic, strong) NSArray<NSString *> *titles;
|
|
///分页控件
|
|
@property (nonatomic, strong) JXCategoryTitleView *titleView;
|
|
///分页lineView
|
|
@property (nonatomic, strong) JXCategoryListContainerView *contentView;
|
|
///tag的列表
|
|
@property (nonatomic,copy) NSArray<HomeTagModel *> *tagList;
|
|
///刷新的话 会重新走一次init的方法
|
|
@property (nonatomic, strong) NSMutableDictionary <NSString *, XPHomeViewController<JXCategoryListContentViewDelegate> *> *listCache;
|
|
@end
|
|
|
|
@implementation XPHomeContainerViewController
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (XPHomeContainerPresenter *)createPresenter {
|
|
return [[XPHomeContainerPresenter alloc] init];
|
|
}
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initHttp];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.view addSubview:self.backImageView];
|
|
[self.view addSubview:self.navView];
|
|
[self.view addSubview:self.backView];
|
|
[self.backView addSubview:self.titleView];
|
|
[self.backView addSubview:self.contentView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.top.right.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(336);
|
|
}];
|
|
|
|
[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.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.top.mas_equalTo(self.backView);
|
|
make.height.mas_equalTo(50);
|
|
}];
|
|
|
|
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.titleView.mas_bottom).offset(10);
|
|
make.left.right.bottom.mas_equalTo(self.backView);
|
|
}];
|
|
}
|
|
|
|
- (void)initHttp {
|
|
[self.presenter getHomeTagList];
|
|
}
|
|
|
|
#pragma mark - JXCategoryViewDelegate
|
|
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
|
|
return self.titles.count;
|
|
}
|
|
|
|
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
|
|
HomeTagModel * hometag = [self.tagList objectAtIndex:index];
|
|
XPHomeViewController<JXCategoryListContentViewDelegate> * list = _listCache[hometag.tid];
|
|
if (list) {
|
|
return list;
|
|
} else {
|
|
XPHomeViewController * homeVC = [[XPHomeViewController alloc] init];
|
|
homeVC.tabId = hometag.tid;
|
|
//①自己缓存已经初始化的列表
|
|
_listCache[hometag.tid] = homeVC;
|
|
return homeVC;
|
|
}
|
|
}
|
|
|
|
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
|
|
HomeTagModel * hometag = [self.tagList objectAtIndex:index];
|
|
XPHomeViewController<JXCategoryListContentViewDelegate> * list = _listCache[hometag.tid];
|
|
list.tabId = hometag.tid;
|
|
}
|
|
|
|
#pragma mark - XPHomeContainerProtocol
|
|
- (void)getHomeTagListSuccess:(NSArray<HomeTagModel *> *)array {
|
|
self.tagList = array;
|
|
NSMutableArray * titles = [NSMutableArray array];
|
|
[array enumerateObjectsUsingBlock:^(HomeTagModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if (obj.name.length > 0) {
|
|
[titles addObject:obj.name];
|
|
}
|
|
}];
|
|
self.titles = titles.copy;
|
|
self.titleView.titles = self.titles;
|
|
[self.titleView reloadData];
|
|
}
|
|
|
|
#pragma mark - XPHoneNavViewDelegate
|
|
- (void)xPHomeNavView:(XPHomeNavView *)view didClickSearch:(UIButton *)sender {
|
|
XPRoomSearchContainerViewController * searchVC = [[XPRoomSearchContainerViewController alloc] init];
|
|
searchVC.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
[self.navigationController presentViewController:searchVC animated:YES completion:nil];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (JXCategoryTitleView *)titleView {
|
|
if (!_titleView) {
|
|
_titleView = [[JXCategoryTitleView alloc] init];
|
|
_titleView.delegate = self;
|
|
_titleView.titles = self.titles;
|
|
_titleView.titleColor = [ThemeColor secondTextColor];
|
|
_titleView.titleSelectedColor = [ThemeColor mainTextColor];
|
|
_titleView.titleFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:13];
|
|
_titleView.titleSelectedFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:16];
|
|
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
|
|
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
|
|
_titleView.defaultSelectedIndex = 0;
|
|
_titleView.listContainer = self.contentView;
|
|
}
|
|
return _titleView;
|
|
}
|
|
|
|
- (JXCategoryListContainerView *)contentView {
|
|
if (!_contentView) {
|
|
_contentView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
|
|
_contentView.defaultSelectedIndex = 0;
|
|
}
|
|
return _contentView;
|
|
}
|
|
|
|
- (UIView *)backView {
|
|
if (!_backView) {
|
|
_backView = [[UIView alloc] init];
|
|
_backView.backgroundColor = [ThemeColor appBackgroundColor];
|
|
_backView.layer.masksToBounds = YES;
|
|
_backView.layer.cornerRadius = 15;
|
|
}
|
|
return _backView;
|
|
}
|
|
- (XPHomeNavView *)navView {
|
|
if (!_navView) {
|
|
_navView = [[XPHomeNavView alloc] init];
|
|
_navView.delegate = self;
|
|
}
|
|
return _navView;
|
|
}
|
|
|
|
- (UIImageView *)backImageView {
|
|
if (!_backImageView) {
|
|
_backImageView = [[UIImageView alloc] init];
|
|
_backImageView.userInteractionEnabled = YES;
|
|
_backImageView.image = [UIImage imageNamed:@"home_nav_background"];
|
|
}
|
|
return _backImageView;
|
|
}
|
|
|
|
|
|
@end
|