首页tag优化

This commit is contained in:
liyuhua
2024-02-22 15:58:48 +08:00
parent 06b39c2671
commit 5f0d52451c
26 changed files with 482 additions and 216 deletions

View File

@@ -0,0 +1,25 @@
//
// PIHoemCategoryCollectionView.h
// YuMi
//
// Created by duoban on 2024/2/21.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@protocol PIHoemCategoryCollectionViewDelegate <NSObject>
-(void)didSelectItemAtIndex:(NSInteger)index;
@end
@interface PIHoemCategoryCollectionView : UIView
@property(nonatomic,strong) NSMutableArray *titleList;
@property(nonatomic,assign) NSInteger index;
@property(nonatomic,weak) id<PIHoemCategoryCollectionViewDelegate>delegate;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,104 @@
//
// PIHoemCategoryCollectionView.m
// YuMi
//
// Created by duoban on 2024/2/21.
//
#import "PIHoemCategoryCollectionView.h"
#import "PIHomeCategoryTitleModel.h"
#import "PIHoemCategoryTitleCell.h"
@interface PIHoemCategoryCollectionView()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong) UICollectionView *pi_collectionView;
@end
@implementation PIHoemCategoryCollectionView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
}
return self;
}
-(void)installUI{
[self addSubview:self.pi_collectionView];
}
-(void)installConstraints{
[self.pi_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
}
-(void)setTitleList:(NSMutableArray *)titleList{
_titleList = titleList;
[self.pi_collectionView reloadData];
}
#pragma mark- UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.titleList.count;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
PIHomeCategoryTitleModel *model = [self.titleList safeObjectAtIndex1:indexPath.row];
CGFloat width = model.isChecked ? model.checkedWidth : model.noCheckedWidth;
return CGSizeMake(width + kGetScaleWidth(10), kGetScaleWidth(44));
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
PIHoemCategoryTitleCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([PIHoemCategoryTitleCell class]) forIndexPath:indexPath];
PIHomeCategoryTitleModel *model = [self.titleList safeObjectAtIndex1:indexPath.row];
cell.tagModel = model;
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
for (PIHomeCategoryTitleModel *model in self.titleList) {
model.isChecked = NO;
}
PIHomeCategoryTitleModel *selectModel = [self.titleList safeObjectAtIndex1:indexPath.row];
selectModel.isChecked = YES;
[self.pi_collectionView reloadData];
if(self.delegate && [self.delegate respondsToSelector:@selector(didSelectItemAtIndex:)]){
[self.delegate didSelectItemAtIndex:indexPath.row];
}
// int i = [selectModel.id isEqualToString:@"-1"] ? 0 : 1;
// if(self.scrolledHandle){
// self.scrolledHandle(i);
// }
}
- (void)setIndex:(NSInteger)index{
_index = index;
for (int i = 0; i < self.titleList.count; i++) {
PIHomeCategoryTitleModel *model = [self.titleList safeObjectAtIndex1:i];
model.isChecked = NO;
}
PIHomeCategoryTitleModel *curModel = [self.titleList safeObjectAtIndex1:_index];
curModel.isChecked = YES;
[self.pi_collectionView reloadData];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.pi_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
});
}
#pragma mark -
- (UICollectionView *)pi_collectionView{
if (!_pi_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = kGetScaleWidth(10);
layout.minimumInteritemSpacing = kGetScaleWidth(10);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.sectionInset = UIEdgeInsetsMake(0, kGetScaleWidth(10), 0, kGetScaleWidth(10));
_pi_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_pi_collectionView.dataSource = self;
_pi_collectionView.delegate = self;
_pi_collectionView.tag = 98777;
_pi_collectionView.showsVerticalScrollIndicator = NO;
_pi_collectionView.showsHorizontalScrollIndicator = NO;
_pi_collectionView.backgroundColor = [UIColor clearColor];
[_pi_collectionView registerClass:[PIHoemCategoryTitleCell class] forCellWithReuseIdentifier:NSStringFromClass([PIHoemCategoryTitleCell class])];
}
return _pi_collectionView;
}
@end

View File

@@ -0,0 +1,18 @@
//
// PIHoemCategoryTitleCell.h
// YuMi
//
// Created by duoban on 2024/2/21.
//
#import <UIKit/UIKit.h>
#import "PIHomeCategoryTitleModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface PIHoemCategoryTitleCell : UICollectionViewCell
@property(nonatomic,strong) PIHomeCategoryTitleModel *tagModel;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,67 @@
//
// PIHoemCategoryTitleCell.m
// YuMi
//
// Created by duoban on 2024/2/21.
//
#import "PIHoemCategoryTitleCell.h"
@interface PIHoemCategoryTitleCell()
@property(nonatomic,strong) UIButton *titleView;
@property(nonatomic,strong) UIImageView *lineVeiw;
@end
@implementation PIHoemCategoryTitleCell
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
}
return self;
}
-(void)installUI{
[self.contentView addSubview:self.lineVeiw];
[self.contentView addSubview:self.titleView];
}
-(void)installConstraints{
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.centerY.trailing.equalTo(self.contentView);
make.height.mas_equalTo(kGetScaleWidth(22));
}];
[self.lineVeiw mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(36));
make.height.mas_equalTo(kGetScaleWidth(8));
make.bottom.equalTo(self.titleView.mas_bottom).mas_offset(-kGetScaleWidth(4));
make.trailing.equalTo(self.titleView.mas_trailing).mas_offset(-kGetScaleWidth(5));
}];
}
-(void)setTagModel:(PIHomeCategoryTitleModel *)tagModel{
_tagModel = tagModel;
[_titleView setTitle:_tagModel.name forState:UIControlStateNormal];
_titleView.selected = _tagModel.isChecked;
_titleView.titleLabel.font = _tagModel.isChecked ? kFontSemibold(16):kFontRegular(14);
_lineVeiw.hidden = !_tagModel.isChecked;
}
#pragma mark -
- (UIImageView *)lineVeiw{
if(!_lineVeiw){
_lineVeiw = [UIImageView new];
_lineVeiw.image = kImage(@"home_slider_bg");
}
return _lineVeiw;
}
- (UIButton *)titleView{
if(!_titleView){
_titleView = [UIButton new];
[_titleView setTitle:YMLocalizedString(@"XPNewHomeViewController1") forState:UIControlStateNormal];
[_titleView setTitleColor:UIColorFromRGB(0x1F1B4F) forState:UIControlStateSelected];
[_titleView setTitleColor:UIColorFromRGB(0x767585) forState:UIControlStateNormal];
_titleView.titleLabel.font = kFontRegular(14);
_titleView.userInteractionEnabled = NO;
}
return _titleView;
}
@end

View File

@@ -15,6 +15,7 @@ typedef void(^ScrolledHandle)(NSInteger type);
@interface PIHoemCategoryTitleView : JXCategoryTitleView
@property(nonatomic,assign) NSInteger index;
@property(nonatomic,copy) ScrolledHandle scrolledHandle;
@property(nonatomic,strong) NSMutableArray *titleList;
@end
NS_ASSUME_NONNULL_END

View File

@@ -6,10 +6,11 @@
//
#import "PIHoemCategoryTitleView.h"
@interface PIHoemCategoryTitleView()
@property(nonatomic,strong) UIButton *fristBnt;
@property(nonatomic,strong) UIButton *secondBnt;
@property(nonatomic,strong) UIImageView *lineImage;
#import "PIHoemCategoryTitleCell.h"
#import "PIHoemCategoryCollectionView.h"
@interface PIHoemCategoryTitleView()<PIHoemCategoryCollectionViewDelegate>
@property(nonatomic,strong) PIHoemCategoryCollectionView *pi_collectionView;
@end
@implementation PIHoemCategoryTitleView
-(instancetype)initWithFrame:(CGRect)frame{
@@ -21,122 +22,40 @@
return self;
}
-(void)installUI{
UIButton *b = [UIButton new];
[self addSubview:b];
[b mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self addSubview:self.lineImage];
[self addSubview:self.fristBnt];
[self addSubview:self.secondBnt];
[self addSubview:self.pi_collectionView];
}
-(void)installConstraints{
[self.fristBnt mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(15));
make.centerY.equalTo(self);
make.height.mas_equalTo(kGetScaleWidth(22));
}];
[self.secondBnt mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(self.fristBnt.mas_trailing).mas_offset(kGetScaleWidth(24));
make.centerY.equalTo(self);
make.height.mas_equalTo(kGetScaleWidth(22));
}];
[self.lineImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(36));
make.height.mas_equalTo(kGetScaleWidth(8));
make.bottom.equalTo(self.fristBnt.mas_bottom).mas_offset(-kGetScaleWidth(4));
make.trailing.equalTo(self.fristBnt.mas_trailing);
[self.pi_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
}
-(void)chooseItem:(UIButton *)sender{
self.fristBnt.titleLabel.font = sender == self.fristBnt ? kFontSemibold(16):kFontRegular(14);
self.secondBnt.titleLabel.font = sender != self.fristBnt ? kFontSemibold(16):kFontRegular(14);
self.fristBnt.selected = sender == self.fristBnt;
self.secondBnt.selected = sender != self.fristBnt;
if(self.fristBnt == sender){
if(self.scrolledHandle){
self.scrolledHandle(0);
}
[self.lineImage mas_remakeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(36));
make.height.mas_equalTo(kGetScaleWidth(8));
make.bottom.equalTo(self.fristBnt.mas_bottom).mas_offset(-kGetScaleWidth(4));
make.trailing.equalTo(self.fristBnt.mas_trailing);
}];
return;
}
if(self.scrolledHandle){
self.scrolledHandle(1);
}
[self.lineImage mas_remakeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(36));
make.height.mas_equalTo(kGetScaleWidth(8));
make.bottom.equalTo(self.secondBnt.mas_bottom).mas_offset(-kGetScaleWidth(4));
make.trailing.equalTo(self.secondBnt.mas_trailing);
}];
-(void)setTitleList:(NSMutableArray *)titleList{
_titleList = titleList;
self.pi_collectionView.titleList = titleList;
}
- (void)setIndex:(NSInteger)index{
_index = index;
self.fristBnt.titleLabel.font = _index == 0 ? kFontSemibold(16):kFontRegular(14);
self.secondBnt.titleLabel.font = _index == 1 ? kFontSemibold(16):kFontRegular(14);
self.fristBnt.selected = _index == 0;
self.secondBnt.selected = _index == 1;
if(_index == 0){
[self.lineImage mas_remakeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(36));
make.height.mas_equalTo(kGetScaleWidth(8));
make.bottom.equalTo(self.fristBnt.mas_bottom).mas_offset(-kGetScaleWidth(4));
make.trailing.equalTo(self.fristBnt.mas_trailing);
}];
return;
self.pi_collectionView.index = _index;
}
#pragma mark - PIHoemCategoryCollectionViewDelegate
- (void)didSelectItemAtIndex:(NSInteger)index{
if(self.scrolledHandle){
self.scrolledHandle(index);
}
[self.lineImage mas_remakeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(36));
make.height.mas_equalTo(kGetScaleWidth(8));
make.bottom.equalTo(self.secondBnt.mas_bottom).mas_offset(-kGetScaleWidth(4));
make.trailing.equalTo(self.secondBnt.mas_trailing);
}];
}
#pragma mark -
- (UIButton *)fristBnt{
if(!_fristBnt){
_fristBnt = [UIButton new];
[_fristBnt setTitle:YMLocalizedString(@"XPNewHomeViewController0") forState:UIControlStateNormal];
[_fristBnt setTitleColor:UIColorFromRGB(0x1F1B4F) forState:UIControlStateSelected];
[_fristBnt setTitleColor:UIColorFromRGB(0x767585) forState:UIControlStateNormal];
_fristBnt.selected = YES;
_fristBnt.titleLabel.font = kFontSemibold(16);
[_fristBnt addTarget:self action:@selector(chooseItem:) forControlEvents:UIControlEventTouchUpInside];
[_fristBnt setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
}
return _fristBnt;
}
- (PIHoemCategoryCollectionView *)pi_collectionView{
if (!_pi_collectionView) {
_pi_collectionView = [[PIHoemCategoryCollectionView alloc] initWithFrame:CGRectZero ];
_pi_collectionView.delegate = self;
- (UIButton *)secondBnt{
if(!_secondBnt){
_secondBnt = [UIButton new];
[_secondBnt setTitle:YMLocalizedString(@"XPNewHomeViewController1") forState:UIControlStateNormal];
[_secondBnt setTitleColor:UIColorFromRGB(0x1F1B4F) forState:UIControlStateSelected];
[_secondBnt setTitleColor:UIColorFromRGB(0x767585) forState:UIControlStateNormal];
_secondBnt.titleLabel.font = kFontRegular(14);
[_secondBnt addTarget:self action:@selector(chooseItem:) forControlEvents:UIControlEventTouchUpInside];
[_secondBnt setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
}
return _secondBnt;
}
- (UIImageView *)lineImage{
if(!_lineImage){
_lineImage = [UIImageView new];
_lineImage.image = kImage(@"home_slider_bg");
}
return _lineImage;
return _pi_collectionView;
}
//- (void)layoutSubviews{
// [super layoutSubviews];
@@ -145,7 +64,7 @@
// //JXCategoryView
//
// CGRect targetFrame = CGRectMake(0, 0, self.bounds.size.width - kGetScaleWidth(159), floor(self.bounds.size.height));
// self.collectionView.frame = targetFrame;
// self.pi_collectionView.frame = targetFrame;
//
//
//}

View File

@@ -7,6 +7,7 @@
#import "MvpViewController.h"
#import <JXPagingView/JXPagerView.h>
#import "PIHomeCategoryTitleModel.h"
NS_ASSUME_NONNULL_BEGIN
@@ -14,13 +15,12 @@ NS_ASSUME_NONNULL_BEGIN
@interface XPHomePartyViewController : MvpViewController<JXPagerViewListViewDelegate>
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
///模块的 ID
@property (nonatomic,copy) NSString *pi_tabId;
///是否是个播
@property (nonatomic,assign) BOOL isAnchor;
@property(nonatomic,copy) HeaderRefreshComplete refreshComplete;
- (void)headerRefresh;
@property(nonatomic,strong) PIHomeCategoryTitleModel *tagModel;
@end
NS_ASSUME_NONNULL_END

View File

@@ -54,6 +54,7 @@
}
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor clearColor];
@@ -64,6 +65,11 @@
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(fooderRefresh)];
footer.stateLabel.textColor = [DJDKMIMOMColor secondTextColor];
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
self.collectionView.mj_footer = footer;
}
@@ -71,12 +77,23 @@
#pragma mark - fangfa
- (void)headerRefresh {
[self.presenter getHomePersonalRoomList];
if([self.tagModel.id isEqualToString:@"-1"]){
[self.presenter getHomePersonalRoomList];
}else{
self.page = 1;
[self.presenter getRecommendRoomList:self.tagModel.id page:self.page pageSize:20];
}
}
-(void)fooderRefresh{
if([self.tagModel.id isEqualToString:@"-1"]){
[self.collectionView.mj_footer endRefreshing];
}else{
self.page++;
[self.presenter getRecommendRoomList:self.tagModel.id page:self.page pageSize:20];
}
}
#pragma mark - UICollectionViewDelegate And UICollectionViewDataSource
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
@@ -116,9 +133,7 @@
#pragma mark - XPHomeProtocol
- (void)getHomePersonalRoomListSuccess:(NSArray *)list{
if(self.refreshComplete){
self.refreshComplete();
}
[[NSNotificationCenter defaultCenter]postNotificationName:@"khomeVCRefreshComplete" object:nil];
for (HomePlayRoomModel *model in list) {
model.width = [UILabel getWidthWithText:@(model.onlineNum).stringValue height:kGetScaleWidth(12) font:kFontBold(10)]+1;
}
@@ -126,11 +141,27 @@
[self.collectionView reloadData];
}
- (void)getHomePersonalRoomListFail{
if(self.refreshComplete){
self.refreshComplete();
}
[[NSNotificationCenter defaultCenter]postNotificationName:@"khomeVCRefreshComplete" object:nil];
}
- (void)getHomeRecommendRoomListSuccess:(NSArray *)list{
[self.collectionView.mj_footer endRefreshing];
for (HomePlayRoomModel *model in list) {
model.width = [UILabel getWidthWithText:@(model.onlineNum).stringValue height:kGetScaleWidth(12) font:kFontBold(10)]+1;
}
if(self.page == 1){
self.datasource = [NSMutableArray arrayWithArray:list];
}else{
[self.datasource addObjectsFromArray:list];
}
[self.collectionView reloadData];
[[NSNotificationCenter defaultCenter]postNotificationName:@"khomeVCRefreshComplete" object:nil];
}
- (void)getHomeRecommendRoomListFail:(NSString *)message{
[self.collectionView.mj_footer endRefreshing];
[[NSNotificationCenter defaultCenter]postNotificationName:@"khomeVCRefreshComplete" object:nil];
}
#pragma mark - JXPagingViewListViewDelegate
- (UIScrollView *)listScrollView {
return self.collectionView;
@@ -152,16 +183,8 @@
#pragma mark - Getters And Setters
- (void)setIsAnchor:(BOOL)isAnchor {
_isAnchor = isAnchor;
if (_isAnchor) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self headerRefresh];
});
}
}
- (void)setPi_tabId:(NSString *)pi_tabId{
_pi_tabId = pi_tabId;
-(void)setTagModel:(PIHomeCategoryTitleModel *)tagModel{
_tagModel = tagModel;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self headerRefresh];
});
@@ -169,6 +192,7 @@
- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
@@ -179,6 +203,7 @@
_collectionView.backgroundColor = [UIColor clearColor];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.tag = 78574;
[_collectionView registerClass:[XPNewHomePartyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPNewHomePartyCollectionViewCell class])];
[_collectionView registerClass:[XPGuildEmptyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGuildEmptyCollectionViewCell class])];
}

View File

@@ -7,6 +7,7 @@
#import "MvpViewController.h"
#import <JXPagingView/JXPagerView.h>
#import "PIHomeCategoryTitleModel.h"
NS_ASSUME_NONNULL_BEGIN
@protocol XPHomeRecommendViewControllerDelegate <NSObject>
@@ -19,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
@property(nonatomic,weak) id<XPHomeRecommendViewControllerDelegate>delegate;
@property(nonatomic,copy) HeaderRefreshComplete refreshComplete;
@property(nonatomic,strong) PIHomeCategoryTitleModel *tagModel;
- (void)headerRefresh;
@end

View File

@@ -51,7 +51,7 @@
#import "XPLoginViewController.h"
#import "BaseNavigationController.h"
#import "XPAdImageTool.h"
#import "PIHomeCategoryTitleModel.h"
UIKIT_EXTERN NSString * kHomeMoreScrollPageKey;
UIKIT_EXTERN NSString * const kOpenRoomNotification;
@@ -66,20 +66,19 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
///
@property(nonatomic,strong) XPNewHomeHeadView *headView;
///
@property (nonatomic, strong) NSArray<NSString *> *titles;
@property (nonatomic, strong) NSMutableArray<PIHomeCategoryTitleModel *> *tagModelList;
///
@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;
@property(nonatomic,strong) XPHomePartyViewController * homeVC;
@property(nonatomic,strong) XPHomeRecommendViewController * recommendVC;
@property(nonatomic,assign) NSInteger type;
@property(nonatomic,assign) BOOL isCheckIp;
@property(nonatomic,assign) NSInteger type;
@property(nonatomic,strong) NSMutableDictionary *validListDict;
@end
@implementation XPNewHomeViewController
@@ -106,6 +105,7 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
- (void)viewDidLoad {
[super viewDidLoad];
if(self.isEmpty == NO){
[self.presenter getHomeTagList];
[self initHttp];
[self initSubViews];
[self initSubViewConstraints];
@@ -148,8 +148,10 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
@kWeakify(self);
timer = [XPWeakTimer scheduledTimerWithTimeInterval:15 block:^(id userInfo) {
@kStrongify(self);
[self.homeVC headerRefresh];
[self.recommendVC headerRefresh];
PIHomeCategoryTitleModel *tagModel = [self.tagModelList safeObjectAtIndex1:self.type];
XPHomePartyViewController *homeVC = [self.validListDict objectForKey:[NSNumber numberWithInteger:self.type]];
homeVC.tagModel = tagModel;
[self.recommendVC headerRefresh];
} userInfo:nil repeats:YES];
}
- (void)initSubViews {
@@ -181,45 +183,52 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
header.stateLabel.textColor = [DJDKMIMOMColor secondTextColor];
header.lastUpdatedTimeLabel.textColor = [DJDKMIMOMColor secondTextColor];
self.pagingView.mainTableView.mj_header = header;
[self.pagingView.mainTableView.mj_header beginRefreshing];
@kWeakify(self);
self.homeVC.refreshComplete = ^{
@kStrongify(self);
if(self.type == 0){
[self.pagingView.mainTableView.mj_header endRefreshing];
}
};
self.recommendVC.refreshComplete = ^{
@kStrongify(self);
if(self.type == 1){
[self.pagingView.mainTableView.mj_header endRefreshing];
}
};
self.titleView.scrolledHandle = ^(NSInteger type) {
@kStrongify(self);
[self.titleView.listContainer didClickSelectedItemAtIndex:type];
[UIView animateWithDuration:0.3 animations:^{
self.pagingView.listContainerView.scrollView.contentOffset = CGPointMake(type * KScreenWidth, 0);
} ];
self.pagingView.listContainerView.scrollView.contentOffset = CGPointMake(type * KScreenWidth, 0);
self.type = type;
};
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(homeVCRefreshComplete) name:@"khomeVCRefreshComplete" object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(logOut) name:@"kInLoginVC" object:nil];
}
-(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 initHttp];
if(self.type == 0){
[self.homeVC headerRefresh];
}else{
if(self.titleView.index == self.tagModelList.count - 1){
[self.recommendVC headerRefresh];
}else{
PIHomeCategoryTitleModel *tagModel = [self.tagModelList safeObjectAtIndex1:self.type];
XPHomePartyViewController *homeVC = [self.validListDict objectForKey:[NSNumber numberWithInteger:self.type]];
homeVC.tagModel = tagModel;
}
}
-(void)openRoomNotification:(NSNotification *)notification{
if([[AccountInfoStorage instance] getUid].length == 0){
return;
@@ -266,6 +275,7 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
}
- (void)initHttp {
[self.presenter getHomeTopBannerList];
[self.presenter getCurrentResourceList];
[self requestCheckIp];
@@ -341,22 +351,25 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
}
- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
return self.titles.count;
return self.tagModelList.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) {
return self.homeVC;
} else {
if (index == self.tagModelList.count - 1) {
self.recommendVC.tagModel = [self.tagModelList safeObjectAtIndex1:index];
return self.recommendVC;
} else {
id homeV = [self.validListDict objectForKey:[NSNumber numberWithInteger:index]];
if (homeV) {
return homeV;
}
XPHomePartyViewController *homeVC = [[XPHomePartyViewController alloc] init];
homeVC.tagModel = [self.tagModelList safeObjectAtIndex1:index];
[self.validListDict setObject:homeVC forKey:@(index)];
return homeVC;
}
}
@@ -379,6 +392,10 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
if(otherGestureRecognizer.view.tag == 9000002){
return NO;
}
if(otherGestureRecognizer.view.tag == 98777){
return NO;
}
return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
}
@@ -391,7 +408,21 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
- (void)getCurrentResourceListSuccess:(NSArray *)list{
self.headView.itemList = list;
}
///tag
- (void)getHomeTagListSuccess:(NSArray<PIHomeCategoryTitleModel *> *)array{
if(array.count == 0)return;
NSMutableArray *list = [NSMutableArray arrayWithArray:array];
[list addObject:self.tagModelList.lastObject];
[list insertObject:self.tagModelList.firstObject atIndex:0];
self.tagModelList = list;
self.titleView.titleList = self.tagModelList;
NSMutableArray *titleArray = [NSMutableArray array];
for (PIHomeCategoryTitleModel *model in self.tagModelList) {
[titleArray addObject:model.name];
}
self.titleView.titles = titleArray;
[self.titleView reloadData];
}
- (void)homeChatPickSuccess:(NSString *)uid {
///
NSString *sessionId = uid;
@@ -405,8 +436,9 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
}
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index{
self.type = index;
self.titleView.index = index;
self.type = index;
}
@@ -489,7 +521,8 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
if (!_titleView) {
_titleView = [[PIHoemCategoryTitleView alloc] initWithFrame:CGRectZero];
_titleView.delegate = self;
_titleView.titles = self.titles;
_titleView.titles = @[YMLocalizedString(@"XPNewHomeViewController0"),YMLocalizedString(@"XPNewHomeViewController1")];
_titleView.titleList = self.tagModelList;
_titleView.backgroundColor = [UIColor clearColor];
_titleView.titleColor = [UIColor clearColor];
_titleView.titleSelectedColor = [UIColor clearColor];
@@ -512,11 +545,26 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
}
return _titleView;
}
- (NSArray<NSString *> *)titles{
if(!_titles){
_titles = @[YMLocalizedString(@"XPNewHomeViewController0"),YMLocalizedString(@"XPNewHomeViewController1")];
- (NSMutableArray<PIHomeCategoryTitleModel *> *)tagModelList{
if(!_tagModelList){
_tagModelList = [NSMutableArray array];
PIHomeCategoryTitleModel *recommendModel = [PIHomeCategoryTitleModel new];
recommendModel.id = @"-1";
recommendModel.name = YMLocalizedString(@"XPNewHomeViewController0");
recommendModel.checkedWidth = [UILabel getWidthWithText:recommendModel.name height:kGetScaleWidth(44) font:kFontSemibold(16)];
recommendModel.noCheckedWidth = [UILabel getWidthWithText:recommendModel.name height:kGetScaleWidth(44) font:kFontRegular(14)];
recommendModel.isChecked = YES;
PIHomeCategoryTitleModel *hotModel = [PIHomeCategoryTitleModel new];
hotModel.id = @"-2";
hotModel.name = YMLocalizedString(@"XPNewHomeViewController1");
hotModel.checkedWidth = [UILabel getWidthWithText:recommendModel.name height:kGetScaleWidth(44) font:kFontSemibold(16)];
hotModel.noCheckedWidth = [UILabel getWidthWithText:recommendModel.name height:kGetScaleWidth(44) font:kFontRegular(14)];
[_tagModelList addObject:recommendModel];
[_tagModelList addObject:hotModel];
}
return _titles;
return _tagModelList;
}
- (JXPagerView *)pagingView {
if (!_pagingView) {
@@ -537,12 +585,7 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
return _recommendItem;
}
- (NSMutableArray<HomeTagModel *> *)tagList {
if (!_tagList) {
_tagList = [NSMutableArray array];
}
return _tagList;
}
- (XPNewHomeNavView *)navView {
if (!_navView) {
@@ -568,12 +611,7 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
}
return _headView;
}
- (XPHomePartyViewController *)homeVC{
if(!_homeVC){
_homeVC = [[XPHomePartyViewController alloc] init];
}
return _homeVC;
}
- (XPHomeRecommendViewController *)recommendVC{
if(!_recommendVC){
_recommendVC = [[XPHomeRecommendViewController alloc] init];
@@ -581,4 +619,10 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
}
return _recommendVC;
}
- (NSMutableDictionary *)validListDict{
if(!_validListDict){
_validListDict = [NSMutableDictionary dictionary];
}
return _validListDict;
}
@end