562 lines
19 KiB
Objective-C
562 lines
19 KiB
Objective-C
//
|
|
// MedalsViewController.m
|
|
// YuMi
|
|
//
|
|
// Created by P on 2025/6/17.
|
|
//
|
|
|
|
#import "MedalsViewController.h"
|
|
#import "MedalsPresenter.h"
|
|
#import "UserInfoModel.h"
|
|
#import "TYCyclePagerView.h"
|
|
#import "MedalsCollectionViewCell.h"
|
|
|
|
typedef enum : NSUInteger {
|
|
MedalsCenterTab_TaskMedals = 1,
|
|
MedalsCenterTab_ActivityMedals = 2,
|
|
MedalsCenterTab_GloryMedals = 3,
|
|
} MedalsCenterTabType;
|
|
|
|
@interface MedalsViewController () <MedalsPresenterProtocol, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
|
|
|
@property (nonatomic, assign) BOOL isForMyMedals;
|
|
@property (nonatomic, strong) UserInfoModel *userInfo;
|
|
@property (nonatomic, copy) NSArray <UIButton *> *centerTabButtons;
|
|
@property (nonatomic, strong) UILabel *medalDescLabel;
|
|
@property (nonatomic, strong) UIButton *emptyUserMedalButton;
|
|
@property (nonatomic, strong) UIView *emptyView;
|
|
@property (nonatomic, copy) UICollectionView *medalsCollectionView;
|
|
|
|
@property (nonatomic, strong) NSMutableArray <MedalSeriesVo *>*datasourceTaskMedals;
|
|
@property (nonatomic, strong) NSMutableArray <MedalSeriesVo *>*datasourceActivityMedals;
|
|
@property (nonatomic, strong) NSMutableArray <MedalSeriesVo *>*datasourceGloryMedals;
|
|
|
|
@property (nonatomic, assign) NSInteger currentPageTaskMedals;
|
|
@property (nonatomic, assign) NSInteger currentPageActivityMedals;
|
|
@property (nonatomic, assign) NSInteger currentPageGloryMedals;
|
|
|
|
@property (nonatomic, assign) MedalsCenterTabType currentTabType;
|
|
|
|
|
|
@end
|
|
|
|
@implementation MedalsViewController
|
|
|
|
- (instancetype)initForMyMedals:(UserInfoModel *)userInfo {
|
|
self = [super init];
|
|
if (self) {
|
|
self.isForMyMedals = YES;
|
|
self.userInfo = userInfo;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initForMedalsSquare {
|
|
self = [super init];
|
|
if (self) {
|
|
self.isForMyMedals = NO;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (MedalsPresenter *)createPresenter {
|
|
return [[MedalsPresenter alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
[self setupUI];
|
|
[self setupData];
|
|
}
|
|
|
|
#pragma mark - UI
|
|
- (void)setupUI {
|
|
[self setupBackground];
|
|
[self setupNavigationBar];
|
|
[self setupCenterTabs];
|
|
|
|
if (self.userInfo.medals.medalCount == 0) {
|
|
[self setupEmptyUserMedals];
|
|
}
|
|
|
|
[self setupWearingButton];
|
|
[self setupBottomMedalsList];
|
|
[self setupEmptyView];
|
|
}
|
|
|
|
- (void)setupNavigationBar {
|
|
[self setupCustomNavigationBar:^{}
|
|
title:YMLocalizedString(@"20.20.61_text_1")
|
|
titleColor:[UIColor whiteColor]];
|
|
[self setupCustonNavigationRightButtons:@[
|
|
[self medalsRankButton],
|
|
[self medalsSquareButton],
|
|
] sizes:@[
|
|
[NSValue valueWithCGSize:CGSizeMake(22, 22)],
|
|
[NSValue valueWithCGSize:CGSizeMake(22, 22)]
|
|
]];
|
|
}
|
|
|
|
- (void)setupBackground {
|
|
self.view.backgroundColor = UIColorFromRGB(0x1B0043);
|
|
UIImageView *topBg = [self topBG];
|
|
UIImageView *bottomBg = [self bottomBG];
|
|
[self.view addSubview:topBg];
|
|
[self.view addSubview:bottomBg];
|
|
[topBg mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.leading.trailing.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(kGetScaleWidth(314));
|
|
}];
|
|
[bottomBg mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.leading.trailing.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(kGetScaleWidth(445));
|
|
}];
|
|
}
|
|
|
|
- (void)setupCenterTabs {
|
|
UIStackView *centerTabsStackView = [self centerTabStack];
|
|
[self.view addSubview:centerTabsStackView];
|
|
[centerTabsStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kGetScaleWidth(314));
|
|
make.bottom.mas_equalTo(kGetScaleWidth(-445));
|
|
make.leading.trailing.mas_equalTo(self.view);
|
|
}];
|
|
}
|
|
|
|
- (void)setupWearingButton {
|
|
UIButton *wearingButton = [self wearingButton];
|
|
[self.view addSubview:wearingButton];
|
|
[wearingButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(90);
|
|
make.trailing.mas_equalTo(-12);
|
|
}];
|
|
}
|
|
|
|
- (void)setupEmptyUserMedals {
|
|
[self.view addSubview:self.emptyUserMedalButton];
|
|
[self.emptyUserMedalButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(100);
|
|
make.centerX.mas_equalTo(self.view);
|
|
make.size.mas_equalTo(CGSizeMake(184, 184));
|
|
}];
|
|
|
|
[self.view addSubview:self.medalDescLabel];
|
|
self.medalDescLabel.text = YMLocalizedString(@"20.20.61_text_6");
|
|
[self.medalDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kGetScaleWidth(290));
|
|
make.leading.trailing.mas_equalTo(self.view).inset(20);
|
|
make.height.mas_equalTo(20);
|
|
}];
|
|
}
|
|
|
|
- (void)setupWearingUserMedals {
|
|
[self.view addSubview:self.medalDescLabel];
|
|
self.medalDescLabel.text = @"显示过期时间";//YMLocalizedString(@"20.20.61_text_6");
|
|
[self.medalDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kGetScaleWidth(290));
|
|
make.leading.trailing.mas_equalTo(self.view).inset(20);
|
|
make.height.mas_equalTo(20);
|
|
}];
|
|
}
|
|
|
|
- (void)setupScrollMedalsList {
|
|
|
|
}
|
|
|
|
- (void)setupBottomMedalsList {
|
|
[self.view addSubview:self.medalsCollectionView];
|
|
[self.medalsCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(self.view);
|
|
make.trailing.leading.mas_equalTo(self.view).inset(26);
|
|
make.height.mas_equalTo(kGetScaleWidth(380));
|
|
}];
|
|
|
|
// 添加下拉刷新
|
|
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
|
|
header.lastUpdatedTimeLabel.hidden = YES;
|
|
self.medalsCollectionView.mj_header = header;
|
|
|
|
// 添加上拉加载更多
|
|
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
|
|
self.medalsCollectionView.mj_footer = footer;
|
|
}
|
|
|
|
- (void)setupEmptyView {
|
|
self.emptyView.hidden = YES;
|
|
[self.view insertSubview:self.emptyView
|
|
belowSubview:self.medalsCollectionView];
|
|
[self.emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.leading.trailing.mas_equalTo(self.medalsCollectionView);
|
|
make.height.mas_equalTo(200);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Refresh Methods
|
|
- (void)headerRefresh {
|
|
NSInteger page = 1;
|
|
switch (self.currentTabType) {
|
|
case MedalsCenterTab_TaskMedals:
|
|
self.currentPageTaskMedals = 1;
|
|
page = self.currentPageTaskMedals;
|
|
break;
|
|
case MedalsCenterTab_ActivityMedals:
|
|
self.currentPageActivityMedals = 1;
|
|
page = self.currentPageActivityMedals;
|
|
break;
|
|
case MedalsCenterTab_GloryMedals:
|
|
self.currentPageGloryMedals = 1;
|
|
page = self.currentPageGloryMedals;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
[self loadMedalsList:self.currentTabType page:page];
|
|
}
|
|
|
|
- (void)footerRefresh {
|
|
NSInteger page = 1;
|
|
switch (self.currentTabType) {
|
|
case MedalsCenterTab_TaskMedals:
|
|
self.currentPageTaskMedals += 1;
|
|
page = self.currentPageTaskMedals;
|
|
break;
|
|
case MedalsCenterTab_ActivityMedals:
|
|
self.currentPageActivityMedals += 1;
|
|
page = self.currentPageActivityMedals;
|
|
break;
|
|
case MedalsCenterTab_GloryMedals:
|
|
self.currentPageGloryMedals += 1;
|
|
page = self.currentPageGloryMedals;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
[self loadMedalsList:self.currentTabType page:page];
|
|
}
|
|
|
|
- (void)endReresh {
|
|
[self.medalsCollectionView.mj_header endRefreshing];
|
|
[self.medalsCollectionView.mj_footer endRefreshing];
|
|
}
|
|
|
|
#pragma mark - Load datas
|
|
- (void)setupData {
|
|
self.datasourceTaskMedals = @[].mutableCopy;
|
|
self.datasourceActivityMedals = @[].mutableCopy;
|
|
self.datasourceGloryMedals = @[].mutableCopy;
|
|
|
|
self.currentPageTaskMedals = 1;
|
|
self.currentPageActivityMedals = 1;
|
|
self.currentPageGloryMedals = 1;
|
|
|
|
self.currentTabType = MedalsCenterTab_TaskMedals;
|
|
|
|
[self loadMedalsList:self.currentTabType page:1];
|
|
}
|
|
|
|
- (void)loadMedalsList:(MedalsCenterTabType)tabType page:(NSInteger)tabPage {
|
|
if (self.isForMyMedals) {
|
|
[self.presenter userMedals:self.userInfo.uid
|
|
page:tabPage
|
|
type:tabPage];
|
|
} else {
|
|
[self.presenter squareMedals:tabPage
|
|
type:tabType];
|
|
}
|
|
}
|
|
|
|
#pragma mark - MedalsPresenterProtocol
|
|
- (void)userMedalsSuccess:(UserMedalsModel *)userMedalsModel {
|
|
[self endReresh];
|
|
[self _updateDataSource:userMedalsModel.medalSeries];
|
|
}
|
|
|
|
- (void)userMedalsFailure {
|
|
[self endReresh];
|
|
[self _updateDataSource:@[]];
|
|
}
|
|
|
|
- (void)squareMedalsSuccess:(UserMedalsModel *)userMedalsModel {
|
|
[self endReresh];
|
|
[self _updateDataSource:userMedalsModel.medalSeries];
|
|
}
|
|
|
|
- (void)squareMedalsFailure {
|
|
[self endReresh];
|
|
}
|
|
|
|
- (void)_updateDataSource:(NSArray *)models {
|
|
|
|
if (models.count < 8) {
|
|
[self.medalsCollectionView.mj_footer endRefreshingWithNoMoreData];
|
|
}
|
|
|
|
switch (self.currentTabType) {
|
|
case MedalsCenterTab_TaskMedals:
|
|
if (self.currentPageTaskMedals == 1) {
|
|
self.emptyView.hidden = (models.count != 0);
|
|
self.datasourceTaskMedals = models.mutableCopy;
|
|
} else {
|
|
[self.datasourceTaskMedals addObjectsFromArray:models];
|
|
}
|
|
break;
|
|
case MedalsCenterTab_ActivityMedals:
|
|
if (self.currentPageActivityMedals == 1) {
|
|
self.emptyView.hidden = (models.count != 0);
|
|
self.datasourceActivityMedals = models.mutableCopy;
|
|
} else {
|
|
[self.datasourceActivityMedals addObjectsFromArray:models];
|
|
}
|
|
break;
|
|
case MedalsCenterTab_GloryMedals:
|
|
if (self.currentPageGloryMedals == 1) {
|
|
self.emptyView.hidden = (models.count != 0);
|
|
self.datasourceGloryMedals = models.mutableCopy;
|
|
} else {
|
|
[self.datasourceGloryMedals addObjectsFromArray:models];
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
[self.medalsCollectionView reloadData];
|
|
}
|
|
|
|
#pragma mark - Button actions
|
|
- (void)didTapSquareButton:(UIButton *)sender {
|
|
|
|
}
|
|
|
|
- (void)didTapRankButton:(UIButton *)sender {
|
|
|
|
}
|
|
|
|
- (void)didTapWearingButton:(UIButton *)sender {
|
|
|
|
}
|
|
|
|
- (void)didTapEmptyMedalButton:(UIButton *)sender {
|
|
|
|
}
|
|
|
|
- (void)didTapCenterTab:(UIButton *)sender {
|
|
if (sender.isSelected == YES) {
|
|
return;
|
|
}
|
|
for (UIButton *b in self.centerTabButtons) {
|
|
b.selected = NO;
|
|
}
|
|
sender.selected = YES;
|
|
|
|
switch (sender.tag) {
|
|
case MedalsCenterTab_TaskMedals:
|
|
[self.presenter userMedals:self.userInfo.uid
|
|
page:1
|
|
type:1];
|
|
break;
|
|
case MedalsCenterTab_ActivityMedals:
|
|
[self.presenter userMedals:self.userInfo.uid
|
|
page:1
|
|
type:2];
|
|
break;
|
|
case MedalsCenterTab_GloryMedals:
|
|
[self.presenter userMedals:self.userInfo.uid
|
|
page:1
|
|
type:3];
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
#pragma mark - UICollectionView DataSource & Delegate
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
switch (self.currentTabType) {
|
|
case MedalsCenterTab_TaskMedals:
|
|
return self.datasourceTaskMedals.count;
|
|
break;
|
|
case MedalsCenterTab_ActivityMedals:
|
|
return self.datasourceActivityMedals.count;
|
|
break;
|
|
case MedalsCenterTab_GloryMedals:
|
|
return self.datasourceGloryMedals.count;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
MedalSeriesVo *model = nil;
|
|
switch (self.currentTabType) {
|
|
case MedalsCenterTab_TaskMedals:
|
|
model = [self.datasourceTaskMedals xpSafeObjectAtIndex:indexPath.item];
|
|
break;
|
|
case MedalsCenterTab_ActivityMedals:
|
|
model = [self.datasourceActivityMedals xpSafeObjectAtIndex:indexPath.item];
|
|
break;
|
|
case MedalsCenterTab_GloryMedals:
|
|
model = [self.datasourceGloryMedals xpSafeObjectAtIndex:indexPath.item];
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
MedalsCollectionViewCell *cell = [MedalsCollectionViewCell cellFor:collectionView atIndexPath:indexPath];
|
|
[cell updateCell:model];
|
|
return cell;
|
|
}
|
|
|
|
#pragma mark - Lazy load
|
|
- (UIButton *)medalsSquareButton {
|
|
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[button addTarget:self action:@selector(didTapSquareButton:) forControlEvents:UIControlEventTouchUpInside];
|
|
[button setBackgroundImage:kImage(@"medals_square") forState:UIControlStateNormal];
|
|
return button;
|
|
}
|
|
|
|
- (UIButton *)medalsRankButton {
|
|
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[button addTarget:self action:@selector(didTapRankButton:) forControlEvents:UIControlEventTouchUpInside];
|
|
[button setBackgroundImage:kImage(@"medals_rank") forState:UIControlStateNormal];
|
|
return button;
|
|
}
|
|
|
|
- (UIButton *)wearingButton {
|
|
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[button addTarget:self action:@selector(didTapWearingButton:) forControlEvents:UIControlEventTouchUpInside];
|
|
[button setTitle:YMLocalizedString(@"20.20.61_text_2") forState:UIControlStateNormal];
|
|
return button;
|
|
}
|
|
|
|
- (UIImageView *)topBG {
|
|
UIImageView *iv = [[UIImageView alloc] initWithImage:kImage(@"medals_top_bg")];
|
|
iv.contentMode = UIViewContentModeScaleAspectFit;
|
|
return iv;
|
|
}
|
|
|
|
- (UIImageView *)bottomBG {
|
|
UIImageView *iv = [[UIImageView alloc] initWithImage:kImage(@"medals_bottom_bg")];
|
|
iv.contentMode = UIViewContentModeScaleAspectFit;
|
|
return iv;
|
|
}
|
|
|
|
- (UIButton *)taskMedalsButton:(MedalsCenterTabType)tabType {
|
|
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
button.tag = tabType;
|
|
switch (tabType) {
|
|
case MedalsCenterTab_TaskMedals:
|
|
[button setTitle:YMLocalizedString(@"20.20.61_text_3") forState:UIControlStateNormal];
|
|
break;
|
|
case MedalsCenterTab_ActivityMedals:
|
|
[button setTitle:YMLocalizedString(@"20.20.61_text_4") forState:UIControlStateNormal];
|
|
break;
|
|
case MedalsCenterTab_GloryMedals:
|
|
[button setTitle:YMLocalizedString(@"20.20.61_text_5") forState:UIControlStateNormal];
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
[button addTarget:self action:@selector(didTapCenterTab:) forControlEvents:UIControlEventTouchUpInside];
|
|
[button setBackgroundImage:kImage(@"medals_tab_normal") forState:UIControlStateNormal];
|
|
[button setBackgroundImage:kImage(@"medals_tab_selected") forState:UIControlStateSelected];
|
|
[button setTitleColor:UIColorFromRGB(0xd8a2ff) forState:UIControlStateNormal];
|
|
[button setTitleColor:UIColorFromRGB(0xFFFFFF) forState:UIControlStateSelected];
|
|
[button.titleLabel setFont:kFontMedium(13)];
|
|
[button setAdjustsImageWhenDisabled:NO];
|
|
return button;
|
|
}
|
|
|
|
- (UIStackView *)centerTabStack {
|
|
UIButton *taskMedalsButton = [self taskMedalsButton:MedalsCenterTab_TaskMedals];
|
|
taskMedalsButton.selected = YES;
|
|
UIButton *activityMedalsButton = [self taskMedalsButton:MedalsCenterTab_ActivityMedals];
|
|
UIButton *gloryMedalsButton = [self taskMedalsButton:MedalsCenterTab_GloryMedals];
|
|
self.centerTabButtons = @[
|
|
taskMedalsButton,
|
|
activityMedalsButton,
|
|
gloryMedalsButton
|
|
];
|
|
|
|
UIStackView *stack = [[UIStackView alloc] initWithArrangedSubviews:self.centerTabButtons];
|
|
stack.distribution = UIStackViewDistributionFillEqually;
|
|
return stack;
|
|
}
|
|
|
|
- (UILabel *)medalDescLabel {
|
|
if (!_medalDescLabel) {
|
|
_medalDescLabel = [UILabel labelInitWithText:@""
|
|
font:kFontRegular(12)
|
|
textColor:[UIColor whiteColor]];
|
|
_medalDescLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _medalDescLabel;
|
|
}
|
|
|
|
- (UIButton *)emptyUserMedalButton {
|
|
if (!_emptyUserMedalButton) {
|
|
_emptyUserMedalButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_emptyUserMedalButton setImage:kImage(@"medals_empty")
|
|
forState:UIControlStateNormal];
|
|
[_emptyUserMedalButton addTarget:self
|
|
action:@selector(didTapEmptyMedalButton:)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _emptyUserMedalButton;
|
|
}
|
|
|
|
- (UICollectionView *)medalsCollectionView {
|
|
if (!_medalsCollectionView) {
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.itemSize = CGSizeMake(kGetScaleWidth(156), kGetScaleWidth(218));
|
|
layout.minimumInteritemSpacing = 6;
|
|
layout.minimumLineSpacing = 6;
|
|
_medalsCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
_medalsCollectionView.backgroundColor = [UIColor clearColor];
|
|
_medalsCollectionView.delegate = self;
|
|
_medalsCollectionView.dataSource = self;
|
|
[MedalsCollectionViewCell registerTo:_medalsCollectionView];
|
|
}
|
|
return _medalsCollectionView;
|
|
}
|
|
|
|
- (UIView *)emptyView {
|
|
if (!_emptyView) {
|
|
_emptyView = [[UIView alloc] init];
|
|
_emptyView.backgroundColor = [UIColor clearColor];
|
|
|
|
UILabel *titleLabel = [UILabel labelInitWithText:YMLocalizedString(@"20.20.61_text_7")
|
|
font:kFontRegular(14)
|
|
textColor:UIColorFromRGB(0xafb1b3)];
|
|
titleLabel.numberOfLines = 2;
|
|
titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
UIImageView *ufoImageView = [[UIImageView alloc] initWithImage:kImage(@"common_empty_UFO")];
|
|
|
|
[_emptyView addSubview:ufoImageView];
|
|
[_emptyView addSubview:titleLabel];
|
|
|
|
[ufoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(_emptyView);
|
|
make.top.mas_equalTo(20);
|
|
make.size.mas_equalTo(CGSizeMake(110, 110));
|
|
}];
|
|
|
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(_emptyView);
|
|
make.top.mas_equalTo(ufoImageView.mas_bottom).offset(10);
|
|
make.leading.trailing.mas_equalTo(_emptyView).inset(20);
|
|
}];
|
|
}
|
|
return _emptyView;
|
|
}
|
|
|
|
@end
|