// // XPHomeContainerViewController.m // xplan-ios // // Created by 冯硕 on 2021/12/2. // #import "XPHomePartyContainerViewController.h" ///Third #import #import #import #import ///Tool #import "XPMacro.h" #import "ThemeColor.h" #import "XPHtmlUrl.h" #import "NSArray+Safe.h" ///Model #import "HomeTagModel.h" ///View #import "XPRoomSearchContainerViewController.h" #import "XPHomePartyViewController.h" #import "XPWebViewController.h" #import "XPHomeLikeViewController.h" #import "XPHomeLittleGameViewController.h" #import "XPHomePartyNavView.h" ///P #import "XPHomeContainerPresenter.h" #import "XPHomeContainerProtocol.h" UIKIT_EXTERN NSString * kHomeMoreScrollPageKey; @interface XPHomePartyContainerViewController () ///分页标题 @property (nonatomic, strong) NSArray *titles; ///分页控件 @property (nonatomic, strong) JXCategoryTitleView *titleView; ///分页lineView @property (nonatomic, strong) JXCategoryListContainerView *contentView; ///tag的列表 @property (nonatomic,copy) NSArray *tagList; ///导航 @property (nonatomic, strong) XPHomePartyNavView *navView; @end @implementation XPHomePartyContainerViewController - (BOOL)isHiddenNavBar { return YES; } - (XPHomeContainerPresenter *)createPresenter { return [[XPHomeContainerPresenter alloc] init]; } - (void)viewDidLoad { [super viewDidLoad]; [self initHttp]; [self initSubViews]; [self initSubViewConstraints]; self.defaultSelectedIndex = 1; } #pragma mark - Private Method - (void)initSubViews { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recommendMoreNotification:) name:kHomeMoreScrollPageKey object:nil]; [self.view addSubview:self.navView]; [self.view addSubview:self.titleView]; [self.view addSubview:self.contentView]; } - (void)initSubViewConstraints { [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); 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)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index { HomeTagModel * hometag = [self.tagList safeObjectAtIndex1:index]; UIViewController * list = (UIViewController *)[self.contentView.validListDict objectForKey:[NSNumber numberWithInteger:index]]; if (list) { return list; } else { if ([hometag.name isEqualToString:@"喜欢"]) { XPHomeLikeViewController * likeVC = [[XPHomeLikeViewController alloc] init]; likeVC.delegate = self; return likeVC; }if ([hometag.name isEqualToString:@"小游戏"]) { XPHomeLittleGameViewController * likeVC = [[XPHomeLittleGameViewController alloc] init]; return likeVC; } else { XPHomePartyViewController * homeVC = [[XPHomePartyViewController alloc] init]; homeVC.tabId = hometag.tid; return homeVC; } } } - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index { HomeTagModel * hometag = [self.tagList safeObjectAtIndex1:index]; if (![hometag.name isEqualToString:@"喜欢"] && ![hometag.name isEqualToString:@"小游戏"]) { XPHomePartyViewController * list = (XPHomePartyViewController *)[self.contentView.validListDict objectForKey:[NSNumber numberWithInteger:index]];; if ([hometag.name isEqualToString:@"个播"]) { list.isAnchor = YES; } list.tabId = hometag.tid; } } #pragma mark - JXCategoryListContentViewDelegate - (UIView *)listView { return self.view; } #pragma mark - XPHomeContainerProtocol - (void)getHomeTagListSuccess:(NSArray *)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]; [self.titleView selectItemAtIndex:self.defaultSelectedIndex]; } #pragma mark - Event Response - (void)recommendMoreNotification:(NSNotification *)notification { NSDictionary * dic = notification.object; 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; } } else if ([[dic objectForKey:@"section"] integerValue] == 3) { if ([obj.name containsString:@"个播"]) { index = idx; *stop = YES; } } }]; [self.titleView selectItemAtIndex:index]; }); } #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]; } #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 = 1; _titleView.cellSpacing = 5; _titleView.cellWidthIncrement = 5; _titleView.listContainer = self.contentView; JXCategoryIndicatorBackgroundView * indocator = [[JXCategoryIndicatorBackgroundView alloc] init]; indocator.indicatorColor = [ThemeColor appMainColor]; indocator.indicatorHeight = 24; indocator.indicatorWidthIncrement = 15; 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; } - (XPHomePartyNavView *)navView { if (!_navView) { _navView = [[XPHomePartyNavView alloc] init]; _navView.delegate = self; } return _navView; } @end