Files
peko-ios/YuMi/Modules/ShoppingMall/ShoppingMallViewController.m
2024-11-15 18:17:15 +08:00

139 lines
4.4 KiB
Objective-C

//
// ShoppingMallViewController.m
// YuMi
//
// Created by P on 2024/11/13.
//
#import "ShoppingMallViewController.h"
#import <SVGA.h>
#import <QGVAPWrapView.h>
#import "ShoppingMallDataPresent.h"
#import "ShoppingMallCategoryListView.h"
@interface ShoppingMallViewController ()
@property (nonatomic, strong) UIView *playEffectMask;
@property (nonatomic, strong) VAPView *mp4Effect;
@property (nonatomic, strong) SVGAImageView *svgaEffect;
@end
@implementation ShoppingMallViewController
- (ShoppingMallDataPresent *)createPresenter {
return [[ShoppingMallDataPresent alloc] init];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = UIColorFromRGB(0x02061D);
UIImageView *topBG = [[UIImageView alloc] initWithImage:kImage(@"mall_top_bg")];
[self.view addSubview:topBG];
[topBG mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(200));
}];
NSInteger top = kNavigationHeight + 56;
ShoppingMallCategoryListView *listView = [[ShoppingMallCategoryListView alloc] initWithFrame:CGRectMake(0, top, KScreenWidth, KScreenHeight - top)];
// 设置数据请求回调
@kWeakify(self);
listView.fetchDataForPage = ^(NSInteger pageIndex, FetchDataCompletion completion) {
// 模拟网络请求或 API 数据请求
@kStrongify(self);
[self fetchDataForPage:pageIndex completion:completion];
};
listView.didTapItemPlay = ^(NSString * _Nonnull resourcePath) {
@kStrongify(self);
[self playItemEffect:resourcePath];
};
[self.view addSubview:listView];
listView.items = @[@{YMLocalizedString(@"XPMineDressUpViewController2") : @1}, // 座驾
@{YMLocalizedString(@"XPMineDressUpViewController1") : @0}, // 头饰
@{YMLocalizedString(@"XPMineDressUpViewController3") : @2}, // 铭牌
@{YMLocalizedString(@"XPMineDressUpViewController4") : @3}, // 资料卡
@{YMLocalizedString(@"XPMineDressUpViewController5") : @4} // 聊天气泡
];
}
- (void)fetchDataForPage:(NSInteger)pageIndex completion:(FetchDataCompletion)completion {
[self.presenter loadCategoryItems:pageIndex success:^(NSArray <DressUpShopModel *>* array) {
if (completion) {
completion(array);
}
} failure:^(NSError * _Nonnull error) {
// TODO: 增加错误处理
}];
}
- (void)playItemEffect:(NSString *)path {
if ([path.lowercaseString hasSuffix:@"svga"]) {
@kWeakify(self);
SVGAParser *p = [[SVGAParser alloc] init];
[p parseWithURL:[NSURL URLWithString:path]
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
@kStrongify(self);
self.svgaEffect.hidden = NO;
self.svgaEffect.videoItem = videoItem;
[self.svgaEffect startAnimation];
} failureBlock:^(NSError * _Nullable error) {
}];
} else if ([path.lowercaseString hasSuffix:@"mp4"]) {
}
}
- (void)stopItemSVGAEffect {
[self.svgaEffect stopAnimation];
self.svgaEffect.hidden = YES;
self.playEffectMask.hidden = YES;
}
#pragma mark -
- (UIView *)playEffectMask {
if (!_playEffectMask) {
_playEffectMask = [[UIView alloc] initWithFrame:self.view.bounds];
_playEffectMask.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5f];
}
return _playEffectMask;
}
- (SVGAImageView *)svgaEffect {
if (!_svgaEffect) {
_svgaEffect = [[SVGAImageView alloc] init];
_svgaEffect.contentMode = UIViewContentModeScaleAspectFit;
_svgaEffect.autoPlay = YES;
_svgaEffect.loops = 0;
_svgaEffect.clearsAfterStop = YES;
_svgaEffect.hidden = YES;
if (!_playEffectMask) {
[self.view addSubview:self.playEffectMask];
}
[self.view addSubview:_svgaEffect];
[_svgaEffect mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.leading.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(KScreenHeight - 100);
}];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stopItemSVGAEffect)];
[_svgaEffect addGestureRecognizer:tap];
}
return _svgaEffect;
}
@end