771 lines
27 KiB
Objective-C
771 lines
27 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"
|
|
#import "MedalsDetailView.h"
|
|
#import "MedalsWearingViewController.h"
|
|
#import "MedalsRankViewController.h"
|
|
#import <QGVAPWrapView.h>
|
|
#import "XPRoomGiftAnimationParser.h"
|
|
|
|
typedef enum : NSInteger {
|
|
MedalsCenterTab_TaskMedals = 1,
|
|
MedalsCenterTab_ActivityMedals = 2,
|
|
MedalsCenterTab_GloryMedals = 3,
|
|
} MedalsCenterTabType;
|
|
|
|
typedef enum : NSInteger {
|
|
MedalsCenterDisplayType_Mine,
|
|
MedalsCenterDisplayType_Other,
|
|
MedalsCenterDisplayType_Square
|
|
} MedalsCenterDisplayType;
|
|
|
|
@interface MedalsViewController () <MedalsPresenterProtocol, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
|
|
|
@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;
|
|
@property (nonatomic, assign) MedalsCenterDisplayType displayType;
|
|
|
|
@property (nonatomic, strong) UserMedalsModel *userMedalsModel;
|
|
|
|
@property (nonatomic, strong) UIImageView *otherBG;
|
|
@property (nonatomic, strong) NetImageView *otherAvatar;
|
|
@property (nonatomic, strong) NetImageView *otherMedal;
|
|
@property (nonatomic, strong) VAPView *otherMP4View;
|
|
@property (nonatomic, strong) XPRoomGiftAnimationParser *mp4Parser;
|
|
@property (nonatomic, strong) UILabel *otherNameLabel;
|
|
@property (nonatomic, strong) UILabel *otherCountLabel;
|
|
|
|
@end
|
|
|
|
@implementation MedalsViewController
|
|
|
|
- (instancetype)initForMyMedals:(UserInfoModel *)userInfo {
|
|
self = [super init];
|
|
if (self) {
|
|
self.displayType = MedalsCenterDisplayType_Mine;
|
|
self.userInfo = userInfo;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initForOtherMedals:(UserInfoModel *)userInfo {
|
|
self = [super init];
|
|
if (self) {
|
|
self.displayType = MedalsCenterDisplayType_Other;
|
|
self.userInfo = userInfo;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initForMedalsSquare {
|
|
self = [super init];
|
|
if (self) {
|
|
self.displayType = MedalsCenterDisplayType_Square;
|
|
}
|
|
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];
|
|
if (self.displayType != MedalsCenterDisplayType_Other) {
|
|
[self setupWearingButton];
|
|
if (self.userInfo.medals.medalCount == 0) {
|
|
[self setupEmptyUserMedals];
|
|
}
|
|
} else {
|
|
[self setupOthersMedalInfo];
|
|
}
|
|
|
|
[self setupCenterTabs];
|
|
[self setupBottomMedalsList];
|
|
[self setupEmptyView];
|
|
|
|
[self setupNavigationBar];
|
|
}
|
|
|
|
- (void)setupNavigationBar {
|
|
NSString *title = @"";
|
|
NSArray *navigationButtons = [NSArray array];
|
|
switch (self.displayType) {
|
|
case MedalsCenterDisplayType_Mine:
|
|
title = YMLocalizedString(@"20.20.61_text_1");
|
|
navigationButtons = @[[self medalsRankButton],
|
|
[self medalsSquareButton]];
|
|
break;
|
|
case MedalsCenterDisplayType_Other:
|
|
title = [NSString stringWithFormat:YMLocalizedString(@"20.20.61_text_14"),
|
|
self.userInfo.nick];
|
|
break;
|
|
case MedalsCenterDisplayType_Square:
|
|
title = YMLocalizedString(@"20.20.61_text_10");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
[self setupCustomNavigationBar:^{}
|
|
title:title
|
|
titleColor:[UIColor whiteColor]];
|
|
[self setupCustonNavigationRightButtons:navigationButtons
|
|
sizes:@[
|
|
[NSValue valueWithCGSize:CGSizeMake(22, 22)],
|
|
[NSValue valueWithCGSize:CGSizeMake(22, 22)]
|
|
]];
|
|
}
|
|
|
|
- (void)setupBackground {
|
|
self.view.backgroundColor = UIColorFromRGB(0x1B0043);
|
|
UIImageView *bottomBg = [self bottomBG];
|
|
[self.view addSubview:bottomBg];
|
|
if (self.displayType == MedalsCenterDisplayType_Other) {
|
|
[bottomBg mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.leading.trailing.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.view).offset(66 + 98 + 44 + kSafeAreaTopHeight);
|
|
}];
|
|
} else {
|
|
UIImageView *topBg = [self topBG];
|
|
[self.view addSubview:topBg];
|
|
[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)setupOthersMedalInfo {
|
|
UIImageView *bg = [[UIImageView alloc] initWithImage:kImage(@"medals_other_bg")];
|
|
[self.view addSubview:bg];
|
|
[bg mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(80);
|
|
make.leading.trailing.mas_equalTo(self.view).inset(12);
|
|
make.height.mas_equalTo(kGetScaleWidth(98));
|
|
}];
|
|
self.otherBG = bg;
|
|
|
|
[self.view addSubview:self.otherAvatar];
|
|
[self.otherAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(bg);
|
|
make.leading.mas_equalTo(bg).offset(15);
|
|
make.size.mas_equalTo(CGSizeMake(53, 53));
|
|
}];
|
|
|
|
self.otherNameLabel = [UILabel labelInitWithText:@""
|
|
font:kFontSemibold(15)
|
|
textColor:UIColorFromRGB(0x313131)];
|
|
[self.view addSubview:self.otherNameLabel];
|
|
[self.otherNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.otherAvatar.mas_trailing).offset(10);
|
|
make.top.mas_equalTo(self.otherAvatar);
|
|
}];
|
|
|
|
UIImageView *rankIcon = [[UIImageView alloc] initWithImage:kImage(@"medals_rank")];
|
|
[self.view addSubview:rankIcon];
|
|
[rankIcon mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.otherAvatar.mas_trailing).offset(10);
|
|
make.bottom.mas_equalTo(self.otherAvatar);
|
|
make.size.mas_equalTo(CGSizeMake(14, 18));
|
|
}];
|
|
|
|
self.otherCountLabel = [UILabel labelInitWithText:@""
|
|
font:kFontMedium(20)
|
|
textColor:UIColorFromRGB(0x313131)];
|
|
[self.view addSubview:self.otherCountLabel];
|
|
[self.otherCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(rankIcon.mas_trailing).offset(6);
|
|
make.centerY.mas_equalTo(rankIcon);
|
|
}];
|
|
|
|
self.otherMedal = [[NetImageView alloc] initWithImage:kImage(@"medals_empty")];
|
|
[self.view addSubview:self.otherMedal];
|
|
[self.otherMedal mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(bg);
|
|
make.trailing.mas_equalTo(bg).offset(-15);
|
|
make.size.mas_equalTo(CGSizeMake(80, 80));
|
|
}];
|
|
}
|
|
|
|
- (void)setupCenterTabs {
|
|
UIStackView *centerTabsStackView = [self centerTabStack];
|
|
[self.view addSubview:centerTabsStackView];
|
|
[centerTabsStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
if (self.displayType == MedalsCenterDisplayType_Other) {
|
|
make.top.mas_equalTo(self.otherBG.mas_bottom).offset(18);
|
|
} else {
|
|
make.top.mas_equalTo(kGetScaleWidth(314));
|
|
// make.bottom.mas_equalTo(kGetScaleWidth(-445));
|
|
}
|
|
make.height.mas_equalTo(44);
|
|
make.leading.trailing.mas_equalTo(self.view);
|
|
}];
|
|
}
|
|
|
|
- (void)setupWearingButton {
|
|
UIView *wearingBg = [[UIView alloc] init];
|
|
[wearingBg addGradientBackgroundWithColors:@[
|
|
UIColorFromRGB(0xf2e7ff),
|
|
UIColorFromRGB(0xb497f6)
|
|
] startPoint:CGPointMake(0, 0.5) endPoint:CGPointMake(1, 0.5) cornerRadius:25/2];
|
|
[wearingBg setAllCornerRadius:25/2 borderWidth:1 borderColor:[UIColor whiteColor]];
|
|
[self.view addSubview:wearingBg];
|
|
|
|
|
|
UIButton *wearingButton = [self wearingButton];
|
|
[self.view addSubview:wearingButton];
|
|
[wearingButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(90);
|
|
make.trailing.mas_equalTo(-12);
|
|
}];
|
|
|
|
[wearingBg mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(wearingButton).insets(UIEdgeInsetsMake(0, -15, 0, -25));
|
|
}];
|
|
}
|
|
|
|
- (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.displayType == MedalsCenterDisplayType_Square) {
|
|
[self.presenter squareMedals:tabPage
|
|
type:tabType];
|
|
} else {
|
|
[self.presenter userMedals:self.userInfo.uid
|
|
page:tabPage
|
|
type:tabType];
|
|
}
|
|
}
|
|
|
|
#pragma mark - MedalsPresenterProtocol
|
|
- (void)userMedalsSuccess:(UserMedalsModel *)userMedalsModel {
|
|
self.userMedalsModel = userMedalsModel;
|
|
[self endReresh];
|
|
[self _updateDataSource:userMedalsModel.medalSeries];
|
|
[self _updateOtherInfo:userMedalsModel];
|
|
}
|
|
|
|
- (void)userMedalsFailure {
|
|
[self endReresh];
|
|
|
|
// 如果是加载更多失败,页码需要回退
|
|
switch (self.currentTabType) {
|
|
case MedalsCenterTab_TaskMedals:
|
|
if (self.currentPageTaskMedals > 1) {
|
|
self.currentPageTaskMedals--;
|
|
}
|
|
break;
|
|
case MedalsCenterTab_ActivityMedals:
|
|
if (self.currentPageActivityMedals > 1) {
|
|
self.currentPageActivityMedals--;
|
|
}
|
|
break;
|
|
case MedalsCenterTab_GloryMedals:
|
|
if (self.currentPageGloryMedals > 1) {
|
|
self.currentPageGloryMedals--;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
[self _updateDataSource:@[]];
|
|
}
|
|
|
|
- (void)squareMedalsSuccess:(NSArray <MedalSeriesVo *>*)squareMedalsModel {
|
|
[self endReresh];
|
|
[self _updateDataSource:squareMedalsModel];
|
|
}
|
|
|
|
- (void)squareMedalsFailure {
|
|
[self endReresh];
|
|
|
|
// 如果是加载更多失败,页码需要回退
|
|
switch (self.currentTabType) {
|
|
case MedalsCenterTab_TaskMedals:
|
|
if (self.currentPageTaskMedals > 1) {
|
|
self.currentPageTaskMedals--;
|
|
}
|
|
break;
|
|
case MedalsCenterTab_ActivityMedals:
|
|
if (self.currentPageActivityMedals > 1) {
|
|
self.currentPageActivityMedals--;
|
|
}
|
|
break;
|
|
case MedalsCenterTab_GloryMedals:
|
|
if (self.currentPageGloryMedals > 1) {
|
|
self.currentPageGloryMedals--;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
- (void)_updateWearingInfo {
|
|
if (self.displayType != MedalsCenterDisplayType_Other) {
|
|
|
|
}
|
|
}
|
|
|
|
- (void)_updateOtherInfo:(UserMedalsModel *)userModel {
|
|
if (self.displayType == MedalsCenterDisplayType_Other) {
|
|
self.otherAvatar.imageUrl = userModel.avatar;
|
|
self.otherNameLabel.text = userModel.nick;
|
|
self.otherCountLabel.text = @(userModel.medalNum).stringValue;
|
|
}
|
|
}
|
|
|
|
- (void)_updateDataSource:(NSArray <MedalSeriesVo *>*)models {
|
|
|
|
if (models.count < [self.presenter pageSize]) {
|
|
[self.medalsCollectionView.mj_footer endRefreshingWithNoMoreData];
|
|
} else {
|
|
[self.medalsCollectionView.mj_footer resetNoMoreData];
|
|
}
|
|
|
|
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 {
|
|
MedalsViewController *vc = [[MedalsViewController alloc] initForMedalsSquare];
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}
|
|
|
|
- (void)didTapRankButton:(UIButton *)sender {
|
|
MedalsRankViewController *vc = [[MedalsRankViewController alloc] init];
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}
|
|
|
|
- (void)didTapWearingButton:(UIButton *)sender {
|
|
MedalsWearingViewController *vc = [[MedalsWearingViewController alloc] init];
|
|
[self addChildViewController:vc];
|
|
[self.view addSubview:vc.view];
|
|
}
|
|
|
|
- (void)didTapEmptyMedalButton:(UIButton *)sender {
|
|
MedalsWearingViewController *vc = [[MedalsWearingViewController alloc] init];
|
|
[self addChildViewController:vc];
|
|
[self.view addSubview:vc.view];
|
|
}
|
|
|
|
- (void)didTapCenterTab:(UIButton *)sender {
|
|
if (sender.isSelected == YES) {
|
|
return;
|
|
}
|
|
for (UIButton *b in self.centerTabButtons) {
|
|
b.selected = NO;
|
|
}
|
|
sender.selected = YES;
|
|
self.currentTabType = sender.tag;
|
|
[self loadMedalsList:self.currentTabType page:1];
|
|
}
|
|
|
|
#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 {
|
|
MedalsCollectionViewCell *cell = [MedalsCollectionViewCell cellFor:collectionView atIndexPath:indexPath];
|
|
[cell updateCell:[self loadModel:indexPath.item]];
|
|
return cell;
|
|
}
|
|
|
|
// 处理 cell 的可见性
|
|
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
if ([cell isKindOfClass:[MedalsCollectionViewCell class]]) {
|
|
[(MedalsCollectionViewCell *)cell willDisplay];
|
|
}
|
|
}
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
if ([cell isKindOfClass:[MedalsCollectionViewCell class]]) {
|
|
[(MedalsCollectionViewCell *)cell didEndDisplaying];
|
|
}
|
|
}
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
MedalsDetailView *view = [[MedalsDetailView alloc] initWithFrame:self.view.bounds];
|
|
view.detailItemVo = [self loadModel:indexPath.item];
|
|
[self.view addSubview:view];
|
|
}
|
|
|
|
- (MedalSeriesVo *)loadModel:(NSInteger)row {
|
|
MedalSeriesVo *model = nil;
|
|
switch (self.currentTabType) {
|
|
case MedalsCenterTab_TaskMedals:
|
|
model = [self.datasourceTaskMedals xpSafeObjectAtIndex:row];
|
|
break;
|
|
case MedalsCenterTab_ActivityMedals:
|
|
model = [self.datasourceActivityMedals xpSafeObjectAtIndex:row];
|
|
break;
|
|
case MedalsCenterTab_GloryMedals:
|
|
model = [self.datasourceGloryMedals xpSafeObjectAtIndex:row];
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return model;
|
|
}
|
|
|
|
#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];
|
|
[button setTitleColor:UIColorFromRGB(0x201440) forState:UIControlStateNormal];
|
|
button.titleLabel.font = kFontMedium(12);
|
|
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;
|
|
}
|
|
|
|
- (NetImageView *)otherAvatar {
|
|
if (!_otherAvatar) {
|
|
NetImageConfig *config = [[NetImageConfig alloc] init];
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_otherAvatar = [[NetImageView alloc] initWithConfig:config];
|
|
[_otherAvatar setAllCornerRadius:53/2 borderWidth:1 borderColor:[UIColor whiteColor]];
|
|
}
|
|
return _otherAvatar;
|
|
}
|
|
|
|
@end
|