This commit is contained in:
2025-12-11 18:36:14 +08:00
parent 14637a21ad
commit cccced6afa
5 changed files with 92 additions and 13 deletions

View File

@@ -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;
// UI
[self.collectionView performBatchUpdates:^{
NSMutableIndexSet *set = [NSMutableIndexSet indexSet];
for (NSIndexPath *ip in selected) { [set addIndex:ip.item]; }
[self.data removeObjectsAtIndexes:set];
[self.collectionView deleteItemsAtIndexPaths:selected];
} completion:^(BOOL finished) {
[self updateBottomUI];
// 0
[self.collectionView kb_endLoadingForEmpty];
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
[weakSelf.collectionView performBatchUpdates:^{
NSMutableIndexSet *set = [NSMutableIndexSet indexSet];
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) {
[weakSelf updateBottomUI];
// 0
[weakSelf.collectionView kb_endLoadingForEmpty];
}];
});
}];
}