202 lines
6.3 KiB
Objective-C
202 lines
6.3 KiB
Objective-C
//
|
|
// XPHomeViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/2/21.
|
|
//
|
|
|
|
#import "XPHomeViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <JXCategoryView/JXCategoryListContainerView.h>
|
|
///Tool
|
|
#import "ThemeColor+Home.h"
|
|
#import "XPMacro.h"
|
|
#import "XPHtmlURL.h"
|
|
#import "XPConstant.h"
|
|
#import "Api+Room.h"
|
|
#import "AccountInfoStorage.h"
|
|
#import "TTPopup.h"
|
|
#import "StatisticsServiceHelper.h"
|
|
///View
|
|
#import "XPHomeNavView.h"
|
|
#import "XPHomeRecommendViewController.h"
|
|
#import "XPRoomSearchContainerViewController.h"
|
|
#import "XPHomePartyContainerViewController.h"
|
|
#import "XPHomePartyViewController.h"
|
|
#import "XPWebViewController.h"
|
|
#import "XPHomeHotRoomViewController.h"
|
|
#import "XPRoomViewController.h"
|
|
#import "XPLittleGameRoomOpenView.h"
|
|
|
|
UIKIT_EXTERN NSString *kHomeMoreScrollPageKey;
|
|
|
|
@interface XPHomeViewController ()<XPHomeNavViewDelegate, JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>
|
|
///标题
|
|
@property (nonatomic,strong) NSArray<NSString *> *titles;
|
|
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
|
|
///背景
|
|
@property (nonatomic,strong) UIImageView *topBackImageView;
|
|
///导航栏
|
|
@property (nonatomic,strong) XPHomeNavView *homeNavView;
|
|
@property (nonatomic,assign) NSInteger defaultSelectedIndex;
|
|
@property (nonatomic,strong) XPHomeRecommendViewController *recommendVC;
|
|
@property (nonatomic,strong) XPHomePartyContainerViewController *partyVC;
|
|
|
|
@end
|
|
|
|
@implementation XPHomeViewController
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.view addSubview:self.topBackImageView];
|
|
[self.view addSubview:self.homeNavView];
|
|
[self.view addSubview:self.listContainerView];
|
|
|
|
self.homeNavView.titleView.titles = self.titles;
|
|
self.homeNavView.titleView.delegate = self;
|
|
self.homeNavView.titleView.listContainer = self.listContainerView;
|
|
[self.homeNavView.titleView reloadData];
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recommendMoreNotification:) name:kHomeMoreScrollPageKey object:nil];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.topBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.top.right.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(336);
|
|
}];
|
|
|
|
[self.homeNavView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.top.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(kNavigationHeight);
|
|
}];
|
|
|
|
[self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.bottom.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.homeNavView.mas_bottom);
|
|
}];
|
|
}
|
|
#pragma mark - JXCategoryListContainerViewDelegate
|
|
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
|
|
return self.titles.count;
|
|
}
|
|
|
|
// 根据下标 index 返回对应遵守并实现 `JXCategoryListContentViewDelegate` 协议的列表实例
|
|
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
|
|
if (index == 0) {
|
|
return self.recommendVC;
|
|
}else if (index == 1) {
|
|
return self.partyVC;
|
|
}
|
|
return nil;
|
|
}
|
|
|
|
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
|
|
if (index == 2) {
|
|
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_card_click];
|
|
}
|
|
}
|
|
|
|
#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];
|
|
}
|
|
|
|
- (void)xPHomeNavView:(XPHomeNavView *)view didClickRank:(UIButton *)sender {
|
|
XPWebViewController * webVC =[[XPWebViewController alloc] init];
|
|
webVC.url = URLWithType(kHomeRankURL);
|
|
[self.navigationController pushViewController:webVC animated:YES];
|
|
}
|
|
|
|
- (void)xPHomeNavView:(XPHomeNavView *)view didClickOpenRoom:(UIButton *)sender {
|
|
NSString* roomUid = [AccountInfoStorage instance].getUid;
|
|
[Api getRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
if (code == 200) {
|
|
RoomInfoModel * roomInfo = [RoomInfoModel modelWithJSON:data.data];
|
|
if (roomInfo.isReselect) {
|
|
XPLittleGameRoomOpenView * roomOpenView = [[XPLittleGameRoomOpenView alloc] init];
|
|
roomOpenView.roomInfo = roomInfo;
|
|
roomOpenView.currentVC = self;
|
|
[TTPopup popupView:roomOpenView style:TTPopupStyleActionSheet];
|
|
} else {
|
|
[XPRoomViewController openRoom:roomUid viewController:self];
|
|
}
|
|
} else {
|
|
[self showErrorToast:msg];
|
|
}
|
|
} uid:roomUid intoUid:roomUid];
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)recommendMoreNotification:(NSNotification *)notification {
|
|
if ([notification.object[@"section"] intValue] == 3) {
|
|
[self.homeNavView.titleView selectItemAtIndex:2];
|
|
} else {
|
|
[self.homeNavView.titleView selectItemAtIndex:1];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (JXCategoryListContainerView *)listContainerView {
|
|
if (!_listContainerView) {
|
|
_listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
|
|
_listContainerView.scrollView.scrollEnabled = YES;
|
|
_listContainerView.scrollView.tag = 1000;
|
|
_listContainerView.listCellBackgroundColor = [UIColor clearColor];
|
|
}
|
|
return _listContainerView;
|
|
}
|
|
|
|
- (XPHomeNavView *)homeNavView {
|
|
if (!_homeNavView) {
|
|
_homeNavView = [[XPHomeNavView alloc] init];
|
|
_homeNavView.delegate = self;
|
|
}
|
|
return _homeNavView;
|
|
}
|
|
|
|
- (UIImageView *)topBackImageView {
|
|
if (!_topBackImageView) {
|
|
_topBackImageView = [[UIImageView alloc] init];
|
|
_topBackImageView.userInteractionEnabled = YES;
|
|
_topBackImageView.image = [UIImage imageNamed:@"home_nav_background"];
|
|
}
|
|
return _topBackImageView;
|
|
}
|
|
|
|
- (NSArray<NSString *> *)titles {
|
|
if (!_titles) {
|
|
_titles = @[@"推荐",@"派对"];
|
|
}
|
|
return _titles;
|
|
}
|
|
|
|
|
|
- (XPHomeRecommendViewController *)recommendVC {
|
|
if (!_recommendVC) {
|
|
_recommendVC = [[XPHomeRecommendViewController alloc] init];
|
|
}
|
|
return _recommendVC;
|
|
}
|
|
|
|
- (XPHomePartyContainerViewController *)partyVC {
|
|
if (!_partyVC) {
|
|
_partyVC = [[XPHomePartyContainerViewController alloc] init];
|
|
}
|
|
return _partyVC;
|
|
}
|
|
|
|
@end
|