1
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
#define API_THEME_LIST_ALL_STYLES @"/themes/listAllStyles" // 查询所有主题风格
|
||||
#define API_THEME_LIST_BY_STYLE @"/themes/listByStyle" // 按风格查询主题列表
|
||||
#define API_THEME_PURCHASED @"/themes/purchased" // 查询已购买主题
|
||||
#define API_THEME_BATCH_DELETE @"/user-themes/batch-delete" // 批量删除用户主题
|
||||
#define API_WALLET_BALANCE @"/wallet/balance" // 查询钱包余额
|
||||
#define API_THEME_DETAIL @"/themes/detail" // 查询主题详情
|
||||
#define API_THEME_PURCHASE @"/themes/purchase" // 购买主题
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#import "HomeMainVC.h"
|
||||
#import "MyVC.h"
|
||||
#import "KBShopVC.h"
|
||||
#import "KBCommunityVC.h"
|
||||
//#import "KBCommunityVC.h"
|
||||
|
||||
#import "BaseNavigationController.h"
|
||||
#import "KBAuthManager.h"
|
||||
|
||||
@@ -151,19 +151,67 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
|
||||
|
||||
- (void)onDelete {
|
||||
// 根据选中项删除
|
||||
NSArray<NSIndexPath *> *selected = [[self.collectionView indexPathsForSelectedItems] sortedArrayUsingSelector:@selector(compare:)];
|
||||
if (selected.count == 0) return;
|
||||
NSArray<NSIndexPath *> *selectedIndexPaths = [[self.collectionView indexPathsForSelectedItems] sortedArrayUsingSelector:@selector(compare:)];
|
||||
if (selectedIndexPaths.count == 0) return;
|
||||
|
||||
NSMutableArray<NSNumber *> *themeIds = [NSMutableArray arrayWithCapacity:selectedIndexPaths.count];
|
||||
for (NSIndexPath *ip in selectedIndexPaths) {
|
||||
if (ip.item >= self.data.count) { continue; }
|
||||
KBMyTheme *theme = self.data[ip.item];
|
||||
id themeIdValue = theme.themeId;
|
||||
NSNumber *numberId = nil;
|
||||
if ([themeIdValue isKindOfClass:[NSNumber class]]) {
|
||||
numberId = (NSNumber *)themeIdValue;
|
||||
} else if ([themeIdValue isKindOfClass:[NSString class]]) {
|
||||
NSString *idString = (NSString *)themeIdValue;
|
||||
if (idString.length > 0) {
|
||||
static NSCharacterSet *nonDigitSet;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
nonDigitSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
|
||||
});
|
||||
if ([idString rangeOfCharacterFromSet:nonDigitSet].location == NSNotFound) {
|
||||
numberId = @([idString longLongValue]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (numberId) {
|
||||
[themeIds addObject:numberId];
|
||||
}
|
||||
}
|
||||
|
||||
if (themeIds.count == 0) {
|
||||
[KBHUD showInfo:KBLocalized(@"Invalid parameter")];
|
||||
return;
|
||||
}
|
||||
|
||||
[KBHUD show];
|
||||
KBWeakSelf
|
||||
[self.viewModel deletePurchasedThemesWithThemeIds:themeIds
|
||||
completion:^(BOOL success, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[KBHUD dismiss];
|
||||
if (!success) {
|
||||
NSString *msg = error.localizedDescription ?: KBLocalized(@"Network error");
|
||||
[KBHUD showInfo:msg];
|
||||
return;
|
||||
}
|
||||
// 批量更新,先改数据,再删 UI
|
||||
[self.collectionView performBatchUpdates:^{
|
||||
[weakSelf.collectionView performBatchUpdates:^{
|
||||
NSMutableIndexSet *set = [NSMutableIndexSet indexSet];
|
||||
for (NSIndexPath *ip in selected) { [set addIndex:ip.item]; }
|
||||
[self.data removeObjectsAtIndexes:set];
|
||||
[self.collectionView deleteItemsAtIndexPaths:selected];
|
||||
for (NSIndexPath *ip in selectedIndexPaths) {
|
||||
if (ip.item < weakSelf.data.count) {
|
||||
[set addIndex:ip.item];
|
||||
}
|
||||
}
|
||||
[weakSelf.data removeObjectsAtIndexes:set];
|
||||
[weakSelf.collectionView deleteItemsAtIndexPaths:selectedIndexPaths];
|
||||
} completion:^(BOOL finished) {
|
||||
[self updateBottomUI];
|
||||
[weakSelf updateBottomUI];
|
||||
// 根据当前数据源显隐空视图(删除到 0 条时应显示空态)
|
||||
[self.collectionView kb_endLoadingForEmpty];
|
||||
[weakSelf.collectionView kb_endLoadingForEmpty];
|
||||
}];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ typedef void(^KBUpdateUserInfoCompletion)(BOOL success, NSError * _Nullable erro
|
||||
typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable error);
|
||||
typedef void(^KBDeleteUserCharacterCompletion)(BOOL success, NSError * _Nullable error);
|
||||
typedef void(^KBMyPurchasedThemesCompletion)(NSArray<KBMyTheme *> *_Nullable themes, NSError *_Nullable error);
|
||||
typedef void(^KBDeleteThemesCompletion)(BOOL success, NSError *_Nullable error);
|
||||
|
||||
@interface KBMyVM : NSObject
|
||||
|
||||
@@ -34,6 +35,9 @@ typedef void(^KBMyPurchasedThemesCompletion)(NSArray<KBMyTheme *> *_Nullable the
|
||||
- (void)fetchCharacterListByUserWithCompletion:(KBCharacterListCompletion)completion;
|
||||
/// 已购买主题列表(/themes/purchased)
|
||||
- (void)fetchPurchasedThemesWithCompletion:(KBMyPurchasedThemesCompletion)completion;
|
||||
/// 批量删除主题(/user-themes/batch-delete)
|
||||
- (void)deletePurchasedThemesWithThemeIds:(NSArray<NSNumber *> *)themeIds
|
||||
completion:(KBDeleteThemesCompletion)completion;
|
||||
/// 更新用户人设排序
|
||||
- (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray
|
||||
completion:(KBUpdateCharacterSortCompletion)completion;
|
||||
|
||||
@@ -114,6 +114,32 @@ NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNo
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)deletePurchasedThemesWithThemeIds:(NSArray<NSNumber *> *)themeIds
|
||||
completion:(KBDeleteThemesCompletion)completion {
|
||||
if (themeIds.count == 0) {
|
||||
if (completion) {
|
||||
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain
|
||||
code:KBNetworkErrorInvalidResponse
|
||||
userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid parameter")}];
|
||||
completion(NO, e);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
/// 更新用户人设排序
|
||||
- (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray
|
||||
completion:(KBUpdateCharacterSortCompletion)completion {
|
||||
|
||||
Reference in New Issue
Block a user