This commit is contained in:
2025-12-11 13:40:32 +08:00
parent d348b35984
commit 45695364e9
11 changed files with 123 additions and 29 deletions

View File

@@ -11,6 +11,9 @@
#import "UIScrollView+KBEmptyView.h" // LYEmptyView
#import "MySkinCell.h"
#import "KBMyVM.h"
#import "KBMyTheme.h"
#import "KBHUD.h"
static NSString * const kMySkinCellId = @"kMySkinCellId";
@@ -20,8 +23,8 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
@property (nonatomic, strong) UILabel *selectedLabel; //
@property (nonatomic, strong) UIButton *deleteButton; //
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *data; //
@property (nonatomic, assign) NSInteger loadCount; // /
@property (nonatomic, strong) NSMutableArray<KBMyTheme *> *data; //
@property (nonatomic, strong) KBMyVM *viewModel;
@property (nonatomic, assign, getter=isEditingMode) BOOL editingMode; //
@end
@@ -62,9 +65,9 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
// LYEmptyView +
KBWeakSelf
[self.collectionView kb_makeDefaultEmptyViewWithImage:nil
title:KBLocalized(@"No skins yet")
title:KBLocalized(@"No data")
detail:KBLocalized(@"Pull down to refresh")
buttonTitle:KBLocalized(@"Retry")
buttonTitle:KBLocalized(@"")
tapHandler:nil
buttonHandler:^{ [weakSelf.collectionView.mj_header beginRefreshing]; }];
[self.collectionView kb_setLYAutoShowEnabled:NO]; //
@@ -73,7 +76,7 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
[self.collectionView kb_endLoadingForEmpty];
// +
self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(fetchData)];
self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(fetchPurchasedThemes)];
//
[self.collectionView.mj_header beginRefreshing];
@@ -82,25 +85,25 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
self.bottomView.hidden = YES;
}
#pragma mark - Data
- (void)fetchData {
// 1.0s
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.loadCount += 1;
// /
[self.data removeAllObjects];
if (self.loadCount % 2 == 0) {
for (int i = 0; i < 8; i++) {
[self.data addObject:@{ @"title": @"Dopamine" }];
- (void)fetchPurchasedThemes {
KBWeakSelf
[self.viewModel fetchPurchasedThemesWithCompletion:^(NSArray<KBMyTheme *> * _Nullable themes, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if ([weakSelf.collectionView.mj_header isRefreshing]) {
[weakSelf.collectionView.mj_header endRefreshing];
}
}
[self.collectionView reloadData];
[self.collectionView kb_endLoadingForEmpty]; // / emptyView
[self.collectionView.mj_header endRefreshing];
});
if (error) {
[weakSelf.collectionView kb_endLoadingForEmpty];
return;
}
[weakSelf.data removeAllObjects];
if (themes.count > 0) {
[weakSelf.data addObjectsFromArray:themes];
}
[weakSelf.collectionView reloadData];
[weakSelf.collectionView kb_endLoadingForEmpty];
});
}];
}
#pragma mark - Actions
@@ -190,8 +193,8 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MySkinCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kMySkinCellId forIndexPath:indexPath];
NSDictionary *d = self.data[indexPath.item];
[cell configWithTitle:d[@"title"] image:nil];
KBMyTheme *theme = self.data[indexPath.item];
[cell configWithTitle:theme.themeName image:nil];
cell.editing = self.isEditingMode; //
//
BOOL selected = [[collectionView indexPathsForSelectedItems] containsObject:indexPath];
@@ -306,4 +309,11 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
return _deleteButton;
}
- (KBMyVM *)viewModel {
if (!_viewModel) {
_viewModel = [[KBMyVM alloc] init];
}
return _viewModel;
}
@end