Files
featherVoice/QXLive/HomePage(声播)/Controlller/QXHomeViewController.m

455 lines
18 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// 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"
@interface QXHomeViewController ()<JXPagerViewDelegate,JXCategoryViewDelegate,GKCycleScrollViewDataSource,GKCycleScrollViewDelegate,QXGiftScrollViewDelegate,SDCycleScrollViewDelegate>
@property (nonatomic, strong) JXPagerView *pagingView;
@property (nonatomic,strong)JXCategoryTitleView *categoryView;
@property (nonatomic,strong)NSMutableArray <UIViewController*>*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);
}];
[self.view addSubview:self.rankRightBtn];
[self.view addSubview:self.searchRightBtn];
[self.view addSubview:self.roomBtn];
[self.roomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(30);
make.centerY.equalTo(tLabel);
make.right.equalTo(self.view).offset(-10);
}];
[self.searchRightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.roomBtn.mas_left).offset(-10);
make.centerY.width.height.equalTo(self.roomBtn);
}];
[self.rankRightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.searchRightBtn.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<JXCategoryViewListContainer>)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<QXMyRoomType *> * _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];
}
-(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<JXPagerViewListViewDelegate>)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)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<QXRoomListModel *> * _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<QXBanner *> * _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((SCREEN_WIDTH)/3, 113);
}
- (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{
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{
QXMyRoomViewController *vc = [[QXMyRoomViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
-(void)gotoSearchVC{
QXSearchViewController *vc = [[QXSearchViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
-(void)gotoRankVC{
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:@"#333333"];
_categoryView.titleColor = [UIColor colorWithHexString:@"#666666"];
_categoryView.cellWidth = JXCategoryViewAutomaticDimension;
_categoryView.contentEdgeInsetLeft = 3;
_categoryView.cellSpacing = 16;
_categoryView.titleLabelZoomEnabled = YES;
_categoryView.titleFont = [UIFont boldSystemFontOfSize:13];
_categoryView.titleSelectedFont = [UIFont boldSystemFontOfSize:18];
_categoryView.averageCellSpacingEnabled = NO;
JXCategoryIndicatorImageView *indicatorView = [[JXCategoryIndicatorImageView alloc] init];
indicatorView.indicatorWidth = JXCategoryViewAutomaticDimension;
indicatorView.indicatorImageView.image = [UIImage imageNamed:@"home_slider"];
indicatorView.indicatorImageViewSize = CGSizeMake(29, 8);
self.indicatorView = indicatorView;
indicatorView.verticalMargin = 11;
_categoryView.indicators = @[indicatorView];
}
return _categoryView;
}
-(UIView *)headerView{
if (!_headerView) {
_headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.cycleScrollView.height+self.bannerScrollView.height)];
[_headerView addSubview:self.cycleScrollView];
[_headerView addSubview:self.bannerScrollView];
}
return _headerView;
}
-(SDCycleScrollView *)bannerScrollView{
if (!_bannerScrollView) {
_bannerScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(16, self.cycleScrollView.bottom, SCREEN_WIDTH-32, ScaleWidth(95)) delegate:self placeholderImage:nil];
// _bannerScrollView.backgroundColor = [UIColor redColor];
_bannerScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
[_bannerScrollView addRoundedCornersWithRadius:8] ;
_bannerScrollView.delegate = self;
}
return _bannerScrollView;
}
-(GKCycleScrollView *)cycleScrollView{
if (!_cycleScrollView) {
_cycleScrollView = [[GKCycleScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(113))];
_cycleScrollView.dataSource = self;
_cycleScrollView.delegate = self;
_cycleScrollView.minimumCellAlpha = 0.0;
_cycleScrollView.leftRightMargin = 16.0f;
_cycleScrollView.topBottomMargin = 10.0f;
}
return _cycleScrollView;
}
-(QXGiftScrollView *)giftScrollView{
if (!_giftScrollView) {
_giftScrollView = [[QXGiftScrollView alloc] initWithFrame:CGRectMake(16, self.cycleScrollView.bottom, SCREEN_WIDTH-32, 31)];
_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