2
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user