Files
yinmeng-ios/xplan-ios/Main/Home/View/XPHomePartyContainerViewController.m

200 lines
6.5 KiB
Mathematica
Raw Normal View History

2021-12-02 14:00:05 +08:00
//
// XPHomeContainerViewController.m
// xplan-ios
//
// Created by on 2021/12/2.
//
2022-02-21 20:06:09 +08:00
#import "XPHomePartyContainerViewController.h"
2021-12-02 14:00:05 +08:00
///Third
#import <Masonry/Masonry.h>
#import <JXCategoryView/JXCategoryView.h>
2022-03-02 19:18:08 +08:00
#import <JXCategoryView/JXCategoryIndicatorBackgroundView.h>
2021-12-02 14:00:05 +08:00
#import <JXCategoryView/JXCategoryListContainerView.h>
///Tool
#import "XPMacro.h"
#import "ThemeColor.h"
2021-12-23 17:14:36 +08:00
#import "XPHtmlUrl.h"
2021-12-02 14:00:05 +08:00
///Model
#import "HomeTagModel.h"
///View
#import "XPRoomSearchContainerViewController.h"
2022-02-21 20:06:09 +08:00
#import "XPHomePartyViewController.h"
2021-12-23 17:14:36 +08:00
#import "XPWebViewController.h"
2022-03-02 19:18:08 +08:00
#import "XPHomeLikeViewController.h"
2021-12-02 14:00:05 +08:00
///P
#import "XPHomeContainerPresenter.h"
#import "XPHomeContainerProtocol.h"
2022-03-02 19:18:08 +08:00
UIKIT_EXTERN NSString * kHomeMoreScrollPageKey;
2021-12-02 14:00:05 +08:00
2022-02-21 20:06:09 +08:00
@interface XPHomePartyContainerViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate, XPHomeContainerProtocol>
2021-12-02 14:00:05 +08:00
///
@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
2022-03-02 19:18:08 +08:00
@property (nonatomic, strong) NSMutableDictionary <NSString *, UIViewController<JXCategoryListContentViewDelegate> *> *listCache;
2021-12-02 14:00:05 +08:00
@end
2022-02-21 20:06:09 +08:00
@implementation XPHomePartyContainerViewController
2021-12-02 14:00:05 +08:00
- (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 {
2022-03-02 19:18:08 +08:00
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recommendMoreNotification:) name:kHomeMoreScrollPageKey object:nil];
2022-02-21 20:06:09 +08:00
self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.titleView];
[self.view addSubview:self.contentView];
2021-12-02 14:00:05 +08:00
}
- (void)initSubViewConstraints {
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
2022-03-02 19:18:08 +08:00
make.top.mas_equalTo(self.view).offset(10);
make.left.right.mas_equalTo(self.view);
make.height.mas_equalTo(30);
2021-12-02 14:00:05 +08:00
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
2022-03-02 19:18:08 +08:00
make.top.mas_equalTo(self.titleView.mas_bottom);
2022-02-21 20:06:09 +08:00
make.left.right.bottom.mas_equalTo(self.view);
2021-12-02 14:00:05 +08:00
}];
}
- (void)initHttp {
[self.presenter getHomeTagList];
}
2021-12-02 18:06:11 +08:00
#pragma mark - JXCategoryViewDelegate
2021-12-02 14:00:05 +08:00
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
return self.titles.count;
}
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
HomeTagModel * hometag = [self.tagList objectAtIndex:index];
2022-03-02 19:18:08 +08:00
UIViewController<JXCategoryListContentViewDelegate> * list = _listCache[hometag.tid];
2021-12-02 14:00:05 +08:00
if (list) {
return list;
} else {
2022-03-02 19:18:08 +08:00
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;
}
2021-12-02 14:00:05 +08:00
}
}
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
HomeTagModel * hometag = [self.tagList objectAtIndex:index];
2022-03-02 19:18:08 +08:00
if (![hometag.name isEqualToString:@"喜欢"]) {
XPHomePartyViewController * list = (XPHomePartyViewController<JXCategoryListContentViewDelegate> *)_listCache[hometag.tid];
list.tabId = hometag.tid;
}
2021-12-02 14:00:05 +08:00
}
2022-02-21 20:06:09 +08:00
#pragma mark - JXCategoryListContentViewDelegate
- (UIView *)listView {
return self.view;
}
2021-12-02 14:00:05 +08:00
#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];
}
2022-03-02 19:18:08 +08:00
#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];
}
});
}
2021-12-02 14:00:05 +08:00
#pragma mark - Getters And Setters
- (JXCategoryTitleView *)titleView {
if (!_titleView) {
_titleView = [[JXCategoryTitleView alloc] init];
_titleView.delegate = self;
_titleView.titles = self.titles;
2022-02-21 20:06:09 +08:00
_titleView.backgroundColor = [UIColor clearColor];
2021-12-02 14:00:05 +08:00
_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;
2022-03-02 19:18:08 +08:00
_titleView.cellSpacing = 0;
_titleView.cellWidthIncrement = 20;
2021-12-02 14:00:05 +08:00
_titleView.listContainer = self.contentView;
2022-03-02 19:18:08 +08:00
JXCategoryIndicatorBackgroundView * indocator = [[JXCategoryIndicatorBackgroundView alloc] init];
indocator.indicatorColor = [ThemeColor appMainColor];
indocator.indicatorHeight = 24;
indocator.indicatorWidthIncrement = 10;
indocator.indicatorCornerRadius = 12;
_titleView.indicators = @[indocator];
2021-12-02 14:00:05 +08:00
}
return _titleView;
}
- (JXCategoryListContainerView *)contentView {
if (!_contentView) {
_contentView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
_contentView.defaultSelectedIndex = 0;
}
return _contentView;
}
2022-03-02 19:18:08 +08:00
- (NSMutableDictionary<NSString *,XPHomePartyViewController<JXCategoryListContentViewDelegate> *> *)listCache {
if (!_listCache) {
_listCache = [NSMutableDictionary dictionary];
}
return _listCache;
}
2021-12-02 14:00:05 +08:00
@end