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

202 lines
6.3 KiB
Mathematica
Raw Normal View History

2021-11-29 21:40:11 +08:00
//
// XPHomeViewController.m
// xplan-ios
//
2022-02-21 20:06:09 +08:00
// Created by on 2022/2/21.
2021-11-29 21:40:11 +08:00
//
#import "XPHomeViewController.h"
///Third
#import <Masonry/Masonry.h>
2022-02-21 20:06:09 +08:00
#import <JXCategoryView/JXCategoryListContainerView.h>
2021-11-29 21:40:11 +08:00
///Tool
2022-02-21 20:06:09 +08:00
#import "ThemeColor+Home.h"
2021-11-29 21:40:11 +08:00
#import "XPMacro.h"
2022-02-21 20:06:09 +08:00
#import "XPHtmlURL.h"
2022-03-01 19:28:16 +08:00
#import "XPConstant.h"
2022-04-01 15:14:46 +08:00
#import "Api+Room.h"
#import "AccountInfoStorage.h"
#import "TTPopup.h"
2022-07-19 18:21:57 +08:00
#import "StatisticsServiceHelper.h"
2021-11-29 21:40:11 +08:00
///View
2022-02-21 20:06:09 +08:00
#import "XPHomeNavView.h"
#import "XPHomeRecommendViewController.h"
#import "XPRoomSearchContainerViewController.h"
#import "XPHomePartyContainerViewController.h"
2022-04-01 15:14:46 +08:00
#import "XPHomePartyViewController.h"
2022-02-21 20:06:09 +08:00
#import "XPWebViewController.h"
2022-04-01 15:14:46 +08:00
#import "XPHomeHotRoomViewController.h"
#import "XPRoomViewController.h"
#import "XPLittleGameRoomOpenView.h"
2022-02-21 20:06:09 +08:00
2022-03-01 19:28:16 +08:00
UIKIT_EXTERN NSString *kHomeMoreScrollPageKey;
2022-02-21 20:06:09 +08:00
@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;
2022-03-02 19:18:08 +08:00
@property (nonatomic,assign) NSInteger defaultSelectedIndex;
@property (nonatomic,strong) XPHomeRecommendViewController *recommendVC;
@property (nonatomic,strong) XPHomePartyContainerViewController *partyVC;
2021-11-29 21:40:11 +08:00
@end
@implementation XPHomeViewController
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
}
2022-02-21 20:06:09 +08:00
2021-11-29 21:40:11 +08:00
#pragma mark - Private Method
- (void)initSubViews {
2022-02-21 20:06:09 +08:00
[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];
2022-03-01 19:28:16 +08:00
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recommendMoreNotification:) name:kHomeMoreScrollPageKey object:nil];
2021-11-29 21:40:11 +08:00
}
- (void)initSubViewConstraints {
2022-02-21 20:06:09 +08:00
[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);
2021-11-29 21:40:11 +08:00
}];
2022-02-21 20:06:09 +08:00
[self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(self.view);
make.top.mas_equalTo(self.homeNavView.mas_bottom);
}];
2021-11-29 21:40:11 +08:00
}
2022-02-21 20:06:09 +08:00
#pragma mark - JXCategoryListContainerViewDelegate
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
return self.titles.count;
2021-11-29 21:40:11 +08:00
}
2022-02-21 20:06:09 +08:00
// index `JXCategoryListContentViewDelegate`
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
if (index == 0) {
2022-03-02 19:18:08 +08:00
return self.recommendVC;
2022-02-21 20:06:09 +08:00
}else if (index == 1) {
2022-03-02 19:18:08 +08:00
return self.partyVC;
2021-11-29 21:40:11 +08:00
}
2022-02-21 20:06:09 +08:00
return nil;
2021-11-29 21:40:11 +08:00
}
2022-04-01 15:14:46 +08:00
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
2022-07-19 18:21:57 +08:00
if (index == 2) {
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_card_click];
}
2022-04-01 15:14:46 +08:00
}
2022-02-21 20:06:09 +08:00
#pragma mark - XPHoneNavViewDelegate
2022-04-01 15:14:46 +08:00
- (void)xPHomeNavView:(XPHomeNavView *)view didClickSearch:(UIButton *)sender {
2022-02-21 20:06:09 +08:00
XPRoomSearchContainerViewController * searchVC = [[XPRoomSearchContainerViewController alloc] init];
searchVC.modalPresentationStyle = UIModalPresentationFullScreen;
[self.navigationController presentViewController:searchVC animated:YES completion:nil];
2021-11-29 21:40:11 +08:00
}
2022-02-21 20:06:09 +08:00
- (void)xPHomeNavView:(XPHomeNavView *)view didClickRank:(UIButton *)sender {
XPWebViewController * webVC =[[XPWebViewController alloc] init];
webVC.url = URLWithType(kHomeRankURL);
[self.navigationController pushViewController:webVC animated:YES];
2021-11-29 21:40:11 +08:00
}
2022-03-01 19:28:16 +08:00
2022-04-01 15:14:46 +08:00
- (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];
}
2022-03-01 19:28:16 +08:00
#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];
}
2022-03-01 19:28:16 +08:00
}
2022-02-21 20:06:09 +08:00
#pragma mark - Getters And Setters
- (JXCategoryListContainerView *)listContainerView {
if (!_listContainerView) {
_listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
2022-03-07 19:32:44 +08:00
_listContainerView.scrollView.scrollEnabled = YES;
_listContainerView.scrollView.tag = 1000;
2022-02-25 21:18:01 +08:00
_listContainerView.listCellBackgroundColor = [UIColor clearColor];
2021-12-02 14:00:05 +08:00
}
2022-02-21 20:06:09 +08:00
return _listContainerView;
2021-12-02 14:00:05 +08:00
}
2022-02-21 20:06:09 +08:00
- (XPHomeNavView *)homeNavView {
if (!_homeNavView) {
_homeNavView = [[XPHomeNavView alloc] init];
_homeNavView.delegate = self;
2021-11-29 21:40:11 +08:00
}
2022-02-21 20:06:09 +08:00
return _homeNavView;
2021-11-29 21:40:11 +08:00
}
2021-12-02 14:00:05 +08:00
2022-02-21 20:06:09 +08:00
- (UIImageView *)topBackImageView {
if (!_topBackImageView) {
_topBackImageView = [[UIImageView alloc] init];
_topBackImageView.userInteractionEnabled = YES;
_topBackImageView.image = [UIImage imageNamed:@"home_nav_background"];
2021-11-29 21:40:11 +08:00
}
2022-02-21 20:06:09 +08:00
return _topBackImageView;
2021-11-29 21:40:11 +08:00
}
2022-02-21 20:06:09 +08:00
- (NSArray<NSString *> *)titles {
if (!_titles) {
2022-07-27 17:12:06 +08:00
_titles = @[@"推荐",@"派对"];
2021-11-29 21:40:11 +08:00
}
2022-02-21 20:06:09 +08:00
return _titles;
2021-11-29 21:40:11 +08:00
}
2022-03-02 19:18:08 +08:00
- (XPHomeRecommendViewController *)recommendVC {
if (!_recommendVC) {
_recommendVC = [[XPHomeRecommendViewController alloc] init];
}
return _recommendVC;
}
- (XPHomePartyContainerViewController *)partyVC {
if (!_partyVC) {
_partyVC = [[XPHomePartyContainerViewController alloc] init];
}
return _partyVC;
}
2022-02-21 20:06:09 +08:00
2021-11-29 21:40:11 +08:00
@end