1
This commit is contained in:
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user