首页请求优化

This commit is contained in:
liyuhua
2023-11-09 16:20:40 +08:00
parent 92844a9619
commit 0161a860af
5 changed files with 113 additions and 95 deletions

View File

@@ -6,25 +6,27 @@
// //
#import "BaseMvpPresenter.h" #import "BaseMvpPresenter.h"
typedef void(^CompleteHandle)(BOOL isSuccess,NSArray *playGameList, NSArray *friendList);
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface XPNewHomeRecommendPresenter : BaseMvpPresenter @interface XPNewHomeRecommendPresenter : BaseMvpPresenter
/// 获取首页顶部的轮播图 /// 获取首页顶部的轮播图
- (void)getHomeTopBannerListWithGroup:(dispatch_group_t)group; - (void)getHomeTopBannerList;
/// 获取首页推荐列表 /// 获取首页推荐列表
- (void)getHomeRecommendRoomListWithGroup:(dispatch_group_t)group; - (void)getHomeRecommendRoomList;
/// 获取首页热门房间列表 /// 获取首页热门房间列表
- (void)getHomeHotRoomListWithGroup:(dispatch_group_t)group; - (void)getHomeHotRoomList;
/// 热门房间(个人房)列表 /// 热门房间(个人房)列表
- (void)getHomePersonalRoomListWithGroup:(dispatch_group_t)group; - (void)getHomePersonalRoomList;
/// 组队开黑房间列表 /// 组队开黑房间列表
/// @param pageNum 当前的页数 /// @param pageNum 当前的页数
- (void)getPlayGameWithTeam:(int)pageNum withGroup:(dispatch_group_t)group; - (void)getPlayGameWithTeam:(int)pageNum;
///发现新朋友 ///发现新朋友
-(void)getFriendListWithGroup:(dispatch_group_t)group; -(void)getFriendList;
///获取小游戏列表 ///获取小游戏列表
- (void)getLittleGameListWithGroup:(dispatch_group_t)group; - (void)getLittleGameList;
///获取首页数据
-(void)getHomeListDataWith:(int)pageNum completeHandle:(CompleteHandle)completeHandle;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@@ -18,9 +18,14 @@
#import "XPNewHomeRecommendProtocol.h" #import "XPNewHomeRecommendProtocol.h"
#import "ClanDetailInfoModel.h" #import "ClanDetailInfoModel.h"
#import "LittleGameInfoModel.h" #import "LittleGameInfoModel.h"
@implementation XPNewHomeRecommendPresenter @implementation XPNewHomeRecommendPresenter
/// ///
- (void)getHomeTopBannerListWithGroup:(dispatch_group_t)group { - (void)getHomeTopBannerList {
RACSubject* banner = [RACSubject subject]; RACSubject* banner = [RACSubject subject];
RACSubject* menu = [RACSubject subject]; RACSubject* menu = [RACSubject subject];
@@ -29,7 +34,7 @@
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
//UI //UI
[[self getView] getHomeTopBannerListSuccess:bannerList menuList:menuList withGroup:group]; [[self getView] getHomeTopBannerListSuccess:bannerList menuList:menuList];
}); });
return nil; return nil;
@@ -37,7 +42,7 @@
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
//UI //UI
[[self getView] getHomeRecommendDataFailWithGroup:group]; [[self getView] getHomeRecommendDataFail];
}); });
}]; }];
@@ -62,7 +67,7 @@
}errorToast:NO] uid:uid]; }errorToast:NO] uid:uid];
} }
/// ///
- (void)getHomeRecommendRoomListWithGroup:(dispatch_group_t)group { - (void)getHomeRecommendRoomList {
NSString * uid = [AccountInfoStorage instance].getUid; NSString * uid = [AccountInfoStorage instance].getUid;
[Api homeRecommendRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) { [Api homeRecommendRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray<HomeRecommendRoomModel *> * array = [HomeRecommendRoomModel modelsWithArray:data.data]; NSArray<HomeRecommendRoomModel *> * array = [HomeRecommendRoomModel modelsWithArray:data.data];
@@ -91,73 +96,107 @@
array = newArray; array = newArray;
} }
[[self getView] getHomeRecommendRoomListSuccess:array withGroup:group]; [[self getView] getHomeRecommendRoomListSuccess:array];
}fail:^(NSInteger code, NSString * _Nullable msg) { }fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getHomeRecommendDataFailWithGroup:group]; [[self getView] getHomeRecommendDataFail];
}errorToast:NO] uid:uid]; }errorToast:NO] uid:uid];
} }
/// ///
- (void)getHomeHotRoomListWithGroup:(dispatch_group_t)group { - (void)getHomeHotRoomList {
[Api homeHotRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) { [Api homeHotRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [HomeRecommendRoomModel modelsWithArray:data.data]; NSArray * array = [HomeRecommendRoomModel modelsWithArray:data.data];
[[self getView] getHomeHotRoomListSuccess:array withGroup:group]; [[self getView] getHomeHotRoomListSuccess:array];
}fail:^(NSInteger code, NSString * _Nullable msg) { }fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getHomeRecommendDataFailWithGroup:group]; [[self getView] getHomeRecommendDataFail];
}]]; }]];
} }
/// ///
/// @param pageNum /// @param pageNum
- (void)getPlayGameWithTeam:(int)pageNum withGroup:(dispatch_group_t)group{ - (void)getPlayGameWithTeam:(int)pageNum{
NSString * uid = [AccountInfoStorage instance].getUid; NSString * uid = [AccountInfoStorage instance].getUid;
NSString * pageNumStr = [NSString stringWithFormat:@"%d", pageNum]; NSString * pageNumStr = [NSString stringWithFormat:@"%d", pageNum];
[Api homePlayGameTeam:[self createHttpCompletion:^(BaseModel * _Nonnull data) { [Api homePlayGameTeam:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [HomePlayRoomModel modelsWithArray:data.data]; NSArray * array = [HomePlayRoomModel modelsWithArray:data.data];
[[self getView] getPlayGameWithTeamSuccess:array withGroup:group]; [[self getView] getPlayGameWithTeamSuccess:array];
}fail:^(NSInteger code, NSString * _Nullable msg) { }fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getHomeRecommendDataFailWithGroup:group]; [[self getView] getHomeRecommendDataFail];
}errorToast:NO] uid:uid pageNum:pageNumStr pageSize:@"20"]; }errorToast:NO] uid:uid pageNum:pageNumStr pageSize:@"20"];
} }
-(void)getHomeListDataWith:(int)pageNum completeHandle:(CompleteHandle)completeHandle{
/// RACSubject* playGame = [RACSubject subject];
- (void)getHomePersonalRoomListWithGroup:(dispatch_group_t)group { RACSubject* friend = [RACSubject subject];
NSString * uid = [AccountInfoStorage instance].getUid; [[RACSignal combineLatest:@[playGame, friend] reduce:^id(NSArray *playGameList, NSArray *friendList){
[Api homePersonalRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) { if(completeHandle){
NSArray * array = [HomePlayRoomModel modelsWithArray:data.data]; completeHandle(YES,playGameList,friendList);
[[self getView] getHomePersonalRoomListSuccess:array withGroup:group]; }
}fail:^(NSInteger code, NSString * _Nullable msg) { return nil;
[[self getView] getHomeRecommendDataFailWithGroup:group]; }] subscribeError:^(NSError * _Nullable error) {
}errorToast:NO] uid:uid]; if(completeHandle){
} completeHandle(NO,@[],@[]);
/// }
-(void)getFriendListWithGroup:(dispatch_group_t)group{ }];
NSString * uid = [AccountInfoStorage instance].getUid;
NSString * pageNumStr = [NSString stringWithFormat:@"%d", pageNum];
[Api homePlayGameTeam:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [HomePlayRoomModel modelsWithArray:data.data];
[playGame sendNext:array];
[playGame sendCompleted];
}fail:^(NSInteger code, NSString * _Nullable msg) {
[playGame sendError:nil];
}errorToast:NO] uid:uid pageNum:pageNumStr pageSize:@"20"];
if([AccountInfoStorage instance].getUid.length == 0){ if([AccountInfoStorage instance].getUid.length == 0){
[[self getView]getFriendListFailWithGroup:group]; [friend sendError:nil];
return; return;
} }
[Api requsetFriendListComplection:[self createHttpCompletion:^(BaseModel * _Nonnull data) { [Api requsetFriendListComplection:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [HomePlayRoomModel modelsWithArray:data.data]; NSArray * array = [HomePlayRoomModel modelsWithArray:data.data];
[[self getView]getFriendListSuccess:array withGroup:group]; [friend sendNext:array];
[friend sendCompleted];
} fail:^(NSInteger code, NSString * _Nullable msg) { } fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView]getFriendListFailWithGroup:group]; [friend sendError:nil];
}]];
}
///
- (void)getHomePersonalRoomList {
NSString * uid = [AccountInfoStorage instance].getUid;
[Api homePersonalRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [HomePlayRoomModel modelsWithArray:data.data];
[[self getView] getHomePersonalRoomListSuccess:array ];
}fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getHomeRecommendDataFail];
}errorToast:NO] uid:uid];
}
///
-(void)getFriendList{
if([AccountInfoStorage instance].getUid.length == 0){
[[self getView]getFriendListFail];
return;
}
[Api requsetFriendListComplection:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [HomePlayRoomModel modelsWithArray:data.data];
[[self getView]getFriendListSuccess:array ];
} fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView]getFriendListFail];
}]]; }]];
} }
/// ///
- (void)getLittleGameListWithGroup:(dispatch_group_t)group { - (void)getLittleGameList {
NSString * uid = [[AccountInfoStorage instance] getUid]; NSString * uid = [[AccountInfoStorage instance] getUid];
if (!uid.length) { if (!uid.length) {
[[self getView] getHomeRecommendDataFailWithGroup:group]; [[self getView] getHomeRecommendDataFail];
return; return;
} }
[Api getLittleGameList:[self createHttpCompletion:^(BaseModel * _Nonnull data) { [Api getLittleGameList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [LittleGameInfoModel modelsWithArray:data.data]; NSArray * array = [LittleGameInfoModel modelsWithArray:data.data];
[[self getView] onGetLittleGameListSuccess:array withGroup:group]; [[self getView] onGetLittleGameListSuccess:array];
}fail:^(NSInteger code, NSString * _Nullable msg) { }fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getHomeRecommendDataFailWithGroup:group]; [[self getView] getHomeRecommendDataFail];
}errorToast:NO]]; }errorToast:NO]];
} }
@end @end

View File

@@ -12,23 +12,23 @@ NS_ASSUME_NONNULL_BEGIN
@protocol XPNewHomeRecommendProtocol <NSObject> @protocol XPNewHomeRecommendProtocol <NSObject>
@optional @optional
///获取首页轮播图列表成功 ///获取首页轮播图列表成功
- (void)getHomeTopBannerListSuccess:(NSArray*)list menuList:(NSArray *)memuList withGroup:(dispatch_group_t)group; - (void)getHomeTopBannerListSuccess:(NSArray*)list menuList:(NSArray *)memuList;
///获取首页推荐列表成功 ///获取首页推荐列表成功
- (void)getHomeRecommendRoomListSuccess:(NSArray *)list withGroup:(dispatch_group_t)group; - (void)getHomeRecommendRoomListSuccess:(NSArray *)list;
///获取首页热门房列表成功 ///获取首页热门房列表成功
- (void)getHomeHotRoomListSuccess:(NSArray *)list withGroup:(dispatch_group_t)group; - (void)getHomeHotRoomListSuccess:(NSArray *)list;
///获取个人房列表成功 ///获取个人房列表成功
- (void)getHomePersonalRoomListSuccess:(NSArray *)list withGroup:(dispatch_group_t)group; - (void)getHomePersonalRoomListSuccess:(NSArray *)list;
///获取组队开黑房间列表成功 ///获取组队开黑房间列表成功
- (void)getPlayGameWithTeamSuccess:(NSArray *)list withGroup:(dispatch_group_t)group; - (void)getPlayGameWithTeamSuccess:(NSArray *)list;
///获取首页数据失败 ///获取首页数据失败
- (void)getHomeRecommendDataFailWithGroup:(dispatch_group_t)group; - (void)getHomeRecommendDataFail;
///发现新朋友 ///发现新朋友
-(void)getFriendListSuccess:(NSArray *)list withGroup:(dispatch_group_t)group; -(void)getFriendListSuccess:(NSArray *)list;
///发现新朋友 ///发现新朋友
-(void)getFriendListFailWithGroup:(dispatch_group_t)group; -(void)getFriendListFail;
///获取小游戏列表 ///获取小游戏列表
- (void)onGetLittleGameListSuccess:(NSArray<LittleGameInfoModel *> *)items withGroup:(dispatch_group_t)group; - (void)onGetLittleGameListSuccess:(NSArray<LittleGameInfoModel *> *)items;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@@ -106,54 +106,39 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
#pragma mark - InitHttp #pragma mark - InitHttp
-(void)requestData{ -(void)requestData{
///
if(self.pi_playAudioCell != nil){ if(self.pi_playAudioCell != nil){
if(self.refreshComplete){ if(self.refreshComplete){
self.refreshComplete(); self.refreshComplete();
} }
return; return;
}///
///退bug
@synchronized (self.presenter) {
if(self.isRequestData == YES){
if(self.refreshComplete){
self.refreshComplete();
}
return;
} }
self.isRequestData = YES; ///
/// if(self.isRequestData == YES){
dispatch_group_t group =dispatch_group_create(); if(self.refreshComplete){
// self.refreshComplete();
dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0); }
return;
}
dispatch_group_enter(group); self.isRequestData = YES;
dispatch_group_async(group, queue, ^{ [self.presenter getHomeListDataWith:1 completeHandle:^(BOOL isSuccess, NSArray *playGameList, NSArray *friendList) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.presenter getPlayGameWithTeam:1 withGroup:group];
});
dispatch_group_enter(group);
dispatch_group_async(group, queue, ^{
[self.presenter getFriendListWithGroup:group];
});
dispatch_group_notify(group,dispatch_get_main_queue(), ^{
self.isRequestData = NO; self.isRequestData = NO;
if(playGameList.count > 0){
self.playTeamList = [NSMutableArray arrayWithArray:playGameList];
}
if(friendList.count > 0){
[self getFriendList:friendList];
}
if(self.refreshComplete){ if(self.refreshComplete){
self.refreshComplete(); self.refreshComplete();
} }
if(self.pi_playAudioCell == nil){/// if(self.pi_playAudioCell == nil){///
[self.tableView reloadData]; [self.tableView reloadData];
} }
}); });
}];
}
} }
- (void)headerRefresh { - (void)headerRefresh {
self.isRequestData = NO; self.isRequestData = NO;
@@ -399,16 +384,8 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
///
- (void)getPlayGameWithTeamSuccess:(NSArray *)list withGroup:(nonnull dispatch_group_t)group{ - (void)getFriendList:(NSArray *)list{
self.playTeamList = [NSMutableArray arrayWithArray:list];
dispatch_group_leave(group);
}
- (void)getHomeRecommendDataFailWithGroup:(dispatch_group_t)group{
dispatch_group_leave(group);
}
- (void)getFriendListSuccess:(NSArray *)list withGroup:(dispatch_group_t)group{
for (int i = 0;i < list.count;i++) { for (int i = 0;i < list.count;i++) {
HomePlayRoomModel *model = list[i]; HomePlayRoomModel *model = list[i];
@@ -425,7 +402,7 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
model.labelsWidthList = widthList; model.labelsWidthList = widthList;
} }
self.personalRoomList = [NSMutableArray arrayWithArray:list]; self.personalRoomList = [NSMutableArray arrayWithArray:list];
dispatch_group_leave(group);
} }
#pragma mark - JXPagingViewListViewDelegate #pragma mark - JXPagingViewListViewDelegate

View File

@@ -42,7 +42,7 @@
#else #else
return API_HOST_URL return API_HOST_URL;
#endif #endif
} }