Files
yinmeng-ios/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGiftInfoView.m

640 lines
24 KiB
Mathematica
Raw Normal View History

2021-11-10 18:42:27 +08:00
//
// XPGiftMiddleView.m
// xplan-ios
//
// Created by on 2021/11/9.
//
#import "XPGiftInfoView.h"
///Third
#import <Masonry/Masonry.h>
2021-11-12 19:30:53 +08:00
///Tool
#import "XPMacro.h"
2022-06-14 19:21:25 +08:00
#import "XPHtmlUrl.h"
2021-11-12 19:30:53 +08:00
#import "ThemeColor+SendGift.h"
2021-11-16 16:31:24 +08:00
///Model
2021-11-12 19:30:53 +08:00
#import "GiftInfoModel.h"
2021-11-16 16:31:24 +08:00
#import "GiftReceiveInfoModel.h"
2021-11-12 19:30:53 +08:00
///View
#import "XPGiftItemCollectionViewCell.h"
2021-11-16 16:31:24 +08:00
#import "XPGiftEmptyCollectionViewCell.h"
2022-06-14 17:31:44 +08:00
#import "XPGiftWeekStarCollectionViewCell.h"
2021-11-12 19:30:53 +08:00
#import "XPGiftCollectionViewFlowLayout.h"
2022-05-07 17:58:15 +08:00
@interface XPGiftInfoView ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, XPGiftWeekStarCollectionViewCellDelegate>
2022-08-23 18:01:34 +08:00
///
@property (nonatomic,strong) UIScrollView *scrollView;
2021-11-12 19:30:53 +08:00
@property (nonatomic,strong) UIStackView *segmentStackView;
2021-11-15 18:59:44 +08:00
///
2021-11-12 19:30:53 +08:00
@property (nonatomic,strong) UIButton *normalGiftButton;
2021-11-15 18:59:44 +08:00
///
2021-11-12 19:30:53 +08:00
@property (nonatomic,strong) UIButton *packGiftButton;
2021-11-15 18:59:44 +08:00
///
2021-11-12 19:30:53 +08:00
@property (nonatomic,strong) UIButton *luckyGiftButton;
2021-12-27 17:17:21 +08:00
///
@property (nonatomic,strong) UIButton *nobleGiftButton;
2022-05-07 17:58:15 +08:00
///
@property (nonatomic, strong) UIButton *weekStarButton;
2022-08-22 20:07:36 +08:00
///
@property (nonatomic,strong) UIButton *graffitiButton;
2021-11-15 18:59:44 +08:00
///
@property (nonatomic,strong) UILabel *totalValueLabel;
2021-11-12 19:30:53 +08:00
///
@property (nonatomic,strong) UIStackView *giftStackView;
///l
@property (nonatomic,strong) UICollectionView *giftcollectionView;
///
@property (nonatomic, strong) UIPageControl *pageController;
2021-11-15 18:59:44 +08:00
///
2021-11-16 16:31:24 +08:00
@property (nonatomic,strong) NSMutableArray <GiftInfoModel *> *datasource;
2021-11-15 18:59:44 +08:00
///
@property (nonatomic,strong) NSArray<GiftInfoModel *> *giftArray;
/////
@property (nonatomic,strong) NSArray<GiftInfoModel *> *giftLuckyArray;
2021-12-27 17:17:21 +08:00
///
@property (nonatomic, strong) NSArray<GiftInfoModel *> *giftNobleArray;
2022-05-07 17:58:15 +08:00
///
@property (nonatomic, strong) NSArray<GiftInfoModel *> *giftWeekStarArray;
2021-11-15 18:59:44 +08:00
/////
@property (nonatomic,strong) NSArray<GiftInfoModel *> *giftPackArray;
2022-08-22 20:07:36 +08:00
///
@property (nonatomic,strong) NSArray<GiftInfoModel *> *giftGraffitiArray;
2021-11-15 18:59:44 +08:00
///
@property (nonatomic,strong) NSAttributedString *totalAttribute;
2021-11-12 19:30:53 +08:00
///
@property (nonatomic,assign) GiftSegmentType segmentType;
2021-11-15 18:59:44 +08:00
///
@property (nonatomic,strong) GiftInfoModel *lastSelectGift;
2022-08-04 18:22:31 +08:00
@property (nonatomic, assign) NSInteger selectIndex;
2021-11-12 19:30:53 +08:00
@end
2021-11-10 18:42:27 +08:00
@implementation XPGiftInfoView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
2021-11-12 19:30:53 +08:00
#pragma mark - Response
- (void)didClickGiftSegmentAction:(UIButton *)sender {
2021-11-15 18:59:44 +08:00
self.normalGiftButton.selected = NO;
self.luckyGiftButton.selected = NO;
2021-12-27 17:17:21 +08:00
self.nobleGiftButton.selected = NO;
2021-11-15 18:59:44 +08:00
self.packGiftButton.selected = NO;
2022-05-07 17:58:15 +08:00
self.weekStarButton.selected = NO;
2022-08-22 20:07:36 +08:00
self.graffitiButton.selected = NO;
2021-11-15 18:59:44 +08:00
sender.selected = !sender.selected;
2021-11-12 19:30:53 +08:00
self.segmentType = sender.tag;
}
2021-11-16 16:31:24 +08:00
#pragma mark - Public Method
- (void)updatePackSource:(GiftReceiveInfoModel *)giftReceiveInfo numberUser:(NSInteger)numberUser {
2021-11-16 16:31:24 +08:00
GiftInfoModel * giftInfo = [self findGiftInfoByGiftId:giftReceiveInfo.giftId.integerValue];
giftInfo.count -= giftReceiveInfo.giftNum * numberUser;
2021-11-16 16:31:24 +08:00
if (giftInfo.count == 0) {
[self.datasource removeObject:giftInfo];
}
[self.giftcollectionView reloadData];
}
- (void)giftHeadTypeHadChange:(NSInteger)headType {
if (headType == 1) {
[self.graffitiButton removeFromSuperview];
[self.segmentStackView addArrangedSubview:self.normalGiftButton];
[self.segmentStackView addArrangedSubview:self.luckyGiftButton];
[self.segmentStackView addArrangedSubview:self.nobleGiftButton];
[self.segmentStackView addArrangedSubview:self.weekStarButton];
if(self.segmentType != GiftSegmentType_Pack) {
[self didClickGiftSegmentAction:self.normalGiftButton];
}
} else {
[self.normalGiftButton removeFromSuperview];
[self.luckyGiftButton removeFromSuperview];
[self.nobleGiftButton removeFromSuperview];
[self.weekStarButton removeFromSuperview];
[self.segmentStackView addArrangedSubview:self.graffitiButton];
if(self.segmentType != GiftSegmentType_Pack) {
[self didClickGiftSegmentAction:self.graffitiButton];
}
}
}
2021-11-10 18:42:27 +08:00
#pragma mark - Private Method
- (void)initSubViews {
2021-11-12 19:30:53 +08:00
2022-08-23 18:01:34 +08:00
[self addSubview:self.scrollView];
2021-11-12 19:30:53 +08:00
[self addSubview:self.giftStackView];
[self addSubview:self.packGiftButton];
[self addSubview:self.totalValueLabel];
2022-08-23 18:01:34 +08:00
[self.scrollView addSubview:self.segmentStackView];
2021-11-12 19:30:53 +08:00
///
[self.segmentStackView addArrangedSubview:self.normalGiftButton];
[self.segmentStackView addArrangedSubview:self.luckyGiftButton];
2021-12-27 17:17:21 +08:00
[self.segmentStackView addArrangedSubview:self.nobleGiftButton];
2022-05-07 17:58:15 +08:00
[self.segmentStackView addArrangedSubview:self.weekStarButton];
2021-11-12 19:30:53 +08:00
///
[self.giftStackView addArrangedSubview:self.giftcollectionView];
[self.giftStackView addArrangedSubview:self.pageController];
2021-11-10 18:42:27 +08:00
}
- (void)initSubViewConstraints {
[self mas_makeConstraints:^(MASConstraintMaker *make) {
2022-06-14 17:31:44 +08:00
make.height.mas_equalTo(30 + 108 * 2 + 10 + 10 + 15);
2021-11-12 19:30:53 +08:00
}];
2022-08-23 18:01:34 +08:00
[self.segmentStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.leading.trailing.height.mas_equalTo(self.scrollView);
}];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self).mas_offset(15);
make.right.mas_equalTo(self.packGiftButton.mas_left);
2022-05-07 17:58:15 +08:00
make.top.mas_equalTo(self);
make.height.mas_equalTo(30);
}];
[self.packGiftButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-15);
make.centerY.height.mas_equalTo(self.scrollView);
make.width.mas_equalTo(30);
}];
[self.totalValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.packGiftButton.mas_left);
make.centerY.mas_equalTo(self.packGiftButton);
}];
2022-06-14 19:21:25 +08:00
2021-11-12 19:30:53 +08:00
[self.giftStackView mas_makeConstraints:^(MASConstraintMaker *make) {
2022-06-14 17:31:44 +08:00
make.top.mas_equalTo(self.segmentStackView.mas_bottom).offset(10);
2021-11-12 19:30:53 +08:00
make.left.right.mas_equalTo(self);
make.height.mas_equalTo(108 * 2 + 20);
}];
2022-06-21 15:50:07 +08:00
2021-11-15 18:59:44 +08:00
[self.pageController mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(10);
2021-11-12 19:30:53 +08:00
}];
}
2021-11-15 18:59:44 +08:00
- (void)resetSelectGift:(NSArray<GiftInfoModel *> *)array {
for (GiftInfoModel * gift in array) {
gift.isSelected = NO;
2021-11-12 19:30:53 +08:00
}
2021-11-15 18:59:44 +08:00
}
- (void)createPackTotalValueAttribute {
__block NSInteger giftTotal = 0;
[self.packOriginArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:GiftInfoModel.class]) {
GiftInfoModel *gift = (GiftInfoModel *)obj;
giftTotal += gift.count * gift.goldPrice;
2021-11-12 19:30:53 +08:00
}
2021-11-15 18:59:44 +08:00
}];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"总价值:" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10],NSForegroundColorAttributeName:[ThemeColor secondTextColor]}];
[str appendAttributedString:[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@钻石",[self countFormatCoinStr:giftTotal]] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor whiteColor]}]];
2021-11-15 18:59:44 +08:00
self.totalAttribute = str;
2021-11-12 19:30:53 +08:00
}
2021-11-15 18:59:44 +08:00
/**
xx.xxW29999W+
@param number
@return
*/
- (NSString *)countFormatCoinStr:(NSInteger)number {
NSString *numStr = [NSString stringWithFormat:@"%li", number];
NSInteger num = number;
if (num > 99990000) {
numStr = @"9999W+";
} else if (num >= 10000) {
CGFloat numF = num / 10000.0;
numStr = [NSString stringWithFormat:@"%.2fW+", numF];
2021-11-12 19:30:53 +08:00
}
2021-11-15 18:59:44 +08:00
return numStr;
2021-11-12 19:30:53 +08:00
}
2021-11-15 18:59:44 +08:00
- (void)dealSelectGift:(GiftInfoModel *)giftInfo {
self.lastSelectGift = giftInfo;
2021-11-16 16:31:24 +08:00
if (self.segmentType == GiftSegmentType_Pack) {
giftInfo.sourceType = GiftSourceType_Pack;
} else {
giftInfo.sourceType = GiftSourceType_Normal;
}
2021-11-15 18:59:44 +08:00
giftInfo.isSelected = YES;
if (self.segmentType == GiftSegmentType_WeekStar) {
if (self.delegate && [self.delegate respondsToSelector:@selector(xpGiftInfoViewDidClickWeekStarGift:)]) {
[self.delegate xpGiftInfoViewDidClickWeekStarGift:giftInfo];
}
}
2021-11-15 18:59:44 +08:00
}
2021-11-16 16:31:24 +08:00
// id
- (GiftInfoModel *)findGiftInfoByGiftId:(NSInteger)giftId {
for (int i=0; i<self.datasource.count ; i++) {
GiftInfoModel *giftInfo = [self.datasource objectAtIndex:i];
if (giftInfo.giftId == giftId) {
return giftInfo;
}
}
return nil;
}
2021-11-15 18:59:44 +08:00
#pragma mark - scrollviewdelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offX = scrollView.contentOffset.x;
CGFloat width = CGRectGetWidth(scrollView.frame);
self.pageController.currentPage = ceilf(offX/width);
}
#pragma mark - UICollectionViewDelegate And UICollectionDatasource
2021-11-16 16:31:24 +08:00
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if (self.segmentType == GiftSegmentType_Pack && self.datasource.count == 0) {
return CGSizeMake(KScreenWidth, 105 * 2 + 10);
}
2022-06-14 17:31:44 +08:00
if (self.segmentType == GiftSegmentType_WeekStar) {
return CGSizeMake(KScreenWidth, 105 * 2 + 10);
}
CGFloat itemWidth = (CGFloat)(KScreenWidth - 15 * 2 - 5 * 3) / (CGFloat)4;
return CGSizeMake(itemWidth, 108);
2021-11-16 16:31:24 +08:00
}
2021-11-12 19:30:53 +08:00
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
2021-11-16 16:31:24 +08:00
if (self.segmentType == GiftSegmentType_Pack && self.datasource.count == 0) {
return 1;
}
2022-06-14 17:31:44 +08:00
if (self.segmentType == GiftSegmentType_WeekStar) {
return 1;
}
2021-11-15 18:59:44 +08:00
return self.datasource.count;
2021-11-12 19:30:53 +08:00
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
2022-06-14 17:31:44 +08:00
if ((self.segmentType ==GiftSegmentType_Pack || self.segmentType == GiftSegmentType_WeekStar) && self.datasource.count == 0) {
2021-11-16 16:31:24 +08:00
XPGiftEmptyCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPGiftEmptyCollectionViewCell class]) forIndexPath:indexPath];
2022-06-14 17:31:44 +08:00
cell.emptyTitle = @"暂时木有礼物~";
return cell;
}
if (self.segmentType == GiftSegmentType_WeekStar) {
XPGiftWeekStarCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPGiftWeekStarCollectionViewCell class]) forIndexPath:indexPath];
cell.delegate = self;
cell.weekStarGiftList = self.datasource;
2021-11-16 16:31:24 +08:00
return cell;
}
2022-06-14 17:31:44 +08:00
2021-11-16 16:31:24 +08:00
XPGiftItemCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPGiftItemCollectionViewCell class]) forIndexPath:indexPath];
GiftInfoModel * giftInfo;
giftInfo= [self.datasource objectAtIndex:indexPath.item];
cell.curUserNobleLevel = self.curUserNobleLevel;
2021-11-16 16:31:24 +08:00
cell.giftInfo = giftInfo;
2021-11-12 19:30:53 +08:00
return cell;
}
2021-11-15 18:59:44 +08:00
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
2021-11-16 16:31:24 +08:00
if (self.datasource.count > 0) {
[self resetSelectGift:self.datasource];
GiftInfoModel * giftInfo= [self.datasource objectAtIndex:indexPath.item];
[self dealSelectGift:giftInfo];
[self.giftcollectionView reloadData];
2022-08-22 20:07:36 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftInfoView:didClickItem:type:)]) {
[self.delegate xPGiftInfoView:self didClickItem:giftInfo type:self.segmentType];
}
2021-11-16 16:31:24 +08:00
}
2021-11-15 18:59:44 +08:00
}
2022-06-14 17:31:44 +08:00
#pragma mark - XPGiftWeekStarCollectionViewCellDelegate
- (void)xPGiftWeekStarCollectionViewCell:(XPGiftWeekStarCollectionViewCell *)view didSelectGift:(GiftInfoModel *)giftInfo {
[self dealSelectGift:giftInfo];
}
2021-11-12 19:30:53 +08:00
#pragma mark - Getters And Setters
- (void)setSegmentType:(GiftSegmentType)segmentType {
2021-11-15 18:59:44 +08:00
if (segmentType == _segmentType) {
return;
}
2021-11-16 16:31:24 +08:00
[_datasource removeAllObjects];
2021-11-12 19:30:53 +08:00
_segmentType = segmentType;
2021-11-15 18:59:44 +08:00
[self resetSelectGift:self.giftArray];
[self resetSelectGift:self.packOriginArray];
[self resetSelectGift:self.giftLuckyArray];
2021-12-27 17:17:21 +08:00
[self resetSelectGift:self.giftNobleArray];
2022-05-07 17:58:15 +08:00
[self resetSelectGift:self.giftWeekStarArray];
2022-08-22 20:07:36 +08:00
[self resetSelectGift:self.giftGraffitiArray];
2021-11-15 18:59:44 +08:00
self.totalValueLabel.hidden = YES;
switch (_segmentType) {
case GiftSegmentType_Normal:
2021-11-16 16:31:24 +08:00
[self.datasource addObjectsFromArray:self.giftArray];
2021-11-15 18:59:44 +08:00
break;
case GiftSegmentType_Lucky:
2021-11-16 16:31:24 +08:00
[self.datasource addObjectsFromArray:self.giftLuckyArray];
2021-11-15 18:59:44 +08:00
break;
2022-05-07 17:58:15 +08:00
case GiftSegmentType_Noble: {
2021-12-27 17:17:21 +08:00
[self.datasource addObjectsFromArray:self.giftNobleArray];
2022-05-07 17:58:15 +08:00
}
break;
case GiftSegmentType_WeekStar: {
[self.datasource addObjectsFromArray:self.giftWeekStarArray];
}
2021-12-27 17:17:21 +08:00
break;
2021-11-15 18:59:44 +08:00
case GiftSegmentType_Pack:
{
2021-11-16 16:31:24 +08:00
[self.datasource addObjectsFromArray:self.packOriginArray];
2021-11-15 18:59:44 +08:00
self.totalValueLabel.hidden = NO;
self.totalValueLabel.attributedText= self.totalAttribute;
}
break;
2022-08-22 20:07:36 +08:00
case GiftSegmentType_Graffiti:
[self.datasource addObjectsFromArray:self.giftGraffitiArray];
break;
2021-11-15 18:59:44 +08:00
default:
2021-11-16 16:31:24 +08:00
[self.datasource addObjectsFromArray:self.giftArray];
2021-11-15 18:59:44 +08:00
break;
}
if (self.datasource.count > 0) {
2022-08-04 18:22:31 +08:00
if (self.defaultSelectGiftId.length) {
for (GiftInfoModel * gift in self.datasource) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
[self dealSelectGift:gift];
self.selectIndex = [self.datasource indexOfObject:gift];
}
}
} else {
GiftInfoModel * gift = [self.datasource firstObject];
[self dealSelectGift:gift];
}
2021-11-15 18:59:44 +08:00
}
NSInteger page = 0;
if (self.datasource.count % 8 == 0) { //
page = self.datasource.count / 8;
} else {
page = self.datasource.count / 8 + 1;
}
2022-06-21 15:50:07 +08:00
self.pageController.hidden = page <= 1 || _segmentType == GiftSegmentType_WeekStar;
2021-11-15 18:59:44 +08:00
[self.pageController setNumberOfPages:page];
self.pageController.currentPage = 0;
2021-11-12 19:30:53 +08:00
[self.giftcollectionView reloadData];
2021-11-16 16:31:24 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftInfoView:didClickSegment:)]) {
[self.delegate xPGiftInfoView:self didClickSegment:_segmentType];
}
2022-08-23 18:01:34 +08:00
if (self.segmentType != GiftSegmentType_Graffiti && self.delegate && [self.delegate respondsToSelector:@selector(xPGiftInfoView:didClickItem:type:)]) {
2022-08-23 18:01:34 +08:00
[self.delegate xPGiftInfoView:self didClickItem:self.lastSelectGift type:_segmentType];
}
2021-11-12 19:30:53 +08:00
}
- (void)setNormalOriginArray:(NSArray *)normalOriginArray {
_normalOriginArray = normalOriginArray;
NSMutableArray * luckyArray = [NSMutableArray array];
2021-12-27 17:17:21 +08:00
NSMutableArray * normaleArray = [NSMutableArray array];
NSMutableArray * nobleArray = [NSMutableArray array];
2022-05-07 17:58:15 +08:00
NSMutableArray * weekStarArray = [NSMutableArray array];
2022-08-23 18:01:34 +08:00
NSMutableArray * graffiti = [NSMutableArray array];
2021-11-12 19:30:53 +08:00
[_normalOriginArray enumerateObjectsUsingBlock:^(GiftInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.giftType == GiftType_Lucky) {
[luckyArray addObject:obj];
} else if(obj.giftType == GiftType_Game) {
2021-11-12 19:30:53 +08:00
[normaleArray addObject:obj];
2021-12-27 17:17:21 +08:00
} else if (obj.giftType == GiftType_Noble) {
[nobleArray addObject:obj];
2022-05-07 17:58:15 +08:00
} else if (obj.giftType == GiftType_WeekStar) {
[weekStarArray addObject:obj];
2022-08-23 18:01:34 +08:00
} else if (obj.giftType == GiftType_Graffiti) {
[graffiti addObject:obj];
}
2021-11-10 18:42:27 +08:00
}];
2021-11-15 18:59:44 +08:00
self.giftArray = normaleArray;
self.giftLuckyArray = luckyArray;
2021-12-27 17:17:21 +08:00
self.giftNobleArray = nobleArray;
2022-05-07 17:58:15 +08:00
self.giftWeekStarArray = weekStarArray;
2022-08-23 18:01:34 +08:00
self.giftGraffitiArray = graffiti;
2022-08-04 18:22:31 +08:00
if (self.defaultSelectGiftId.length) {
for (GiftInfoModel *gift in self.normalOriginArray) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
self.segmentType = GiftSegmentType_Normal;
break;
}
}
for (GiftInfoModel *gift in self.giftLuckyArray) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
self.segmentType = GiftSegmentType_Lucky;
break;
}
}
for (GiftInfoModel *gift in self.giftNobleArray) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
self.segmentType = GiftSegmentType_Noble;
break;
}
}
for (GiftInfoModel *gift in self.giftWeekStarArray) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
self.segmentType = GiftSegmentType_WeekStar;
break;
}
}
2022-08-22 20:07:36 +08:00
for (GiftInfoModel *gift in self.giftGraffitiArray) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
self.segmentType = GiftSegmentType_Graffiti;
break;
}
}
2022-08-04 18:22:31 +08:00
} else {
self.segmentType = GiftSegmentType_Normal;
}
2021-11-12 19:30:53 +08:00
}
- (void)setPackOriginArray:(NSArray *)packOriginArray {
_packOriginArray = packOriginArray;
2021-11-15 18:59:44 +08:00
[self createPackTotalValueAttribute];
2021-11-10 18:42:27 +08:00
}
- (void)setCurUserNobleLevel:(NSInteger)curUserNobleLevel {
_curUserNobleLevel = curUserNobleLevel;
[self.giftcollectionView reloadData];
}
2021-11-12 19:30:53 +08:00
2022-04-21 20:06:43 +08:00
- (void)setUsingplaceType:(SendGiftType)usingplaceType {
_usingplaceType = usingplaceType;
if (_usingplaceType == SendGiftType_User) {
self.luckyGiftButton.hidden = YES;
2022-08-23 18:01:34 +08:00
self.graffitiButton.hidden = YES;
2022-04-21 20:06:43 +08:00
}
}
2022-08-04 18:22:31 +08:00
- (void)setDefaultSelectGiftId:(NSString *)defaultSelectGiftId {
_defaultSelectGiftId = defaultSelectGiftId;
}
2021-11-12 19:30:53 +08:00
- (UIStackView *)segmentStackView {
if (!_segmentStackView) {
_segmentStackView = [[UIStackView alloc] init];
_segmentStackView.axis = UILayoutConstraintAxisHorizontal;
_segmentStackView.distribution = UIStackViewDistributionFill;
_segmentStackView.alignment = UIStackViewAlignmentCenter;
2022-06-21 15:50:07 +08:00
_segmentStackView.spacing = 10;
2021-11-19 19:04:26 +08:00
_segmentStackView.backgroundColor = [UIColor clearColor];
2021-11-12 19:30:53 +08:00
}
return _segmentStackView;
}
- (UIStackView *)giftStackView {
if (!_giftStackView) {
_giftStackView = [[UIStackView alloc] init];
_giftStackView.axis = UILayoutConstraintAxisVertical;
_giftStackView.distribution = UIStackViewDistributionFill;
_giftStackView.alignment = UIStackViewAlignmentFill;
_giftStackView.spacing = 0;
}
return _giftStackView;
}
- (UIButton *)normalGiftButton {
if (!_normalGiftButton) {
_normalGiftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_normalGiftButton setTitle:@"礼物" forState:UIControlStateNormal];
2021-12-17 19:31:26 +08:00
[_normalGiftButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
2021-11-12 19:30:53 +08:00
[_normalGiftButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_normalGiftButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
2021-11-12 19:30:53 +08:00
_normalGiftButton.tag = GiftSegmentType_Normal;
_normalGiftButton.selected = YES;
[_normalGiftButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _normalGiftButton;
}
- (UIButton *)luckyGiftButton {
2021-12-27 17:17:21 +08:00
if (!_luckyGiftButton) {
_luckyGiftButton = [UIButton buttonWithType:UIButtonTypeCustom];
2022-06-14 19:21:25 +08:00
[_luckyGiftButton setTitle:@"幸运礼物" forState:UIControlStateNormal];
2021-12-27 17:17:21 +08:00
[_luckyGiftButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
[_luckyGiftButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_luckyGiftButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
2021-12-27 17:17:21 +08:00
_luckyGiftButton.tag = GiftSegmentType_Lucky;
_luckyGiftButton.selected = NO;
[_luckyGiftButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _luckyGiftButton;
}
- (UIButton *)nobleGiftButton {
if (!_nobleGiftButton) {
_nobleGiftButton = [UIButton buttonWithType:UIButtonTypeCustom];
2022-05-07 17:58:15 +08:00
[_nobleGiftButton setTitle:@"贵族" forState:UIControlStateNormal];
2021-12-27 17:17:21 +08:00
[_nobleGiftButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
[_nobleGiftButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_nobleGiftButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
2021-12-27 17:17:21 +08:00
_nobleGiftButton.tag = GiftSegmentType_Noble;
_nobleGiftButton.selected = NO;
[_nobleGiftButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _nobleGiftButton;
2021-11-12 19:30:53 +08:00
}
2022-05-07 17:58:15 +08:00
- (UIButton *)weekStarButton {
if (!_weekStarButton) {
_weekStarButton = [UIButton buttonWithType:UIButtonTypeCustom];
2022-06-14 19:21:25 +08:00
[_weekStarButton setTitle:@"周星礼物" forState:UIControlStateNormal];
2022-05-07 17:58:15 +08:00
[_weekStarButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
[_weekStarButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_weekStarButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
2022-05-07 17:58:15 +08:00
_weekStarButton.tag = GiftSegmentType_WeekStar;
_weekStarButton.selected = NO;
[_weekStarButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _weekStarButton;
}
2021-11-12 19:30:53 +08:00
- (UIButton *)packGiftButton {
if (!_packGiftButton) {
_packGiftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_packGiftButton setTitle:@"背包" forState:UIControlStateNormal];
2021-12-17 19:31:26 +08:00
[_packGiftButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
2021-11-12 19:30:53 +08:00
[_packGiftButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_packGiftButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
2021-11-12 19:30:53 +08:00
_packGiftButton.tag = GiftSegmentType_Pack;
_packGiftButton.selected = NO;
[_packGiftButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _packGiftButton;
}
2022-08-22 20:07:36 +08:00
- (UIButton *)graffitiButton {
if (!_graffitiButton) {
_graffitiButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_graffitiButton setTitle:@"涂鸦礼物" forState:UIControlStateNormal];
[_graffitiButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
[_graffitiButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_graffitiButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
2022-08-22 20:07:36 +08:00
_graffitiButton.tag = GiftSegmentType_Graffiti;
_graffitiButton.selected = NO;
[_graffitiButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _graffitiButton;
}
2021-11-15 18:59:44 +08:00
- (UILabel *)totalValueLabel {
if (!_totalValueLabel) {
_totalValueLabel = [[UILabel alloc] init];
}
return _totalValueLabel;
}
2021-11-12 19:30:53 +08:00
- (UICollectionView *)giftcollectionView{
if (!_giftcollectionView) {
XPGiftCollectionViewFlowLayout *layout = [[XPGiftCollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 5;
layout.minimumInteritemSpacing = 5;
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
2021-11-12 19:30:53 +08:00
_giftcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_giftcollectionView.dataSource = self;
_giftcollectionView.delegate = self;
_giftcollectionView.backgroundColor = [UIColor clearColor];
2021-11-15 18:59:44 +08:00
_giftcollectionView.pagingEnabled = YES;
2021-11-12 19:30:53 +08:00
[_giftcollectionView registerClass:[XPGiftItemCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGiftItemCollectionViewCell class])];
2021-11-16 16:31:24 +08:00
[_giftcollectionView registerClass:[XPGiftEmptyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGiftEmptyCollectionViewCell class])];
2022-06-14 17:31:44 +08:00
[_giftcollectionView registerClass:[XPGiftWeekStarCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGiftWeekStarCollectionViewCell class])];
_giftcollectionView.showsHorizontalScrollIndicator = NO;
2021-11-12 19:30:53 +08:00
}
return _giftcollectionView;
}
- (UIPageControl *)pageController {
if (!_pageController) {
_pageController = [[UIPageControl alloc] init];
_pageController.currentPageIndicatorTintColor = [ThemeColor giftPageIndicatorColor];
}
return _pageController;
}
2021-11-16 16:31:24 +08:00
- (NSMutableArray<GiftInfoModel *> *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
2022-08-23 18:01:34 +08:00
- (UIScrollView *)scrollView {
if (!_scrollView) {
_scrollView = [[UIScrollView alloc] init];
_scrollView.backgroundColor = [UIColor clearColor];
_scrollView.showsHorizontalScrollIndicator = NO;
}
return _scrollView;
}
2021-11-12 19:30:53 +08:00
2021-11-10 18:42:27 +08:00
@end