
主要变更: 1. 从 Podfile 中移除 mob_linksdk_pro 依赖,减少项目依赖。 2. 从 AppDelegate 和相关文件中删除 MobLink 初始化及相关逻辑,清理未使用的代码。 3. 移除 ClientConfig 中的 inviteCode 属性,简化配置管理。 此更新旨在提升项目的可维护性,减少冗余依赖,确保代码结构更加清晰。
982 lines
35 KiB
Objective-C
982 lines
35 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>
|
||
#import <MJRefresh/MJRefresh.h>
|
||
#import "SDWebImageManager.h"
|
||
#import <UIKit/UIKit.h>
|
||
///Tool
|
||
#import "Api+Home.h"
|
||
#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"
|
||
#import "XPWeakTimer.h"
|
||
#import "XPRoomAnimationHitView.h"
|
||
///Model
|
||
#import "HomeTagModel.h"
|
||
#import "AccountModel.h"
|
||
#import "XPLittleGameRoomOpenView.h"
|
||
|
||
#import "PIHomeItemModel.h"
|
||
|
||
#import "HomeMenuSourceModel.h"
|
||
|
||
///View
|
||
#import "XPRoomSearchContainerViewController.h"
|
||
#import "XPHomePartyViewController.h"
|
||
#import "XPWebViewController.h"
|
||
|
||
#import "XPNewHomeNavView.h"
|
||
#import "XPRoomViewController.h"
|
||
#import "XPNewHomeHeadView.h"
|
||
#import "PIHoemCategoryTitleView.h"
|
||
#import "XPHomeRecommendOtherRoomView.h"
|
||
///P
|
||
#import "XPHomeContainerPresenter.h"
|
||
#import "XPHomeContainerProtocol.h"
|
||
#import "ClientConfig.h"
|
||
#import "SessionViewController.h"
|
||
#import "Api+Main.h"
|
||
#import "LoginViewController.h"
|
||
#import "BaseNavigationController.h"
|
||
#import "XPAdImageTool.h"
|
||
#import "PIHomeCategoryTitleModel.h"
|
||
|
||
#import "RegionListViewController.h"
|
||
#import "EventCenterViewController.h"
|
||
|
||
UIKIT_EXTERN NSString * kHomeMoreScrollPageKey;
|
||
UIKIT_EXTERN NSString * const kOpenRoomNotification;
|
||
|
||
|
||
@interface HomeCategoryTabListCell : UICollectionViewCell
|
||
@property(nonatomic, assign) BOOL isSelected;
|
||
@property(nonatomic, strong) UIView *selectedBackground;
|
||
@property(nonatomic, strong) NetImageView *iconImageView;
|
||
@property(nonatomic, strong) PIHomeCategoryTitleModel *cellModel;
|
||
@property(nonatomic, copy) void(^didTapCategoryModel)(PIHomeCategoryTitleModel *model);
|
||
@end
|
||
|
||
@implementation HomeCategoryTabListCell
|
||
|
||
- (instancetype)initWithFrame:(CGRect)frame
|
||
{
|
||
if (self = [super initWithFrame:frame]) {
|
||
self.backgroundColor = [UIColor clearColor];
|
||
[self.contentView setCornerRadius:15];
|
||
self.contentView.backgroundColor = [UIColor whiteColor];
|
||
[self.contentView addSubview:self.selectedBackground];
|
||
[self.selectedBackground mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.edges.mas_equalTo(self.contentView);
|
||
}];
|
||
|
||
[self.contentView addSubview:self.iconImageView];
|
||
[self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.center.mas_equalTo(self.contentView);
|
||
make.size.mas_equalTo(CGSizeMake(36, 23));
|
||
}];
|
||
}
|
||
return self;
|
||
}
|
||
|
||
- (void)setCellModel:(PIHomeCategoryTitleModel *)cellModel {
|
||
_cellModel = cellModel;
|
||
self.iconImageView.imageUrl = cellModel.icon;
|
||
}
|
||
|
||
- (void)setSelected:(BOOL)selected {
|
||
[super setSelected:selected];
|
||
self.selectedBackground.hidden = !selected;
|
||
if (selected && self.didTapCategoryModel) {
|
||
self.didTapCategoryModel(self.cellModel);
|
||
}
|
||
}
|
||
|
||
#pragma mark -
|
||
- (UIView *)selectedBackground {
|
||
if (!_selectedBackground) {
|
||
_selectedBackground = [[UIView alloc] init];
|
||
_selectedBackground.backgroundColor = [UIColor whiteColor];
|
||
[_selectedBackground setCornerRadius:15
|
||
corners:kCALayerMaxXMaxYCorner | kCALayerMaxXMinYCorner | kCALayerMinXMaxYCorner | kCALayerMinXMinYCorner
|
||
borderWidth:1
|
||
borderColor:UIColorFromRGB(0xFF8C03)];
|
||
_selectedBackground.hidden = YES;
|
||
}
|
||
return _selectedBackground;
|
||
}
|
||
|
||
- (NetImageView *)iconImageView {
|
||
if (!_iconImageView) {
|
||
_iconImageView = [[NetImageView alloc] init];
|
||
}
|
||
return _iconImageView;
|
||
}
|
||
|
||
@end
|
||
|
||
@interface HomeCategoryTabList : UIView <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
||
|
||
@property(nonatomic, assign) NSInteger lastSelectedIndex;
|
||
@property(nonatomic, strong) UIButton *arrowButton;
|
||
@property(nonatomic, strong) UIView *gradientMask;
|
||
@property(nonatomic, strong) UICollectionView *tabCollectionView;
|
||
@property(nonatomic, copy) NSArray <PIHomeCategoryTitleModel*> *tabArray;
|
||
@property(nonatomic, copy) void(^didTapCategoryModel)(PIHomeCategoryTitleModel *model);
|
||
@property(nonatomic, copy) void(^didTapArrow)(void);
|
||
@property(nonatomic, assign) BOOL firstLoad;
|
||
|
||
- (void)closeArrow;
|
||
- (void)updateIndex:(NSInteger)index;
|
||
|
||
@end
|
||
|
||
@implementation HomeCategoryTabList
|
||
|
||
- (instancetype)init {
|
||
if (self = [super init]) {
|
||
self.backgroundColor = [[ClientConfig shareConfig] bgColor];
|
||
self.lastSelectedIndex = -1;
|
||
self.firstLoad = YES;
|
||
[self addSubview:self.tabCollectionView];
|
||
[self addSubview:self.arrowButton];
|
||
|
||
[self.tabCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.bottom.mas_equalTo(self);
|
||
make.leading.mas_equalTo(0);
|
||
make.trailing.mas_equalTo(self).offset(-15);
|
||
}];
|
||
|
||
[self.arrowButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.centerY.mas_equalTo(self);
|
||
make.size.mas_equalTo(CGSizeMake(24, 24));
|
||
make.trailing.mas_equalTo(-15);
|
||
}];
|
||
|
||
_gradientMask = [[UIView alloc] init];
|
||
NSArray *colorArr = @[[UIColor colorWithWhite:1 alpha:0.0],
|
||
[[ClientConfig shareConfig] bgColor]];
|
||
if (isMSRTL()) {
|
||
colorArr = @[[[ClientConfig shareConfig] bgColor],
|
||
[UIColor colorWithWhite:1 alpha:0.0]];
|
||
[_gradientMask addGradientBackgroundWithColors:colorArr
|
||
startPoint:CGPointMake(0.7, 0.5)
|
||
endPoint:CGPointMake(1.0, 0.5)
|
||
cornerRadius:0];
|
||
} else {
|
||
[_gradientMask addGradientBackgroundWithColors:colorArr
|
||
startPoint:CGPointMake(0.2, 0.5)
|
||
endPoint:CGPointMake(0.4, 0.5)
|
||
cornerRadius:0];
|
||
}
|
||
[self insertSubview:self.gradientMask belowSubview:self.arrowButton];
|
||
[self.gradientMask mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.leading.mas_equalTo(self.arrowButton).offset(-20);
|
||
make.trailing.mas_equalTo(self);
|
||
make.top.bottom.mas_equalTo(self);
|
||
}];
|
||
|
||
}
|
||
return self;
|
||
}
|
||
|
||
- (void)handleTapArrow {
|
||
if (_didTapArrow) {
|
||
self.didTapArrow();
|
||
}
|
||
}
|
||
|
||
- (void)setTabArray:(NSArray<PIHomeCategoryTitleModel *> *)tabArray {
|
||
if (tabArray == nil) {
|
||
tabArray = @[];
|
||
}
|
||
_tabArray = tabArray;
|
||
// 如果 tab items 总长度到达或超过边缘,要显示箭头按钮
|
||
if (46 * self.tabArray.count + 12 * (self.tabArray.count-1) > KScreenWidth-30) {
|
||
self.gradientMask.hidden = NO;
|
||
self.arrowButton.hidden = NO;
|
||
} else {
|
||
self.gradientMask.hidden = YES;
|
||
self.arrowButton.hidden = YES;
|
||
}
|
||
[self.tabCollectionView reloadData];
|
||
if (tabArray.count > 0 && self.firstLoad == YES) {
|
||
self.firstLoad = NO;
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||
[self.tabCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
|
||
animated:NO
|
||
scrollPosition:UICollectionViewScrollPositionNone];
|
||
});
|
||
}
|
||
|
||
@kWeakify(self);
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
@kStrongify(self);
|
||
if (!self) {
|
||
return;
|
||
}
|
||
|
||
if (tabArray.count > 0) {
|
||
if (self.lastSelectedIndex > -1 && self.lastSelectedIndex < tabArray.count - 1) {
|
||
[self.tabCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:self.lastSelectedIndex inSection:0]
|
||
animated:NO
|
||
scrollPosition:UICollectionViewScrollPositionNone];
|
||
} else {
|
||
// 阿语环境可能会出现选中错误的 index
|
||
if (isMSRTL()) {
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||
[self.tabCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
|
||
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
|
||
animated:YES];
|
||
});
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
- (void)closeArrow {
|
||
|
||
}
|
||
|
||
- (void)updateIndex:(NSInteger)index {
|
||
if (index == self.lastSelectedIndex) {
|
||
return;
|
||
}
|
||
if (index < self.tabArray.count) {
|
||
self.lastSelectedIndex = index;
|
||
[self.tabCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]
|
||
animated:YES
|
||
scrollPosition:UICollectionViewScrollPositionNone];
|
||
}
|
||
}
|
||
|
||
#pragma mark -
|
||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
||
return self.tabArray.count;
|
||
}
|
||
|
||
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||
HomeCategoryTabListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeCategoryTabListCell" forIndexPath:indexPath];
|
||
cell.cellModel = [self.tabArray xpSafeObjectAtIndex:indexPath.row];
|
||
@kWeakify(self);
|
||
[cell setDidTapCategoryModel:^(PIHomeCategoryTitleModel *model) {
|
||
@kStrongify(self);
|
||
if (self.didTapCategoryModel) {
|
||
self.didTapCategoryModel(model);
|
||
}
|
||
}];
|
||
return cell;
|
||
}
|
||
|
||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
||
self.lastSelectedIndex = indexPath.row;
|
||
}
|
||
|
||
#pragma mark -
|
||
- (UIButton *)arrowButton {
|
||
if (!_arrowButton) {
|
||
_arrowButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
_arrowButton.backgroundColor = [UIColor clearColor];
|
||
[_arrowButton setImage:kImage(@"common_down_arrow")
|
||
forState:UIControlStateNormal];
|
||
[_arrowButton addTarget:self
|
||
action:@selector(handleTapArrow)
|
||
forControlEvents:UIControlEventTouchUpInside];
|
||
}
|
||
return _arrowButton;
|
||
}
|
||
|
||
- (UIScrollView *)tabCollectionView {
|
||
if (!_tabCollectionView) {
|
||
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||
layout.itemSize = CGSizeMake(46, 30);
|
||
layout.minimumLineSpacing = 12;
|
||
layout.minimumInteritemSpacing = 12;
|
||
layout.sectionInset = UIEdgeInsetsMake(0, 14, 0, 30);
|
||
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
||
_tabCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero
|
||
collectionViewLayout:layout];
|
||
_tabCollectionView.backgroundColor = [UIColor clearColor];
|
||
_tabCollectionView.showsHorizontalScrollIndicator = NO;
|
||
_tabCollectionView.delegate = self;
|
||
_tabCollectionView.dataSource = self;
|
||
[_tabCollectionView registerClass:[HomeCategoryTabListCell class]
|
||
forCellWithReuseIdentifier:@"HomeCategoryTabListCell"];
|
||
}
|
||
return _tabCollectionView;
|
||
}
|
||
|
||
@end
|
||
|
||
|
||
@interface XPNewHomeViewController ()<
|
||
JXPagerViewDelegate,
|
||
JXPagerMainTableViewGestureDelegate,
|
||
JXCategoryViewDelegate,
|
||
XPHomeContainerProtocol,
|
||
XPNewHomeNavViewDelegate,
|
||
XPNewHomeHeadViewDelegate,
|
||
XPHomeRecommendOtherRoomViewDelegate>
|
||
|
||
///头视图
|
||
@property(nonatomic,strong) XPNewHomeHeadView *headView;
|
||
///分页标题
|
||
@property (nonatomic, strong) NSMutableArray<PIHomeCategoryTitleModel *> *tagModelList;
|
||
///分页控件
|
||
@property (nonatomic, strong) JXCategoryTitleView *titleView;
|
||
@property(nonatomic, strong) HomeCategoryTabList *categoryTagList;
|
||
|
||
///分页lineView
|
||
@property (nonatomic, strong) JXPagerView *pagingView;
|
||
|
||
@property (nonatomic,strong) HomeTagModel *recommendItem;
|
||
///解决弱网时首页底部出现一片空白bug
|
||
@property (nonatomic,assign) BOOL isEmpty;
|
||
@property(nonatomic,assign) BOOL isCheckIp;
|
||
@property(nonatomic,assign) NSInteger type;
|
||
@property(nonatomic,strong) NSMutableDictionary *validListDict;
|
||
|
||
@property (nonatomic, copy) NSArray<HomeBannerInfoModel *> *bannerInfoList;
|
||
@property (nonatomic, copy) NSArray<HomeBannerInfoModel *> *secondBannerInfoList;
|
||
|
||
@property(nonatomic, assign) NSInteger maxReloadTagsLimitCount;
|
||
@property(nonatomic, assign) NSInteger reloadTagsLimitCount;
|
||
|
||
@property (nonatomic, assign) bool hasLoadAPIs;
|
||
|
||
@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.maxReloadTagsLimitCount = 5;
|
||
self.reloadTagsLimitCount = 0;
|
||
|
||
[self initSubViews];
|
||
[self initSubViewConstraints];
|
||
|
||
[self requestCheckIp];
|
||
}
|
||
}
|
||
|
||
- (void)viewDidAppear:(BOOL)animated {
|
||
[super viewDidAppear:animated];
|
||
|
||
if (!self.hasLoadAPIs) {
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||
[self.pagingView.mainTableView.mj_header beginRefreshing];
|
||
});
|
||
self.hasLoadAPIs = YES;
|
||
}
|
||
|
||
}
|
||
|
||
- (void)tokenInvalid {
|
||
[[AccountInfoStorage instance] saveAccountInfo:nil];
|
||
[[AccountInfoStorage instance] saveTicket:nil];
|
||
if ([NIMSDK sharedSDK].loginManager.isLogined) {
|
||
[[NIMSDK sharedSDK].loginManager logout:nil];
|
||
}
|
||
LoginViewController *lvc = [[LoginViewController alloc] init];
|
||
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:lvc];
|
||
nav.modalPresentationStyle = UIModalPresentationFullScreen;
|
||
kWindow.rootViewController = nav;
|
||
XPAdImageTool.shareImageTool.isImLogin = NO;
|
||
}
|
||
|
||
- (void)createTagScrollView {
|
||
if (_categoryTagList) {
|
||
return;
|
||
}
|
||
|
||
[self.titleView addSubview:self.categoryTagList];
|
||
[self.categoryTagList mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.edges.mas_equalTo(self.titleView);
|
||
}];
|
||
}
|
||
|
||
#pragma mark - Private Method
|
||
|
||
- (void)initSubViews {
|
||
self.type = 0;
|
||
self.view.backgroundColor = [UIColor clearColor];
|
||
[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;
|
||
}
|
||
|
||
if([ClientConfig shareConfig].pushChatId != nil){
|
||
NIMSession * session = [NIMSession session:[ClientConfig shareConfig].pushChatId type:NIMSessionTypeP2P];
|
||
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
|
||
[self.navigationController pushViewController:sessionVC animated:YES];
|
||
[ClientConfig shareConfig].pushChatId = nil;
|
||
}
|
||
|
||
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
|
||
header.stateLabel.font = [UIFont systemFontOfSize:10.0];
|
||
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:10.0];
|
||
header.stateLabel.textColor = [DJDKMIMOMColor secondTextColor];
|
||
header.lastUpdatedTimeLabel.textColor = [DJDKMIMOMColor secondTextColor];
|
||
self.pagingView.mainTableView.mj_header = header;
|
||
|
||
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(homeVCRefreshComplete) name:@"khomeVCRefreshComplete" object:nil];
|
||
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(logOut) name:@"kInLoginVC" object:nil];
|
||
|
||
// [header beginRefreshing];
|
||
}
|
||
|
||
-(void)homeVCRefreshComplete{
|
||
[self.pagingView.mainTableView.mj_header endRefreshing];
|
||
[self.pagingView.mainTableView.mj_footer endRefreshing];
|
||
}
|
||
|
||
-(void)logOut{
|
||
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
||
selector:@selector(requestCheckIp)
|
||
object:nil];
|
||
}
|
||
|
||
-(void)headerRefresh{
|
||
[self.presenter getHomeTopData];
|
||
[self.presenter getHomeTagList];
|
||
[self.presenter getHomeRanks];
|
||
|
||
PIHomeCategoryTitleModel *tagModel = [self.tagModelList xpSafeObjectAtIndex:self.type];
|
||
XPHomePartyViewController *homeVC = [self.validListDict objectForKey:[NSNumber numberWithInteger:self.type]];
|
||
homeVC.tagModel = tagModel;
|
||
homeVC.bannerInfoList = self.bannerInfoList;
|
||
@kWeakify(self);
|
||
[homeVC setDidTapBannerItem:^(HomeBannerInfoModel * _Nonnull itemModel) {
|
||
@kStrongify(self);
|
||
[self handleTapBannerItem:itemModel];
|
||
}];
|
||
}
|
||
|
||
-(void)openRoomNotification:(NSNotification *)notification{
|
||
if([[AccountInfoStorage instance] getUid].length == 0){
|
||
return;
|
||
}
|
||
NSString *uid = notification.userInfo[@"uid"];
|
||
NSString *type = notification.userInfo[@"type"];
|
||
BOOL isNoAttention = [notification.userInfo[@"isNoAttention"] boolValue];
|
||
if([type isEqualToString:@"kOpenChat"]){
|
||
if (uid.length > 0) {
|
||
NIMSession * session = [NIMSession session:uid type:NIMSessionTypeP2P];
|
||
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
|
||
sessionVC.isAttention = !isNoAttention;
|
||
[self.navigationController pushViewController:sessionVC animated:YES];
|
||
if(isNoAttention == YES){
|
||
[ClientConfig shareConfig].pushChatId = nil;
|
||
}else{
|
||
[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.pagingView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.top.equalTo(self.view).mas_offset(10);
|
||
make.leading.bottom.trailing.mas_equalTo(0);
|
||
}];
|
||
}
|
||
|
||
- (void)showAllTags {
|
||
RegionListViewController *vc = [[RegionListViewController alloc] initForHomeTags:self.tagModelList
|
||
currentItem:self.tagModelList[self.titleView.selectedIndex]];
|
||
@kWeakify(self);
|
||
vc.handleDismiss = ^{
|
||
@kStrongify(self);
|
||
[self.categoryTagList closeArrow];
|
||
};
|
||
vc.handleTapCategiryComfirm = ^(PIHomeCategoryTitleModel *tagModel) {
|
||
@kStrongify(self);
|
||
NSInteger index = [self.tagModelList indexOfObject:tagModel];
|
||
[self.titleView selectItemAtIndex:index];
|
||
[self.categoryTagList updateIndex:index];
|
||
};
|
||
[self presentViewController:vc animated:YES completion:^{ }];
|
||
}
|
||
|
||
#pragma mark - XPNewHomeNavViewDelegate
|
||
- (void)xPNewHomeNavView:(XPNewHomeNavView *)view didClickRank:(UIButton *)sender {
|
||
XPWebViewController * webVC =[[XPWebViewController alloc] initWithRoomUID:nil];
|
||
webVC.url = URLWithType(kRankV2);
|
||
[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{
|
||
@kWeakify(self);
|
||
[Api getRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||
@kStrongify(self);
|
||
if(code == 401){
|
||
[self tokenInvalid];
|
||
[self showErrorToast:msg];
|
||
return;
|
||
}
|
||
|
||
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
|
||
- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
|
||
if (self.headView.bannerList.count == 0){
|
||
return kGetScaleWidth(80);
|
||
}
|
||
return kGetScaleWidth(170);
|
||
}
|
||
|
||
- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
|
||
return self.headView;
|
||
}
|
||
- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
|
||
return kGetScaleWidth(40);
|
||
}
|
||
- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
|
||
return self.titleView;
|
||
}
|
||
|
||
- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
|
||
return self.tagModelList.count;
|
||
}
|
||
|
||
- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
|
||
id homeV = [self.validListDict objectForKey:@(index)];
|
||
if (homeV) {
|
||
return homeV;
|
||
}
|
||
|
||
XPHomePartyViewController *homeVC = [[XPHomePartyViewController alloc] init];
|
||
homeVC.bannerInfoList = self.bannerInfoList;
|
||
homeVC.tagModel = [self.tagModelList xpSafeObjectAtIndex:index];
|
||
@kWeakify(self);
|
||
[homeVC setDidTapBannerItem:^(HomeBannerInfoModel * _Nonnull itemModel) {
|
||
@kStrongify(self);
|
||
[self handleTapBannerItem:itemModel];
|
||
}];
|
||
[homeVC setDidAppear:^(PIHomeCategoryTitleModel * _Nonnull displayModel) {
|
||
@kStrongify(self);
|
||
if (self.validListDict.count > 1) {
|
||
NSInteger currentIndex = [self.tagModelList indexOfObject:displayModel];
|
||
[self.titleView selectItemAtIndex:index];
|
||
[self.categoryTagList updateIndex:currentIndex];
|
||
}
|
||
}];
|
||
[self.validListDict setObject:homeVC forKey:@(index)];
|
||
|
||
return homeVC;
|
||
}
|
||
|
||
- (NSString *)pagerView:(JXPagerView *)pagerView listIdentifierAtIndex:(NSInteger)index {
|
||
|
||
return @(index).stringValue;
|
||
}
|
||
|
||
#pragma mark - JXCategoryListContentViewDelegate
|
||
- (UIView *)listView {
|
||
return self.view;
|
||
}
|
||
|
||
#pragma mark - JXPagerMainTableViewGestureDelegate
|
||
- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
|
||
// 优化手势冲突处理逻辑
|
||
|
||
// 1. 禁止categoryView左右滑动的时候,上下和左右都可以滚动
|
||
if (otherGestureRecognizer.view == self.pagingView.listContainerView) {
|
||
return NO;
|
||
}
|
||
|
||
// 2. 处理特定tag的视图手势冲突
|
||
if(otherGestureRecognizer.view.tag == 9000001){
|
||
return NO;
|
||
}
|
||
if(otherGestureRecognizer.view.tag == 9000002){
|
||
return NO;
|
||
}
|
||
if(otherGestureRecognizer.view.tag == 98777){
|
||
return NO;
|
||
}
|
||
|
||
// // 3. 处理RoomAnimationView的banner手势冲突
|
||
// // 检查otherGestureRecognizer是否来自RoomAnimationView的bannerContainer
|
||
// if ([otherGestureRecognizer.view isKindOfClass:[XPRoomAnimationHitView class]] &&
|
||
// [NSStringFromClass([otherGestureRecognizer.view class]) containsString:@"XPRoomAnimationHitView"]) {
|
||
// // 如果是bannerContainer的手势,允许同时识别,但优先级较低
|
||
// NSLog(@"🎯 JXPagerView与Banner手势冲突处理: 允许同时识别");
|
||
// return YES;
|
||
// }
|
||
|
||
// 4. 默认处理:只允许Pan手势同时识别
|
||
return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
|
||
}
|
||
#pragma mark - XPHomeContainerProtocol
|
||
- (void)getHomeTopDataSuccess:(NSArray*)list menuList:(NSArray *)memuList{
|
||
self.headView.bannerList = list;
|
||
self.bannerInfoList = list;
|
||
[self.pagingView reloadData];
|
||
[self.pagingView resizeTableHeaderViewHeightWithAnimatable:NO duration:0 curve:0];
|
||
}
|
||
|
||
- (void)getHomeTopDataSuccess:(NSArray *)resourceList
|
||
banners:(NSArray *)banners
|
||
rankAvatars:(NSArray *)rankAvatars {
|
||
self.headView.bannerList = banners;
|
||
self.headView.rankAvatars = rankAvatars;
|
||
[self.pagingView reloadData];
|
||
[self.pagingView resizeTableHeaderViewHeightWithAnimatable:NO duration:0 curve:0];
|
||
}
|
||
|
||
- (void)getHomeRanksSuccess:(NSArray *)resourceList
|
||
{
|
||
self.headView.rankAvatars = resourceList;
|
||
}
|
||
|
||
///获取所有的tag成功
|
||
- (void)getHomeTagListSuccess:(NSArray<PIHomeCategoryTitleModel *> *)array{
|
||
if(array.count == 0) {
|
||
[self getHomeTagListFailure];
|
||
return;
|
||
}
|
||
|
||
self.reloadTagsLimitCount = 0;
|
||
|
||
NSMutableArray *list = [NSMutableArray new];
|
||
NSMutableArray *titleArray = [NSMutableArray array];
|
||
for (PIHomeCategoryTitleModel *model in array) {
|
||
if (model.isHomeRecommend == YES){
|
||
[list insertObject:model atIndex:0];
|
||
[titleArray insertObject:model.name atIndex:0];
|
||
}else{
|
||
[list addObject:model];
|
||
[titleArray addObject:model.name];
|
||
}
|
||
}
|
||
self.tagModelList = list;
|
||
|
||
self.titleView.titles = titleArray;
|
||
[self.titleView reloadData];
|
||
|
||
[self createTagScrollView];
|
||
[self.categoryTagList setTabArray:list];
|
||
}
|
||
|
||
- (void)getHomeTagListFailure {
|
||
[self.pagingView.mainTableView.mj_header endRefreshing];
|
||
[self tryReloadTags];
|
||
}
|
||
|
||
- (void)tryReloadTags {
|
||
if (self.reloadTagsLimitCount >= self.maxReloadTagsLimitCount) {
|
||
return;
|
||
}
|
||
self.reloadTagsLimitCount += 1;
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||
[self.pagingView.mainTableView.mj_header beginRefreshing];
|
||
});
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||
[self.presenter getHomeTagList];
|
||
});
|
||
}
|
||
|
||
- (void)displayEmpatyDataView {
|
||
|
||
}
|
||
|
||
- (void)homeChatPickSuccess:(NSString *)uid {
|
||
/// 跳聊天
|
||
NSString *sessionId = uid;
|
||
NIMSession *session = [NIMSession session:sessionId type:NIMSessionTypeP2P];
|
||
SessionViewController *sessionVC = [[SessionViewController alloc] initWithSession:session];
|
||
[self.navigationController pushViewController:sessionVC animated:YES];
|
||
}
|
||
|
||
- (void)homeChatPickFail:(NSString *)msg {
|
||
|
||
}
|
||
|
||
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
|
||
self.type = index;
|
||
}
|
||
|
||
|
||
|
||
#pragma mark - XPNewHomeHeadViewDelegate
|
||
///
|
||
-(void)checkIpRegionSuccess:(NSInteger)seconds{
|
||
if(seconds <= 0)return;
|
||
[self performSelector:@selector(requestCheckIp) withObject:nil afterDelay:seconds];
|
||
}
|
||
- (void)checkIpRegionFailWithMsg:(NSString *)msg{
|
||
[self tokenInvalid];
|
||
[self showErrorToast:msg];
|
||
}
|
||
-(void)requestCheckIp{
|
||
if([AccountInfoStorage instance].getTicket.length > 0 &&
|
||
[AccountInfoStorage instance].name.length > 0){
|
||
[self.presenter checkIpRegionAction];
|
||
}
|
||
}
|
||
///选择
|
||
- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath {
|
||
switch (indexPath.row) {
|
||
case 0: {
|
||
// TODO: 通过 API 来获取最新的 排行榜 link
|
||
XPWebViewController * webVC =[[XPWebViewController alloc] initWithRoomUID:nil];
|
||
webVC.url = URLWithType(kRankV2);
|
||
[self.navigationController pushViewController:webVC animated:YES];
|
||
}
|
||
break;
|
||
case 1: {
|
||
EventCenterViewController *vc = [[EventCenterViewController alloc] init];
|
||
[self.navigationController pushViewController:vc animated:YES];
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
//-(void)selectItemWithModel:(PIHomeItemModel *)model{
|
||
// switch (model.resourceType) {
|
||
// case HomeMenuResourceType_H5: {
|
||
// XPWebViewController * webVC = [[ XPWebViewController alloc] initWithRoomUID:nil];
|
||
// webVC.url = model.resourceContent;
|
||
// [self.navigationController pushViewController:webVC animated:YES];
|
||
// }
|
||
// break;
|
||
// case HomeMenuResourceType_Match:
|
||
// [self.presenter homeChatPick];
|
||
// break;
|
||
// case HomeMenuResourceType_Room_Game: {
|
||
// @kWeakify(self);
|
||
// [Api homePickResource:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||
// @kStrongify(self);
|
||
// if (code == 200) {
|
||
// HomeMenuSourceModel * sourceModel = [HomeMenuSourceModel modelWithDictionary:data.data];
|
||
// if (sourceModel.isPick) {
|
||
// if (sourceModel.uid.integerValue > 0) {
|
||
// [XPRoomViewController openRoom:sourceModel.uid fromNick:nil fromType:UserEnterRoomFromType_Home_Recommend fromUid:nil viewController:self];
|
||
// }
|
||
// } else {
|
||
// XPHomeRecommendOtherRoomView * recommendView = [[XPHomeRecommendOtherRoomView alloc] init];
|
||
// recommendView.delegate = self;
|
||
// recommendView.roomInfo = sourceModel;
|
||
// [TTPopup popupView:recommendView style:TTPopupStyleAlert];
|
||
// }
|
||
// } else {
|
||
// [XNDJTDDLoadingTool showErrorWithMessage:msg];
|
||
// }
|
||
// } uid:uid rid:model.ID];
|
||
// }
|
||
// default:
|
||
// {
|
||
// EventCenterViewController *vc = [[EventCenterViewController alloc] init];
|
||
// [self.navigationController pushViewController:vc animated:YES];
|
||
// vc.officialEventModels = self.headView.bannerList;
|
||
// }
|
||
// break;
|
||
// }
|
||
//}
|
||
|
||
-(void)selectBannerListWithModel:(HomeBannerInfoModel *)model{
|
||
[self handleTapBannerItem:model];
|
||
}
|
||
///点击了进入房间
|
||
- (void)xPHomeRecommendOtherRoomView:(XPHomeRecommendOtherRoomView *)view didClickEnterRoom:(HomeMenuSourceModel *)model{
|
||
if (model.uid.integerValue > 0) {
|
||
[XPRoomViewController openRoom:model.uid fromNick:nil fromType:UserEnterRoomFromType_Home_Recommend fromUid:nil viewController:self];
|
||
}
|
||
}
|
||
|
||
#pragma mark -
|
||
- (void)handleTapBannerItem:(HomeBannerInfoModel *)model {
|
||
switch (model.skipType) {
|
||
case HomeBannerInfoSkipType_Room:{
|
||
if (model.skipUri.length > 0) {
|
||
[XPRoomViewController openRoom:model.skipUri viewController:self];
|
||
}
|
||
}
|
||
break;
|
||
case HomeBannerInfoSkipType_Web:
|
||
case HomeBannerInfoSkipType_Web_CP:
|
||
case HomeBannerInfoSkipType_Web_Custom:
|
||
case HomeBannerInfoSkipType_Web_WeekStar:
|
||
{
|
||
XPWebViewController *vc = [[XPWebViewController alloc] initWithRoomUID:nil];
|
||
vc.url = model.skipUri;
|
||
[self.navigationController pushViewController:vc animated:YES];
|
||
}
|
||
break;
|
||
case HomeBannerInfoSkipType_APP:
|
||
case HomeBannerInfoSkipType_None:
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
#pragma mark - Getters And Setters
|
||
- (JXCategoryTitleView *)titleView {
|
||
if (!_titleView) {
|
||
_titleView = [[JXCategoryTitleView alloc] initWithFrame:CGRectZero];
|
||
_titleView.delegate = self;
|
||
_titleView.titles = @[];
|
||
_titleView.backgroundColor = [UIColor clearColor];
|
||
_titleView.titleColor = UIColorFromRGB(0x767585);
|
||
_titleView.titleSelectedColor = UIColorFromRGB(0x1E1E1E);
|
||
_titleView.titleFont = kFontBold(14);
|
||
_titleView.titleSelectedFont = kFontBold(14);
|
||
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
|
||
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
|
||
_titleView.defaultSelectedIndex = 0;
|
||
|
||
_titleView.cellSpacing = kGetScaleWidth(20);
|
||
|
||
_titleView.listContainer = (id<JXCategoryViewListContainer>)self.pagingView.listContainerView;
|
||
}
|
||
return _titleView;
|
||
}
|
||
|
||
|
||
- (NSMutableArray<PIHomeCategoryTitleModel *> *)tagModelList{
|
||
if(!_tagModelList){
|
||
_tagModelList = [NSMutableArray array];
|
||
}
|
||
return _tagModelList;
|
||
}
|
||
- (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;
|
||
}
|
||
|
||
- (XPNewHomeHeadView *)headView{
|
||
if(!_headView){
|
||
_headView = [[XPNewHomeHeadView alloc]initWithFrame:CGRectZero];
|
||
_headView.delegate = self;
|
||
}
|
||
return _headView;
|
||
}
|
||
|
||
- (NSMutableDictionary *)validListDict{
|
||
if(!_validListDict){
|
||
_validListDict = [NSMutableDictionary dictionary];
|
||
}
|
||
return _validListDict;
|
||
}
|
||
|
||
- (HomeCategoryTabList *)categoryTagList {
|
||
if (!_categoryTagList) {
|
||
_categoryTagList = [[HomeCategoryTabList alloc] init];
|
||
@kWeakify(self);
|
||
[_categoryTagList setDidTapArrow:^{
|
||
@kStrongify(self);
|
||
[self showAllTags];
|
||
}];
|
||
[_categoryTagList setDidTapCategoryModel:^(PIHomeCategoryTitleModel *model) {
|
||
@kStrongify(self);
|
||
NSInteger index = [self.tagModelList indexOfObject:model];
|
||
[self.titleView selectItemAtIndex:index];
|
||
}];
|
||
}
|
||
return _categoryTagList;
|
||
}
|
||
@end
|