Files
keyboard/keyBoard/Class/Home/VC/FunctionTest/KBSkinCenterVC.m

181 lines
7.7 KiB
Mathematica
Raw Normal View History

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:// +
@"zip_url": @"",
// // 便
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