首页请求优化
This commit is contained in:
@@ -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
|
||||||
|
@@ -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
|
||||||
|
@@ -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
|
||||||
|
@@ -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
|
||||||
|
@@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
return API_HOST_URL
|
return API_HOST_URL;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user