// // QXHomeViewController.m // QXLive // // Created by 启星 on 2025/4/24. // #import "QXHomeViewController.h" #import "JXCategoryView.h" #import "GKCycleScrollView.h" #import "QXHomeTopCell.h" #import "QXHomeSubViewController.h" #import "QXSearchViewController.h" #import "QXRankHomeVC.h" #import "SDCycleScrollView.h" #import "JXPagerView.h" #import "QXHomePageNetwork.h" #import "QXMyRoomViewController.h" #import "QXUserHomePageViewController.h" #import "QXFirstRechargePopView.h" #import "QXRechargeView.h" #import "QXAppstoreHomeView.h" #import "QXConfig.h" #import "QXSkyPraizeView.h" @interface QXHomeViewController () @property (nonatomic, strong) JXPagerView *pagingView; @property (nonatomic,strong)JXCategoryTitleView *categoryView; @property (nonatomic,strong)NSMutableArray *listVCArray; @property (nonatomic,strong)NSMutableArray *titles; @property (nonatomic,strong)NSArray *titleModelArray; @property (nonatomic,strong)GKCycleScrollView *cycleScrollView; @property (nonatomic,strong)JXCategoryIndicatorImageView *indicatorView; @property (nonatomic,strong)UIButton *rankRightBtn; @property (nonatomic,strong)UIButton *searchRightBtn; @property (nonatomic,strong)UIButton *roomBtn; @property (nonatomic,strong)QXGiftScrollView *giftScrollView; @property (nonatomic,strong)SDCycleScrollView *bannerScrollView; @property (nonatomic,assign)BOOL isShowGiftScrollView; @property (nonatomic,strong)NSMutableArray *bannerArry; @property (nonatomic,strong)UIView *headerView; @property (nonatomic,strong)UIView *sectionView; @property (nonatomic,strong)UIButton *firstRechargeBtn; @property (nonatomic,strong)UIButton *skyDownBtn; @property (nonatomic,strong)QXFirstRechargePopView *firstRechargeView; @property (nonatomic,strong)QXAppstoreHomeView *appStoreView; @end @implementation QXHomeViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:noticeUserLogin object:nil]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:YES]; } - (void)initSubViews{ // UILabel *tLabel = [[UILabel alloc] init]; // tLabel.text = QXText(@"秘地"); // tLabel.font = [UIFont boldSystemFontOfSize:20]; // [self.view addSubview:tLabel]; // [tLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.mas_equalTo(16); // make.top.mas_equalTo(kSafeAreaTop +10); // }]; if ([QXConfig.backgroundImage hasPrefix:@"http"] || [QXConfig.backgroundImage hasPrefix:@"https"]) { [self updateBgImage:QXConfig.backgroundImage]; }else{ [self updateBgImage:@"app_bg"]; } UIImageView *logoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mi_di"]]; [self.view addSubview:logoImageView]; [logoImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(16); make.top.mas_equalTo(kSafeAreaTop +8); make.width.mas_equalTo(66); make.height.mas_equalTo(32); }]; [self.view addSubview:self.rankRightBtn]; [self.view addSubview:self.searchRightBtn]; [self.view addSubview:self.roomBtn]; [self.roomBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(30); make.height.mas_equalTo(30); make.centerY.equalTo(logoImageView); make.right.equalTo(self.view).offset(-10); }]; [self.rankRightBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.roomBtn.mas_left).offset(-10); make.centerY.equalTo(self.roomBtn); make.width.height.mas_equalTo(32); }]; [self.searchRightBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.rankRightBtn.mas_left).offset(-10); make.centerY.equalTo(self.roomBtn); make.width.height.mas_equalTo(30); }]; self.listVCArray = [NSMutableArray array]; [self requestSlideToolData]; [self getTopRoomList]; _pagingView = [[JXPagerView alloc] initWithDelegate:self]; _pagingView.mainTableView.backgroundColor = [UIColor clearColor]; self.pagingView.backgroundColor = [UIColor clearColor]; [self.view addSubview:self.pagingView]; self.categoryView.listContainer = (id)self.pagingView.listContainerView; self.pagingView.listContainerView.listCellBackgroundColor = [UIColor clearColor]; // [self performSelector:@selector(giftScrollViewShow) afterDelay:5]; MJWeakSelf self.pagingView.mainTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ [weakSelf requestSlideToolData]; [weakSelf getTopRoomList]; [weakSelf getBanner]; }]; self.firstRechargeBtn.hidden = YES; [self.view addSubview:self.firstRechargeBtn]; [self.firstRechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(-(TabbarContentHeight+5)); make.right.equalTo(self.view).offset(-17); make.width.height.mas_equalTo(ScaleWidth(57)); }]; [self getBanner]; [self getFirstRechargePermission]; self.appStoreView.hidden = YES; [self.view addSubview:self.appStoreView]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; self.pagingView.frame = CGRectMake(0, NavContentHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight-TabbarContentHeight); } -(void)loginSuccess{ [self requestSlideToolData]; [self getTopRoomList]; [self getBanner]; } - (void)requestSlideToolData { __weak typeof(self) weakSelf = self; [QXHomePageNetwork homeRoomLabelListsuccessBlock:^(NSArray * _Nonnull list) { [weakSelf.titles removeAllObjects]; NSMutableArray *arr = [NSMutableArray array]; [weakSelf.titles addObjectsFromArray:list]; for (QXMyRoomType *md in list) { [arr addObject:md.label_name]; } weakSelf.categoryView.titles = arr; [weakSelf.categoryView reloadData]; [weakSelf.pagingView.mainTableView.mj_header endRefreshing]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { [weakSelf.pagingView.mainTableView.mj_header endRefreshing]; }]; } -(void)getFirstRechargePermission{ MJWeakSelf [QXHomePageNetwork getFirstRechargePermissionSuccessBlock:^(BOOL isShow) { weakSelf.firstRechargeBtn.hidden = !isShow; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)firstAction{ [self popFirstRechargeView]; // QXSkyPraizeView *v = [[QXSkyPraizeView alloc] init]; // [v showInView:self.view]; } -(void)popFirstRechargeView{ MJWeakSelf // view.giftArray = @[@"",@"",@"",@"",@"",@""]; self.firstRechargeView.closeActionBlock = ^{ [[QXGlobal shareGlobal].alertViewController hideViewFinishBlock:^{ QXLOG(@"页面关闭"); }]; }; self.firstRechargeView.rechargeActionBlock = ^(NSString * _Nonnull money) { [[QXGlobal shareGlobal].alertViewController hideViewFinishBlock:^{ QXLOG(@"页面关闭"); QXRechargeView *recharge = [[QXRechargeView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; QXRechargeListModel *model = [[QXRechargeListModel alloc] init]; model.money = money; recharge.selectedModel = model; recharge.isPop = YES; recharge.isOnlyDisplayPayType = YES; [recharge showInView:KEYWINDOW]; }]; }; [self.firstRechargeView reloadData]; [[QXGlobal shareGlobal] showView:self.firstRechargeView popType:(PopViewTypeTopToCenter) tapDismiss:NO finishBlock:^{ }]; } #pragma mark - JXPagingViewDelegate - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView { return self.headerView; } - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView { return self.headerView.height; } - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return 48; } - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return self.sectionView; } - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView { return self.titles.count; } - (id)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index { QXHomeSubViewController *vc = [[QXHomeSubViewController alloc] init]; QXMyRoomType *model = self.titles[index]; vc.roomType = model; return vc; } -(void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index{ } -(void)giftScrollViewShowWithModel:(QXGiftScrollModel*)model{ if (self.isShowGiftScrollView == NO) { // self.categoryView.frame = CGRectMake(15, self.giftScrollView.bottom, SCREEN_WIDTH-30, 44); // self.containerView.frame = CGRectMake(0, self.categoryView.bottom, SCREEN_WIDTH, SCREEN_HEIGHT-self.categoryView.bottom-TabbarHeight); self.bannerScrollView.top = self.giftScrollView.bottom+12; self.headerView.height += 12+self.giftScrollView.height; [self.headerView addSubview:self.giftScrollView]; // [self.pagingView reloadData]; [self.pagingView resizeTableHeaderViewHeightWithAnimatable:YES duration:0.1 curve:UIViewAnimationCurveLinear]; } ++self.page; self.giftScrollView.model = model; self.isShowGiftScrollView = YES; } -(void)giftScrollViewShowWithModelList:(NSArray*)list{ if (self.isShowGiftScrollView == NO) { self.bannerScrollView.top = self.giftScrollView.bottom+12; self.headerView.height += 12+self.giftScrollView.height; [self.headerView addSubview:self.giftScrollView]; [self.pagingView resizeTableHeaderViewHeightWithAnimatable:YES duration:0.1 curve:UIViewAnimationCurveLinear]; } ++self.page; self.giftScrollView.list = list; self.isShowGiftScrollView = YES; } -(void)didClickGiftScrollView:(QXGiftScrollView *)giftScrollView index:(NSInteger)index model:(QXGiftScrollModel *)model{ [[QXGlobal shareGlobal] joinRoomWithRoomId:model.roomId isRejoin:NO navagationController:self.navigationController]; } - (void)getTopRoomList { __weak typeof(self)weakSelf = self; [QXHomePageNetwork homeRoomListWithPage:0 is_top:YES label_id:@"" successBlock:^(NSArray * _Nonnull list, BOOL isAppStore) { [weakSelf.dataArray removeAllObjects]; [weakSelf.dataArray addObjectsFromArray:list]; if (isAppStore) { self.appStoreView.hidden = NO; }else{ self.appStoreView.hidden = YES; } // weakSelf.appStoreView.dataArray = list; [weakSelf.cycleScrollView reloadData]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)getBanner{ MJWeakSelf [QXHomePageNetwork homeBannerSuccessBlock:^(NSArray * _Nonnull list) { NSMutableArray *arr = [NSMutableArray array]; for (QXBanner *banner in list) { [arr addObject:banner.image]; } [weakSelf.bannerArry removeAllObjects]; [weakSelf.bannerArry addObjectsFromArray:list]; weakSelf.appStoreView.bannerArray = list; weakSelf.bannerScrollView.imageURLStringsGroup = arr; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } #pragma mark - GKCycleScrollViewDataSource,GKCycleScrollViewDelegate - (NSInteger)numberOfCellsInCycleScrollView:(GKCycleScrollView *)cycleScrollView { return self.dataArray.count; } - (GKCycleScrollViewCell *)cycleScrollView:(GKCycleScrollView *)cycleScrollView cellForViewAtIndex:(NSInteger)index { GKCycleScrollViewCell *cell = [cycleScrollView dequeueReusableCell]; if (!cell) { cell = [QXHomeTopCell new]; } QXHomeTopCell *topcell = (QXHomeTopCell*)cell; topcell.roomModel = [self.dataArray objectAtIndex:index]; return cell; } - (CGSize)sizeForCellInCycleScrollView:(GKCycleScrollView *)cycleScrollView { return CGSizeMake(180, 155); } - (void)cycleScrollView:(GKCycleScrollView *)cycleScrollView didSelectCellAtIndex:(NSInteger)index { QXRoomListModel *model = self.dataArray[index]; [[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_id isRejoin:NO navagationController:self.navigationController]; } #pragma mark - SDCycleScrollViewDelegate -(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{ if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } QXBanner *banner = self.bannerArry[index]; if ([banner.type isEqualToString:@"2"]) { QXBaseWebViewController *webVc = [[QXBaseWebViewController alloc] init]; webVc.urlStr = banner.url; [self.navigationController pushViewController:webVc animated:YES]; }else if ([banner.type isEqualToString:@"3"]){ [[QXGlobal shareGlobal] joinRoomWithRoomId:banner.aid isRejoin:NO navagationController:self.navigationController]; }else if ([banner.type isEqualToString:@"4"]){ QXUserHomePageViewController *userHomePage = [[QXUserHomePageViewController alloc] init]; userHomePage.user_id = banner.aid; [self.navigationController pushViewController:userHomePage animated:YES]; } } -(void)gotoRoom{ if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } QXMyRoomViewController *vc = [[QXMyRoomViewController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } -(void)gotoSearchVC{ if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } QXSearchViewController *vc = [[QXSearchViewController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } -(void)gotoRankVC{ if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } QXRankHomeVC *vc = [[QXRankHomeVC alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } -(UIButton *)roomBtn{ if (!_roomBtn) { _roomBtn = [[UIButton alloc] init]; [_roomBtn setImage:[UIImage imageNamed:@"home_room"] forState:UIControlStateNormal]; [_roomBtn setImage:[UIImage imageNamed:@"home_room"] forState:UIControlStateHighlighted]; [_roomBtn addTarget:self action:@selector(gotoRoom) forControlEvents:UIControlEventTouchUpInside]; } return _roomBtn; } - (UIButton *)rankRightBtn { if (!_rankRightBtn) { _rankRightBtn = [[UIButton alloc] init]; [_rankRightBtn setImage:[UIImage imageNamed:@"home_ranking"] forState:UIControlStateNormal]; [_rankRightBtn setImage:[UIImage imageNamed:@"home_ranking"] forState:UIControlStateHighlighted]; [_rankRightBtn addTarget:self action:@selector(gotoRankVC) forControlEvents:UIControlEventTouchUpInside]; } return _rankRightBtn; } - (UIButton *)searchRightBtn { if (!_searchRightBtn) { _searchRightBtn = [[UIButton alloc] init]; [_searchRightBtn setImage:[UIImage imageNamed:@"home_search"] forState:UIControlStateNormal]; [_searchRightBtn setImage:[UIImage imageNamed:@"home_search"] forState:UIControlStateHighlighted]; [_searchRightBtn addTarget:self action:@selector(gotoSearchVC) forControlEvents:UIControlEventTouchUpInside]; } return _searchRightBtn; } -(UIView *)sectionView{ if (!_sectionView) { _sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)]; [_sectionView addSubview:self.categoryView]; } return _sectionView; } -(JXCategoryTitleView *)categoryView{ if (!_categoryView) { _categoryView = [[JXCategoryTitleView alloc] init]; _categoryView.frame = CGRectMake(15, 0, SCREEN_WIDTH-30, 44); _categoryView.delegate = self; _categoryView.titleSelectedColor = [UIColor colorWithHexString:@"#FFFFFF"]; _categoryView.titleColor = RGB16A(0xF1ECFF, 0.45); _categoryView.cellWidth = JXCategoryViewAutomaticDimension; _categoryView.contentEdgeInsetLeft = 3; _categoryView.cellSpacing = 16; _categoryView.titleLabelZoomEnabled = YES; _categoryView.titleFont = [UIFont boldSystemFontOfSize:16]; _categoryView.titleSelectedFont = [UIFont boldSystemFontOfSize:20]; _categoryView.averageCellSpacingEnabled = NO; JXCategoryIndicatorImageView *indicatorView = [[JXCategoryIndicatorImageView alloc] init]; indicatorView.indicatorWidth = JXCategoryViewAutomaticDimension; indicatorView.indicatorImageView.image = [UIImage imageNamed:@"home_slider"]; indicatorView.indicatorImageViewSize = CGSizeMake(50, 28); self.indicatorView = indicatorView; indicatorView.verticalMargin = 5; _categoryView.indicators = @[indicatorView]; } return _categoryView; } -(UIView *)headerView{ if (!_headerView) { _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.cycleScrollView.height+self.bannerScrollView.height+10)]; [_headerView addSubview:self.cycleScrollView]; [_headerView addSubview:self.bannerScrollView]; } return _headerView; } -(SDCycleScrollView *)bannerScrollView{ if (!_bannerScrollView) { _bannerScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(16, self.cycleScrollView.bottom+10, SCREEN_WIDTH-32, ScaleWidth(95)) delegate:self placeholderImage:nil]; _bannerScrollView.backgroundColor = [UIColor clearColor]; _bannerScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill; [_bannerScrollView addRoundedCornersWithRadius:8] ; _bannerScrollView.delegate = self; } return _bannerScrollView; } -(GKCycleScrollView *)cycleScrollView{ if (!_cycleScrollView) { _cycleScrollView = [[GKCycleScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 155)]; _cycleScrollView.dataSource = self; _cycleScrollView.delegate = self; _cycleScrollView.minimumCellAlpha = 0.0; _cycleScrollView.leftRightMargin = 16.0f; _cycleScrollView.topBottomMargin = 15.0f; _cycleScrollView.isInfiniteLoop = YES; _cycleScrollView.isAutoScroll = YES; } return _cycleScrollView; } -(QXGiftScrollView *)giftScrollView{ if (!_giftScrollView) { _giftScrollView = [[QXGiftScrollView alloc] initWithFrame:CGRectMake(16, self.cycleScrollView.bottom, SCREEN_WIDTH-32, 36)]; _giftScrollView.delegate = self; } return _giftScrollView; } -(NSMutableArray *)titles{ if (!_titles) { _titles = [NSMutableArray array]; } return _titles; } -(NSMutableArray *)bannerArry{ if (!_bannerArry) { _bannerArry = [NSMutableArray array]; } return _bannerArry; } -(UIButton *)firstRechargeBtn{ if (!_firstRechargeBtn) { _firstRechargeBtn = [[UIButton alloc] init]; [_firstRechargeBtn setBackgroundImage:[UIImage imageNamed:@"first_recharge_icon"] forState:(UIControlStateNormal)]; [_firstRechargeBtn addTarget:self action:@selector(firstAction) forControlEvents:(UIControlEventTouchUpInside)]; } return _firstRechargeBtn; } -(UIButton *)skyDownBtn{ if (!_skyDownBtn) { _skyDownBtn = [[UIButton alloc] init]; [_skyDownBtn setBackgroundImage:[UIImage imageNamed:@"sky_down_gift_icon"] forState:(UIControlStateNormal)]; } return _skyDownBtn; } -(QXFirstRechargePopView *)firstRechargeView{ if (!_firstRechargeView) { _firstRechargeView = [[QXFirstRechargePopView alloc] init]; } return _firstRechargeView; } -(QXAppstoreHomeView *)appStoreView{ if (!_appStoreView) { _appStoreView = [[QXAppstoreHomeView alloc] initWithFrame:CGRectMake(0, NavContentHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight-TabbarContentHeight)]; } return _appStoreView; } @end