401 lines
14 KiB
Objective-C
401 lines
14 KiB
Objective-C
//
|
||
// XPNewHomeViewController.m
|
||
// YuMi
|
||
//
|
||
// Created by YuMi on 2023/6/18.
|
||
//
|
||
|
||
#import "XPNewHomeViewController.h"
|
||
///Third
|
||
#import <Masonry/Masonry.h>
|
||
#import <JXPagingView/JXPagerView.h>
|
||
#import <JXPagingView/JXPagerListRefreshView.h>
|
||
#import <JXCategoryView/JXCategoryView.h>
|
||
///Tool
|
||
#import "YUMIMacroUitls.h"
|
||
#import "DJDKMIMOMColor.h"
|
||
#import "YUMIHtmlUrl.h"
|
||
#import "UIImage+Utils.h"
|
||
#import "AccountInfoStorage.h"
|
||
#import "Api+Room.h"
|
||
#import "TTPopup.h"
|
||
#import "NSArray+Safe.h"
|
||
///Model
|
||
#import "HomeTagModel.h"
|
||
#import "XPLittleGameRoomOpenView.h"
|
||
///View
|
||
#import "XPRoomSearchContainerViewController.h"
|
||
#import "XPHomePartyViewController.h"
|
||
#import "XPWebViewController.h"
|
||
#import "XPHomeRecommendViewController.h"
|
||
#import "XPNewHomeNavView.h"
|
||
#import "XPRoomViewController.h"
|
||
#import "XPNewHomeHeadView.h"
|
||
#import "PIHoemCategoryTitleView.h"
|
||
///P
|
||
#import "XPHomeContainerPresenter.h"
|
||
#import "XPHomeContainerProtocol.h"
|
||
#import "ClientConfig.h"
|
||
#import "SessionViewController.h"
|
||
|
||
UIKIT_EXTERN NSString * kHomeMoreScrollPageKey;
|
||
UIKIT_EXTERN NSString * const kOpenRoomNotification;
|
||
|
||
@interface XPNewHomeViewController ()<JXPagerViewDelegate,JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate, XPHomeContainerProtocol, XPNewHomeNavViewDelegate>
|
||
///背景
|
||
@property (nonatomic,strong) UIImageView *backImageView;
|
||
///导航
|
||
@property (nonatomic,strong) XPNewHomeNavView *navView;
|
||
///头视图
|
||
@property(nonatomic,strong) XPNewHomeHeadView *headView;
|
||
///分页标题
|
||
@property (nonatomic, strong) NSArray<NSString *> *titles;
|
||
///分页控件
|
||
@property (nonatomic, strong) PIHoemCategoryTitleView *titleView;
|
||
///分页lineView
|
||
@property (nonatomic, strong) JXPagerView *pagingView;
|
||
///tag的列表
|
||
@property (nonatomic,copy) NSMutableArray<HomeTagModel *> *tagList;
|
||
@property (nonatomic,strong) HomeTagModel *recommendItem;
|
||
///解决弱网时首页底部出现一片空白bug
|
||
@property (nonatomic,assign) BOOL isEmpty;
|
||
@end
|
||
|
||
@implementation XPNewHomeViewController
|
||
-(instancetype)initWithIsEmpty:(BOOL)isEmpty{
|
||
self = [super init];
|
||
if(self){
|
||
self.isEmpty = isEmpty;
|
||
}
|
||
return self;
|
||
}
|
||
-(void)dealloc{
|
||
[[NSNotificationCenter defaultCenter]removeObserver:self];
|
||
}
|
||
- (BOOL)isHiddenNavBar {
|
||
return YES;
|
||
}
|
||
|
||
- (XPHomeContainerPresenter *)createPresenter {
|
||
return [[XPHomeContainerPresenter alloc] init];
|
||
}
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
if(self.isEmpty == NO){
|
||
[self initHttp];
|
||
[self initSubViews];
|
||
[self initSubViewConstraints];
|
||
}
|
||
|
||
|
||
}
|
||
|
||
#pragma mark - Private Method
|
||
- (void)initSubViews {
|
||
self.view.backgroundColor = [DJDKMIMOMColor colorWithHexString:@"#F3F5FA"];
|
||
[self.view addSubview:self.backImageView];
|
||
[self.view addSubview:self.navView];
|
||
[self.view addSubview:self.pagingView];
|
||
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(openRoomNotification:) name:kOpenRoomNotification object:nil];
|
||
if([[AccountInfoStorage instance] getUid].length == 0){
|
||
return;
|
||
}
|
||
if([ClientConfig shareConfig].roomId != nil){
|
||
[self opRoom:[ClientConfig shareConfig].roomId];
|
||
[ClientConfig shareConfig].roomId = nil;
|
||
}
|
||
if([ClientConfig shareConfig].chatId != nil){
|
||
NIMSession * session = [NIMSession session:[ClientConfig shareConfig].chatId type:NIMSessionTypeP2P];
|
||
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
|
||
sessionVC.isAttention = YES;
|
||
[self.navigationController pushViewController:sessionVC animated:YES];
|
||
[ClientConfig shareConfig].chatId = nil;
|
||
}
|
||
}
|
||
-(void)openRoomNotification:(NSNotification *)notification{
|
||
if([[AccountInfoStorage instance] getUid].length == 0){
|
||
return;
|
||
}
|
||
NSString *uid = notification.userInfo[@"uid"];
|
||
NSString *type = notification.userInfo[@"type"];
|
||
if([type isEqualToString:@"kOpenChat"]){
|
||
if (uid.length > 0) {
|
||
NIMSession * session = [NIMSession session:uid type:NIMSessionTypeP2P];
|
||
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
|
||
sessionVC.isAttention = YES;
|
||
[self.navigationController pushViewController:sessionVC animated:YES];
|
||
[ClientConfig shareConfig].chatId = nil;
|
||
}
|
||
return;
|
||
}
|
||
|
||
ClientConfig *config = [ClientConfig shareConfig];
|
||
config.chatId = uid;
|
||
if(uid != nil){
|
||
[self opRoom:uid];
|
||
[ClientConfig shareConfig].roomId = nil;
|
||
}
|
||
}
|
||
- (void)initSubViewConstraints {
|
||
|
||
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.left.right.top.mas_equalTo(self.view);
|
||
make.height.mas_equalTo(170 + kSafeAreaTopHeight);
|
||
}];
|
||
|
||
[self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.left.right.top.mas_equalTo(self.view);
|
||
make.height.mas_equalTo(kNavigationHeight);
|
||
}];
|
||
|
||
|
||
[self.pagingView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.equalTo(self.navView.mas_bottom).mas_offset(kGetScaleWidth(10));
|
||
make.leading.bottom.trailing.mas_equalTo(0);
|
||
}];
|
||
|
||
}
|
||
|
||
- (void)initHttp {
|
||
[self.presenter getHomeTagList];
|
||
[self.presenter getHomeTopBannerList];
|
||
}
|
||
|
||
|
||
#pragma mark - XPNewHomeNavViewDelegate
|
||
- (void)xPNewHomeNavView:(XPNewHomeNavView *)view didClickRank:(UIButton *)sender {
|
||
XPWebViewController * webVC =[[XPWebViewController alloc] init];
|
||
webVC.url = URLWithType(kHomeRankURL);
|
||
[self.navigationController pushViewController:webVC animated:YES];
|
||
}
|
||
|
||
- (void)xPNewHomeNavView:(XPNewHomeNavView *)view didClickOpenRoom:(UIButton *)sender {
|
||
NSString* roomUid = [AccountInfoStorage instance].getUid;
|
||
[self opRoom:roomUid];
|
||
|
||
}
|
||
-(void)opRoom:(NSString *)roomUid{
|
||
|
||
[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];
|
||
|
||
|
||
}
|
||
|
||
- (void)xPNewHomeNavView:(XPNewHomeNavView *)view didClickSearch:(UIView *)sender {
|
||
XPRoomSearchContainerViewController * searchVC = [[XPRoomSearchContainerViewController alloc] init];
|
||
searchVC.modalPresentationStyle = UIModalPresentationFullScreen;
|
||
[self.navigationController presentViewController:searchVC animated:YES completion:nil];
|
||
}
|
||
|
||
#pragma mark - JXCategoryViewDelegate
|
||
//- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
|
||
// return self.titles.count;
|
||
//}
|
||
//
|
||
//- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
|
||
// HomeTagModel * hometag = [self.tagList safeObjectAtIndex1:index];
|
||
//
|
||
// UIViewController<JXCategoryListContentViewDelegate> * list = (UIViewController<JXCategoryListContentViewDelegate> *)[self.contentView.validListDict objectForKey:[NSNumber numberWithInteger:index]];
|
||
// if (list) {
|
||
// return list;
|
||
// } else {
|
||
// if ([hometag.name isEqualToString:YMLocalizedString(@"XPNewHomeViewController0")]) {
|
||
// XPHomeRecommendViewController * recommendVC = [[XPHomeRecommendViewController alloc] init];
|
||
// return recommendVC;
|
||
// } else {
|
||
// XPHomePartyViewController * homeVC = [[XPHomePartyViewController alloc] init];
|
||
// homeVC.pi_tabId = hometag.tid;
|
||
// return homeVC;
|
||
// }
|
||
// }
|
||
//}
|
||
//
|
||
//
|
||
//
|
||
//- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
|
||
// HomeTagModel * hometag = [self.tagList safeObjectAtIndex1:index];
|
||
// if (![hometag.name isEqualToString:YMLocalizedString(@"XPNewHomeViewController1")]) {
|
||
// XPHomePartyViewController * list = (XPHomePartyViewController<JXCategoryListContentViewDelegate> *)[self.contentView.validListDict objectForKey:[NSNumber numberWithInteger:index]];;
|
||
// list.pi_tabId = hometag.tid;
|
||
// }
|
||
//}
|
||
#pragma mark - JXCategoryViewDelegate
|
||
- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
|
||
if(self.headView.bannerList.count == 0)return kGetScaleWidth(103);
|
||
return kGetScaleWidth(188);
|
||
}
|
||
|
||
- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
|
||
return self.headView;
|
||
}
|
||
- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
|
||
return kGetScaleWidth(44);
|
||
}
|
||
- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
|
||
return self.titleView;
|
||
}
|
||
|
||
- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
|
||
return self.titles.count;
|
||
}
|
||
|
||
- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
|
||
|
||
XPHomeRecommendViewController<JXPagerViewListViewDelegate> * homeV = (XPHomeRecommendViewController<JXPagerViewListViewDelegate> *)[self.pagingView.validListDict objectForKey:[NSNumber numberWithInteger:index]];
|
||
if (homeV) {
|
||
return homeV;
|
||
}
|
||
if (index == 0) {
|
||
XPHomeRecommendViewController * recommendVC = [[XPHomeRecommendViewController alloc] init];
|
||
return recommendVC;
|
||
} else {
|
||
XPHomePartyViewController * homeVC = [[XPHomePartyViewController alloc] init];
|
||
|
||
return homeVC;
|
||
}
|
||
|
||
}
|
||
|
||
#pragma mark - JXCategoryListContentViewDelegate
|
||
- (UIView *)listView {
|
||
return self.view;
|
||
}
|
||
|
||
|
||
#pragma mark - JXPagerMainTableViewGestureDelegate
|
||
- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
|
||
//禁止categoryView左右滑动的时候,上下和左右都可以滚动
|
||
if (otherGestureRecognizer.view == self.pagingView.listContainerView) {
|
||
return NO;
|
||
}
|
||
if(otherGestureRecognizer.view.tag == 9000001){
|
||
return NO;
|
||
}
|
||
if(otherGestureRecognizer.view.tag == 9000002){
|
||
return NO;
|
||
}
|
||
|
||
return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
|
||
}
|
||
#pragma mark - XPHomeContainerProtocol
|
||
-(void)getHomeTopBannerListSuccess:(NSArray *)list{
|
||
self.headView.bannerList = list;
|
||
[self.pagingView reloadData];
|
||
[self.pagingView resizeTableHeaderViewHeightWithAnimatable:NO duration:0 curve:0];
|
||
}
|
||
- (void)getHomeTagListSuccess:(NSArray<HomeTagModel *> *)array {
|
||
// [self.tagList addObject:self.recommendItem];
|
||
// [self.tagList addObjectsFromArray:array];
|
||
// NSMutableArray * titles = [NSMutableArray array];
|
||
// [titles addObject:YMLocalizedString(@"XPNewHomeViewController2")];
|
||
// [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];
|
||
}
|
||
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
|
||
self.titleView.index = (int)index;
|
||
}
|
||
#pragma mark - Getters And Setters
|
||
- (PIHoemCategoryTitleView *)titleView {
|
||
if (!_titleView) {
|
||
_titleView = [[PIHoemCategoryTitleView alloc] init];
|
||
_titleView.delegate = self;
|
||
_titleView.titles = self.titles;
|
||
_titleView.backgroundColor = [UIColor clearColor];
|
||
_titleView.titleColor = [UIColor clearColor];
|
||
_titleView.titleSelectedColor = [UIColor clearColor];
|
||
_titleView.titleFont = kFontSemibold(16);
|
||
_titleView.titleSelectedFont = kFontRegular(14);
|
||
_titleView. titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
|
||
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
|
||
_titleView.defaultSelectedIndex = 0;
|
||
|
||
_titleView.cellSpacing = kGetScaleWidth(2);
|
||
_titleView.cellWidth = kGetScaleWidth(20);
|
||
_titleView.listContainer = (id<JXCategoryViewListContainer>)self.pagingView.listContainerView;
|
||
|
||
// JXCategoryIndicatorImageView * indocator = [[JXCategoryIndicatorImageView alloc] init];
|
||
// indocator.indicatorImageView.image = [UIImage imageNamed:@"home_slider_bg"];
|
||
// indocator.indicatorImageViewSize = CGSizeMake(kGetScaleWidth(36), kGetScaleWidth(8));
|
||
// indocator.verticalMargin = 4;
|
||
// indocator.contentMode = UIViewContentModeScaleAspectFit;
|
||
// _titleView.indicators = @[indocator];
|
||
}
|
||
return _titleView;
|
||
}
|
||
- (NSArray<NSString *> *)titles{
|
||
if(!_titles){
|
||
_titles = @[YMLocalizedString(@"XPNewHomeViewController0"),YMLocalizedString(@"XPNewHomeViewController1")];
|
||
}
|
||
return _titles;
|
||
}
|
||
- (JXPagerView *)pagingView {
|
||
if (!_pagingView) {
|
||
_pagingView = [[JXPagerView alloc] initWithDelegate:self listContainerType:0];
|
||
_pagingView.mainTableView.gestureDelegate = self;
|
||
_pagingView.backgroundColor = [UIColor clearColor];
|
||
_pagingView.listContainerView.backgroundColor = [UIColor clearColor];
|
||
_pagingView.listContainerView.listCellBackgroundColor = [UIColor clearColor];
|
||
_pagingView.mainTableView.backgroundColor = [UIColor clearColor];
|
||
}
|
||
return _pagingView;
|
||
}
|
||
- (HomeTagModel *)recommendItem {
|
||
if (!_recommendItem) {
|
||
_recommendItem = [[HomeTagModel alloc] init];
|
||
_recommendItem.name = YMLocalizedString(@"XPNewHomeViewController3");
|
||
}
|
||
return _recommendItem;
|
||
}
|
||
|
||
- (NSMutableArray<HomeTagModel *> *)tagList {
|
||
if (!_tagList) {
|
||
_tagList = [NSMutableArray array];
|
||
}
|
||
return _tagList;
|
||
}
|
||
|
||
- (XPNewHomeNavView *)navView {
|
||
if (!_navView) {
|
||
_navView = [[XPNewHomeNavView alloc] init];
|
||
_navView.delegate = self;
|
||
}
|
||
return _navView;
|
||
}
|
||
|
||
- (UIImageView *)backImageView {
|
||
if (!_backImageView) {
|
||
_backImageView = [[UIImageView alloc] init];
|
||
_backImageView.image = [UIImage imageNamed:@"home_top_bg"];
|
||
_backImageView.layer.masksToBounds = YES;
|
||
_backImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||
}
|
||
return _backImageView;
|
||
}
|
||
- (XPNewHomeHeadView *)headView{
|
||
if(!_headView){
|
||
_headView = [[XPNewHomeHeadView alloc]initWithFrame:CGRectZero];
|
||
}
|
||
return _headView;
|
||
}
|
||
@end
|