This commit is contained in:
2025-12-08 16:39:47 +08:00
parent 0a1c30f669
commit fd8c08316b
30 changed files with 306 additions and 85 deletions

View File

@@ -78,9 +78,6 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center,
CFNotificationSuspensionBehaviorDeliverImmediately);
[self kb_consumePendingShopSkin];
// NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:AppGroup];
// NSString *value = [sharedDefaults objectForKey:@"TestSharedString"];
// NSLog(@"[Keyboard] 读取到的数据: %@", value);
}
- (void)viewWillAppear:(BOOL)animated{

View File

@@ -4,7 +4,7 @@
//
#import <UIKit/UIKit.h>
#import "KBTagItemModel.h"
NS_ASSUME_NONNULL_BEGIN
@class KBFunctionTagListView;
@@ -19,7 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, weak, nullable) id<KBFunctionTagListViewDelegate> delegate;
@property (nonatomic, strong, readonly) UICollectionView *collectionView;
- (void)setItems:(NSArray<NSString *> *)items;
//- (void)setItems:(NSArray<NSString *> *)items;
- (void)setItems:(NSArray<KBTagItemModel *> *)items;
/// 在指定 index 上显示/隐藏加载指示(若 cell 不可见,内部会记录状态,待出现时应用)
- (void)setLoading:(BOOL)loading atIndex:(NSInteger)index;

View File

@@ -10,7 +10,7 @@ static CGFloat const kKBItemSpace = 4;
@interface KBFunctionTagListView () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionViewInternal;
@property (nonatomic, copy) NSArray<NSString *> *items;
@property (nonatomic, copy) NSArray<KBTagItemModel *> *items;
@property (nonatomic, strong) NSMutableSet<NSNumber *> *loadingIndexes; // loadingindex
@end
@@ -38,7 +38,8 @@ static CGFloat const kKBItemSpace = 4;
return self;
}
- (void)setItems:(NSArray<NSString *> *)items { _items = [items copy]; [self.collectionViewInternal reloadData]; }
//- (void)setItems:(NSArray<NSString *> *)items { _items = [items copy]; [self.collectionViewInternal reloadData]; }
- (void)setItems:(NSArray<KBTagItemModel *> *)items{ _items = [items copy]; [self.collectionViewInternal reloadData]; }
- (UICollectionView *)collectionView { return self.collectionViewInternal; }
@@ -48,7 +49,8 @@ static CGFloat const kKBItemSpace = 4;
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
KBFunctionTagCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kKBFunctionTagCellId2 forIndexPath:indexPath];
cell.titleLabel.text = (indexPath.item < self.items.count) ? self.items[indexPath.item] : @"";
KBTagItemModel *itemModel = (indexPath.item < self.items.count) ? self.items[indexPath.item] : [KBTagItemModel new];
cell.itemModel = itemModel;
BOOL loading = [self.loadingIndexes containsObject:@(indexPath.item)];
[cell setLoading:loading];
return cell;
@@ -65,8 +67,8 @@ static CGFloat const kKBItemSpace = 4;
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if ([self.delegate respondsToSelector:@selector(tagListView:didSelectIndex:title:)]) {
NSString *title = (indexPath.item < self.items.count) ? self.items[indexPath.item] : @"";
[self.delegate tagListView:self didSelectIndex:indexPath.item title:title];
KBTagItemModel *model = (indexPath.item < self.items.count) ? self.items[indexPath.item] : [KBTagItemModel new];
[self.delegate tagListView:self didSelectIndex:indexPath.item title:model.characterName];
}
}

View File

@@ -6,7 +6,7 @@
// 话术标签Cell左图标+右标题,圆角灰白底
#import <UIKit/UIKit.h>
#import "KBTagItemModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface KBFunctionTagCell : UICollectionViewCell
@@ -17,6 +17,10 @@ NS_ASSUME_NONNULL_BEGIN
/// 头像/图标
@property (nonatomic, strong, readonly) UIImageView *iconView;
@property (nonatomic, strong) KBTagItemModel *itemModel;
/// 显示/隐藏加载指示(小菊花)
- (void)setLoading:(BOOL)loading;

View File

@@ -9,8 +9,8 @@
#import "Masonry.h"
@interface KBFunctionTagCell ()
@property (nonatomic, strong) UILabel *emojiLabel;
@property (nonatomic, strong) UILabel *titleLabelInternal;
@property (nonatomic, strong) UIImageView *iconViewInternal;
@property (nonatomic, strong) UIActivityIndicatorView *loadingView;
@end
@@ -40,17 +40,17 @@
make.right.lessThanOrEqualTo(self.contentView).offset(-6);
}];
[centerContainer addSubview:self.iconViewInternal];
[centerContainer addSubview:self.emojiLabel];
[centerContainer addSubview:self.titleLabelInternal];
[self.iconViewInternal mas_makeConstraints:^(MASConstraintMaker *make) {
[self.emojiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(centerContainer.mas_left);
make.centerY.equalTo(centerContainer.mas_centerY);
// emoji
make.width.height.mas_equalTo(24);
}];
[self.titleLabelInternal mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.iconViewInternal.mas_right).offset(3);
make.left.equalTo(self.emojiLabel.mas_right).offset(3);
make.top.equalTo(centerContainer.mas_top);
make.bottom.equalTo(centerContainer.mas_bottom);
make.right.equalTo(centerContainer.mas_right);
@@ -59,23 +59,23 @@
return self;
}
- (void)setItemModel:(KBTagItemModel *)itemModel{
_itemModel = itemModel;
self.emojiLabel.text = itemModel.emoji;
self.titleLabelInternal.text = itemModel.characterName;
}
#pragma mark - Lazy
- (UIImageView *)iconViewInternal {
if (!_iconViewInternal) {
_iconViewInternal = [[UIImageView alloc] init];
UILabel *emoji = [[UILabel alloc] init];
emoji.text = @"🙂"; //
emoji.textAlignment = NSTextAlignmentCenter;
emoji.font = [UIFont systemFontOfSize:20];
emoji.adjustsFontSizeToFitWidth = YES;
emoji.minimumScaleFactor = 0.8;
[_iconViewInternal addSubview:emoji];
[emoji mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(_iconViewInternal);
}];
- (UILabel *)emojiLabel {
if (!_emojiLabel) {
_emojiLabel = [[UILabel alloc] init];
_emojiLabel.textAlignment = NSTextAlignmentCenter;
_emojiLabel.font = [KBFont medium:20];
_emojiLabel.adjustsFontSizeToFitWidth = YES;
}
return _iconViewInternal;
return _emojiLabel;
}
- (UILabel *)titleLabelInternal {
@@ -109,7 +109,6 @@ static UIActivityIndicatorViewStyle KBSpinnerStyle(void) { return UIActivityIndi
#pragma mark - Expose
- (UILabel *)titleLabel { return self.titleLabelInternal; }
- (UIImageView *)iconView { return self.iconViewInternal; }
- (void)setLoading:(BOOL)loading {
if (loading) {

View File

@@ -22,6 +22,8 @@
#import "KBStreamOverlayView.h" //
#import "KBFunctionTagListView.h"
#import "KBStreamFetcher.h" //
#import "KBTagItemModel.h"
#import <MJExtension/MJExtension.h>
@interface KBFunctionView () <KBFunctionBarViewDelegate, KBStreamOverlayViewDelegate, KBFunctionTagListViewDelegate>
// UI
@@ -44,7 +46,8 @@
@property (nonatomic, copy, nullable) NSString *loadingTagTitle;
// Data
@property (nonatomic, strong) NSArray<NSString *> *itemsInternal;
//@property (nonatomic, strong) NSArray<NSString *> *itemsInternal;
@property (nonatomic, strong) NSMutableArray<KBTagItemModel *> *modelArray;
//
@property (nonatomic, strong) NSTimer *pasteboardTimer; // 线
@@ -63,7 +66,9 @@
[self kb_applyTheme];
[self setupUI];
[self reloadDemoData];
// [self reloadDemoData];
[self kb_reloadTagsFromSharedDefaults];
//
_lastHandledPBCount = [UIPasteboard generalPasteboard].changeCount;
@@ -82,6 +87,27 @@
return self;
}
#pragma mark - Data
/// App Group NSUserDefaults JSON model +
- (void)kb_reloadTagsFromSharedDefaults {
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:AppGroup];
NSDictionary *jsonDict = [sharedDefaults objectForKey:AppGroup_MyKbJson];
if (jsonDict != nil) {
id dataObj = jsonDict[@"data"];
NSArray<KBTagItemModel *> *modelList = [KBTagItemModel mj_objectArrayWithKeyValuesArray:(NSArray *)dataObj];
if (modelList.count > 0) {
self.modelArray = [NSMutableArray array];
[self.modelArray addObjectsFromArray:modelList];
// [self.collectionView reloadData];
[self.tagListView setItems:self.modelArray];
}
}else{
NSLog(@"json❎");
}
}
#pragma mark - Theme
- (void)kb_applyTheme {
@@ -176,20 +202,20 @@
#pragma mark - Data
- (void)reloadDemoData {
//
self.itemsInternal = @[KBLocalized(@"Warm hearted man"),
KBLocalized(@"Warm2 hearted man"),
KBLocalized(@"Warm3 hearted man"),
KBLocalized(@"撩女生啊u发顺丰大师傅"),
KBLocalized(@"Warm = man"),
KBLocalized(@"Warm hearted man"),
KBLocalized(@"一枚暖男发放"),
KBLocalized(@"聊天搭子"),
KBLocalized(@"表达爱意"),
KBLocalized(@"更多话术")];
[self.tagListView setItems:self.itemsInternal];
}
//- (void)reloadDemoData {
// //
// self.itemsInternal = @[KBLocalized(@"Warm hearted man"),
// KBLocalized(@"Warm2 hearted man"),
// KBLocalized(@"Warm3 hearted man"),
// KBLocalized(@"撩女生啊u发顺丰大师傅"),
// KBLocalized(@"Warm = man"),
// KBLocalized(@"Warm hearted man"),
// KBLocalized(@"一枚暖男发放"),
// KBLocalized(@"聊天搭子"),
// KBLocalized(@"表达爱意"),
// KBLocalized(@"更多话术")];
// [self.tagListView setItems:self.itemsInternal];
//}
// UICollectionView KBFunctionTagListView
@@ -409,8 +435,8 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// + 访访
if ([[KBFullAccessManager shared] hasFullAccess]) {
NSString *title = (indexPath.item < self.itemsInternal.count) ? self.itemsInternal[indexPath.item] : @"";
[self kb_showStreamTextViewIfNeededWithTitle:title];
KBTagItemModel *selModel = self.modelArray[indexPath.item];
[self kb_showStreamTextViewIfNeededWithTitle:selModel.characterName];
return;
}
@@ -419,7 +445,7 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
UIInputViewController *ivc = KBFindInputViewController(self);
if (!ivc) return;
NSString *title = (indexPath.item < self.itemsInternal.count) ? self.itemsInternal[indexPath.item] : @"";
NSString *title = self.modelArray[indexPath.item].characterName;
NSString *encodedTitle = [title stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]] ?: @"";
NSURL *ul = [NSURL URLWithString:[NSString stringWithFormat:@"%@?src=functionView&index=%ld&title=%@", KB_UL_LOGIN, (long)indexPath.item, encodedTitle]];
@@ -676,7 +702,7 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
#pragma mark - Expose
- (UICollectionView *)collectionView { return self.tagListView.collectionView; }
- (NSArray<NSString *> *)items { return self.itemsInternal; }
//- (NSArray<NSString *> *)items { return self.itemsInternal; }
- (KBFunctionBarView *)barView { return self.barViewInternal; }
- (KBFunctionPasteView *)pasteView { return self.pasteViewInternal; }
- (UIButton *)pasteButton { return self.pasteButtonInternal; }