This commit is contained in:
2025-12-11 15:19:23 +08:00
parent 04c7d19c37
commit 4fd0a52a36
9 changed files with 125 additions and 16 deletions

View File

@@ -12,6 +12,7 @@
#import "KBSkinSectionTitleCell.h"
#import "KBSkinBottomActionView.h"
#import "KBShopVM.h"
#import "KBShopThemeTagModel.h"
static NSString * const kHeaderCellId = @"kHeaderCellId";
static NSString * const kTagsContainerCellId = @"kTagsContainerCellId";
@@ -32,6 +33,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
@property (nonatomic, copy) NSArray<NSString *> *tags; //
@property (nonatomic, copy) NSArray<NSDictionary *> *gridData; //
@property (nonatomic, strong) KBShopVM *shopVM;
@property (nonatomic, strong, nullable) KBShopThemeDetailModel *detailModel;
@end
@implementation KBSkinDetailVC
@@ -40,8 +42,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//
self.tags = @[ @"Cute", @"Fresh", @"Cute", @"Fresh", @"Cute", @"Fresh" ];
self.tags = @[];
self.gridData = @[
@{ @"title": @"Dopamine" }, @{ @"title": @"Dopamine" },
@{ @"title": @"Dopamine" }, @{ @"title": @"Dopamine" },
@@ -80,7 +81,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
switch (section) {
case KBSkinDetailSectionHeader: return 1; //
case KBSkinDetailSectionTags: return 1; //
case KBSkinDetailSectionTags: return self.tags.count > 0 ? 1 : 0;
case KBSkinDetailSectionTitle: return 1; //
case KBSkinDetailSectionGrid: return self.gridData.count; // 2
}
@@ -91,7 +92,10 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
switch (indexPath.section) {
case KBSkinDetailSectionHeader: {
KBSkinDetailHeaderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kHeaderCellId forIndexPath:indexPath];
[cell configWithTitle:@"Dopamine" right:@"Download: 1 Million"];
NSString *title = self.detailModel.themeName.length ? self.detailModel.themeName : @"Dopamine";
NSString *download = self.detailModel.themeDownload.length ? self.detailModel.themeDownload : @"0";
NSString *right = [NSString stringWithFormat:@"%@: %@", KBLocalized(@"Download"), download];
[cell configWithTitle:title right:right];
return cell;
}
case KBSkinDetailSectionTags: {
@@ -128,7 +132,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
}
case KBSkinDetailSectionTags: {
CGFloat h = [KBSkinTagsContainerCell heightForTags:self.tags width:W];
return CGSizeMake(contentW, 25);
return CGSizeMake(contentW, MAX(h, 0.1));
}
case KBSkinDetailSectionTitle: {
return CGSizeMake(contentW, 44);
@@ -216,14 +220,24 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
return;
}
__weak typeof(self) weakSelf = self;
[self.shopVM fetchThemeDetailWithId:self.themeId completion:^(NSDictionary * _Nullable json, NSError * _Nullable error) {
[self.shopVM fetchThemeDetailWithId:self.themeId completion:^(KBShopThemeDetailModel * _Nullable detail, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
NSLog(@"[KBSkinDetailVC] fetch detail failed: %@", error);
return;
}
NSLog(@"[KBSkinDetailVC] theme detail json: %@", json);
// TODO: parse json into models once the structure is finalized.
if (!detail) {
NSLog(@"[KBSkinDetailVC] theme detail is empty");
return;
}
weakSelf.detailModel = detail;
NSMutableArray<NSString *> *tagNames = [NSMutableArray array];
for (KBShopThemeTagModel *tag in detail.themeTag) {
if (tag.label.length) {
[tagNames addObject:tag.label];
}
}
weakSelf.tags = tagNames.copy;
[weakSelf.collectionView reloadData];
});
}];