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