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

@@ -76,7 +76,7 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
[self.collectionView kb_endLoadingForEmpty];
// +
self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(fetchPurchasedThemes)];
self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(fetchDownloadedThemes)];
//
[self.collectionView.mj_header beginRefreshing];
@@ -85,9 +85,9 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
self.bottomView.hidden = YES;
}
- (void)fetchPurchasedThemes {
- (void)fetchDownloadedThemes {
KBWeakSelf
[self.viewModel fetchPurchasedThemesWithCompletion:^(NSArray<KBMyTheme *> * _Nullable themes, NSError * _Nullable error) {
[self.viewModel fetchDownloadedThemesWithCompletion:^(NSArray<KBMyTheme *> * _Nullable themes, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if ([weakSelf.collectionView.mj_header isRefreshing]) {
[weakSelf.collectionView.mj_header endRefreshing];
@@ -154,29 +154,19 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
NSArray<NSIndexPath *> *selectedIndexPaths = [[self.collectionView indexPathsForSelectedItems] sortedArrayUsingSelector:@selector(compare:)];
if (selectedIndexPaths.count == 0) return;
NSMutableArray<NSNumber *> *themeIds = [NSMutableArray arrayWithCapacity:selectedIndexPaths.count];
NSMutableArray<NSString *> *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]);
}
}
NSString *stringId = nil;
if ([themeIdValue isKindOfClass:[NSString class]]) {
stringId = [(NSString *)themeIdValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
} else if ([themeIdValue respondsToSelector:@selector(stringValue)]) {
stringId = [[themeIdValue stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
if (numberId) {
[themeIds addObject:numberId];
if (stringId.length > 0) {
[themeIds addObject:stringId];
}
}
@@ -187,12 +177,12 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
[KBHUD show];
KBWeakSelf
[self.viewModel deletePurchasedThemesWithThemeIds:themeIds
completion:^(BOOL success, NSError * _Nullable error) {
[self.viewModel deleteDownloadedThemesWithIds:themeIds
completion:^(BOOL success, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
[KBHUD dismiss];
if (!success) {
NSString *msg = error.localizedDescription ?: KBLocalized(@"Network error");
NSString *msg = error.localizedDescription ?: KBLocalized(@"Operation failed");
[KBHUD showInfo:msg];
return;
}
@@ -242,7 +232,7 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MySkinCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kMySkinCellId forIndexPath:indexPath];
KBMyTheme *theme = self.data[indexPath.item];
[cell configWithTitle:theme.themeName image:nil];
[cell configWithTitle:theme.themeName imageURL:theme.themePreviewImageUrl];
cell.editing = self.isEditingMode; //
//
BOOL selected = [[collectionView indexPathsForSelectedItems] containsObject:indexPath];