Files
peko-ios/YuMi/Modules/YMNewHome/Presenter/XPNewHomeRecommendPresenter.m
2023-09-28 14:08:01 +08:00

162 lines
6.1 KiB
Objective-C

//
// XPNewHomeRecommendPresenter.m
// YuMi
//
// Created by YuMi on 2023/6/18.
//
#import "XPNewHomeRecommendPresenter.h"
#import <ReactiveObjC/ReactiveObjC.h>
#import "Api+Home.h"
#import "Api+Guild.h"
#import "Api+LittleGame.h"
#import "AccountInfoStorage.h"
#import "HomeMenuInfoModel.h"
#import "HomeRecommendRoomModel.h"
#import "HomeBannerInfoModel.h"
#import "HomePlayRoomModel.h"
#import "XPNewHomeRecommendProtocol.h"
#import "ClanDetailInfoModel.h"
#import "LittleGameInfoModel.h"
@implementation XPNewHomeRecommendPresenter
/// 获取首页顶部的轮播图
- (void)getHomeTopBannerListWithGroup:(dispatch_group_t)group {
RACSubject* banner = [RACSubject subject];
RACSubject* menu = [RACSubject subject];
[[RACSignal combineLatest:@[banner, menu] reduce:^id(NSArray* bannerList, NSArray* menuList){
//在这里 进行请求后的方法,回到主线程
dispatch_async(dispatch_get_main_queue(), ^{
//更新UI操作
[[self getView] getHomeTopBannerListSuccess:bannerList menuList:menuList withGroup:group];
});
return nil;
}] subscribeError:^(NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
//更新UI操作
[[self getView] getHomeRecommendDataFailWithGroup:group];
});
}];
NSString * uid = [AccountInfoStorage instance].getUid;
[Api homeBannerList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [HomeBannerInfoModel modelsWithArray:data.data];
[banner sendNext:array];
[banner sendCompleted];
}fail:^(NSInteger code, NSString * _Nullable msg) {
[banner sendError:nil];
[banner sendCompleted];
} errorToast:NO] uid:uid type:@"1"];
[Api homeMenuList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [HomeMenuInfoModel modelsWithArray:data.data];
[menu sendNext:array];
[menu sendCompleted];
} fail:^(NSInteger code, NSString * _Nullable msg) {
[menu sendError:nil];
[menu sendCompleted];
}errorToast:NO] uid:uid];
}
/// 获取首页推荐列表
- (void)getHomeRecommendRoomListWithGroup:(dispatch_group_t)group {
NSString * uid = [AccountInfoStorage instance].getUid;
[Api homeRecommendRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray<HomeRecommendRoomModel *> * array = [HomeRecommendRoomModel modelsWithArray:data.data];
if (array.count > 1) {
///排列顺序 1 - 6 0
NSArray * newArray = [array sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
HomeRecommendRoomModel * model1 = obj1;
HomeRecommendRoomModel * model2 = obj2;
return [model1.seq compare:model2.seq];
}];
if (newArray.count > 0) {
NSMutableArray * array = [NSMutableArray arrayWithArray:newArray];
NSMutableArray * temAray = [NSMutableArray array];
[newArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
HomeRecommendRoomModel * model = obj;
if (model.seq.intValue == 0) {
[temAray addObject:model];
[array removeObject:model];
}
}];
if (temAray.count > 0) {
[array addObjectsFromArray:temAray];
}
newArray = array.copy;
}
array = newArray;
}
[[self getView] getHomeRecommendRoomListSuccess:array withGroup:group];
}fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getHomeRecommendDataFailWithGroup:group];
}errorToast:NO] uid:uid];
}
/// 获取首页热门房间列表
- (void)getHomeHotRoomListWithGroup:(dispatch_group_t)group {
[Api homeHotRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [HomeRecommendRoomModel modelsWithArray:data.data];
[[self getView] getHomeHotRoomListSuccess:array withGroup:group];
}fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getHomeRecommendDataFailWithGroup:group];
}]];
}
/// 组队开黑房间列表
/// @param pageNum 当前的页数
- (void)getPlayGameWithTeam:(int)pageNum withGroup:(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];
[[self getView] getPlayGameWithTeamSuccess:array withGroup:group];
}fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getHomeRecommendDataFailWithGroup:group];
}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{
if([AccountInfoStorage instance].getUid.length == 0)return;
[Api requsetFriendListComplection:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
if([AccountInfoStorage instance].getUid.length == 0)return;
NSArray * array = [HomePlayRoomModel modelsWithArray:data.data];
[[self getView]getFriendListSuccess:array withGroup:group];
} fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView]getFriendListFailWithGroup:group];
}]];
}
///获取小游戏列表
- (void)getLittleGameListWithGroup:(dispatch_group_t)group {
NSString * uid = [[AccountInfoStorage instance] getUid];
if (!uid.length) {
[[self getView] getHomeRecommendDataFailWithGroup:group];
return;
}
[Api getLittleGameList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [LittleGameInfoModel modelsWithArray:data.data];
[[self getView] onGetLittleGameListSuccess:array withGroup:group];
}fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getHomeRecommendDataFailWithGroup:group];
}errorToast:NO]];
}
@end