309 lines
10 KiB
Objective-C
309 lines
10 KiB
Objective-C
//
|
|
// XPNewHomeViewController.m
|
|
// YuMi
|
|
//
|
|
// Created by YuMi on 2023/6/18.
|
|
//
|
|
|
|
#import "XPNewHomeViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <JXCategoryView/JXCategoryView.h>
|
|
#import <JXCategoryView/JXCategoryIndicatorBackgroundView.h>
|
|
#import <JXCategoryView/JXCategoryListContainerView.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"
|
|
|
|
///View
|
|
#import "XPRoomSearchContainerViewController.h"
|
|
#import "XPHomePartyViewController.h"
|
|
#import "XPWebViewController.h"
|
|
#import "XPHomeRecommendViewController.h"
|
|
#import "XPNewHomeNavView.h"
|
|
#import "XPRoomViewController.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 ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate, XPHomeContainerProtocol, XPNewHomeNavViewDelegate>
|
|
@property (nonatomic,strong) UIImageView *backImageView;
|
|
@property (nonatomic,strong) XPNewHomeNavView *navView;
|
|
///分页标题
|
|
@property (nonatomic, strong) NSArray<NSString *> *titles;
|
|
///分页控件
|
|
@property (nonatomic, strong) JXCategoryTitleView *titleView;
|
|
///分页lineView
|
|
@property (nonatomic, strong) JXCategoryListContainerView *contentView;
|
|
///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.titleView];
|
|
[self.view addSubview:self.contentView];
|
|
[[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];
|
|
[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];
|
|
[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.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.navView.mas_bottom).offset(10);
|
|
make.left.right.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(30);
|
|
}];
|
|
|
|
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.titleView.mas_bottom);
|
|
make.left.right.bottom.mas_equalTo(self.view);
|
|
}];
|
|
|
|
}
|
|
|
|
- (void)initHttp {
|
|
[self.presenter getHomeTagList];
|
|
}
|
|
|
|
|
|
#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{
|
|
[XPRoomViewController openRoom:roomUid viewController:self];
|
|
}
|
|
|
|
- (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 - JXCategoryListContentViewDelegate
|
|
- (UIView *)listView {
|
|
return self.view;
|
|
}
|
|
|
|
#pragma mark - XPHomeContainerProtocol
|
|
- (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];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (JXCategoryTitleView *)titleView {
|
|
if (!_titleView) {
|
|
_titleView = [[JXCategoryTitleView alloc] init];
|
|
_titleView.delegate = self;
|
|
_titleView.titles = self.titles;
|
|
_titleView.backgroundColor = [UIColor clearColor];
|
|
_titleView.titleColor = [DJDKMIMOMColor secondTextColor];
|
|
_titleView.titleSelectedColor = [UIColor whiteColor];
|
|
_titleView.titleFont = [UIFont systemFontOfSize:14];
|
|
_titleView.titleSelectedFont = [UIFont systemFontOfSize:14];
|
|
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
|
|
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
|
|
_titleView.defaultSelectedIndex = 0;
|
|
_titleView.cellSpacing = 20;
|
|
_titleView.cellWidthIncrement = 5;
|
|
_titleView.listContainer = self.contentView;
|
|
|
|
JXCategoryIndicatorImageView * indocator = [[JXCategoryIndicatorImageView alloc] init];
|
|
indocator.indicatorImageView.image = [UIImage imageNamed:@"home_slider_bg"];
|
|
indocator.indicatorImageViewSize = CGSizeMake(50, 24);
|
|
indocator.verticalMargin = 4;
|
|
indocator.contentMode = UIViewContentModeScaleAspectFit;
|
|
_titleView.indicators = @[indocator];
|
|
}
|
|
return _titleView;
|
|
}
|
|
|
|
- (JXCategoryListContainerView *)contentView {
|
|
if (!_contentView) {
|
|
_contentView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
|
|
_contentView.defaultSelectedIndex = 0;
|
|
}
|
|
return _contentView;
|
|
}
|
|
|
|
- (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;
|
|
}
|
|
|
|
@end
|