Files
peko-ios/YuMi/Modules/YMMine/View/Medals/MedalsWearingViewController.m

238 lines
8.4 KiB
Objective-C

//
// MedalsWearingViewController.m
// YuMi
//
// Created by P on 2025/6/19.
//
#import "MedalsWearingViewController.h"
#import "MedalsPresenter.h"
#import "MedalsWearingListCollectionViewCell.h"
#import "MedalsWearingControlCollectionViewCell.h"
#import "MJRefresh.h"
@interface MedalsWearingViewController () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (nonatomic, strong) UIView *dismissArea;
@property (nonatomic, strong) UIView *contentArea;
@property (nonatomic, strong) UIImageView *controlAreaBG;
@property (nonatomic, strong) UICollectionView *controlAreaCollectionView;
@property (nonatomic, strong) UICollectionView *medalsAreaCollectionView;
@property (nonatomic, assign) NSInteger medalsAreaPage;
@property (nonatomic, copy) NSArray <MedalVo *> *allMedalsVo;
@property (nonatomic, copy) NSArray <VipMedalSeatVo *> *vipSeatVo;
@end
@implementation MedalsWearingViewController
- (MedalsPresenter *)createPresenter {
return [[MedalsPresenter alloc] init];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.medalsAreaPage = 1;
[self setupUI];
[self setupRefresh];
[self loadMedals];
}
- (void)setupUI {
self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
[self.view addSubview:self.dismissArea];
[self.view addSubview:self.contentArea];
[self.contentArea addSubview:self.controlAreaBG];
[self.contentArea addSubview:self.controlAreaCollectionView];
[self.controlAreaBG mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(46);
make.leading.trailing.mas_equalTo(self.contentArea).inset(14);
make.height.mas_equalTo(kGetScaleWidth(147));
}];
[self.controlAreaCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.controlAreaBG);
}];
[self.contentArea addSubview:self.medalsAreaCollectionView];
[self.medalsAreaCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.controlAreaCollectionView.mas_bottom).offset(14);
make.leading.trailing.mas_equalTo(self.controlAreaCollectionView);
make.bottom.mas_equalTo(self.contentArea);
}];
}
- (void)setupRefresh {
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
header.lastUpdatedTimeLabel.hidden = YES;
header.stateLabel.hidden = YES;
self.medalsAreaCollectionView.mj_header = header;
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
self.medalsAreaCollectionView.mj_footer = footer;
}
- (void)loadMedals {
[self.presenter mineAllMedals:self.medalsAreaPage];
}
#pragma mark - User Actions
- (void)handleTapGesture:(id)sender {
[self.view removeFromSuperview];
[self removeFromParentViewController];
}
#pragma mark -
- (void)mineAllMedalsSuccess:(MineAllMedalModel *)model {
[self endRefresh];
self.vipSeatVo = model.vipMedalSeatVos;
self.allMedalsVo = model.allMedals;
if (model.allMedals.count < [self.presenter pageSize]) {
// TODO: footer 显示无更多
}
[self.controlAreaCollectionView reloadData];
[self.medalsAreaCollectionView reloadData];
}
- (void)mineAllMedalsFailure {
[self endRefresh];
// 如果是加载更多失败,页码需要回退
if (self.medalsAreaPage > 1) {
self.medalsAreaPage--;
}
}
- (void)endRefresh {
[self.medalsAreaCollectionView.mj_header endRefreshing];
[self.medalsAreaCollectionView.mj_footer endRefreshing];
}
#pragma mark -
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (collectionView == self.controlAreaCollectionView) {
return 10;
} else if (collectionView == self.medalsAreaCollectionView) {
return self.allMedalsVo.count;
}
return 0;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if (collectionView == self.controlAreaCollectionView) {
MedalsWearingControlCollectionViewCell *cell = [MedalsWearingControlCollectionViewCell cellFor:collectionView atIndexPath:indexPath];
for (VipMedalSeatVo *vo in self.vipSeatVo) {
if (vo.medalSeatNum-1 == indexPath.row) {
[cell updateVIPLevel:vo.vipLevel];
break;
}
}
return cell;
} else if (collectionView == self.medalsAreaCollectionView) {
MedalsWearingListCollectionViewCell *cell = [MedalsWearingListCollectionViewCell cellFor:collectionView atIndexPath:indexPath];
[cell updateCell:[self.allMedalsVo xpSafeObjectAtIndex:indexPath.row]];
return cell;
}
return nil;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
MedalVo *vo = [self.allMedalsVo xpSafeObjectAtIndex:indexPath.row];
if (vo) {
[self.presenter updateMedalUseStatus:vo.medalId isUse:!vo.useStatus];
}
}
#pragma mark - Refresh Actions
- (void)headerRefresh {
// TODO: 实现下拉刷新逻辑
self.medalsAreaPage = 1;
[self loadMedals];
}
- (void)footerRefresh {
// TODO: 实现上拉加载更多逻辑
self.medalsAreaPage++;
[self loadMedals];
}
#pragma mark - Lazy Load
- (UIView *)dismissArea {
if (!_dismissArea) {
_dismissArea = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kGetScaleWidth(192))];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[_dismissArea addGestureRecognizer:tap];
}
return _dismissArea;
}
- (UIView *)contentArea {
if (!_contentArea) {
_contentArea = [[UIView alloc] initWithFrame:CGRectMake(0, kGetScaleWidth(192), KScreenWidth, KScreenHeight - kGetScaleWidth(192))];
[_contentArea setBackgroundColor:UIColorFromRGB(0x1B0043)];
[_contentArea setCornerRadius:16 corners:kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner borderWidth:0 borderColor:[UIColor clearColor]];
UILabel *titleLabel = [UILabel labelInitWithText:YMLocalizedString(@"20.20.61_text_2") font:kFontMedium(16) textColor:[UIColor whiteColor]];
[_contentArea addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(_contentArea);
make.top.mas_equalTo(12);
make.height.mas_equalTo(22);
}];
}
return _contentArea;
}
- (UIImageView *)controlAreaBG {
if (!_controlAreaBG) {
_controlAreaBG = [[UIImageView alloc] initWithImage:kImage(@"medals_control_bg")];
}
return _controlAreaBG;
}
- (UICollectionView *)controlAreaCollectionView {
if (!_controlAreaCollectionView) {
CGFloat length = (KScreenWidth - 60 - 21 *4)/5.0;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(length, length);
layout.minimumInteritemSpacing = 21;
layout.minimumLineSpacing = 19;
_controlAreaCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_controlAreaCollectionView.backgroundColor = [UIColor clearColor];
_controlAreaCollectionView.delegate = self;
_controlAreaCollectionView.dataSource = self;
[MedalsWearingControlCollectionViewCell registerTo:_controlAreaCollectionView];
}
return _controlAreaCollectionView;
}
- (UICollectionView *)medalsAreaCollectionView {
if (!_medalsAreaCollectionView) {
CGFloat length = kGetScaleWidth(166);
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(length, length);
layout.minimumInteritemSpacing = 12;
layout.minimumLineSpacing = 14;
_medalsAreaCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_medalsAreaCollectionView.backgroundColor = [UIColor clearColor];
_medalsAreaCollectionView.delegate = self;
_medalsAreaCollectionView.dataSource = self;
[MedalsWearingListCollectionViewCell registerTo:_medalsAreaCollectionView];
}
return _medalsAreaCollectionView;
}
@end