2
This commit is contained in:
@@ -120,7 +120,7 @@
|
||||
}
|
||||
|
||||
// “我的” tab 默认为第 4 个(索引 3),未登录时先跳转登录页
|
||||
if (index == 2 && ![KBUserSessionManager shared].isLoggedIn) {
|
||||
if ((index == 1 || index == 2) && ![KBUserSessionManager shared].isLoggedIn) {
|
||||
[[KBUserSessionManager shared] goLoginVC];
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,12 @@ typedef NS_ENUM(NSUInteger, KBSkinSourceMode) {
|
||||
mode:(KBSkinSourceMode)mode
|
||||
completion:(nullable KBSkinApplyCompletion)completion;
|
||||
|
||||
typedef void(^KBSkinDeleteCompletion)(BOOL success, NSError *_Nullable error);
|
||||
|
||||
/// 删除本地皮肤资源,并在必要时自动切换到其他已下载皮肤或默认皮肤。
|
||||
- (void)deleteSkinsWithIds:(NSArray<NSString *> *)skinIds
|
||||
completion:(nullable KBSkinDeleteCompletion)completion;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -279,10 +279,102 @@
|
||||
[KBSkinInstallBridge recordInstalledSkinWithId:skinId
|
||||
name:name
|
||||
preview:preview
|
||||
zipURL:zipName];
|
||||
zipURL:zipName
|
||||
themeJSON:themeJSON];
|
||||
}
|
||||
[KBHUD showInfo:(ok ? KBLocalized(@"已应用,切到键盘查看") : KBLocalized(@"应用皮肤失败"))];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)deleteSkinsWithIds:(NSArray<NSString *> *)skinIds
|
||||
completion:(KBSkinDeleteCompletion)completion {
|
||||
if (skinIds.count == 0) {
|
||||
if (completion) {
|
||||
NSError *error = [NSError errorWithDomain:KBSkinBridgeErrorDomain
|
||||
code:KBSkinBridgeErrorInvalidPayload
|
||||
userInfo:@{NSLocalizedDescriptionKey: @"Invalid skin ids"}];
|
||||
completion(NO, error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
|
||||
NSArray<KBSkinDownloadRecord *> *beforeDesc = [KBSkinInstallBridge installedSkinRecords];
|
||||
NSArray<KBSkinDownloadRecord *> *beforeAsc = beforeDesc.count > 0 ? [[[beforeDesc reverseObjectEnumerator] allObjects] copy] : @[];
|
||||
NSString *currentId = [KBSkinManager shared].current.skinId ?: @"";
|
||||
NSSet<NSString *> *deleteSet = [NSSet setWithArray:skinIds];
|
||||
NSError *lastError = nil;
|
||||
for (NSString *skinId in skinIds) {
|
||||
if (skinId.length == 0) { continue; }
|
||||
BOOL ok = [KBSkinInstallBridge removeInstalledSkinWithId:skinId error:&lastError];
|
||||
if (!ok) { break; }
|
||||
}
|
||||
if (!lastError && [deleteSet containsObject:currentId]) {
|
||||
NSArray<KBSkinDownloadRecord *> *afterDesc = [KBSkinInstallBridge installedSkinRecords];
|
||||
NSArray<KBSkinDownloadRecord *> *afterAsc = afterDesc.count > 0 ? [[[afterDesc reverseObjectEnumerator] allObjects] copy] : @[];
|
||||
NSString *fallbackId = [self kb_fallbackSkinIdForCurrent:currentId
|
||||
orderAsc:beforeAsc
|
||||
deletedSet:deleteSet
|
||||
remainingAsc:afterAsc];
|
||||
if (fallbackId.length > 0) {
|
||||
BOOL ok = [KBSkinInstallBridge applyInstalledSkinWithId:fallbackId error:&lastError];
|
||||
if (!ok) {
|
||||
if (lastError == nil) {
|
||||
lastError = [NSError errorWithDomain:KBSkinBridgeErrorDomain
|
||||
code:KBSkinBridgeErrorApplyFailed
|
||||
userInfo:nil];
|
||||
}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[KBSkinManager shared] resetToDefault];
|
||||
});
|
||||
}
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[KBSkinManager shared] resetToDefault];
|
||||
});
|
||||
}
|
||||
}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (completion) completion(lastError == nil, lastError);
|
||||
if (lastError) {
|
||||
NSLog(@"[KBSkinService] delete skins failed: %@", lastError);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
- (NSString *)kb_fallbackSkinIdForCurrent:(NSString *)currentId
|
||||
orderAsc:(NSArray<KBSkinDownloadRecord *> *)orderAsc
|
||||
deletedSet:(NSSet<NSString *> *)deletedSet
|
||||
remainingAsc:(NSArray<KBSkinDownloadRecord *> *)remainingAsc {
|
||||
if (currentId.length == 0) { return nil; }
|
||||
NSInteger idx = NSNotFound;
|
||||
for (NSInteger i = 0; i < (NSInteger)orderAsc.count; i++) {
|
||||
KBSkinDownloadRecord *record = orderAsc[i];
|
||||
if ([record.skinId isEqualToString:currentId]) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (idx != NSNotFound) {
|
||||
for (NSInteger left = idx - 1; left >= 0; left--) {
|
||||
KBSkinDownloadRecord *candidate = orderAsc[left];
|
||||
if (candidate.skinId.length > 0 && ![deletedSet containsObject:candidate.skinId]) {
|
||||
return candidate.skinId;
|
||||
}
|
||||
}
|
||||
for (NSInteger right = idx + 1; right < (NSInteger)orderAsc.count; right++) {
|
||||
KBSkinDownloadRecord *candidate = orderAsc[right];
|
||||
if (candidate.skinId.length > 0 && ![deletedSet containsObject:candidate.skinId]) {
|
||||
return candidate.skinId;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (KBSkinDownloadRecord *record in remainingAsc) {
|
||||
if (record.skinId.length > 0) {
|
||||
return record.skinId;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -126,8 +126,7 @@
|
||||
- (void)configWithTitle:(NSString *)title imageURL:(NSString *)imageURL {
|
||||
self.titleLabel.text = title.length ? title : @"Dopamine";
|
||||
self.coverView.backgroundColor = [UIColor colorWithWhite:0.92 alpha:1.0];
|
||||
UIImage *placeholder = [UIImage imageNamed:@"my_skin_placeholder"];
|
||||
[self.coverView kb_setImageURL:imageURL placeholder:placeholder];
|
||||
[self.coverView kb_setImageURL:imageURL placeholder:nil];
|
||||
}
|
||||
|
||||
- (void)setEditing:(BOOL)editing {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#import "KBAPI.h"
|
||||
//#import <MJExtension/MJExtension.h>
|
||||
#import "KBMyMainModel.h"
|
||||
#import "KBSkinService.h"
|
||||
#import "KBSkinInstallBridge.h"
|
||||
|
||||
NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNotification";
|
||||
@@ -117,22 +118,12 @@ NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNo
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
|
||||
NSError *lastError = nil;
|
||||
for (NSString *skinId in themeIds) {
|
||||
if (skinId.length == 0) { continue; }
|
||||
BOOL ok = [KBSkinInstallBridge removeInstalledSkinWithId:skinId error:&lastError];
|
||||
if (!ok) {
|
||||
break;
|
||||
}
|
||||
[[KBSkinService shared] deleteSkinsWithIds:themeIds
|
||||
completion:^(BOOL success, NSError * _Nullable error) {
|
||||
if (completion) {
|
||||
completion(success, error);
|
||||
}
|
||||
BOOL success = (lastError == nil);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (completion) {
|
||||
completion(success, lastError);
|
||||
}
|
||||
});
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
/// 更新用户人设排序
|
||||
|
||||
Reference in New Issue
Block a user