2
This commit is contained in:
@@ -33,11 +33,11 @@ typedef void(^KBDeleteThemesCompletion)(BOOL success, NSError *_Nullable error);
|
||||
|
||||
/// 用户人设列表(/character/listByUser)
|
||||
- (void)fetchCharacterListByUserWithCompletion:(KBCharacterListCompletion)completion;
|
||||
/// 已购买主题列表(/themes/purchased)
|
||||
- (void)fetchPurchasedThemesWithCompletion:(KBMyPurchasedThemesCompletion)completion;
|
||||
/// 批量删除主题(/user-themes/batch-delete)
|
||||
- (void)deletePurchasedThemesWithThemeIds:(NSArray<NSNumber *> *)themeIds
|
||||
completion:(KBDeleteThemesCompletion)completion;
|
||||
/// 本地已下载主题列表
|
||||
- (void)fetchDownloadedThemesWithCompletion:(KBMyPurchasedThemesCompletion)completion;
|
||||
/// 删除本地主题资源
|
||||
- (void)deleteDownloadedThemesWithIds:(NSArray<NSString *> *)themeIds
|
||||
completion:(KBDeleteThemesCompletion)completion;
|
||||
/// 更新用户人设排序
|
||||
- (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray
|
||||
completion:(KBUpdateCharacterSortCompletion)completion;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// 更新用户人设排序
|
||||
|
||||
Reference in New Issue
Block a user