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

237 lines
7.9 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"
2022-11-11 17:46:37 +08:00
#import "NSArray+Safe.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"
2022-03-24 22:06:23 +08:00
#import "XPHomeLittleGameViewController.h"
2022-09-22 14:08:26 +08:00
#import "XPHomePartyNavView.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-09-22 14:08:26 +08:00
@interface XPHomePartyContainerViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate, XPHomeContainerProtocol, XPHomeLikeViewControllerDelegate, XPHomePartyNavViewDelegate>
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;
2022-09-22 14:08:26 +08:00
///
@property (nonatomic, strong) XPHomePartyNavView *navView;
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];
2022-09-22 14:08:26 +08:00
self.defaultSelectedIndex = 1;
2021-12-02 14:00:05 +08:00
}
#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-09-22 14:08:26 +08:00
[self.view addSubview:self.navView];
2022-02-21 20:06:09 +08:00
[self.view addSubview:self.titleView];
[self.view addSubview:self.contentView];
2021-12-02 14:00:05 +08:00
}
- (void)initSubViewConstraints {
2022-09-22 14:08:26 +08:00
[self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.left.right.mas_equalTo(self.view);
make.height.mas_equalTo(kNavigationHeight);
}];
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.navView.mas_bottom);
2022-03-02 19:18:08 +08:00
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 {
2022-11-11 17:46:37 +08:00
HomeTagModel * hometag = [self.tagList safeObjectAtIndex1:index];
UIViewController<JXCategoryListContentViewDelegate> * list = (UIViewController<JXCategoryListContentViewDelegate> *)[self.contentView.validListDict objectForKey:[NSNumber numberWithInteger:index]];
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];
likeVC.delegate = self;
2022-03-02 19:18:08 +08:00
return likeVC;
2022-03-24 22:06:23 +08:00
}if ([hometag.name isEqualToString:@"小游戏"]) {
XPHomeLittleGameViewController * likeVC = [[XPHomeLittleGameViewController alloc] init];
return likeVC;
2022-03-02 19:18:08 +08:00
} else {
XPHomePartyViewController * homeVC = [[XPHomePartyViewController alloc] init];
homeVC.tabId = hometag.tid;
return homeVC;
}
2021-12-02 14:00:05 +08:00
}
}
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
2022-11-11 17:46:37 +08:00
HomeTagModel * hometag = [self.tagList safeObjectAtIndex1:index];
2022-03-24 22:06:23 +08:00
if (![hometag.name isEqualToString:@"喜欢"] && ![hometag.name isEqualToString:@"小游戏"]) {
XPHomePartyViewController * list = (XPHomePartyViewController<JXCategoryListContentViewDelegate> *)[self.contentView.validListDict objectForKey:[NSNumber numberWithInteger:index]];;
if ([hometag.name isEqualToString:@"个播"]) {
list.isAnchor = YES;
}
2022-03-02 19:18:08 +08:00
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-09-22 14:08:26 +08:00
[self.titleView selectItemAtIndex:self.defaultSelectedIndex];
2021-12-02 14:00:05 +08:00
}
2022-03-02 19:18:08 +08:00
#pragma mark - Event Response
- (void)recommendMoreNotification:(NSNotification *)notification {
NSDictionary * dic = notification.object;
2022-03-02 19:18:08 +08:00
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
__block NSUInteger index;
[self.tagList enumerateObjectsUsingBlock:^(HomeTagModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([[dic objectForKey:@"section"] integerValue] == 2) {
if ([obj.name containsString:@"交友"]) {
index = idx;
*stop = YES;
}
2022-08-08 11:18:05 +08:00
} else if ([[dic objectForKey:@"section"] integerValue] == 3) {
if ([obj.name containsString:@"个播"]) {
index = idx;
*stop = YES;
}
}
}];
[self.titleView selectItemAtIndex:index];
2022-03-02 19:18:08 +08:00
});
}
2022-09-22 14:08:26 +08:00
#pragma mark - XPHomeNavViewDelegate
- (void)xPHomePartyNavViewDidClickBack {
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - XPHomeLikeViewControllerDelegate
- (void)xPHomeLikeViewControllerToFriendTab:(XPHomeLikeViewController *)viewController {
__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;
2022-09-22 14:08:26 +08:00
_titleView.defaultSelectedIndex = 1;
_titleView.cellSpacing = 5;
_titleView.cellWidthIncrement = 5;
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 = 15;
2022-03-02 19:18:08 +08:00
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
2022-09-22 14:08:26 +08:00
- (XPHomePartyNavView *)navView {
if (!_navView) {
_navView = [[XPHomePartyNavView alloc] init];
_navView.delegate = self;
}
return _navView;
}
2021-12-02 14:00:05 +08:00
@end