This commit is contained in:
2025-12-11 19:43:55 +08:00
parent cccced6afa
commit 577b749198
12 changed files with 244 additions and 80 deletions

View File

@@ -12,6 +12,7 @@
#import "KBAPI.h"
//#import <MJExtension/MJExtension.h>
#import "KBMyMainModel.h"
#import "KBSkinInstallBridge.h"
NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNotification";
@@ -86,36 +87,26 @@ NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNo
}];
}
- (void)fetchPurchasedThemesWithCompletion:(KBMyPurchasedThemesCompletion)completion {
[[KBNetworkManager shared] GET:API_THEME_PURCHASED
parameters:nil
headers:nil
autoShowBusinessError:NO
completion:^(NSDictionary *jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
NSString *msg = KBBizMessageFromJSONObject(jsonOrData) ?: error.localizedDescription ?: KBLocalized(@"Network error");
[KBHUD showInfo:msg];
if (completion) completion(nil, error);
return;
- (void)fetchDownloadedThemesWithCompletion:(KBMyPurchasedThemesCompletion)completion {
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
NSArray<KBSkinDownloadRecord *> *records = [KBSkinInstallBridge installedSkinRecords];
NSMutableArray<KBMyTheme *> *themes = [NSMutableArray arrayWithCapacity:records.count];
for (KBSkinDownloadRecord *record in records) {
KBMyTheme *theme = [KBMyTheme new];
theme.themeId = record.skinId;
theme.themeName = record.name;
theme.themeDownload = record.zipURL;
theme.themePreviewImageUrl = record.previewImage;
[themes addObject:theme];
}
id dataObj = jsonOrData[KBData] ?: jsonOrData[@"data"];
if (![dataObj isKindOfClass:[NSArray class]]) {
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain
code:KBNetworkErrorInvalidResponse
userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid response")}];
[KBHUD showInfo:e.localizedDescription];
if (completion) completion(nil, e);
return;
}
NSArray<KBMyTheme *> *themes = [KBMyTheme mj_objectArrayWithKeyValuesArray:(NSArray *)dataObj];
if (completion) completion(themes, nil);
}];
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) completion(themes.copy, nil);
});
});
}
- (void)deletePurchasedThemesWithThemeIds:(NSArray<NSNumber *> *)themeIds
completion:(KBDeleteThemesCompletion)completion {
- (void)deleteDownloadedThemesWithIds:(NSArray<NSString *> *)themeIds
completion:(KBDeleteThemesCompletion)completion {
if (themeIds.count == 0) {
if (completion) {
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain
@@ -126,18 +117,22 @@ NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNo
return;
}
NSDictionary *params = @{@"themeIds": themeIds};
[[KBNetworkManager shared] POST:API_THEME_BATCH_DELETE
jsonBody:params
headers:nil
autoShowBusinessError:YES
completion:^(NSDictionary * _Nullable json,
NSURLResponse * _Nullable response,
NSError * _Nullable error) {
if (completion) {
completion(error == nil, error);
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;
}
}
}];
BOOL success = (lastError == nil);
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) {
completion(success, lastError);
}
});
});
}
///