新增房间礼物特效相关功能,更新 XPGiftEffectAction 类以支持根据房间状态创建对应的 Action 实例,并优化了相关的通知逻辑。同时,新增 kRoomGiftEffectUpdateNotificationKey 常量以便于通知管理,提升代码可维护性和功能扩展性。
This commit is contained in:
@@ -19,6 +19,7 @@ UIKIT_EXTERN NSString * const kTuWenMessageHistory;///图文消息已读记录
|
||||
UIKIT_EXTERN NSString * const kRoomQuickMessageCloseCount;
|
||||
UIKIT_EXTERN NSString * const kLoginMethod;
|
||||
UIKIT_EXTERN NSString * const kMessageFromPublicRoomWithAttachmentNotification;
|
||||
UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
|
||||
typedef NS_ENUM(NSUInteger, Pi_KeyType) {
|
||||
KeyType_PasswordEncode,///密码 des 加密的
|
||||
KeyType_TRTC,///TRTC key
|
||||
|
@@ -7,6 +7,8 @@
|
||||
|
||||
#import "../Model/XPRoomMoreMenuAction.h"
|
||||
|
||||
@class RoomInfoModel;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
@@ -24,6 +26,13 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
*/
|
||||
+ (instancetype)closeAction;
|
||||
|
||||
/**
|
||||
* 根据房间状态创建对应的 Action
|
||||
* @param roomInfo 房间信息
|
||||
* @return 对应的 Action 实例
|
||||
*/
|
||||
+ (instancetype)actionWithRoomInfo:(RoomInfoModel *)roomInfo;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -10,6 +10,9 @@
|
||||
#import "YUMIConstant.h"
|
||||
#import "YUMIMacroUitls.h"
|
||||
#import "DJDKMIMOMColor.h"
|
||||
#import "RoomInfoModel.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BaseViewController.h"
|
||||
|
||||
UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
|
||||
|
||||
@@ -17,7 +20,7 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
|
||||
|
||||
+ (instancetype)openAction {
|
||||
XPGiftEffectAction *action = [[XPGiftEffectAction alloc] init];
|
||||
action.title = @"禮物特效已開啟"; // 暂时使用硬编码,后续改为本地化
|
||||
action.title = YMLocalizedString(@"XPMoreMenuPresenter5"); // 暂时使用硬编码,后续改为本地化
|
||||
action.imageName = @"room_more_menu_gift_effect"; // 使用正确的图片名称
|
||||
action.type = RoomMoreMenuType_Gift_Effect_Open;
|
||||
action.isEnabled = YES;
|
||||
@@ -27,7 +30,7 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
|
||||
|
||||
+ (instancetype)closeAction {
|
||||
XPGiftEffectAction *action = [[XPGiftEffectAction alloc] init];
|
||||
action.title = @"禮物特效已關閉"; // 暂时使用硬编码,后续改为本地化
|
||||
action.title = YMLocalizedString(@"XPMoreMenuPresenter28"); // 暂时使用硬编码,后续改为本地化
|
||||
action.imageName = @"room_more_menu_gift_effect"; // 使用正确的图片名称
|
||||
action.type = RoomMoreMenuType_Gift_Effect_Close;
|
||||
action.isEnabled = YES;
|
||||
@@ -35,48 +38,98 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
|
||||
return action;
|
||||
}
|
||||
|
||||
// 根据房间状态创建对应的 Action
|
||||
+ (instancetype)actionWithRoomInfo:(RoomInfoModel *)roomInfo {
|
||||
if (roomInfo.hasAnimationEffect) {
|
||||
return [self closeAction];
|
||||
} else {
|
||||
return [self openAction];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)canExecuteWithContext:(XPRoomMoreMenuActionContext *)context {
|
||||
NSLog(@"=== XPGiftEffectAction canExecuteWithContext ===");
|
||||
NSLog(@"Action 标题: %@", self.title);
|
||||
NSLog(@"Action isEnabled: %@", self.isEnabled ? @"YES" : @"NO");
|
||||
|
||||
// 礼物特效开关没有特殊权限要求,所有用户都可以操作
|
||||
return self.isEnabled;
|
||||
BOOL canExecute = self.isEnabled;
|
||||
NSLog(@"canExecuteWithContext 返回: %@", canExecute ? @"YES" : @"NO");
|
||||
return canExecute;
|
||||
}
|
||||
|
||||
- (void)executeWithContext:(XPRoomMoreMenuActionContext *)context {
|
||||
// 根据类型执行不同的操作
|
||||
if (self.type == RoomMoreMenuType_Gift_Effect_Open) {
|
||||
[self executeOpenAction];
|
||||
} else if (self.type == RoomMoreMenuType_Gift_Effect_Close) {
|
||||
[self executeCloseAction];
|
||||
}
|
||||
NSLog(@"=== XPGiftEffectAction executeWithContext ===");
|
||||
NSLog(@"Action 类型: %ld", (long)self.type);
|
||||
NSLog(@"Action 标题: %@", self.title);
|
||||
|
||||
// 根据类型执行不同的操作
|
||||
if (self.type == RoomMoreMenuType_Gift_Effect_Open) {
|
||||
NSLog(@"执行开启礼物特效操作");
|
||||
[self executeOpenAction];
|
||||
} else if (self.type == RoomMoreMenuType_Gift_Effect_Close) {
|
||||
NSLog(@"执行关闭礼物特效操作");
|
||||
[self executeCloseAction];
|
||||
} else {
|
||||
NSLog(@"❌ 未知的 Action 类型: %ld", (long)self.type);
|
||||
}
|
||||
|
||||
// 显示成功提示
|
||||
[self showSuccessToastWithContext:context];
|
||||
|
||||
// 关闭当前页面
|
||||
if (context.presentingViewController && [context.presentingViewController respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) {
|
||||
NSLog(@"关闭当前页面");
|
||||
BaseViewController *viewController = (BaseViewController *)context.presentingViewController;
|
||||
[viewController dismissViewControllerAnimated:YES completion:nil];
|
||||
} else {
|
||||
NSLog(@"❌ 无法关闭页面:presentingViewController 无效");
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods
|
||||
|
||||
- (void)executeOpenAction {
|
||||
// 显示成功提示
|
||||
// 注意:这里需要访问 presentingViewController 来显示 toast
|
||||
// 暂时注释掉,等重构完成后通过 context 传递
|
||||
|
||||
// 发送通知
|
||||
NSDictionary *dic = @{@"hasAnimationEffect": @(1)};
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomGiftEffectUpdateNotificationKey object:dic];
|
||||
|
||||
// 关闭当前页面
|
||||
// 注意:这里需要访问 presentingViewController 来关闭页面
|
||||
// 暂时注释掉,等重构完成后通过 context 传递
|
||||
NSLog(@"=== executeOpenAction ===");
|
||||
|
||||
// 发送通知
|
||||
NSDictionary *dic = @{@"hasAnimationEffect": @(1)};
|
||||
NSLog(@"发送开启礼物特效通知: %@", dic);
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomGiftEffectUpdateNotificationKey object:dic];
|
||||
|
||||
NSLog(@"executeOpenAction 执行完成");
|
||||
}
|
||||
|
||||
- (void)executeCloseAction {
|
||||
// 显示成功提示
|
||||
// 注意:这里需要访问 presentingViewController 来显示 toast
|
||||
// 暂时注释掉,等重构完成后通过 context 传递
|
||||
|
||||
// 发送通知
|
||||
NSDictionary *dic = @{@"hasAnimationEffect": @(0)};
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomGiftEffectUpdateNotificationKey object:dic];
|
||||
|
||||
// 关闭当前页面
|
||||
// 注意:这里需要访问 presentingViewController 来关闭页面
|
||||
// 暂时注释掉,等重构完成后通过 context 传递
|
||||
NSLog(@"=== executeCloseAction ===");
|
||||
|
||||
// 发送通知
|
||||
NSDictionary *dic = @{@"hasAnimationEffect": @(0)};
|
||||
NSLog(@"发送关闭礼物特效通知: %@", dic);
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kRoomGiftEffectUpdateNotificationKey object:dic];
|
||||
|
||||
NSLog(@"executeCloseAction 执行完成");
|
||||
}
|
||||
|
||||
- (void)showSuccessToastWithContext:(XPRoomMoreMenuActionContext *)context {
|
||||
NSString *message;
|
||||
if (self.type == RoomMoreMenuType_Gift_Effect_Open) {
|
||||
message = YMLocalizedString(@"XPRoomMoreMenuViewController4");
|
||||
} else if (self.type == RoomMoreMenuType_Gift_Effect_Close) {
|
||||
message = YMLocalizedString(@"XPRoomMoreMenuViewController5");
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"显示成功提示: %@", message);
|
||||
|
||||
// 通过 context 显示 toast
|
||||
if (context.presentingViewController && [context.presentingViewController respondsToSelector:@selector(showSuccessToast:)]) {
|
||||
BaseViewController *viewController = (BaseViewController *)context.presentingViewController;
|
||||
[viewController showSuccessToast:message];
|
||||
} else {
|
||||
NSLog(@"❌ 无法显示 toast:presentingViewController 无效或没有 showSuccessToast 方法");
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -24,8 +24,8 @@
|
||||
}
|
||||
|
||||
- (BOOL)canExecuteWithContext:(XPRoomMoreMenuActionContext *)context {
|
||||
// 房间设置通常只有房主或管理员可以操作
|
||||
// 这里暂时允许所有用户,后续可以根据权限调整
|
||||
// 房间设置只有房主或管理员可以操作
|
||||
// 这里需要根据用户身份判断,暂时返回 YES
|
||||
return self.isEnabled;
|
||||
}
|
||||
|
||||
|
@@ -63,8 +63,12 @@
|
||||
#pragma mark - XPRoomMoreMenuAction Override
|
||||
|
||||
- (BOOL)canExecuteWithContext:(XPRoomMoreMenuActionContext *)context {
|
||||
// 所有社交功能都可以执行
|
||||
return YES;
|
||||
// 根据原有逻辑,社交功能的显示条件:
|
||||
// 1. 邀请粉丝:所有用户都可以
|
||||
// 2. 发布广播:所有用户都可以
|
||||
// 3. VIP小喇叭:所有用户都可以
|
||||
// 4. 举报房间:所有用户都可以
|
||||
return self.isEnabled;
|
||||
}
|
||||
|
||||
- (void)executeWithContext:(XPRoomMoreMenuActionContext *)context {
|
||||
|
@@ -11,22 +11,23 @@
|
||||
#import "XPGiftEffectAction.h"
|
||||
#import "XPRoomSettingAction.h"
|
||||
#import "XPSocialAction.h"
|
||||
#import "RoomInfoModel.h"
|
||||
|
||||
@implementation XPRoomMoreMenuActionFactory
|
||||
|
||||
+ (NSArray<XPRoomMoreMenuAction *> *)createActionsWithContext:(XPRoomMoreMenuActionContext *)context {
|
||||
NSMutableArray *actions = [NSMutableArray array];
|
||||
|
||||
// 根据上下文条件创建不同的操作列表
|
||||
// 根据原有逻辑创建 Action 列表
|
||||
|
||||
// 1. 礼物特效相关操作
|
||||
[actions addObject:[XPGiftEffectAction openAction]];
|
||||
[actions addObject:[XPGiftEffectAction closeAction]];
|
||||
// 1. 礼物特效 - 根据房间状态只显示一个
|
||||
[actions addObject:[XPGiftEffectAction actionWithRoomInfo:context.roomInfo]];
|
||||
|
||||
// 2. 房间设置
|
||||
// 2. 房间设置 - 只有房主或管理员可以操作
|
||||
// 这里暂时添加,后续需要根据用户身份判断
|
||||
[actions addObject:[XPRoomSettingAction action]];
|
||||
|
||||
// 3. 社交功能
|
||||
// 3. 社交功能 - 所有用户都可以使用
|
||||
[actions addObject:[XPSocialAction inviteFansAction]];
|
||||
[actions addObject:[XPSocialAction releaseRadioAction]];
|
||||
[actions addObject:[XPSocialAction trumpetAction]];
|
||||
|
@@ -93,7 +93,7 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
|
||||
[self initSubViewConstraints];
|
||||
|
||||
// 测试新的架构实现
|
||||
[self testNewArchitecture];
|
||||
// [self testNewArchitecture];
|
||||
|
||||
///自己是公会超管
|
||||
BOOL meIsSuperAdmin = NO;
|
||||
@@ -311,6 +311,9 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
|
||||
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
|
||||
XPRoomMoreItemModel * item = [self.datasource xpSafeObjectAtIndex:indexPath.row];
|
||||
|
||||
NSLog(@"=== 点击菜单项 ===");
|
||||
NSLog(@"点击的菜单项: 标题=%@, 类型=%ld", item.title, (long)item.type);
|
||||
|
||||
// 创建上下文
|
||||
XPRoomMoreMenuActionContext *context = [XPRoomMoreMenuActionContext
|
||||
contextWithRoomInfo:self.roomInfo
|
||||
@@ -324,9 +327,23 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
|
||||
// 查找对应的 Action
|
||||
XPRoomMoreMenuAction *action = [self findActionForItem:item];
|
||||
|
||||
if (action && [action canExecuteWithContext:context]) {
|
||||
[action executeWithContext:context];
|
||||
NSLog(@"找到的 Action: %@", action ? @"是" : @"否");
|
||||
if (action) {
|
||||
NSLog(@"Action 标题: %@, 类型: %ld", action.title, (long)action.type);
|
||||
NSLog(@"准备调用 canExecuteWithContext...");
|
||||
BOOL canExecute = [action canExecuteWithContext:context];
|
||||
NSLog(@"Action 可以执行: %@", canExecute ? @"是" : @"否");
|
||||
|
||||
if (canExecute) {
|
||||
NSLog(@"开始执行 Action...");
|
||||
[action executeWithContext:context];
|
||||
NSLog(@"Action 执行完成");
|
||||
} else {
|
||||
NSLog(@"Action 无法执行,使用 fallback 逻辑");
|
||||
[self handleItemWithLegacyLogic:item];
|
||||
}
|
||||
} else {
|
||||
NSLog(@"未找到 Action,使用 fallback 逻辑");
|
||||
// 如果找不到对应的 Action,使用原有的 switch 逻辑作为 fallback
|
||||
[self handleItemWithLegacyLogic:item];
|
||||
}
|
||||
@@ -346,13 +363,20 @@ UIKIT_EXTERN NSString * const kRoomGiftEffectUpdateNotificationKey;
|
||||
// 获取所有 Action
|
||||
NSArray<XPRoomMoreMenuAction *> *actions = [XPRoomMoreMenuActionFactory createActionsWithContext:context];
|
||||
|
||||
NSLog(@"=== findActionForItem 调试 ===");
|
||||
NSLog(@"查找类型: %ld", (long)item.type);
|
||||
NSLog(@"工厂创建了 %lu 个 Action", (unsigned long)actions.count);
|
||||
|
||||
// 查找匹配的 Action
|
||||
for (XPRoomMoreMenuAction *action in actions) {
|
||||
NSLog(@"检查 Action: 标题=%@, 类型=%ld", action.title, (long)action.type);
|
||||
if (action.type == item.type) {
|
||||
NSLog(@"✅ 找到匹配的 Action: %@", action.title);
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
||||
NSLog(@"❌ 未找到匹配的 Action");
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user