新增房间礼物特效相关功能,更新 XPGiftEffectAction 类以支持根据房间状态创建对应的 Action 实例,并优化了相关的通知逻辑。同时,新增 kRoomGiftEffectUpdateNotificationKey 常量以便于通知管理,提升代码可维护性和功能扩展性。

This commit is contained in:
edwinQQQ
2025-09-01 14:29:21 +08:00
parent 406cf003f5
commit 860304ea15
7 changed files with 136 additions and 44 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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(@"❌ 无法显示 toastpresentingViewController 无效或没有 showSuccessToast 方法");
}
}
@end

View File

@@ -24,8 +24,8 @@
}
- (BOOL)canExecuteWithContext:(XPRoomMoreMenuActionContext *)context {
//
//
//
// YES
return self.isEnabled;
}

View File

@@ -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 {

View File

@@ -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]];

View File

@@ -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;
}