Files
peko-ios/YuMi/Modules/YMNewHome/Presenter/XPNewHomeRecommendPresenter.m

162 lines
6.1 KiB
Mathematica
Raw Normal View History

2023-07-14 18:50:55 +08:00
//
// 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"
2023-09-21 17:44:59 +08:00
#import "Api+LittleGame.h"
2023-07-14 18:50:55 +08:00
#import "AccountInfoStorage.h"
#import "HomeMenuInfoModel.h"
#import "HomeRecommendRoomModel.h"
#import "HomeBannerInfoModel.h"
#import "HomePlayRoomModel.h"
#import "XPNewHomeRecommendProtocol.h"
#import "ClanDetailInfoModel.h"
2023-09-21 17:44:59 +08:00
#import "LittleGameInfoModel.h"
2023-07-14 18:50:55 +08:00
@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];
}
2023-09-05 15:37:02 +08:00
///
-(void)getFriendListWithGroup:(dispatch_group_t)group{
2023-09-27 23:28:00 +08:00
if([AccountInfoStorage instance].getUid.length == 0)return;
2023-09-05 15:37:02 +08:00
[Api requsetFriendListComplection:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
2023-09-27 23:28:59 +08:00
if([AccountInfoStorage instance].getUid.length == 0)return;
2023-09-05 15:37:02 +08:00
NSArray * array = [HomePlayRoomModel modelsWithArray:data.data];
[[self getView]getFriendListSuccess:array withGroup:group];
} fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView]getFriendListFailWithGroup:group];
}]];
}
2023-09-21 17:44:59 +08:00
///
- (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]];
}
2023-07-14 18:50:55 +08:00
@end