首页请求优化
This commit is contained in:
@@ -6,25 +6,27 @@
|
||||
//
|
||||
|
||||
#import "BaseMvpPresenter.h"
|
||||
|
||||
typedef void(^CompleteHandle)(BOOL isSuccess,NSArray *playGameList, NSArray *friendList);
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@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 当前的页数
|
||||
- (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
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -18,9 +18,14 @@
|
||||
#import "XPNewHomeRecommendProtocol.h"
|
||||
#import "ClanDetailInfoModel.h"
|
||||
#import "LittleGameInfoModel.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@implementation XPNewHomeRecommendPresenter
|
||||
/// 获取首页顶部的轮播图
|
||||
- (void)getHomeTopBannerListWithGroup:(dispatch_group_t)group {
|
||||
- (void)getHomeTopBannerList {
|
||||
RACSubject* banner = [RACSubject subject];
|
||||
RACSubject* menu = [RACSubject subject];
|
||||
|
||||
@@ -29,7 +34,7 @@
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
//更新UI操作
|
||||
[[self getView] getHomeTopBannerListSuccess:bannerList menuList:menuList withGroup:group];
|
||||
[[self getView] getHomeTopBannerListSuccess:bannerList menuList:menuList];
|
||||
});
|
||||
|
||||
return nil;
|
||||
@@ -37,7 +42,7 @@
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
//更新UI操作
|
||||
[[self getView] getHomeRecommendDataFailWithGroup:group];
|
||||
[[self getView] getHomeRecommendDataFail];
|
||||
});
|
||||
|
||||
}];
|
||||
@@ -62,7 +67,7 @@
|
||||
}errorToast:NO] uid:uid];
|
||||
}
|
||||
/// 获取首页推荐列表
|
||||
- (void)getHomeRecommendRoomListWithGroup:(dispatch_group_t)group {
|
||||
- (void)getHomeRecommendRoomList {
|
||||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||||
[Api homeRecommendRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||||
NSArray<HomeRecommendRoomModel *> * array = [HomeRecommendRoomModel modelsWithArray:data.data];
|
||||
@@ -91,73 +96,107 @@
|
||||
array = newArray;
|
||||
}
|
||||
|
||||
[[self getView] getHomeRecommendRoomListSuccess:array withGroup:group];
|
||||
[[self getView] getHomeRecommendRoomListSuccess:array];
|
||||
|
||||
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
[[self getView] getHomeRecommendDataFailWithGroup:group];
|
||||
[[self getView] getHomeRecommendDataFail];
|
||||
}errorToast:NO] uid:uid];
|
||||
}
|
||||
|
||||
/// 获取首页热门房间列表
|
||||
- (void)getHomeHotRoomListWithGroup:(dispatch_group_t)group {
|
||||
- (void)getHomeHotRoomList {
|
||||
[Api homeHotRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||||
NSArray * array = [HomeRecommendRoomModel modelsWithArray:data.data];
|
||||
[[self getView] getHomeHotRoomListSuccess:array withGroup:group];
|
||||
[[self getView] getHomeHotRoomListSuccess:array];
|
||||
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
[[self getView] getHomeRecommendDataFailWithGroup:group];
|
||||
[[self getView] getHomeRecommendDataFail];
|
||||
}]];
|
||||
}
|
||||
|
||||
|
||||
/// 组队开黑房间列表
|
||||
/// @param pageNum 当前的页数
|
||||
- (void)getPlayGameWithTeam:(int)pageNum withGroup:(dispatch_group_t)group{
|
||||
- (void)getPlayGameWithTeam:(int)pageNum{
|
||||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||||
NSString * pageNumStr = [NSString stringWithFormat:@"%d", pageNum];
|
||||
[Api homePlayGameTeam:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||||
NSArray * array = [HomePlayRoomModel modelsWithArray:data.data];
|
||||
[[self getView] getPlayGameWithTeamSuccess:array withGroup:group];
|
||||
[[self getView] getPlayGameWithTeamSuccess:array];
|
||||
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
[[self getView] getHomeRecommendDataFailWithGroup:group];
|
||||
[[self getView] getHomeRecommendDataFail];
|
||||
}errorToast:NO] uid:uid pageNum:pageNumStr pageSize:@"20"];
|
||||
}
|
||||
|
||||
|
||||
/// 热门房间(个人房)列表
|
||||
- (void)getHomePersonalRoomListWithGroup:(dispatch_group_t)group {
|
||||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||||
[Api homePersonalRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||||
NSArray * array = [HomePlayRoomModel modelsWithArray:data.data];
|
||||
[[self getView] getHomePersonalRoomListSuccess:array withGroup:group];
|
||||
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
[[self getView] getHomeRecommendDataFailWithGroup:group];
|
||||
}errorToast:NO] uid:uid];
|
||||
}
|
||||
///发现新朋友
|
||||
-(void)getFriendListWithGroup:(dispatch_group_t)group{
|
||||
-(void)getHomeListDataWith:(int)pageNum completeHandle:(CompleteHandle)completeHandle{
|
||||
RACSubject* playGame = [RACSubject subject];
|
||||
RACSubject* friend = [RACSubject subject];
|
||||
[[RACSignal combineLatest:@[playGame, friend] reduce:^id(NSArray *playGameList, NSArray *friendList){
|
||||
if(completeHandle){
|
||||
completeHandle(YES,playGameList,friendList);
|
||||
}
|
||||
return nil;
|
||||
}] subscribeError:^(NSError * _Nullable error) {
|
||||
if(completeHandle){
|
||||
completeHandle(NO,@[],@[]);
|
||||
}
|
||||
}];
|
||||
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){
|
||||
[[self getView]getFriendListFailWithGroup:group];
|
||||
[friend sendError:nil];
|
||||
return;
|
||||
}
|
||||
[Api requsetFriendListComplection:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||||
NSArray * array = [HomePlayRoomModel modelsWithArray:data.data];
|
||||
[[self getView]getFriendListSuccess:array withGroup:group];
|
||||
[friend sendNext:array];
|
||||
[friend sendCompleted];
|
||||
} 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];
|
||||
if (!uid.length) {
|
||||
[[self getView] getHomeRecommendDataFailWithGroup:group];
|
||||
[[self getView] getHomeRecommendDataFail];
|
||||
return;
|
||||
}
|
||||
[Api getLittleGameList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||||
NSArray * array = [LittleGameInfoModel modelsWithArray:data.data];
|
||||
[[self getView] onGetLittleGameListSuccess:array withGroup:group];
|
||||
[[self getView] onGetLittleGameListSuccess:array];
|
||||
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
[[self getView] getHomeRecommendDataFailWithGroup:group];
|
||||
[[self getView] getHomeRecommendDataFail];
|
||||
}errorToast:NO]];
|
||||
}
|
||||
@end
|
||||
|
@@ -12,23 +12,23 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@protocol XPNewHomeRecommendProtocol <NSObject>
|
||||
@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
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -106,54 +106,39 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
|
||||
#pragma mark - InitHttp
|
||||
|
||||
-(void)requestData{
|
||||
///正在播放声音,不能刷新数据
|
||||
if(self.pi_playAudioCell != nil){
|
||||
if(self.refreshComplete){
|
||||
self.refreshComplete();
|
||||
}
|
||||
return;
|
||||
}///正在播放声音,不能刷新数据
|
||||
///加锁,防止测试发现偶尔会出现闪退bug
|
||||
@synchronized (self.presenter) {
|
||||
if(self.isRequestData == YES){
|
||||
if(self.refreshComplete){
|
||||
self.refreshComplete();
|
||||
}
|
||||
return;
|
||||
}
|
||||
self.isRequestData = YES;
|
||||
///网络请求异步加载
|
||||
dispatch_group_t group =dispatch_group_create();
|
||||
// 并行队列
|
||||
dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
|
||||
|
||||
|
||||
dispatch_group_enter(group);
|
||||
dispatch_group_async(group, 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(), ^{
|
||||
///正在请求数据,不用重新请求
|
||||
if(self.isRequestData == YES){
|
||||
if(self.refreshComplete){
|
||||
self.refreshComplete();
|
||||
}
|
||||
return;
|
||||
}
|
||||
self.isRequestData = YES;
|
||||
[self.presenter getHomeListDataWith:1 completeHandle:^(BOOL isSuccess, NSArray *playGameList, NSArray *friendList) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.isRequestData = NO;
|
||||
if(playGameList.count > 0){
|
||||
self.playTeamList = [NSMutableArray arrayWithArray:playGameList];
|
||||
}
|
||||
if(friendList.count > 0){
|
||||
[self getFriendList:friendList];
|
||||
}
|
||||
if(self.refreshComplete){
|
||||
self.refreshComplete();
|
||||
}
|
||||
if(self.pi_playAudioCell == nil){///播放音频时不能刷新数据
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
- (void)headerRefresh {
|
||||
self.isRequestData = NO;
|
||||
@@ -399,16 +384,8 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
|
||||
|
||||
|
||||
|
||||
///扩列交友
|
||||
- (void)getPlayGameWithTeamSuccess:(NSArray *)list withGroup:(nonnull dispatch_group_t)group{
|
||||
|
||||
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{
|
||||
|
||||
- (void)getFriendList:(NSArray *)list{
|
||||
|
||||
for (int i = 0;i < list.count;i++) {
|
||||
HomePlayRoomModel *model = list[i];
|
||||
@@ -425,7 +402,7 @@ UIKIT_EXTERN NSString * const kShieldingNotification;
|
||||
model.labelsWidthList = widthList;
|
||||
}
|
||||
self.personalRoomList = [NSMutableArray arrayWithArray:list];
|
||||
dispatch_group_leave(group);
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - JXPagingViewListViewDelegate
|
||||
|
@@ -42,7 +42,7 @@
|
||||
|
||||
#else
|
||||
|
||||
return API_HOST_URL
|
||||
return API_HOST_URL;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user