2025-11-04 21:01:46 +08:00
|
|
|
|
//
|
|
|
|
|
|
// KBSkinCenterVC.m
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#import "KBSkinCenterVC.h"
|
|
|
|
|
|
#import "Masonry.h"
|
|
|
|
|
|
#import "KBNetworkManager.h"
|
|
|
|
|
|
#import "KBSkinManager.h"
|
|
|
|
|
|
#import "KBHUD.h"
|
2025-11-18 20:53:47 +08:00
|
|
|
|
#import "KBConfig.h"
|
|
|
|
|
|
#import "KBSkinService.h"
|
2025-11-25 16:53:38 +08:00
|
|
|
|
#import "KBSkinInstallBridge.h"
|
2025-11-04 21:01:46 +08:00
|
|
|
|
|
|
|
|
|
|
@interface KBSkinCell : UITableViewCell
|
|
|
|
|
|
@property (nonatomic, strong) UIButton *applyBtn;
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation KBSkinCell
|
|
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
|
|
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
|
|
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
|
|
_applyBtn = [UIButton buttonWithType:UIButtonTypeSystem];
|
2025-11-17 20:07:39 +08:00
|
|
|
|
[_applyBtn setTitle:KBLocalized(@"Download & Apply") forState:UIControlStateNormal];
|
2025-11-04 21:01:46 +08:00
|
|
|
|
_applyBtn.layer.cornerRadius = 6; _applyBtn.layer.borderWidth = 1;
|
|
|
|
|
|
_applyBtn.layer.borderColor = [UIColor colorWithWhite:0.85 alpha:1].CGColor;
|
|
|
|
|
|
[self.contentView addSubview:_applyBtn];
|
|
|
|
|
|
[_applyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.right.equalTo(self.contentView).offset(-16);
|
|
|
|
|
|
make.centerY.equalTo(self.contentView);
|
2025-11-25 16:10:08 +08:00
|
|
|
|
make.width.mas_greaterThanOrEqualTo(110);
|
2025-11-04 21:01:46 +08:00
|
|
|
|
make.height.mas_equalTo(34);
|
|
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
|
|
return self;
|
|
|
|
|
|
}
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@interface KBSkinCenterVC () <UITableViewDelegate, UITableViewDataSource>
|
|
|
|
|
|
@property (nonatomic, strong) UITableView *tableView;
|
2025-11-18 20:53:47 +08:00
|
|
|
|
@property (nonatomic, copy) NSArray<NSDictionary *> *skins; // 每个元素即一套皮肤的 JSON(与后端约定格式一致)
|
2025-11-19 20:30:30 +08:00
|
|
|
|
@property (nonatomic, strong) UIButton *resetButton;
|
2025-11-04 21:01:46 +08:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation KBSkinCenterVC
|
|
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
|
[super viewDidLoad];
|
2025-11-18 13:48:22 +08:00
|
|
|
|
// self.title = KBLocalized(@"皮肤中心");
|
2025-11-04 21:01:46 +08:00
|
|
|
|
self.view.backgroundColor = [UIColor whiteColor];
|
2025-11-25 16:53:38 +08:00
|
|
|
|
self.skins = @[
|
|
|
|
|
|
@{
|
|
|
|
|
|
@"id": @"local002",
|
|
|
|
|
|
@"name": KBLocalized(@"本地002皮肤"),
|
|
|
|
|
|
// 关键:zip_url 写成 bundle:// 前缀 + 文件名
|
|
|
|
|
|
@"zip_url": @"bundle://002.zip",
|
2025-11-18 20:53:47 +08:00
|
|
|
|
|
2025-11-25 16:53:38 +08:00
|
|
|
|
// 颜色你可以先随便写一套,或者继承默认
|
|
|
|
|
|
@"background": @"#F5FFE8",
|
|
|
|
|
|
@"key_bg": @"#FFFFFF",
|
|
|
|
|
|
@"key_text": @"#4A4A4A",
|
|
|
|
|
|
@"key_highlight": @"#D9F4C4",
|
|
|
|
|
|
@"accent": @"#A4D68A"
|
|
|
|
|
|
// 不写 key_icons,代码会自动用本地那份映射表
|
|
|
|
|
|
},
|
|
|
|
|
|
@{
|
|
|
|
|
|
@"id": @"remote002",
|
|
|
|
|
|
@"name": KBLocalized(@"远程皮肤"),
|
|
|
|
|
|
// 关键:zip_url 写成 bundle:// 前缀 + 文件名
|
2025-11-25 20:35:08 +08:00
|
|
|
|
@"zip_url": @"https://raw.githubusercontent.com/CoderST/XDCouponAlertView/master/Christmas.zip",
|
2025-11-25 16:53:38 +08:00
|
|
|
|
|
|
|
|
|
|
// // 颜色你可以先随便写一套,或者继承默认
|
2025-11-19 15:39:47 +08:00
|
|
|
|
// @"background": @"#F5FFE8",
|
|
|
|
|
|
// @"key_bg": @"#FFFFFF",
|
|
|
|
|
|
// @"key_text": @"#4A4A4A",
|
|
|
|
|
|
// @"key_highlight": @"#D9F4C4",
|
2025-11-25 16:53:38 +08:00
|
|
|
|
// @"accent": @"#A4D68A"
|
|
|
|
|
|
// 不写 key_icons,代码会自动用本地那份映射表
|
|
|
|
|
|
},
|
2025-11-18 20:53:47 +08:00
|
|
|
|
@{
|
2025-11-25 16:53:38 +08:00
|
|
|
|
@"id": @"圣诞001",
|
|
|
|
|
|
@"name": KBLocalized(@"本地圣诞皮肤"),
|
2025-11-19 15:39:47 +08:00
|
|
|
|
// 关键:zip_url 写成 bundle:// 前缀 + 文件名
|
2025-11-25 16:53:38 +08:00
|
|
|
|
@"zip_url": @"bundle://Christmas.zip",
|
2025-11-19 15:39:47 +08:00
|
|
|
|
|
|
|
|
|
|
// 颜色你可以先随便写一套,或者继承默认
|
2025-11-18 20:53:47 +08:00
|
|
|
|
@"background": @"#F5FFE8",
|
|
|
|
|
|
@"key_bg": @"#FFFFFF",
|
|
|
|
|
|
@"key_text": @"#4A4A4A",
|
|
|
|
|
|
@"key_highlight": @"#D9F4C4",
|
2025-11-19 15:39:47 +08:00
|
|
|
|
@"accent": @"#A4D68A"
|
|
|
|
|
|
// 不写 key_icons,代码会自动用本地那份映射表
|
2025-11-25 16:53:38 +08:00
|
|
|
|
},
|
2025-11-04 21:01:46 +08:00
|
|
|
|
];
|
|
|
|
|
|
|
2025-11-18 13:48:22 +08:00
|
|
|
|
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, KB_NAV_TOTAL_HEIGHT, KB_SCREEN_WIDTH, KB_SCREEN_HEIGHT - KB_NAV_TOTAL_HEIGHT) style:UITableViewStyleInsetGrouped];
|
2025-11-04 21:01:46 +08:00
|
|
|
|
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
|
|
|
self.tableView.delegate = self; self.tableView.dataSource = self;
|
|
|
|
|
|
[self.view addSubview:self.tableView];
|
2025-11-19 20:30:30 +08:00
|
|
|
|
|
|
|
|
|
|
// 底部添加“恢复默认皮肤”测试按钮
|
|
|
|
|
|
UIButton *reset = [UIButton buttonWithType:UIButtonTypeSystem];
|
|
|
|
|
|
[reset setTitle:KBLocalized(@"恢复默认皮肤") forState:UIControlStateNormal];
|
|
|
|
|
|
reset.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
|
|
|
|
|
|
reset.layer.cornerRadius = 8.0;
|
|
|
|
|
|
reset.layer.borderWidth = 1.0;
|
|
|
|
|
|
reset.layer.borderColor = [UIColor colorWithWhite:0.85 alpha:1.0].CGColor;
|
|
|
|
|
|
[reset addTarget:self action:@selector(onResetDefault:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
[self.view addSubview:reset];
|
|
|
|
|
|
self.resetButton = reset;
|
|
|
|
|
|
|
|
|
|
|
|
[reset mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.left.equalTo(self.view).offset(16);
|
|
|
|
|
|
make.right.equalTo(self.view).offset(-16);
|
|
|
|
|
|
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-16);
|
|
|
|
|
|
make.height.mas_equalTo(44);
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
// 让 tableView 的内容区域避免被按钮遮挡
|
|
|
|
|
|
UIEdgeInsets inset = self.tableView.contentInset;
|
|
|
|
|
|
inset.bottom += 44 + 24; // 按钮高度 + 上下间距
|
|
|
|
|
|
self.tableView.contentInset = inset;
|
|
|
|
|
|
self.tableView.scrollIndicatorInsets = inset;
|
2025-11-04 21:01:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - UITableView
|
|
|
|
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.skins.count; }
|
|
|
|
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
static NSString *cid = @"skin.cell";
|
|
|
|
|
|
KBSkinCell *cell = [tableView dequeueReusableCellWithIdentifier:cid];
|
|
|
|
|
|
if (!cell) { cell = [[KBSkinCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cid]; }
|
|
|
|
|
|
NSDictionary *skin = self.skins[indexPath.row];
|
|
|
|
|
|
cell.textLabel.text = skin[@"name"]; cell.detailTextLabel.text = skin[@"id"];
|
|
|
|
|
|
[cell.applyBtn removeTarget:nil action:NULL forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
[cell.applyBtn addTarget:self action:@selector(onApplyBtn:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
cell.applyBtn.tag = indexPath.row;
|
|
|
|
|
|
return cell;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)onApplyBtn:(UIButton *)sender {
|
|
|
|
|
|
NSInteger idx = sender.tag;
|
|
|
|
|
|
if (idx < 0 || idx >= self.skins.count) return;
|
|
|
|
|
|
NSDictionary *skin = self.skins[idx];
|
2025-11-18 20:53:47 +08:00
|
|
|
|
if (!skin) return;
|
2025-11-25 16:53:38 +08:00
|
|
|
|
if (idx == 0) {
|
|
|
|
|
|
[[KBSkinService shared] applySkinWithJSON:skin
|
|
|
|
|
|
fromViewController:self
|
|
|
|
|
|
mode:KBSkinSourceModeLocalBundleZip
|
|
|
|
|
|
completion:nil];
|
|
|
|
|
|
}else if (idx == 1){
|
|
|
|
|
|
[[KBSkinService shared] applySkinWithJSON:skin
|
|
|
|
|
|
fromViewController:self
|
|
|
|
|
|
mode:KBSkinSourceModeRemoteZip
|
|
|
|
|
|
completion:nil];
|
|
|
|
|
|
}else if (idx == 2){
|
|
|
|
|
|
// [[KBSkinService shared] applySkinWithJSON:skin
|
|
|
|
|
|
// fromViewController:self
|
|
|
|
|
|
// mode:KBSkinSourceModeLocalBundleZip
|
|
|
|
|
|
// completion:nil];
|
|
|
|
|
|
static NSString * const kKBBundleSkinId002 = @"bundle_Christmas";
|
|
|
|
|
|
[KBSkinInstallBridge publishBundleSkinRequestWithId:kKBBundleSkinId002
|
|
|
|
|
|
name:@"" ?: kKBBundleSkinId002
|
|
|
|
|
|
zipName:@"Christmas.zip"
|
|
|
|
|
|
iconShortNames:nil];
|
|
|
|
|
|
[KBHUD showInfo:KBLocalized(@"已通知键盘解压,切换到自定义键盘即可生效")];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 21:01:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-19 20:30:30 +08:00
|
|
|
|
- (void)onResetDefault:(UIButton *)sender {
|
|
|
|
|
|
// 不需要皮肤 JSON,传空字典即可
|
|
|
|
|
|
[[KBSkinService shared] applySkinWithJSON:@{}
|
|
|
|
|
|
fromViewController:self
|
|
|
|
|
|
mode:KBSkinSourceModeResetToDefault
|
|
|
|
|
|
completion:nil];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 21:01:46 +08:00
|
|
|
|
@end
|