diff --git a/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/Contents.json b/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/Contents.json new file mode 100644 index 0000000..8f9ae45 --- /dev/null +++ b/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "close_icon@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "close_icon@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/close_icon@2x.png b/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/close_icon@2x.png new file mode 100644 index 0000000..77df800 Binary files /dev/null and b/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/close_icon@2x.png differ diff --git a/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/close_icon@3x.png b/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/close_icon@3x.png new file mode 100644 index 0000000..fc54891 Binary files /dev/null and b/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/close_icon@3x.png differ diff --git a/CustomKeyboard/KeyboardViewController.m b/CustomKeyboard/KeyboardViewController.m index ad4d5d7..5b001c0 100644 --- a/CustomKeyboard/KeyboardViewController.m +++ b/CustomKeyboard/KeyboardViewController.m @@ -794,6 +794,26 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, [self kb_playChatAudioAtPath:message.audioFilePath]; } +- (void)chatPanelViewDidTapClose:(KBChatPanelView *)view { + for (KBChatMessage *msg in self.chatMessages) { + if (msg.audioFilePath.length > 0) { + NSString *tmpRoot = NSTemporaryDirectory(); + if (tmpRoot.length > 0 && + [msg.audioFilePath hasPrefix:tmpRoot]) { + [[NSFileManager defaultManager] removeItemAtPath:msg.audioFilePath + error:nil]; + } + } + } + [self.chatMessages removeAllObjects]; + [self.chatPanelView kb_reloadWithMessages:@[]]; + if (self.chatAudioPlayer.isPlaying) { + [self.chatAudioPlayer stop]; + } + self.chatAudioPlayer = nil; + [self showChatPanel:NO]; +} + #pragma mark - Chat Helpers - (void)kb_handleChatSendAction { @@ -1432,6 +1452,7 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, NSLog(@"⌨️[Keyboard] apply theme id=%@ hasBg=%d", t.skinId, (img != nil)); [self kb_logSkinDiagnosticsWithTheme:t backgroundImage:img]; self.bgImageView.image = img; +// [self.chatPanelView kb_setBackgroundImage:img]; BOOL hasImg = (img != nil); // 触发键区按主题重绘 if ([self.keyBoardMainView respondsToSelector:@selector(kb_applyTheme)]) { diff --git a/CustomKeyboard/View/KBChatMessageCell.m b/CustomKeyboard/View/KBChatMessageCell.m index fc4ef37..5b8dde7 100644 --- a/CustomKeyboard/View/KBChatMessageCell.m +++ b/CustomKeyboard/View/KBChatMessageCell.m @@ -21,6 +21,7 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.backgroundColor = [UIColor clearColor]; + self.contentView.backgroundColor = [UIColor clearColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self.contentView addSubview:self.avatarView]; diff --git a/CustomKeyboard/View/KBChatPanelView.h b/CustomKeyboard/View/KBChatPanelView.h index 255ffec..8c4c2ac 100644 --- a/CustomKeyboard/View/KBChatPanelView.h +++ b/CustomKeyboard/View/KBChatPanelView.h @@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN @optional - (void)chatPanelView:(KBChatPanelView *)view didSendText:(NSString *)text; - (void)chatPanelView:(KBChatPanelView *)view didTapMessage:(KBChatMessage *)message; +- (void)chatPanelViewDidTapClose:(KBChatPanelView *)view; @end @interface KBChatPanelView : UIView @@ -20,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong, readonly) UITableView *tableView; +//- (void)kb_setBackgroundImage:(nullable UIImage *)image; - (void)kb_reloadWithMessages:(NSArray *)messages; @end diff --git a/CustomKeyboard/View/KBChatPanelView.m b/CustomKeyboard/View/KBChatPanelView.m index bfb25b2..c2eb651 100644 --- a/CustomKeyboard/View/KBChatPanelView.m +++ b/CustomKeyboard/View/KBChatPanelView.m @@ -9,6 +9,10 @@ #import "Masonry.h" @interface KBChatPanelView () +//@property (nonatomic, strong) UIImageView *backgroundImageView; +@property (nonatomic, strong) UIView *headerView; +@property (nonatomic, strong) UILabel *titleLabel; +@property (nonatomic, strong) UIButton *closeButton; @property (nonatomic, strong) UITableView *tableViewInternal; @property (nonatomic, copy) NSArray *messages; @end @@ -17,13 +21,25 @@ - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { - self.backgroundColor = [UIColor colorWithHex:0xD1D3DB]; + self.backgroundColor = [UIColor clearColor]; +// [self addSubview:self.backgroundImageView]; + [self addSubview:self.headerView]; [self addSubview:self.tableViewInternal]; +// [self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) { +// make.edges.equalTo(self); +// }]; + + [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.right.equalTo(self); + make.top.equalTo(self.mas_top); + make.height.mas_equalTo(KBFit(36.0f)); + }]; + [self.tableViewInternal mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self); - make.top.equalTo(self.mas_top).offset(8); + make.top.equalTo(self.headerView.mas_bottom).offset(4); make.bottom.equalTo(self.mas_bottom).offset(-8); }]; } @@ -43,6 +59,18 @@ } } +//- (void)kb_setBackgroundImage:(UIImage *)image { +// self.backgroundImageView.image = image; +//} + +#pragma mark - Actions + +- (void)kb_onTapClose { + if ([self.delegate respondsToSelector:@selector(chatPanelViewDidTapClose:)]) { + [self.delegate chatPanelViewDidTapClose:self]; + } +} + #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { @@ -80,6 +108,7 @@ if (!_tableViewInternal) { _tableViewInternal = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _tableViewInternal.backgroundColor = [UIColor clearColor]; + _tableViewInternal.backgroundView = nil; _tableViewInternal.separatorStyle = UITableViewCellSeparatorStyleNone; _tableViewInternal.dataSource = self; _tableViewInternal.delegate = self; @@ -90,6 +119,61 @@ return _tableViewInternal; } +- (UIView *)headerView { + if (!_headerView) { + _headerView = [[UIView alloc] init]; + _headerView.backgroundColor = [UIColor clearColor]; + [_headerView addSubview:self.titleLabel]; + [_headerView addSubview:self.closeButton]; + + [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(_headerView.mas_left).offset(12); + make.centerY.equalTo(_headerView); + }]; + + [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.right.equalTo(_headerView.mas_right).offset(-12); + make.centerY.equalTo(_headerView); + make.width.height.mas_equalTo(KBFit(24.0f)); + }]; + } + return _headerView; +} + +- (UILabel *)titleLabel { + if (!_titleLabel) { + _titleLabel = [[UILabel alloc] init]; + _titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightMedium]; + _titleLabel.textColor = [UIColor colorWithHex:0x1B1F1A]; + _titleLabel.text = KBLocalized(@"AI对话"); + } + return _titleLabel; +} + +- (UIButton *)closeButton { + if (!_closeButton) { + _closeButton = [UIButton buttonWithType:UIButtonTypeCustom]; + UIImage *icon = [UIImage imageNamed:@"close_icon"]; + [_closeButton setImage:icon forState:UIControlStateNormal]; + _closeButton.backgroundColor = [UIColor clearColor]; + [_closeButton addTarget:self + action:@selector(kb_onTapClose) + forControlEvents:UIControlEventTouchUpInside]; + } + return _closeButton; +} + +//- (UIImageView *)backgroundImageView { +// if (!_backgroundImageView) { +// _backgroundImageView = [[UIImageView alloc] init]; +// _backgroundImageView.contentMode = UIViewContentModeScaleAspectFill; +// _backgroundImageView.clipsToBounds = YES; +// _backgroundImageView.backgroundColor = [UIColor clearColor]; +// _backgroundImageView.userInteractionEnabled = NO; +// } +// return _backgroundImageView; +//} + #pragma mark - Expose - (UITableView *)tableView { return self.tableViewInternal; }