首页tag优化
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user