Files
yinmeng-ios/xplan-ios/Main/Home/Presenter/XPHomePresenter.m
2023-03-16 14:34:53 +08:00

93 lines
3.6 KiB
Objective-C

//
// XPHomePresenter.m
// xplan-ios
//
// Created by 冯硕 on 2021/11/29.
//
#import "XPHomePresenter.h"
#import "Api+Home.h"
#import "AccountInfoStorage.h"
///Model
#import "HomeRecommendRoomModel.h"
#import "UserInfoModel.h"
///P
#import "XPHomeProtocol.h"
@implementation XPHomePresenter
/// 请求首页
/// @param tabId id
/// @param page 当前的页数
/// @param pageSize 一页有多少个
- (void)getRecommendRoomList:(NSString *)tabId page:(int)page pageSize:(int)pageSize state:(BOOL)state {
NSString * uid = [AccountInfoStorage instance].getUid;
NSString * pageStr = [NSString stringWithFormat:@"%d", page];
NSString * pageSizeStr = [NSString stringWithFormat:@"%d", pageSize];
[Api getRecommendListComplection:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [HomeRecommendRoomModel modelsWithArray:data.data];
[[self getView] getHomeRecommendRoomListSuccess:array state:state];
}fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getHomeRecommendRoomListFail:msg state:state];
}] uid:uid tabId:tabId pageNum:pageStr pageSize:pageSizeStr];
}
/// 获取更多的个播房间
- (void)getHomeMoreAnchorRoomList {
[Api homeAnchorMoreRoomList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [HomeRecommendRoomModel modelsWithArray:data.data];
[[self getView] getHomeMoreAnchorRoomListSuccess:array];
}fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getHomeMoreAnchorRoomListFail:msg];
}] singleRoomSortId:@""];
}
/// 获取派对推荐列表
- (void)getPartyRecommendRoomList {
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] getPartyRecommendRoomListSuccess:array];
}fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getPartyRecommendDataFail];
}] uid:uid];
}
/// 发现新朋友
- (void)getNewFriendListWithGender:(nullable NSString *)gender {
[Api getNewFriendListcomplection:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
NSArray * array = [UserInfoModel modelsWithArray:data.data];
[[self getView] getNewFriendListSuccess:array];
}fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] getNewFriendListFail];
}] gender:gender];
}
@end