This commit is contained in:
2025-12-11 16:39:22 +08:00
parent e4442afe72
commit 7f90240731
6 changed files with 207 additions and 32 deletions

View File

@@ -13,6 +13,8 @@
#import "KBSkinBottomActionView.h"
#import "KBShopVM.h"
#import "KBShopThemeTagModel.h"
#import "KBHUD.h"
#import "KBSkinService.h"
static NSString * const kHeaderCellId = @"kHeaderCellId";
static NSString * const kTagsContainerCellId = @"kTagsContainerCellId";
@@ -34,6 +36,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
@property (nonatomic, copy) NSArray<NSDictionary *> *gridData; //
@property (nonatomic, strong) KBShopVM *shopVM;
@property (nonatomic, strong, nullable) KBShopThemeDetailModel *detailModel;
@property (nonatomic, assign) BOOL isProcessingAction;
@end
@implementation KBSkinDetailVC
@@ -69,6 +72,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
make.bottom.equalTo(self.bottomBar.mas_top).offset(-10);
}];
[self updateBottomBarAppearance];
[self fetchThemeDetailIfNeeded];
}
@@ -208,7 +212,87 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
#pragma mark - Actions
- (void)handleDownloadAction {
// /
if (self.isProcessingAction) { return; }
if (self.themeId.length == 0) {
[KBHUD showInfo:KBLocalized(@"主题信息缺失")];
return;
}
if (!self.detailModel) {
[KBHUD showInfo:KBLocalized(@"正在加载主题详情")];
return;
}
if (self.detailModel.isPurchased) {
[self requestDownload];
} else {
[self purchaseCurrentTheme];
}
}
- (void)purchaseCurrentTheme {
if (self.isProcessingAction) { return; }
self.isProcessingAction = YES;
[KBHUD show];
__weak typeof(self) weakSelf = self;
[self.shopVM purchaseThemeWithId:self.themeId completion:^(BOOL success, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.isProcessingAction = NO;
[KBHUD dismiss];
if (error || !success) {
NSString *msg = error.localizedDescription ?: KBLocalized(@"购买失败");
[KBHUD showInfo:msg];
return;
}
weakSelf.detailModel.isPurchased = YES;
[weakSelf updateBottomBarAppearance];
[weakSelf requestDownload];
});
}];
}
- (void)requestDownload {
if (self.isProcessingAction) { return; }
self.isProcessingAction = YES;
[KBHUD show];
NSMutableDictionary *skin = [NSMutableDictionary dictionary];
if (!skin[@"id"] && self.detailModel.themeId) {
skin[@"id"] = self.detailModel.themeId;
}
if (!skin[@"name"] && self.detailModel.themeName) {
skin[@"name"] = self.detailModel.themeName;
}
if (!skin[@"themeDownloadUrl"]) {
[KBHUD showInfo:KBLocalized(@"缺少下载地址")];
return;
}
skin[@"themeDownloadUrl"] = self.detailModel.themeDownloadUrl;
[[KBSkinService shared] applySkinWithJSON:skin
fromViewController:self
mode:KBSkinSourceModeRemoteZip
completion:^(BOOL success) {
if (success) {
[KBHUD showSuccess:KBLocalized(@"已开始下载")];
} else {
[KBHUD showInfo:KBLocalized(@"下载失败")];
}
}];
}
- (void)updateBottomBarAppearance {
BOOL purchased = self.detailModel.isPurchased;
if (purchased) {
self.bottomBar.titleText = KBLocalized(@"Download again");
self.bottomBar.showsPrice = NO;
} else {
NSString *price = self.detailModel ? [NSString stringWithFormat:@"%.2f", self.detailModel.themePrice] : @"0";
self.bottomBar.titleText = KBLocalized(@"Download");
self.bottomBar.priceText = price;
self.bottomBar.showsPrice = YES;
UIImage *coin = [UIImage imageNamed:@"shop_jb_icon"];
if (coin) {
self.bottomBar.iconImage = coin;
}
}
}
- (void)fetchThemeDetailIfNeeded {
@@ -235,6 +319,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) {
}
}
weakSelf.tags = tagNames.copy;
[weakSelf updateBottomBarAppearance];
[weakSelf.collectionView reloadData];
});
}];