Commit 0d5eb2b5 by suolong

修改api 修复bug

parent 70447a07
Showing with 172 additions and 102 deletions
#import <UIKit/UIKit.h>
@class FUSLiveGiftDataModel;
@class FUSLiveGiftInteractOptionModel;
NS_ASSUME_NONNULL_BEGIN
@interface FUSLiveGiftInteractAddPopView : UIView
@property (nonatomic, copy) void (^saveHandler)(NSString *desc, FUSLiveGiftDataModel *gift, NSInteger count);
/// 可选择的礼物列表
@property (nonatomic, copy) NSArray<FUSLiveGiftInteractOptionModel *> *giftList;
/// 保存回调
@property (nonatomic, copy) void (^saveHandler)(NSString *desc, FUSLiveGiftInteractOptionModel *gift, NSInteger count);
/// 消失回调
@property (nonatomic, copy, nullable) void (^dismissHandler)(void);
/// 请求礼物列表数据回调(外部获取后给 giftList 赋值并调用 fus_presentGiftPicker)
@property (nonatomic, copy, nullable) void (^requestGiftListHandler)(void);
- (void)show;
- (void)showInView:(UIView *)view;
- (void)dismiss;
/// 外部获取数据并赋值 giftList 后,调用此方法展示下拉框
- (void)fus_presentGiftPicker;
@end
NS_ASSUME_NONNULL_END
#import "FUSLiveGiftInteractAddPopView.h"
#import "FUSGiftDataCenter.h"
#import "FUSDialogView.h"
#import "FUSLiveGiftDataModel.h"
#import "FUSLiveGiftInteractOptionModel.h"
#import "FUSLiveGiftInteractGiftDropdownView.h"
#import "FUSTextField.h"
#import "UIViewController+FUSExpand.h"
......@@ -35,8 +34,7 @@
@property (nonatomic, strong) UIButton *cancelBtn;
@property (nonatomic, strong) UIButton *saveBtn;
@property (nonatomic, strong) FUSLiveGiftDataModel *selectedGift;
@property (nonatomic, copy) NSArray<FUSLiveGiftDataModel *> *giftList;
@property (nonatomic, strong) FUSLiveGiftInteractOptionModel *selectedGift;
@end
......@@ -242,9 +240,9 @@
FUSLiveGiftInteractGiftDropdownView *dropdown = [[FUSLiveGiftInteractGiftDropdownView alloc] initWithFrame:CGRectZero];
dropdown.hidden = YES;
__weak typeof(self) weakSelf = self;
dropdown.selectHandler = ^(FUSLiveGiftDataModel *gift) {
dropdown.selectHandler = ^(FUSLiveGiftInteractOptionModel *gift) {
weakSelf.selectedGift = gift;
NSString *name = gift.name.length ? gift.name : [NSString fus_localString:@"礼物"];
NSString *name = gift.giftName.length ? gift.giftName : [NSString fus_localString:@"礼物"];
weakSelf.giftLabel.textColor = [UIColor colorWithHex:@"#22222B"];
weakSelf.giftLabel.text = name;
[weakSelf fus_hideGiftDropdown];
......@@ -351,31 +349,9 @@
return;
}
[FUSDialogView fus_showDialog:[NSString fus_localString:@"正在加载礼物..."]];
__weak typeof(self) weakSelf = self;
[[FUSGiftDataCenter sharedCenter] fus_fetchLiveGiftDataWithType:ReadMemoryBegin success:^(NSArray<FUSLiveGiftDataModel *> *liveGiftArr, NSArray<FUSLiveGiftCategoryDataModel *> *liveGiftCategoryArr) {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.giftList = liveGiftArr ?: @[];
if (weakSelf.giftList.count == 0) {
[[FUSGiftDataCenter sharedCenter] fus_fetchLiveGiftDataWithType:ReadServerBegin success:^(NSArray<FUSLiveGiftDataModel *> *liveGiftArr2, NSArray<FUSLiveGiftCategoryDataModel *> *liveGiftCategoryArr2) {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.giftList = liveGiftArr2 ?: @[];
[weakSelf fus_presentGiftPicker];
});
} failure:^(NSString *msg, int code) {
dispatch_async(dispatch_get_main_queue(), ^{
[FUSDialogView fus_showDialog:(msg.length ? msg : [NSString fus_localString:@"礼物加载失败"])];
});
}];
return;
}
[weakSelf fus_presentGiftPicker];
});
} failure:^(NSString *msg, int code) {
dispatch_async(dispatch_get_main_queue(), ^{
[FUSDialogView fus_showDialog:(msg.length ? msg : [NSString fus_localString:@"礼物加载失败"])];
});
}];
if (self.requestGiftListHandler) {
self.requestGiftListHandler();
}
}
- (void)fus_presentGiftPicker {
......@@ -434,55 +410,12 @@
self.giftArrowView.image = [FUSShowRoomCenterBunble imageNamed:imgName];
}
- (void)fus_updateCountOptionsForGift:(FUSLiveGiftDataModel *)gift {
NSArray *batchs = gift.batchs;
if (![batchs isKindOfClass:[NSArray class]] || batchs.count == 0) {
self.countOptions = @[@(1)];
[self fus_applyCountIndex:0];
return;
}
NSMutableArray<NSNumber *> *numbers = [NSMutableArray arrayWithCapacity:batchs.count];
for (id obj in batchs) {
NSInteger value = 0;
if ([obj respondsToSelector:@selector(integerValue)]) {
value = [obj integerValue];
}
if (value > 0 && value != INT_MAX) {
[numbers addObject:@(value)];
}
}
if (numbers.count == 0) {
self.countOptions = @[@(1)];
[self fus_applyCountIndex:0];
return;
- (void)fus_updateCountOptionsForGift:(FUSLiveGiftInteractOptionModel *)gift {
if (gift.giftNumList.count > 0) {
self.countOptions = gift.giftNumList;
} else {
self.countOptions = @[@1, @10, @66, @99, @188, @520, @1314, @3344, @5200];
}
NSArray<NSNumber *> *sorted = [numbers sortedArrayUsingComparator:^NSComparisonResult(NSNumber * _Nonnull obj1, NSNumber * _Nonnull obj2) {
if (obj1.integerValue < obj2.integerValue) {
return NSOrderedAscending;
} else if (obj1.integerValue > obj2.integerValue) {
return NSOrderedDescending;
}
return NSOrderedSame;
}];
NSMutableArray<NSNumber *> *unique = [NSMutableArray array];
NSNumber *last = nil;
for (NSNumber *n in sorted) {
if (!last || n.integerValue != last.integerValue) {
[unique addObject:n];
last = n;
}
}
if (unique.count == 0) {
self.countOptions = @[@(1)];
[self fus_applyCountIndex:0];
return;
}
self.countOptions = [unique copy];
[self fus_applyCountIndex:0];
}
......
#import <UIKit/UIKit.h>
@class FUSLiveGiftDataModel;
@class FUSLiveGiftInteractOptionModel;
NS_ASSUME_NONNULL_BEGIN
@interface FUSLiveGiftInteractGiftDropdownView : UIView
@property (nonatomic, copy) NSArray<FUSLiveGiftDataModel *> *giftList;
@property (nonatomic, strong, nullable) FUSLiveGiftDataModel *selectedGift;
@property (nonatomic, copy, nullable) void (^selectHandler)(FUSLiveGiftDataModel *gift);
@property (nonatomic, copy) NSArray<FUSLiveGiftInteractOptionModel *> *giftList;
@property (nonatomic, strong, nullable) FUSLiveGiftInteractOptionModel *selectedGift;
@property (nonatomic, copy, nullable) void (^selectHandler)(FUSLiveGiftInteractOptionModel *gift);
- (CGFloat)fus_preferredHeightWithMaxHeight:(CGFloat)maxHeight;
- (void)fus_reload;
......
#import "FUSLiveGiftInteractGiftDropdownView.h"
#import "FUSLiveGiftDataModel.h"
#import "FUSLiveGiftInteractOptionModel.h"
#import "FUSLiveGiftInteractGiftDropdownCell.h"
@interface FUSLiveGiftInteractGiftDropdownView () <UITableViewDataSource, UITableViewDelegate>
......@@ -62,8 +62,8 @@
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FUSLiveGiftInteractGiftDropdownCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FUSLiveGiftInteractGiftDropdownCell" forIndexPath:indexPath];
if (indexPath.row < self.giftList.count) {
FUSLiveGiftDataModel *model = self.giftList[indexPath.row];
BOOL selected = (self.selectedGift && [self.selectedGift.gid isEqualToString:model.gid]);
FUSLiveGiftInteractOptionModel *model = self.giftList[indexPath.row];
BOOL selected = (self.selectedGift && [self.selectedGift.giftId isEqualToString:model.giftId]);
[cell fus_setupWithModel:model selected:selected];
}
return cell;
......@@ -73,7 +73,7 @@
if (indexPath.row >= self.giftList.count) {
return;
}
FUSLiveGiftDataModel *model = self.giftList[indexPath.row];
FUSLiveGiftInteractOptionModel *model = self.giftList[indexPath.row];
self.selectedGift = model;
[self.tableView reloadData];
......
......@@ -6,7 +6,7 @@
#import "FUSLiveGiftInteractSettingEnableCell.h"
#import "FUSLiveGiftInteractSettingItemCell.h"
#import "FUSLiveGiftInteractSettingItemModel.h"
#import "FUSLiveGiftDataModel.h"
#import "FUSLiveGiftInteractOptionModel.h"
#import "FUSLiveHelper.h"
#import "FUSLiveHttpHelper.h"
......@@ -122,13 +122,40 @@ static NSInteger const FUSLiveGiftInteractMaxItemCount = 6;
weakSelf.addPopView.dismissHandler = ^{
weakSelf.addPopView = nil;
};
weakSelf.addPopView.saveHandler = ^(NSString * _Nonnull desc, FUSLiveGiftDataModel * _Nonnull gift, NSInteger count) {
weakSelf.addPopView.saveHandler = ^(NSString * _Nonnull desc, FUSLiveGiftInteractOptionModel * _Nonnull gift, NSInteger count) {
[weakSelf fus_addGiftInteractWithDesc:desc gift:gift count:count];
};
weakSelf.addPopView.requestGiftListHandler = ^{
[weakSelf fus_requestGiftListForPopView];
};
[weakSelf.addPopView show];
}
- (void)fus_addGiftInteractWithDesc:(NSString *)desc gift:(FUSLiveGiftDataModel *)gift count:(NSInteger)count {
- (void)fus_requestGiftListForPopView {
[FUSDialogView fus_showDialog:[NSString fus_localString:@"正在加载礼物..."] autoDismiss:NO];
NSString *uid = FUSCacheDataShare.shareStore.userDetailInfo.uid ?: @"";
NSString *roomId = [FUSLiveHelper shareInstance].roomInfoModel.roomId ?: @"";
NSString *channelId = [FUSLiveHelper shareInstance].roomInfoModel.channelId ?: @"";
__weak typeof(self) weakSelf = self;
[FUSLiveHttpHelper fus_requestGiftInteractManageOptionListWithUid:uid roomId:roomId channelId:channelId succeed:^(NSArray<FUSLiveGiftInteractOptionModel *> * _Nonnull dataList) {
dispatch_async(dispatch_get_main_queue(), ^{
[FUSDialogView fus_dismissDialog];
if (dataList.count == 0) {
[FUSDialogView fus_showDialog:[NSString fus_localString:@"暂无可用礼物"]];
return;
}
weakSelf.addPopView.giftList = dataList;
[weakSelf.addPopView fus_presentGiftPicker];
});
} failure:^(NSString * _Nonnull msg, NSInteger code) {
dispatch_async(dispatch_get_main_queue(), ^{
[FUSDialogView fus_dismissDialog];
[FUSDialogView fus_showDialog:(msg.length ? msg : [NSString fus_localString:@"礼物加载失败"])];
});
}];
}
- (void)fus_addGiftInteractWithDesc:(NSString *)desc gift:(FUSLiveGiftInteractOptionModel *)gift count:(NSInteger)count {
if (self.items.count >= FUSLiveGiftInteractMaxItemCount) {
[FUSDialogView fus_showDialog:[NSString fus_localString:@"互动内容数量已达上限"]];
return;
......@@ -136,7 +163,7 @@ static NSInteger const FUSLiveGiftInteractMaxItemCount = 6;
NSString *uid = FUSCacheDataShare.shareStore.userDetailInfo.uid ?: @"";
NSString *roomId = [FUSLiveHelper shareInstance].roomInfoModel.roomId ?: @"";
NSString *channelId = [FUSLiveHelper shareInstance].roomInfoModel.channelId ?: @"";
NSString *giftId = gift.gid ?: @"";
NSString *giftId = gift.giftId ?: @"";
[FUSLiveHttpHelper fus_requestGiftInteractManageAddWithUid:uid roomId:roomId channelId:channelId name:desc giftId:giftId giftNum:count succeed:^{
[self fus_fetchManageList];
} failure:^(NSString *msg, NSInteger code) {
......
//
// FUSLiveGiftInteractOptionModel.h
// FUSShowRoomModule
//
#import "FUSBaseModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface FUSLiveGiftInteractOptionModel : FUSBaseModel
/// 礼物ID
@property (nonatomic, copy) NSString *giftId;
/// 礼物图标
@property (nonatomic, copy) NSString *giftIcon;
/// 礼物名称
@property (nonatomic, copy) NSString *giftName;
/// 礼物数量集合
@property (nonatomic, copy) NSArray<NSNumber *> *giftNumList;
@end
NS_ASSUME_NONNULL_END
//
// FUSLiveGiftInteractOptionModel.m
// FUSShowRoomModule
//
#import "FUSLiveGiftInteractOptionModel.h"
@implementation FUSLiveGiftInteractOptionModel
@end
#import <UIKit/UIKit.h>
@class FUSLiveGiftDataModel;
@class FUSLiveGiftInteractOptionModel;
NS_ASSUME_NONNULL_BEGIN
@interface FUSLiveGiftInteractGiftDropdownCell : UITableViewCell
- (void)fus_setupWithModel:(FUSLiveGiftDataModel *)model selected:(BOOL)selected;
- (void)fus_setupWithModel:(FUSLiveGiftInteractOptionModel *)model selected:(BOOL)selected;
@end
......
#import "FUSLiveGiftInteractGiftDropdownCell.h"
#import "FUSLiveGiftDataModel.h"
#import "FUSLiveGiftInteractOptionModel.h"
@interface FUSLiveGiftInteractGiftDropdownCell ()
......@@ -69,12 +69,11 @@
[self.priceButton setTitle:nil forState:UIControlStateNormal];
}
- (void)fus_setupWithModel:(FUSLiveGiftDataModel *)model selected:(BOOL)selected {
NSString *name = model.name.length ? model.name : [NSString fus_localString:@"礼物"];
- (void)fus_setupWithModel:(FUSLiveGiftInteractOptionModel *)model selected:(BOOL)selected {
NSString *name = model.giftName.length ? model.giftName : [NSString fus_localString:@"礼物"];
self.nameLabel.text = name;
[self.giftImageView setWebImageWithSubURLString:model.resource];
NSString *price = model.price.length ? model.price : @"";
[self.priceButton setTitle:price forState:UIControlStateNormal];
[self.giftImageView setWebImageWithSubURLString:model.giftIcon];
self.priceButton.hidden = YES;
self.selectedBackgroundView.hidden = !selected;
}
......
......@@ -34,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
@class FUSTicketShowUserBuyResultModel;
@class FUSBarrageCardModel;
@class FUSLiveGiftInteractOptionModel;
@interface FUSLiveHttpHelper : NSObject
......@@ -1305,6 +1306,18 @@ NS_ASSUME_NONNULL_BEGIN
succeed:(void (^)(NSArray *dataList))succeed
failure:(void (^)(NSString *msg, NSInteger code))failure;
/// 礼物互动行为-可选的礼物列表
/// @param uid 用户ID
/// @param roomId 房间ID
/// @param channelId 频道ID
/// @param succeed 成功回调(返回 FUSLiveGiftInteractOptionModel 数组)
/// @param failure 失败回调
+ (void)fus_requestGiftInteractManageOptionListWithUid:(NSString *)uid
roomId:(NSString *)roomId
channelId:(NSString *)channelId
succeed:(void (^)(NSArray<FUSLiveGiftInteractOptionModel *> *dataList))succeed
failure:(void (^)(NSString *msg, NSInteger code))failure;
/// 礼物互动行为-管理获取配置列表
/// @param uid 用户ID
/// @param roomId 房间ID
......
......@@ -29,6 +29,8 @@
#define FUS_LIVE_FONT(fontSize) [UIFont fus_themeMediumFont:fontSize]
#import "FUSLiveGiftInteractOptionModel.h"
@implementation FUSLiveHttpHelper
/**
......@@ -400,6 +402,44 @@
}];
}
/// 礼物互动行为-可选的礼物列表
+ (void)fus_requestGiftInteractManageOptionListWithUid:(NSString *)uid
roomId:(NSString *)roomId
channelId:(NSString *)channelId
succeed:(void (^)(NSArray<FUSLiveGiftInteractOptionModel *> *dataList))succeed
failure:(void (^)(NSString *msg, NSInteger code))failure {
if ([NSString isNullWithString:uid] ||
[NSString isNullWithString:roomId] ||
[NSString isNullWithString:channelId]) {
if (failure) {
failure(@"参数错误", ERROR_CODE);
}
return;
}
NSDictionary *params = @{@"uid": uid,
@"roomId": roomId,
@"channelId": channelId};
[FUSHttpHelper postRequestBinaryWithUrl:FUSShowRoomURLs.fus_URL_interactionGiftManageOptionList params:params success:^(NSDictionary *dataDict, int code) {
NSArray *list = [dataDict[@"dataList"] isKindOfClass:NSArray.class] ? dataDict[@"dataList"] : @[];
NSMutableArray *modelList = [NSMutableArray array];
for (NSDictionary *dict in list) {
if ([dict isKindOfClass:[NSDictionary class]]) {
FUSLiveGiftInteractOptionModel *model = [FUSLiveGiftInteractOptionModel fus_modelWithDict:dict];
if (model) {
[modelList addObject:model];
}
}
}
if (succeed) {
succeed(modelList);
}
} failure:^(NSDictionary *dataDict, int code) {
if (failure) {
failure(FAILURE_MESSAGE, code);
}
}];
}
/// 礼物互动行为-管理获取配置列表
+ (void)fus_requestGiftInteractManageListWithUid:(NSString *)uid
RoomId:(NSString *)roomId
......
......@@ -513,6 +513,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 礼物互动行为-管理更新状态
+ (NSString *)fus_URL_interactionGiftManageUpdStatus;
/// 礼物互动行为-可选的礼物列表
+ (NSString *)fus_URL_interactionGiftManageOptionList;
/// 获取模式列表
+ (NSString *)fus_URL_vsTypeGetList;
......
......@@ -832,6 +832,11 @@
return [FUSConfig.sharedInstanced.pathConfigs apiUrl:@"/interaction/gift/manage/updstatus"];
}
/// 礼物互动行为-可选的礼物列表
+ (NSString *)fus_URL_interactionGiftManageOptionList{
return [FUSConfig.sharedInstanced.pathConfigs apiUrl:@"/interaction/gift/manage/optionlist"];
}
/// 获取模式列表
+ (NSString *)fus_URL_vsTypeGetList{
return [FUSConfig.sharedInstanced.pathConfigs apiUrl:@"/vs/type/getList"];
......
......@@ -229,7 +229,12 @@ class FUSCompleteUserInfoVoiceSignView: FUSBaseView {
}
// 初始化时随机一个位置,避免每次进来都是同一个提示
self.voiceDemoTipIndex = Int(arc4random())%(FUSCacheDataShare.shareStore().voiceSignArray.count)
let voiceSignArrayCount = FUSCacheDataShare.shareStore().voiceSignArray?.count ?? 0
if voiceSignArrayCount > 0 {
self.voiceDemoTipIndex = Int(arc4random()) % voiceSignArrayCount
} else {
self.voiceDemoTipIndex = 0
}
self.fus_updateSignExampleContent()
self.fus_resetRecordState()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment