200 lines
6.5 KiB
Objective-C
200 lines
6.5 KiB
Objective-C
//
|
|
// XPHomeContainerViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/12/2.
|
|
//
|
|
|
|
#import "XPHomePartyContainerViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <JXCategoryView/JXCategoryView.h>
|
|
#import <JXCategoryView/JXCategoryIndicatorBackgroundView.h>
|
|
#import <JXCategoryView/JXCategoryListContainerView.h>
|
|
///Tool
|
|
#import "XPMacro.h"
|
|
#import "ThemeColor.h"
|
|
#import "XPHtmlUrl.h"
|
|
///Model
|
|
#import "HomeTagModel.h"
|
|
///View
|
|
#import "XPRoomSearchContainerViewController.h"
|
|
#import "XPHomePartyViewController.h"
|
|
#import "XPWebViewController.h"
|
|
#import "XPHomeLikeViewController.h"
|
|
///P
|
|
#import "XPHomeContainerPresenter.h"
|
|
#import "XPHomeContainerProtocol.h"
|
|
|
|
UIKIT_EXTERN NSString * kHomeMoreScrollPageKey;
|
|
|
|
@interface XPHomePartyContainerViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate, XPHomeContainerProtocol>
|
|
///分页标题
|
|
@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 *, UIViewController<JXCategoryListContentViewDelegate> *> *listCache;
|
|
@end
|
|
|
|
@implementation XPHomePartyContainerViewController
|
|
|
|
- (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 {
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recommendMoreNotification:) name:kHomeMoreScrollPageKey object:nil];
|
|
self.view.backgroundColor = [UIColor clearColor];
|
|
[self.view addSubview:self.titleView];
|
|
[self.view addSubview:self.contentView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.view).offset(10);
|
|
make.left.right.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(30);
|
|
}];
|
|
|
|
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.titleView.mas_bottom);
|
|
make.left.right.bottom.mas_equalTo(self.view);
|
|
}];
|
|
}
|
|
|
|
- (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];
|
|
UIViewController<JXCategoryListContentViewDelegate> * list = _listCache[hometag.tid];
|
|
if (list) {
|
|
return list;
|
|
} else {
|
|
if ([hometag.name isEqualToString:@"喜欢"]) {
|
|
XPHomeLikeViewController * likeVC = [[XPHomeLikeViewController alloc] init];
|
|
//①自己缓存已经初始化的列表
|
|
_listCache[hometag.tid] = likeVC;
|
|
return likeVC;
|
|
} else {
|
|
XPHomePartyViewController * homeVC = [[XPHomePartyViewController 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];
|
|
if (![hometag.name isEqualToString:@"喜欢"]) {
|
|
XPHomePartyViewController * list = (XPHomePartyViewController<JXCategoryListContentViewDelegate> *)_listCache[hometag.tid];
|
|
list.tabId = hometag.tid;
|
|
}
|
|
|
|
}
|
|
|
|
#pragma mark - JXCategoryListContentViewDelegate
|
|
- (UIView *)listView {
|
|
return self.view;
|
|
}
|
|
|
|
#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 - Event Response
|
|
- (void)recommendMoreNotification:(NSNotification *)notification {
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
if ([notification.object[@"section"] integerValue] == 3) {
|
|
__block NSUInteger index;
|
|
[self.tagList enumerateObjectsUsingBlock:^(HomeTagModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if ([obj.name containsString:@"个播"]) {
|
|
index = idx;
|
|
*stop = YES;
|
|
}
|
|
}];
|
|
self.titleView.defaultSelectedIndex = index;
|
|
[self.titleView reloadData];
|
|
}
|
|
});
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (JXCategoryTitleView *)titleView {
|
|
if (!_titleView) {
|
|
_titleView = [[JXCategoryTitleView alloc] init];
|
|
_titleView.delegate = self;
|
|
_titleView.titles = self.titles;
|
|
_titleView.backgroundColor = [UIColor clearColor];
|
|
_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.cellSpacing = 0;
|
|
_titleView.cellWidthIncrement = 20;
|
|
_titleView.listContainer = self.contentView;
|
|
|
|
JXCategoryIndicatorBackgroundView * indocator = [[JXCategoryIndicatorBackgroundView alloc] init];
|
|
indocator.indicatorColor = [ThemeColor appMainColor];
|
|
indocator.indicatorHeight = 24;
|
|
indocator.indicatorWidthIncrement = 10;
|
|
indocator.indicatorCornerRadius = 12;
|
|
_titleView.indicators = @[indocator];
|
|
}
|
|
return _titleView;
|
|
}
|
|
|
|
- (JXCategoryListContainerView *)contentView {
|
|
if (!_contentView) {
|
|
_contentView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
|
|
_contentView.defaultSelectedIndex = 0;
|
|
}
|
|
return _contentView;
|
|
}
|
|
|
|
- (NSMutableDictionary<NSString *,XPHomePartyViewController<JXCategoryListContentViewDelegate> *> *)listCache {
|
|
if (!_listCache) {
|
|
_listCache = [NSMutableDictionary dictionary];
|
|
}
|
|
return _listCache;
|
|
}
|
|
|
|
@end
|