Files
peko-ios/YuMi/Modules/YMRoom/View/LuckyPackage/LuckyPackageViewController.m

2343 lines
89 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// LuckyPackageViewController.m
// YuMi
//
// Created by P on 2025/1/10.
//
#import "LuckyPackageViewController.h"
#import "MoliMoneyLabel.h"
#import "EmptyDataView.h"
#import "NSDate+DateUtils.h"
#import "RoomInfoModel.h"
#import "UserInfoModel.h"
#import "LuckyPackagePresenter.h"
#import "XPIAPRechargeViewController.h"
#import "XCCurrentVCStackManager.h"
#import "LuckyPackageLogicManager.h"
#import "LuckyPackageBannerView.h"
#import "XPWebViewController.h"
#import "XPGiftCollectionViewFlowLayout.h"
@interface LuckyPackageRuleView : UIView
@property(nonatomic, assign) UIButton *backButton;
@property(nonatomic, strong) XPWebViewController *webView;
@end
@implementation LuckyPackageRuleView
@end
@interface LuckyPackageRecordsCell : UITableViewCell
@property(nonatomic, strong) RedEnvelopeListVo *cellModel;
@property(nonatomic, assign) NSInteger type;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *timeLabel;
@property(nonatomic, strong) UILabel *moneyLabel;
@property(nonatomic, strong) UILabel *giftNumLabel;
@property(nonatomic, strong) UIImageView *moneyImageView;
@end
@implementation LuckyPackageRecordsCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.backgroundColor = [UIColor clearColor];
self.contentView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.timeLabel];
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.moneyLabel];
[self.contentView addSubview:self.giftNumLabel];
[self.contentView addSubview:self.moneyImageView];
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.contentView);
make.bottom.mas_equalTo(self.contentView).offset(-12);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.contentView);
make.top.mas_equalTo(self.contentView).offset(8);
}];
[self.moneyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.centerY.mas_equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(17, 17));
}];
[self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(self.moneyImageView.mas_leading).offset(-4);
make.centerY.mas_equalTo(self.moneyImageView);
}];
[self.giftNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.centerY.mas_equalTo(self.contentView);
}];
}
return self;
}
- (void)setCellModel:(RedEnvelopeListVo *)cellModel {
_cellModel = cellModel;
if (self.type == 1) {
self.timeLabel.text = [[NSDate dateWithTimeIntervalSince1970:cellModel.beginTime/1000] stringForYearMonthDayDashed];
} else {
self.timeLabel.text = [[NSDate dateWithTimeIntervalSince1970:cellModel.createTime/1000] stringForYearMonthDayDashed];
}
if ([cellModel.type isEqualToString:@"DIAMOND"]) {
self.giftNumLabel.hidden = YES;
self.moneyLabel.hidden = NO;
self.moneyImageView.hidden = NO;
self.moneyLabel.text = @(cellModel.originalAmount).stringValue;
if (self.type == 1) {
self.titleLabel.text = YMLocalizedString(@"1.0.37_text_2");
} else {
self.titleLabel.text = cellModel.nick;
}
} else if ([cellModel.type isEqualToString:@"GIFT"]) {
self.giftNumLabel.hidden = NO;
self.moneyLabel.hidden = YES;
self.moneyImageView.hidden = YES;
if (self.type == 1) {
self.titleLabel.text = YMLocalizedString(@"1.0.37_text_1");
self.giftNumLabel.text = [NSString stringWithFormat:@"%@*%@", YMLocalizedString(@"1.0.37_text_10"), @(cellModel.num)];
} else {
self.titleLabel.text = cellModel.nick;
self.giftNumLabel.text = [NSString stringWithFormat:@"%@*%@", cellModel.giftName, @(cellModel.originalAmount)];
}
}
}
#pragma mark -
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel labelInitWithText:@"" font:kFontMedium(14) textColor:UIColorFromRGB(0xffea5c)];
}
return _titleLabel;
}
- (UILabel *)timeLabel {
if (!_timeLabel) {
_timeLabel = [UILabel labelInitWithText:@"" font:kFontMedium(12) textColor:UIColorFromRGB(0xffea5c)];
_timeLabel.alpha = 0.6;
}
return _timeLabel;
}
- (UILabel *)moneyLabel {
if (!_moneyLabel) {
_moneyLabel = [UILabel labelInitWithText:@"" font:kFontMedium(15) textColor:UIColorFromRGB(0xffea5c)];
}
return _moneyLabel;
}
- (UILabel *)giftNumLabel {
if (!_giftNumLabel) {
_giftNumLabel = [UILabel labelInitWithText:@"" font:kFontMedium(15) textColor:UIColorFromRGB(0xffea5c)];
}
return _giftNumLabel;
}
- (UIImageView *)moneyImageView {
if (!_moneyImageView) {
_moneyImageView = [[UIImageView alloc] initWithImage:kImage(@"moli_money_icon")];
}
return _moneyImageView;
}
@end
@interface LuckyPackageRecordsListView : UIView <UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, strong) NSMutableArray *dataSource;
@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, assign) NSInteger type;
@property(nonatomic, strong) UIImageView *emptyImage;
@end
@implementation LuckyPackageRecordsListView
- (instancetype)init
{
self = [super init];
if (self) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.separatorColor = UIColorFromRGB(0xb75a6f);
_tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0); // 左右间距 15
[_tableView registerClass:[LuckyPackageRecordsCell class] forCellReuseIdentifier:@"LuckyPackageRecordsCell"];
[self addSubview:_tableView];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.mas_equalTo(self);
make.leading.trailing.mas_equalTo(self).inset(22.5);
}];
_emptyImage = [[UIImageView alloc] initWithImage:kImage(@"缺省")];
_emptyImage.hidden = YES;
[self addSubview:_emptyImage];
[self.emptyImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.centerX.mas_equalTo(self);
make.size.mas_equalTo(CGSizeMake(123, 123));
}];
}
return self;
}
- (void)setDataSource:(NSMutableArray *)dataSource {
_dataSource = dataSource;
[self.tableView reloadData];
self.emptyImage.hidden = dataSource.count > 0;
}
#pragma mark -
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
LuckyPackageRecordsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LuckyPackageRecordsCell" forIndexPath:indexPath];
cell.type = self.type;
cell.cellModel = [self.dataSource xpSafeObjectAtIndex:indexPath.row];
return cell;
}
@end
@interface LuckyPackageRecordsView : UIView
{
UIImageView *backgroundImageView;
UIView *topButtonsContainer;
UIView *selectedPill;
}
@property(nonatomic, strong) NetImageView *avatarImageView;
@property(nonatomic, strong) UILabel *nickLabel;
@property(nonatomic, strong) LuckyPackageRecordsListView *sentRecordsView;
@property(nonatomic, strong) LuckyPackageRecordsListView *receiveRecordsView;
@property(nonatomic, strong) UIButton *backButton;
@property(nonatomic, strong) UIButton *receivedButton;
@property(nonatomic, strong) UIButton *sentButton;
@property(nonatomic, assign) BOOL currentSelectedIsReceive;
@property(nonatomic, copy)void(^tapBackButton)(void);
@property(nonatomic, copy)void(^switchTap)(BOOL isReceive);
@property(nonatomic, copy)NSArray *dateSource;
- (void)updateWithUserInfo:(UserInfoModel *)userInfo;
@end
@implementation LuckyPackageRecordsView
- (instancetype)init
{
self = [super init];
if (self) {
backgroundImageView = [[UIImageView alloc] initWithImage:kImage(@"luck_package_records_bg")];
[self addSubview:backgroundImageView];
[backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
topButtonsContainer = [[UIView alloc] init];
topButtonsContainer.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];
[topButtonsContainer setCornerRadius:17.5];
[self addSubview:topButtonsContainer];
[topButtonsContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(40);
make.leading.trailing.mas_equalTo(self).inset(23);
make.height.mas_equalTo(35);
}];
selectedPill = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 165, 35)];
[selectedPill addGradientBackgroundWithColors:@[
UIColorFromRGB(0xfff437),
UIColorFromRGB(0xff9f00)
]
startPoint:CGPointMake(0.5, 0)
endPoint:CGPointMake(0.5, 1)
cornerRadius:17.5];
[self addSubview:selectedPill];
[self addSubview:self.sentButton];
[self addSubview:self.receivedButton];
[self.sentButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.trailing.bottom.mas_equalTo(topButtonsContainer);
make.width.mas_equalTo(topButtonsContainer.mas_width).multipliedBy(0.5);
}];
[self.receivedButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.bottom.mas_equalTo(topButtonsContainer);
make.width.mas_equalTo(topButtonsContainer.mas_width).multipliedBy(0.5);
}];
[selectedPill mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.receivedButton);
make.size.mas_equalTo(self.receivedButton);
}];
[self addSubview:self.avatarImageView];
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.top.mas_equalTo(topButtonsContainer.mas_bottom).offset(14);
make.size.mas_equalTo(65);
}];
[self addSubview:self.nickLabel];
[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.top.mas_equalTo(self.avatarImageView.mas_bottom).offset(9);
}];
[self addSubview:self.backButton];
[self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self);
make.leading.mas_equalTo(11);
make.size.mas_equalTo(CGSizeMake(30, 30));
}];
[self addSubview:self.sentRecordsView];
[self addSubview:self.receiveRecordsView];
[self.sentRecordsView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.nickLabel.mas_bottom).offset(20);
make.leading.bottom.trailing.mas_equalTo(self);
}];
[self.receiveRecordsView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.nickLabel.mas_bottom).offset(20);
make.leading.bottom.trailing.mas_equalTo(self);
}];
[self didTapReceive];
}
return self;
}
- (void)setDateSource:(NSArray *)dateSource {
_dateSource = dateSource;
if (self.currentSelectedIsReceive) {
[self.receiveRecordsView setDataSource:dateSource.mutableCopy];
} else {
[self.sentRecordsView setDataSource:dateSource.mutableCopy];
}
self.avatarImageView.hidden = dateSource.count == 0;
self.nickLabel.hidden = dateSource.count == 0;
}
- (void)didTapBack {
if (_tapBackButton) {
_tapBackButton();
}
}
- (void)didTapSent {
if (!self.currentSelectedIsReceive) {
return;
}
[selectedPill mas_remakeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.sentButton);
make.size.mas_equalTo(self.sentButton);
}];
self.sentButton.selected = YES;
self.receivedButton.selected = NO;
self.sentRecordsView.hidden = NO;
self.receiveRecordsView.hidden = YES;
self.currentSelectedIsReceive = NO;
if (_switchTap) {
self.switchTap(NO);
}
}
- (void)didTapReceive {
if (self.currentSelectedIsReceive) {
return;
}
[selectedPill mas_remakeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.receivedButton);
make.size.mas_equalTo(self.receivedButton);
}];
self.sentButton.selected = NO;
self.receivedButton.selected = YES;
self.sentRecordsView.hidden = YES;
self.receiveRecordsView.hidden = NO;
self.currentSelectedIsReceive = YES;
if (_switchTap) {
self.switchTap(YES);
}
}
- (void)updateWithUserInfo:(UserInfoModel *)userInfo {
self.avatarImageView.imageUrl = userInfo.avatar;
self.nickLabel.text = userInfo.nick;
}
#pragma mark -
- (NetImageView *)avatarImageView {
if (!_avatarImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
[_avatarImageView setAllCornerRadius:65/2
borderWidth:2
borderColor:UIColorFromRGB(0xffd168)];
}
return _avatarImageView;
}
- (UILabel *)nickLabel {
if (!_nickLabel) {
_nickLabel = [UILabel labelInitWithText:@"" font:kFontMedium(14) textColor:UIColorFromRGB(0xffea5c)];
_nickLabel.textAlignment = NSTextAlignmentCenter;
}
return _nickLabel;
}
- (LuckyPackageRecordsListView *)sentRecordsView {
if (!_sentRecordsView) {
_sentRecordsView = [[LuckyPackageRecordsListView alloc] init];
_sentRecordsView.type = 1;
}
return _sentRecordsView;
}
- (LuckyPackageRecordsListView *)receiveRecordsView {
if (!_receiveRecordsView) {
_receiveRecordsView = [[LuckyPackageRecordsListView alloc] init];
_receiveRecordsView.type = 2;
}
return _receiveRecordsView;
}
- (UIButton *)backButton {
if (!_backButton) {
_backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_backButton setImage:kImage(@"luck_package_records_back") forState:UIControlStateNormal];
[_backButton addTarget:self action:@selector(didTapBack) forControlEvents:UIControlEventTouchUpInside];
}
return _backButton;
}
- (UIButton *)sentButton {
if (!_sentButton) {
_sentButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_sentButton setTitle:YMLocalizedString(@"1.0.37_text_15") forState:UIControlStateNormal];
[_sentButton setTitleColor:UIColorFromRGB(0xffea5c) forState:UIControlStateNormal];
[_sentButton setTitleColor:UIColorFromRGB(0x292601) forState:UIControlStateSelected];
[_sentButton addTarget:self action:@selector(didTapSent) forControlEvents:UIControlEventTouchUpInside];
}
return _sentButton;
}
- (UIButton *)receivedButton {
if (!_receivedButton) {
_receivedButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_receivedButton setTitle:YMLocalizedString(@"1.0.37_text_14") forState:UIControlStateNormal];
[_receivedButton setTitleColor:UIColorFromRGB(0xffea5c) forState:UIControlStateNormal];
[_receivedButton setTitleColor:UIColorFromRGB(0x292601) forState:UIControlStateSelected];
[_receivedButton addTarget:self action:@selector(didTapReceive) forControlEvents:UIControlEventTouchUpInside];
_receivedButton.selected = YES;
}
return _receivedButton;
}
@end
@interface GiftCountCalculator : UIView
@property(nonatomic, assign) NSInteger count;
@property(nonatomic, strong) UILabel *countLabel;
@property(nonatomic, strong) UIButton *reduceButton;
@property(nonatomic, strong) UIButton *increaseButton;
@property(nonatomic, copy) void(^tapReduce)(NSInteger count);
@property(nonatomic, copy) void(^tapIncrease)(NSInteger count);
@property(nonatomic, copy) void(^tapCountLabel)(void);
- (void)reset;
- (void)updateCount:(NSInteger)count;
@end
@implementation GiftCountCalculator
- (instancetype)init
{
self = [super init];
if (self) {
self.count = 0;
self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];
[self setCornerRadius:4];
_countLabel = [UILabel labelInitWithText:@"0" font:kFontMedium(12) textColor:[UIColor whiteColor]];
_countLabel.textAlignment = NSTextAlignmentCenter;
_countLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
_countLabel.userInteractionEnabled = YES;
[_countLabel setCornerRadius:4];
_reduceButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_reduceButton setImage:kImage(@"luck_package_item_reduce") forState:UIControlStateNormal];
[_reduceButton addTarget:self action:@selector(didTapReduce) forControlEvents:UIControlEventTouchUpInside];
_increaseButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_increaseButton setImageEdgeInsets:UIEdgeInsetsMake(2, 2, 2, 2)];
[_increaseButton setImage:kImage(@"mine_guild_add_room") forState:UIControlStateNormal];
[_increaseButton addTarget:self action:@selector(didTapIncrease) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.countLabel];
[self addSubview:self.reduceButton];
[self addSubview:self.increaseButton];
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self);
make.size.mas_equalTo(CGSizeMake(22, 18));
}];
[self.reduceButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.bottom.mas_equalTo(self);
make.width.mas_equalTo(self.reduceButton.mas_height);
}];
[self.increaseButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.trailing.bottom.mas_equalTo(self);
make.width.mas_equalTo(self.reduceButton.mas_height);
}];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(displayKeyboard)];
[self.countLabel addGestureRecognizer:tap];
}
return self;
}
- (void)reset {
self.count = 0;
self.countLabel.text = @"0";
}
- (void)updateCount:(NSInteger)count {
self.count = count;
self.countLabel.text = @(self.count).stringValue;
}
- (void)didTapReduce {
_count = MAX(0, _count-1);
self.countLabel.text = @(self.count).stringValue;
if (_tapReduce) {
_tapReduce(_count);
}
}
- (void)didTapIncrease {
_count = MIN(99, _count+1);
self.countLabel.text = @(self.count).stringValue;
if (_tapIncrease) {
_tapIncrease(_count);
}
}
- (void)displayKeyboard {
if (_tapCountLabel) {
self.tapCountLabel();
}
}
@end
@interface OneLineImageItemCell : UICollectionViewCell
- (void)updateCell:(NSNumber *)content index:(NSInteger)index;
@end
@implementation OneLineImageItemCell
{
UIImageView *normalBGImageView;
UIImageView *selectedBGImageView;
UIImageView *iconImageView;
UILabel *numberLabel;
UIImageView *moneyImageView;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self.contentView setCornerRadius:12
corners:UIRectCornerTopLeft|UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight
borderWidth:1
borderColor:UIColorFromRGB(0xffd168)];
normalBGImageView = [[UIImageView alloc] initWithImage:[UIImage gradientColorImageFromColors:@[
UIColorFromRGB(0x97000c),
UIColorFromRGB(0x610015)
]
gradientType:GradientTypeTopToBottom
imgSize:CGSizeMake(75, 100)]];
selectedBGImageView = [[UIImageView alloc] initWithImage:[UIImage gradientColorImageFromColors:@[
UIColorFromRGB(0xFFF437),
UIColorFromRGB(0xFF9f00)
]
gradientType:GradientTypeTopToBottom
imgSize:CGSizeMake(75, 100)]];
selectedBGImageView.hidden = YES;
iconImageView = [[UIImageView alloc] init];
numberLabel = [UILabel labelInitWithText:@"0" font:kFontRegular(13) textColor:UIColorFromRGB(0xffea5c)];
moneyImageView = [[UIImageView alloc] initWithImage:kImage(@"moli_money_icon")];
moneyImageView.contentMode = UIViewContentModeScaleAspectFit;
UIStackView *stack = [[UIStackView alloc] initWithArrangedSubviews:@[
numberLabel,
moneyImageView
]];
stack.spacing = 2.5;
stack.axis = UILayoutConstraintAxisHorizontal;
[self.contentView addSubview:normalBGImageView];
[self.contentView addSubview:selectedBGImageView];
[self.contentView addSubview:iconImageView];
[self.contentView addSubview:stack];
[normalBGImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
[selectedBGImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
[iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.trailing.mas_equalTo(self.contentView).inset(6.5);
make.height.mas_equalTo(iconImageView.mas_width);
}];
[stack mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.bottom.mas_equalTo(self.contentView).offset(-6);
make.height.mas_equalTo(16);
}];
}
return self;
}
- (void)setSelected:(BOOL)selected {
[super setSelected:selected];
if (selected) {
normalBGImageView.hidden = YES;
selectedBGImageView.hidden = NO;
numberLabel.textColor = UIColorFromRGB(0x292601);
} else {
normalBGImageView.hidden = NO;
selectedBGImageView.hidden = YES;
numberLabel.textColor = UIColorFromRGB(0xffea5c);
}
}
- (void)updateCell:(NSNumber *)content index:(NSInteger)index {
switch (index) {
case 0:
iconImageView.image = kImage(@"luck_package_bag_lv1");
break;
case 1:
iconImageView.image = kImage(@"luck_package_bag_lv2");
break;
case 2:
iconImageView.image = kImage(@"luck_package_bag_lv3");
break;
case 3:
iconImageView.image = kImage(@"luck_package_bag_lv4");
break;
default:
break;
}
numberLabel.text = content.stringValue;
}
@end
@interface OneLineImageButtons : UIView <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property(nonatomic, copy) NSArray<NSNumber *> *dataSource;
@property(nonatomic, copy) void(^didSelected)(NSInteger index);
@end
@implementation OneLineImageButtons
{
UICollectionView *collectionView;
}
- (instancetype)init
{
self = [super init];
if (self) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(kGetScaleWidth(75), kGetScaleWidth(100));
layout.sectionInset = UIEdgeInsetsMake(0, 20, 0, 20);
collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
collectionView.backgroundColor = [UIColor clearColor];
collectionView.delegate = self;
collectionView.dataSource = self;
[collectionView registerClass:[OneLineImageItemCell class] forCellWithReuseIdentifier:@"OneLineImageItemCell"];
[self addSubview:collectionView];
[collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
}
return self;
}
- (void)setDataSource:(NSArray<NSNumber *> *)dataSource {
_dataSource = dataSource;
[collectionView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
NSIndexPath *firstIndexPath = [NSIndexPath indexPathForItem:0 inSection:0];
[self->collectionView selectItemAtIndexPath:firstIndexPath
animated:NO
scrollPosition:UICollectionViewScrollPositionNone];
});
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataSource.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
OneLineImageItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"OneLineImageItemCell" forIndexPath:indexPath];
[cell updateCell:[self.dataSource xpSafeObjectAtIndex:indexPath.item] index:indexPath.item];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (_didSelected) {
self.didSelected(indexPath.item);
}
}
@end
@interface OneLineButtons : UIView
@property(nonatomic, copy) NSArray<NSString *> *dataSource;
@property(nonatomic, copy) void(^didSelected)(NSInteger index);
@end
@implementation OneLineButtons
{
UIButton *button_1;
UIButton *button_2;
UIButton *button_3;
UIButton *button_4;
}
- (instancetype)init
{
self = [super init];
if (self) {
button_1 = [self createButton:0];
button_2 = [self createButton:1];
button_3 = [self createButton:2];
button_4 = [self createButton:3];
UIStackView *stack = [[UIStackView alloc] initWithArrangedSubviews:@[
button_1,
button_2,
button_3,
button_4
]];
stack.spacing = 10;
stack.distribution = UIStackViewDistributionFillEqually;
[self addSubview:stack];
[stack mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self).insets(UIEdgeInsetsMake(0, 20, 0, 20));
}];
button_1.selected = YES;
}
return self;
}
- (UIButton *)createButton:(NSInteger)tag {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
b.tag = tag;
b.frame = CGRectMake(0, 0, kGetScaleWidth(80), 30);
UIImage *normalImage = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0x97000C), UIColorFromRGB(0x610015)]
gradientType:GradientTypeTopToBottom
imgSize:CGSizeMake(kGetScaleWidth(80), 30)];
UIImage *selectedImage = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xFFF437), UIColorFromRGB(0xFF9F00)]
gradientType:GradientTypeTopToBottom
imgSize:CGSizeMake(kGetScaleWidth(80), 30)];
[b setCornerRadius:6
corners:UIRectCornerTopLeft|UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight
borderWidth:0.5
borderColor:UIColorFromRGB(0xFEF057)];
[b setBackgroundImage:normalImage forState:UIControlStateNormal];
[b setBackgroundImage:selectedImage forState:UIControlStateSelected];
[b setTitleColor:UIColorFromRGB(0xFFEA5C) forState:UIControlStateNormal];
[b setTitleColor:UIColorFromRGB(0x292601) forState:UIControlStateSelected];
[b.titleLabel setFont:kFontRegular(12)];
[b addTarget:self action:@selector(handleTapEvent:) forControlEvents:UIControlEventTouchUpInside];
return b;
}
- (void)setDataSource:(NSArray<NSString *> *)dataSource {
_dataSource = dataSource;
[button_1 setTitle:dataSource[0] forState:UIControlStateNormal];
[button_2 setTitle:dataSource[1] forState:UIControlStateNormal];
[button_3 setTitle:dataSource[2] forState:UIControlStateNormal];
[button_4 setTitle:dataSource[3] forState:UIControlStateNormal];
}
- (void)handleTapEvent:(UIButton *)sender {
button_1.selected = NO;
button_2.selected = NO;
button_3.selected = NO;
button_4.selected = NO;
sender.selected = YES;
if (_didSelected) {
self.didSelected(sender.tag);
}
}
@end
@interface WalletBalanceDisplayView : UIView
@property(nonatomic, strong) UIImageView *moneyImageView;
@property(nonatomic, strong) UILabel *balanceLabel;
@property(nonatomic, strong) UIButton *addButton;
@property(nonatomic, strong) UIView *spacer;
@property(nonatomic, strong) UIStackView *stack;
@property(nonatomic, copy) void(^tapAddButton)(void);
- (void)hideAddButton;
- (void)updatePrice:(double)price;
@end
@implementation WalletBalanceDisplayView
- (instancetype)init
{
self = [super init];
if (self) {
_moneyImageView = [[UIImageView alloc] initWithImage:kImage(@"moli_money_icon")];
_moneyImageView.contentMode = UIViewContentModeScaleAspectFit;
// [self addSubview:self.moneyImageView];
_balanceLabel = [UILabel labelInitWithText:@"0" font:kFontMedium(15) textColor:UIColorFromRGB(0xFFEA5C)];
// [self addSubview:self.balanceLabel];
_addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_addButton setImage:kImage(@"luck_package_add") forState:UIControlStateNormal];
[self.addButton addTarget:self action:@selector(didTapAddButton) forControlEvents:UIControlEventTouchUpInside];
_spacer = [[UIView alloc] init];
self.spacer.backgroundColor = [UIColor clearColor];
_stack = [[UIStackView alloc] initWithArrangedSubviews:@[
self.moneyImageView,
self.balanceLabel,
self.addButton,
self.spacer
]];
self.stack.spacing = 4;
self.stack.alignment = UIStackViewAlignmentLeading;
self.stack.distribution = UIStackViewDistributionFill;
[self addSubview:self.stack];
[self.stack mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
// **让 spacer 充满右侧空间**
[self.spacer setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
}
return self;
}
- (void)hideAddButton {
self.addButton.hidden = YES;
self.spacer.hidden = YES;
self.stack.alignment = UIStackViewAlignmentCenter;
}
- (void)updatePrice:(double)price {
self.balanceLabel.text = @(price).stringValue;
}
- (void)didTapAddButton {
if (_tapAddButton) {
self.tapAddButton();
}
}
@end
@interface ChooseViewTitleBar : UIView
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UIImageView *leftImageView;
@property(nonatomic, strong) UIImageView *rightImageView;
- (void)updateTitle:(NSString *)content;
@end
@implementation ChooseViewTitleBar
- (instancetype)init
{
self = [super init];
if (self) {
_titleLabel = [UILabel labelInitWithText:@"" font:kFontMedium(14) textColor:UIColorFromRGB(0xffea5c)];
if (isMSRTL()) {
_leftImageView = [[UIImageView alloc] initWithImage:kImage(@"luck_package_right")];
_rightImageView = [[UIImageView alloc] initWithImage:kImage(@"luck_package_left")];
} else {
_leftImageView = [[UIImageView alloc] initWithImage:kImage(@"luck_package_left")];
_rightImageView = [[UIImageView alloc] initWithImage:kImage(@"luck_package_right")];
}
_leftImageView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
_rightImageView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
[self addSubview:self.titleLabel];
[self addSubview:self.leftImageView];
[self addSubview:self.rightImageView];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self);
make.height.mas_equalTo(18);
}];
[self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.titleLabel);
make.trailing.mas_equalTo(self.titleLabel.mas_leading).offset(-15);
make.size.mas_equalTo(CGSizeMake(80, 15));
}];
[self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.titleLabel);
make.leading.mas_equalTo(self.titleLabel.mas_trailing).offset(15);
make.size.mas_equalTo(CGSizeMake(80, 15));
}];
}
return self;
}
- (void)updateTitle:(NSString *)content {
self.titleLabel.text = content;
}
@end
@interface ChooseCoinView : UIView
@property(nonatomic, strong) UIScrollView *scrollView;
@property(nonatomic, strong) OneLineImageButtons *oneLineImageButtons;
@property(nonatomic, strong) ChooseViewTitleBar *luckyBagTitleBar;
@property(nonatomic, strong) ChooseViewTitleBar *waitingTitleBar;
@property(nonatomic, strong) OneLineButtons *luckyBagOneLineButtons;
@property(nonatomic, strong) OneLineButtons *waitingTimeOneLineButtons;
@property(nonatomic, strong) UILabel *totalCostLabel;
@property(nonatomic, strong) WalletBalanceDisplayView *walletView;
@property(nonatomic, strong) UIButton *sendButton;
@property(nonatomic, copy) void(^tapSendCoin)(void);
@end
@implementation ChooseCoinView
- (instancetype)init
{
self = [super init];
if (self) {
_scrollView = [[UIScrollView alloc] init];
[self addSubview:self.scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
// 创建容器视图,承载所有内容
UIView *contentView = [[UIView alloc] init];
contentView.backgroundColor = [UIColor clearColor];
[self.scrollView addSubview:contentView];
// 使用 Masonry 设置容器视图的约束
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.scrollView); // 与 scrollView 对齐
make.width.mas_equalTo(self.scrollView); // 宽度与 scrollView 相同
}];
_oneLineImageButtons = [[OneLineImageButtons alloc] init];
[contentView addSubview:self.oneLineImageButtons];
[self.oneLineImageButtons mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(50);
make.leading.trailing.mas_equalTo(contentView);
make.height.mas_equalTo(kGetScaleWidth(100));
}];
_luckyBagTitleBar = [[ChooseViewTitleBar alloc] init];
[contentView addSubview:self.luckyBagTitleBar];
[self.luckyBagTitleBar updateTitle:YMLocalizedString(@"1.0.37_text_8")];
[self.luckyBagTitleBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.oneLineImageButtons.mas_bottom).offset(46);
make.leading.trailing.mas_equalTo(contentView);
make.height.mas_equalTo(18);
}];
_luckyBagOneLineButtons = [[OneLineButtons alloc] init];
[contentView addSubview:self.luckyBagOneLineButtons];
[self.luckyBagOneLineButtons mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.luckyBagTitleBar.mas_bottom).offset(12.5);
make.leading.trailing.mas_equalTo(contentView);
make.height.mas_equalTo(30);
}];
_waitingTitleBar = [[ChooseViewTitleBar alloc] init];
[contentView addSubview:self.waitingTitleBar];
[self.waitingTitleBar updateTitle:YMLocalizedString(@"1.0.37_text_5")];
[self.waitingTitleBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.luckyBagOneLineButtons.mas_bottom).offset(46);
make.leading.trailing.mas_equalTo(contentView);
make.height.mas_equalTo(18);
}];
_waitingTimeOneLineButtons = [[OneLineButtons alloc] init];
[contentView addSubview:self.waitingTimeOneLineButtons];
[self.waitingTimeOneLineButtons mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.waitingTitleBar.mas_bottom).offset(12.5);
make.leading.trailing.mas_equalTo(contentView);
make.height.mas_equalTo(30);
}];
_totalCostLabel = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:UIColorFromRGB(0xffea5c)];
_totalCostLabel.textAlignment = NSTextAlignmentCenter;
[contentView addSubview:self.totalCostLabel];
[self.totalCostLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.waitingTimeOneLineButtons.mas_bottom).offset(30);
make.leading.trailing.mas_equalTo(contentView);
}];
UIView *space = [[UIView alloc] init];
[contentView addSubview:space];
[space mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.leading.trailing.mas_equalTo(contentView);
make.top.mas_equalTo(self.totalCostLabel.mas_bottom);
make.height.mas_equalTo(100);
}];
_walletView = [[WalletBalanceDisplayView alloc] init];
[_walletView setTapAddButton:^{
// @kStrongify(self);
// [self gotoChargeView];
}];
[self addSubview:self.walletView];
[self.walletView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self).offset(-32);
make.leading.mas_equalTo(self).offset(23);
make.width.mas_equalTo(150);
make.height.mas_equalTo(24);
}];
_sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_sendButton.titleLabel setFont:kFontSemibold(15)];
[_sendButton setBackgroundImage:kImage(@"luck_package_send_bg") forState:UIControlStateNormal];
[_sendButton setTitle:YMLocalizedString(@"1.0.37_text_15.2") forState:UIControlStateNormal];
[_sendButton setTitleColor:UIColorFromRGB(0x292601) forState:UIControlStateNormal];
[_sendButton addTarget:self action:@selector(didTapSendButton) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.sendButton];
[self.sendButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.trailing.mas_equalTo(self).offset(-18);
make.width.mas_equalTo(190);
make.height.mas_equalTo(50);
}];
[self setupDataSource];
}
return self;
}
- (void)setupDataSource {
NSArray *moneys = [[LuckyPackageLogicManager sharedInstance] loadConfigLuckyBagMoneys];
[self.oneLineImageButtons setDataSource:moneys];
[self.oneLineImageButtons setDidSelected:^(NSInteger index) {
[[LuckyPackageLogicManager sharedInstance] updateSelectedBag:[moneys[index] integerValue]];
}];
NSMutableArray *arr_bag = @[].mutableCopy;
NSArray *bagNumber = [[LuckyPackageLogicManager sharedInstance] loadConfigLuckyBagNumbers];
for (NSNumber *num in bagNumber) {
[arr_bag addObject:num.stringValue];
}
[self.luckyBagOneLineButtons setDataSource:arr_bag.copy];
[self.luckyBagOneLineButtons setDidSelected:^(NSInteger index) {
[[LuckyPackageLogicManager sharedInstance] updateSelectedBagNum:[bagNumber[index] integerValue]];
}];
NSArray *times = [[LuckyPackageLogicManager sharedInstance] loadConfigWaitingTimesMins];
NSMutableArray *arr_time = @[].mutableCopy;
for (NSNumber *time in times) {
[arr_time addObject:[NSString stringWithFormat:YMLocalizedString(@"1.0.37_text_7"), time]];
}
[self.waitingTimeOneLineButtons setDataSource:arr_time.copy];
[self.waitingTimeOneLineButtons setDidSelected:^(NSInteger index) {
[[LuckyPackageLogicManager sharedInstance] updateSelectedBagWaitingTime:[times[index] integerValue] * 60];
}];
[self.walletView updatePrice:[[LuckyPackageLogicManager sharedInstance] loadSavedWalletInfo].diamonds.doubleValue];
self.totalCostLabel.attributedText = [[LuckyPackageLogicManager sharedInstance] loadCoinTotalCostString];
@kWeakify(self);
[[LuckyPackageLogicManager sharedInstance] registerCoinTotalCostString:^(NSAttributedString * _Nonnull content) {
@kStrongify(self);
self.totalCostLabel.attributedText = content;
}];
}
- (void)didTapSendButton {
if (_tapSendCoin) {
_tapSendCoin();
}
}
@end
@interface ChooseGiftCell : UICollectionViewCell
@property(nonatomic, strong) GiftInfoModel *cellModel;
@property(nonatomic, assign) NSInteger giftCount;
@property(nonatomic, strong) UIView *bgView;
@property(nonatomic, strong) NetImageView *giftIconImageView;
@property(nonatomic, strong) MarqueeLabel *giftNameLabel;
@property(nonatomic, strong) UILabel *giftCountLabel;
@property(nonatomic, strong) GiftCountCalculator *giftCountView;
@property(nonatomic, strong) MoliMoneyLabel *priceLabel;
@property(nonatomic, copy) void(^modifySelectedGift)(GiftInfoModel *model, NSInteger count);
@property(nonatomic, copy) void(^editGiftCount)(GiftInfoModel *model);
@end
@implementation ChooseGiftCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.contentView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.bgView];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.trailing.mas_equalTo(self.contentView);
make.height.mas_equalTo(self.bgView.mas_width);
}];
[self.contentView addSubview:self.giftIconImageView];
[self.giftIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.bgView).insets(UIEdgeInsetsMake(6, 6, 6, 6));
}];
[self.contentView addSubview:self.giftNameLabel];
[self.giftNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.contentView);
make.top.mas_equalTo(self.bgView.mas_bottom).offset(6);
make.height.mas_equalTo(14);
}];
[self.contentView addSubview:self.priceLabel];
[self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.top.mas_equalTo(self.giftNameLabel.mas_bottom).offset(3);
make.height.mas_equalTo(16);
}];
[self.contentView addSubview:self.giftCountView];
[self.giftCountView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(4);
make.height.mas_equalTo(20);
make.width.mas_equalTo(60);
}];
}
return self;
}
- (void)prepareForReuse {
[super prepareForReuse];
[self.giftCountView reset];
}
- (void)setCellModel:(GiftInfoModel *)cellModel {
_cellModel = cellModel;
self.giftIconImageView.imageUrl = cellModel.giftUrl;
self.giftNameLabel.text = cellModel.giftName;
[self.priceLabel updateContent:@(cellModel.goldPrice).stringValue];
[self.giftCountView updateCount:cellModel.luckyPackageCount];
}
- (void)setGiftCount:(NSInteger)giftCount {
_giftCount = giftCount;
if (!_giftCountLabel) {
[self.giftCountView removeFromSuperview];
_giftCountLabel = [UILabel labelInitWithText:[NSString stringWithFormat:@"x%@", @(giftCount)]
font:kFontRegular(13)
textColor:UIColorFromRGB(0xffea5c)];
[self.contentView addSubview:_giftCountLabel];
[self.giftCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(2);
make.height.mas_equalTo(14);
}];
}
self.giftCountLabel.text = [NSString stringWithFormat:@"x%@", @(giftCount)];
}
- (UIView *)bgView {
if (!_bgView) {
_bgView = [[UIView alloc] init];
[_bgView addGradientBackgroundWithColors:@[UIColorFromRGB(0x610015), UIColorFromRGB(0x97000c)]
startPoint:CGPointMake(0.5, 0)
endPoint:CGPointMake(0.5, 1)
cornerRadius:12];
[_bgView setCornerRadius:12
corners:UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight
borderWidth:1
borderColor:UIColorFromRGB(0xFEF057)];
}
return _bgView;
}
- (NetImageView *)giftIconImageView {
if (!_giftIconImageView) {
NetImageConfig *config = [[NetImageConfig alloc] init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_giftIconImageView = [[NetImageView alloc] initWithConfig:config];
_giftIconImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _giftIconImageView;
}
- (MarqueeLabel *)giftNameLabel {
if (!_giftNameLabel) {
_giftNameLabel = [[MarqueeLabel alloc] init];
_giftNameLabel.text = @"Name";
_giftNameLabel.font = kFontRegular(13);
_giftNameLabel.textColor = UIColorFromRGB(0xffea5c);
_giftNameLabel.textAlignment = NSTextAlignmentCenter;
_giftNameLabel.scrollDuration = 3.0;
_giftNameLabel.fadeLength = 8.0f;
_giftNameLabel.animationDelay = 1.0;
}
return _giftNameLabel;
}
- (GiftCountCalculator *)giftCountView {
if (!_giftCountView) {
_giftCountView = [[GiftCountCalculator alloc] init];
@kWeakify(self);
[_giftCountView setTapIncrease:^(NSInteger count){
@kStrongify(self);
if (self.modifySelectedGift) {
self.modifySelectedGift(self.cellModel, count);
}
}];
[_giftCountView setTapReduce:^(NSInteger count) {
@kStrongify(self);
if (self.modifySelectedGift) {
self.modifySelectedGift(self.cellModel, count);
}
}];
[_giftCountView setTapCountLabel:^{
@kStrongify(self);
if (self.editGiftCount) {
self.editGiftCount(self.cellModel);
}
}];
}
return _giftCountView;
}
- (MoliMoneyLabel *)priceLabel {
if (!_priceLabel) {
_priceLabel = [MoliMoneyLabel moneyLabelWithTextColot:UIColorFromRGB(0xffea5c) font:kFontRegular(13) moneyPostion:1 moneySize:CGSizeMake(16, 16)];
[_priceLabel removeSpace];
}
return _priceLabel;
}
@end
@interface ChooseGiftView : UIView <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property(nonatomic, assign) NSInteger watiingTime;
@property(nonatomic, strong) UIScrollView *scrollView;
@property(nonatomic, strong) ChooseViewTitleBar *chooseGiftTitleBar;
@property(nonatomic, strong) ChooseViewTitleBar *waitingTitleBar;
@property(nonatomic, strong) UICollectionView *giftsCollectionView;
@property(nonatomic, strong) UIPageControl *pageControl;
@property(nonatomic, strong) NSArray <GiftInfoModel *>*dataSources;
@property(nonatomic, assign) NSInteger pageCount;
@property(nonatomic, strong) OneLineButtons *waitingTimeOneLineButtons;
@property(nonatomic, strong) UILabel *totalCostLabel;
@property(nonatomic, strong) WalletBalanceDisplayView *walletView;
@property(nonatomic, strong) UIButton *sendButton;
@property(nonatomic, strong) UITextField *hiddenTextField;
@property(nonatomic, strong) UITextField *inputTextField;
@property(nonatomic, strong) GiftInfoModel *editingModel;
@property (nonatomic, strong) UIView *customInputView;
@property(nonatomic, copy) void(^forceClose)(void);
@property(nonatomic, copy) void(^tapSendGift)(void);
- (void)refreshData;
@end
@implementation ChooseGiftView
- (instancetype)init
{
self = [super init];
if (self) {
self.watiingTime = 5;
@kWeakify(self);
[[LuckyPackageLogicManager sharedInstance] registerGiftTotalCostString:^(NSAttributedString * _Nonnull content) {
@kStrongify(self);
self.totalCostLabel.attributedText = content;
} key:@"ChooseGiftView"];
_scrollView = [[UIScrollView alloc] init];
[self addSubview:self.scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
// 创建容器视图,承载所有内容
UIView *contentView = [[UIView alloc] init];
contentView.backgroundColor = [UIColor clearColor];
[self.scrollView addSubview:contentView];
// 使用 Masonry 设置容器视图的约束
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.scrollView); // 与 scrollView 对齐
make.width.mas_equalTo(self.scrollView); // 宽度与 scrollView 相同
}];
_chooseGiftTitleBar = [[ChooseViewTitleBar alloc] init];
[self.chooseGiftTitleBar updateTitle:YMLocalizedString(@"1.0.37_text_3")];
_waitingTitleBar = [[ChooseViewTitleBar alloc] init];
[self.waitingTitleBar updateTitle:YMLocalizedString(@"1.0.37_text_5")];
[contentView addSubview:self.chooseGiftTitleBar];
[self.chooseGiftTitleBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(contentView).offset(6);
make.leading.trailing.mas_equalTo(contentView);
make.height.mas_equalTo(18);
}];
CGFloat itemWidth = (KScreenWidth - 40 - 30)/4.0;
CGFloat itemHeight = kGetScaleWidth(75) + 6 + 12 + 3 + 16 + 4 + 28;
XPGiftCollectionViewFlowLayout *layout = [[XPGiftCollectionViewFlowLayout alloc] init];
layout.minimumInteritemSpacing = 10;
layout.minimumLineSpacing = 10;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.itemSize = CGSizeMake(itemWidth, itemHeight);
layout.sectionInset = UIEdgeInsetsMake(10, 0, 0, 0);
_giftsCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_giftsCollectionView.clipsToBounds = YES;
_giftsCollectionView.backgroundColor = [UIColor clearColor];
_giftsCollectionView.delegate = self;
_giftsCollectionView.dataSource = self;
_giftsCollectionView.pagingEnabled = YES;
_giftsCollectionView.showsHorizontalScrollIndicator = NO;
[_giftsCollectionView registerClass:[ChooseGiftCell class] forCellWithReuseIdentifier:@"ChooseGiftCell"];
_giftsCollectionView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
[contentView addSubview:self.giftsCollectionView];
[self.giftsCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(contentView).inset(20);
make.top.mas_equalTo(self.chooseGiftTitleBar.mas_bottom).offset(10);
make.height.mas_equalTo(itemHeight * 2 + 30);
}];
_pageControl = [[UIPageControl alloc] init];
_pageControl.numberOfPages = 1;
_pageControl.currentPage = 0;
_pageControl.pageIndicatorTintColor = [UIColor colorWithWhite:0 alpha:0.3];
_pageControl.currentPageIndicatorTintColor = UIColorFromRGB(0xffea5c);
[contentView addSubview:self.pageControl];
[self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.giftsCollectionView.mas_bottom).offset(3);
make.leading.trailing.mas_equalTo(contentView);
make.height.mas_equalTo(10);
}];
[contentView addSubview:self.waitingTitleBar];
[self.waitingTitleBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.pageControl.mas_bottom).offset(10);
make.leading.trailing.mas_equalTo(contentView);
make.height.mas_equalTo(18);
}];
_waitingTimeOneLineButtons = [[OneLineButtons alloc] init];
[_waitingTimeOneLineButtons setDidSelected:^(NSInteger index) {
@kStrongify(self);
[self selectWaitingTime:index];
}];
[contentView addSubview:_waitingTimeOneLineButtons];
[self.waitingTimeOneLineButtons mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.waitingTitleBar.mas_bottom).offset(12);
make.leading.trailing.mas_equalTo(contentView);
make.height.mas_equalTo(30);
}];
_walletView = [[WalletBalanceDisplayView alloc] init];
[_walletView setTapAddButton:^{
@kStrongify(self);
[self gotoChargeView];
}];
[self addSubview:self.walletView];
[self.walletView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self).offset(-32);
make.leading.mas_equalTo(self).offset(23);
make.width.mas_equalTo(150);
make.height.mas_equalTo(24);
}];
_sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_sendButton.titleLabel setFont:kFontSemibold(15)];
[_sendButton setBackgroundImage:kImage(@"luck_package_send_bg") forState:UIControlStateNormal];
[_sendButton setTitle:YMLocalizedString(@"1.0.37_text_15.1") forState:UIControlStateNormal];
[_sendButton setTitleColor:UIColorFromRGB(0x292601) forState:UIControlStateNormal];
[_sendButton addTarget:self action:@selector(didTapSendButton) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.sendButton];
[self.sendButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.trailing.mas_equalTo(self).offset(-18);
make.width.mas_equalTo(190);
make.height.mas_equalTo(50);
}];
_totalCostLabel = [UILabel labelInitWithText:@""
font:kFontRegular(12)
textColor:UIColorFromRGB(0xFFEA5C)];
_totalCostLabel.attributedText = [[LuckyPackageLogicManager sharedInstance] loadGiftTotalCostString];
_totalCostLabel.textAlignment = NSTextAlignmentCenter;
[contentView addSubview:_totalCostLabel];
[self.totalCostLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.waitingTimeOneLineButtons.mas_bottom).offset(12);
make.leading.trailing.mas_equalTo(contentView);
make.height.mas_equalTo(20);
}];
NSArray *times = [[LuckyPackageLogicManager sharedInstance] loadConfigWaitingTimesMins];
NSMutableArray *arr = @[].mutableCopy;
for (NSNumber *time in times) {
[arr addObject:[NSString stringWithFormat:YMLocalizedString(@"1.0.37_text_7"), time]];
}
[self.waitingTimeOneLineButtons setDataSource:arr.copy];
self.hiddenTextField = [[UITextField alloc] initWithFrame:CGRectMake(KScreenWidth, KScreenHeight, KScreenWidth, 50)];
self.hiddenTextField.keyboardType = UIKeyboardTypeNumberPad;
[self addSubview:self.hiddenTextField];
self.customInputView = [self createInputAccessoryView];
self.hiddenTextField.inputAccessoryView = self.customInputView;
UIView *space = [[UIView alloc] init];
[contentView addSubview:space];
[space mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.leading.trailing.mas_equalTo(contentView);
make.top.mas_equalTo(self.totalCostLabel.mas_bottom);
make.height.mas_equalTo(100);
}];
}
return self;
}
- (void)refreshData {
[self.giftsCollectionView reloadData];
}
- (void)setDataSources:(NSArray<GiftInfoModel *> *)dataSources {
_dataSources = dataSources;
self.pageCount = ceil(self.dataSources.count / 8.0);
self.pageControl.numberOfPages = self.pageCount;
[self.giftsCollectionView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
[self adjustCollectionViewContentInset];
});
}
// **创建 inputAccessoryView输入栏 + 确认按钮)**
- (UIView *)createInputAccessoryView {
UIView *toolbar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 50)];
toolbar.backgroundColor = UIColorFromRGB(0xf4f4f4);
// **确认按钮**
UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
[confirmButton setTitle:YMLocalizedString(@"TTAlertConfig0") forState:UIControlStateNormal];
[confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[confirmButton.titleLabel setFont:kFontRegular(14)];
[confirmButton setCornerRadius:17];
[confirmButton addGradientBackgroundWithColors:@[
UIColorFromRGB(0xe29030),
UIColorFromRGB(0xfcc074)
] startPoint:CGPointMake(0, 0.5) endPoint:CGPointMake(1, 1) cornerRadius:17];
[confirmButton addTarget:self action:@selector(confirmButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[toolbar addSubview:confirmButton];
[confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(toolbar);
make.trailing.mas_equalTo(toolbar).offset(-15);
make.size.mas_equalTo(CGSizeMake(74, 34));
}];
// 输入栏
UITextField *inputField = [[UITextField alloc] init];
inputField.backgroundColor = [UIColor whiteColor];
[inputField setCornerRadius:17];
inputField.borderStyle = UITextBorderStyleNone;
inputField.keyboardType = UIKeyboardTypeNumberPad;
inputField.placeholder = YMLocalizedString(@"1.0.37_text_30");
[inputField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
[toolbar addSubview:inputField];
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 8, 1)];
inputField.leftView = paddingView;
inputField.leftViewMode = UITextFieldViewModeAlways;
[inputField mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(toolbar);
make.leading.mas_equalTo(toolbar).offset(15);
make.trailing.mas_equalTo(confirmButton.mas_leading).offset(-10);
make.height.mas_equalTo(34);
}];
self.inputTextField = inputField;
return toolbar;
}
// **确认按钮点击事件**
- (void)confirmButtonTapped:(UIButton *)sender {
if (self.inputTextField.text.length > 0) {
self.editingModel.luckyPackageCount = self.inputTextField.text.integerValue;
} else {
self.editingModel.luckyPackageCount = 0;
}
[[LuckyPackageLogicManager sharedInstance] updateSelectedGift:self.editingModel
count:self.editingModel.luckyPackageCount];
[self.giftsCollectionView reloadData];
// **收起键盘**
[self.hiddenTextField resignFirstResponder];
[self.inputTextField resignFirstResponder];
[self endEditing:YES];
}
#pragma mark -
- (void)textFieldDidChange:(UITextField *)textField {
NSInteger value = [textField.text integerValue];
if (value > 99) {
textField.text = @"99"; // 超过 99强制改成 99
}
}
#pragma mark -
- (void)didTapSendButton {
if (_tapSendGift) {
_tapSendGift();
}
}
- (void)gotoChargeView {
XPIAPRechargeViewController * rechargeVC = [[XPIAPRechargeViewController alloc] init];
rechargeVC.type = @"4";
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:rechargeVC animated:YES];
if (_forceClose) {
self.forceClose();
}
}
- (void)selectWaitingTime:(NSInteger)index {
NSArray *times = [[LuckyPackageLogicManager sharedInstance] loadConfigWaitingTimesMins];
NSNumber *num = [times xpSafeObjectAtIndex:index];
self.watiingTime = num.integerValue;
[[LuckyPackageLogicManager sharedInstance] updateSelectedGiftWaitingTime:self.watiingTime * 60];
}
#pragma mark -
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataSources.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ChooseGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ChooseGiftCell" forIndexPath:indexPath];
cell.cellModel = [self.dataSources xpSafeObjectAtIndex:indexPath.item];
[cell setModifySelectedGift:^(GiftInfoModel *model, NSInteger count) {
model.luckyPackageCount = count;
[[LuckyPackageLogicManager sharedInstance] updateSelectedGift:model count:count];
}];
@kWeakify(self);
[cell setEditGiftCount:^(GiftInfoModel *model) {
@kStrongify(self);
self.editingModel = model;
[self.hiddenTextField becomeFirstResponder];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.inputTextField.text = @(model.luckyPackageCount).stringValue;
[self.inputTextField becomeFirstResponder];
});
}];
return cell;
}
// 监听滑动,更新 PageControl
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat pageWidth = self.giftsCollectionView.frame.size.width;
NSInteger currentPage = (self.giftsCollectionView.contentOffset.x + pageWidth / 2) / pageWidth;
self.pageControl.currentPage = currentPage;
}
- (void)adjustCollectionViewContentInset {
CGFloat pageWidth = self.giftsCollectionView.frame.size.width;
NSInteger totalPages = ceil((double)self.dataSources.count / 8.0);
CGFloat fullContentWidth = totalPages * pageWidth;
CGFloat remainingWidth = fullContentWidth - self.giftsCollectionView.contentSize.width;
if (remainingWidth > 0) {
self.giftsCollectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, remainingWidth);
}
}
@end
@interface ComfirmChooseGiftView : UIView <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property(nonatomic, strong) UIScrollView *scrollView;
@property(nonatomic, strong) UICollectionView *giftsCollectionView; // 不需要分页了
@property(nonatomic, strong) UILabel *waitingTimeLabel;
@property(nonatomic, strong) UILabel *totalCostLabel;
@property(nonatomic, strong) UIButton *sendButton;
@property(nonatomic, strong) UIButton *modifyButton;
@property(nonatomic, strong) NSArray <GiftInfoModel *>*dataSources;
@property(nonatomic, copy) void(^returnToModity)(void);
@property(nonatomic, copy) void(^tapButtonForGiftLuckyPackage)(void);
- (void)refreshContent;
@end
@implementation ComfirmChooseGiftView
- (instancetype)init
{
self = [super init];
if (self) {
self.backgroundColor = [UIColor clearColor];
@kWeakify(self);
[[LuckyPackageLogicManager sharedInstance] registerGiftTotalCostString:^(NSAttributedString * _Nonnull content) {
@kStrongify(self);
self.totalCostLabel.attributedText = content;
} key:@"ComfirmChooseGiftView"];
_scrollView = [[UIScrollView alloc] init];
[self addSubview:self.scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
// 创建容器视图,承载所有内容
UIView *contentView = [[UIView alloc] init];
contentView.backgroundColor = [UIColor clearColor];
[self.scrollView addSubview:contentView];
// 使用 Masonry 设置容器视图的约束
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.scrollView); // 与 scrollView 对齐
make.width.mas_equalTo(self.scrollView); // 宽度与 scrollView 相同
}];
UIView *space = [[UIView alloc] init];
[contentView addSubview:space];
CGFloat itemWidth = (KScreenWidth - 40 - 30)/4.0;
CGFloat itemHeight = kGetScaleWidth(75) + 6 + 12 + 3 + 16 + 4 + 28;
XPGiftCollectionViewFlowLayout *layout = [[XPGiftCollectionViewFlowLayout alloc] init];
layout.minimumInteritemSpacing = 10;
layout.minimumLineSpacing = 10;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.itemSize = CGSizeMake(itemWidth, itemHeight);
_giftsCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_giftsCollectionView.clipsToBounds = YES;
_giftsCollectionView.backgroundColor = [UIColor clearColor];
_giftsCollectionView.delegate = self;
_giftsCollectionView.dataSource = self;
_giftsCollectionView.pagingEnabled = YES;
_giftsCollectionView.showsHorizontalScrollIndicator = NO;
[_giftsCollectionView registerClass:[ChooseGiftCell class] forCellWithReuseIdentifier:@"ChooseGiftCell"];
[contentView addSubview:self.giftsCollectionView];
[self.giftsCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(contentView).inset(20);
make.top.mas_equalTo(contentView).offset(60);
make.height.mas_equalTo(itemHeight * 2 + 30);
}];
_waitingTimeLabel = [UILabel labelInitWithText:
[NSString stringWithFormat:YMLocalizedString(@"1.0.37_text_13"), @([[LuckyPackageLogicManager sharedInstance] loadGiftWaitingTime]/60)]
font:kFontMedium(14)
textColor:UIColorFromRGB(0xFFEA5C)];
_waitingTimeLabel.textAlignment = NSTextAlignmentCenter;
[contentView addSubview:_waitingTimeLabel];
[self.waitingTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.giftsCollectionView.mas_bottom).offset(30);
make.centerX.mas_equalTo(contentView);
make.height.mas_equalTo(16);
}];
_modifyButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_modifyButton.titleLabel setFont:kFontRegular(12)];
[_modifyButton setTitleColor:UIColorFromRGB(0xffea5c) forState:UIControlStateNormal];
NSTextAttachment *attchment = [[NSTextAttachment alloc] init];
attchment.image = kImage(@"luck_package_arrow");
attchment.bounds = CGRectMake(0, -1, 11, 11);
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attchment];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"1.0.37_text_12")
attributes:@{
NSFontAttributeName: kFontRegular(12),
NSForegroundColorAttributeName: UIColorFromRGB(0xffea5c)
}];
[attributedString appendAttributedString:string];
[_modifyButton setAttributedTitle:attributedString forState:UIControlStateNormal];
[_modifyButton addTarget:self action:@selector(didTapModifyButton) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:_modifyButton];
[self.modifyButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.waitingTimeLabel.mas_bottom).offset(24);
make.centerX.mas_equalTo(contentView);
make.height.mas_equalTo(16);
}];
_totalCostLabel = [UILabel labelInitWithText:@""
font:kFontRegular(12)
textColor:UIColorFromRGB(0xFFEA5C)];
_totalCostLabel.textAlignment = NSTextAlignmentCenter;
[contentView addSubview:_totalCostLabel];
[self.totalCostLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.modifyButton.mas_bottom).offset(24);
make.centerX.mas_equalTo(contentView);
make.height.mas_equalTo(16);
}];
[space mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.leading.trailing.mas_equalTo(contentView);
make.top.mas_equalTo(self.totalCostLabel.mas_bottom);
make.height.mas_equalTo(100);
}];
_sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_sendButton.titleLabel setFont:kFontSemibold(15)];
[_sendButton setBackgroundImage:kImage(@"luck_package_send_bg") forState:UIControlStateNormal];
[_sendButton setTitle:YMLocalizedString(@"1.0.37_text_15.1") forState:UIControlStateNormal];
[_sendButton setTitleColor:UIColorFromRGB(0x292601) forState:UIControlStateNormal];
[_sendButton addTarget:self action:@selector(didTapSendButton) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.sendButton];
[self.sendButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.bottom.mas_equalTo(self).offset(-18);
make.width.mas_equalTo(190);
make.height.mas_equalTo(50);
}];
}
return self;
}
- (void)refreshContent {
[self.scrollView setContentOffset:CGPointZero];
_dataSources = [[LuckyPackageLogicManager sharedInstance] loadAllSelectedGifts];
[self.giftsCollectionView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
[self adjustCollectionViewContentInset];
});
self.waitingTimeLabel.text = [NSString stringWithFormat:YMLocalizedString(@"1.0.37_text_13"), @([[LuckyPackageLogicManager sharedInstance] loadGiftWaitingTime]/60)];
self.totalCostLabel.attributedText = [[LuckyPackageLogicManager sharedInstance] loadGiftTotalCostString];
}
- (void)didTapModifyButton {
if (_returnToModity) {
self.returnToModity();
}
}
- (void)didTapSendButton {
if (_tapButtonForGiftLuckyPackage) {
self.tapButtonForGiftLuckyPackage();
}
}
#pragma mark -
- (void)adjustCollectionViewContentInset {
CGFloat pageWidth = self.giftsCollectionView.frame.size.width;
NSInteger totalPages = ceil((double)self.dataSources.count / 8.0);
CGFloat fullContentWidth = totalPages * pageWidth;
CGFloat remainingWidth = fullContentWidth - self.giftsCollectionView.contentSize.width;
if (remainingWidth > 0) {
self.giftsCollectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, remainingWidth);
} else {
self.giftsCollectionView.contentInset = UIEdgeInsetsZero;
}
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataSources.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ChooseGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ChooseGiftCell" forIndexPath:indexPath];
cell.cellModel = [self.dataSources xpSafeObjectAtIndex:indexPath.item];
[cell setModifySelectedGift:^(GiftInfoModel *model, NSInteger count) {
model.luckyPackageCount = count;
[[LuckyPackageLogicManager sharedInstance] updateSelectedGift:model count:count];
}];
return cell;
}
@end
@interface LuckyPackageViewController () <LuckyPackagePresenterProtocol>
@property (nonatomic,weak) id<RoomHostDelegate>hostDelegate;
@property(nonatomic, strong) UIButton *closeButton;
@property(nonatomic, strong) UIImageView *bgImageView;
@property(nonatomic, strong) UIButton *giftButton;
@property(nonatomic, strong) UIButton *coinButton;
@property(nonatomic, strong) UIImageView *gemImageView;
@property(nonatomic, strong) UIButton *recordsButton;
@property(nonatomic, strong) UIButton *rulesButton;
@property(nonatomic, strong) UIView *coinContainer;
@property(nonatomic, strong) UIView *giftContainer;
@property(nonatomic, strong) UIView *createLuckyPackageContainer;
@property(nonatomic, strong) ChooseCoinView *chooseCoin;
@property(nonatomic, strong) ChooseGiftView *chooseGift;
@property(nonatomic, strong) ComfirmChooseGiftView *comfirmChooseGift;
@property(nonatomic, strong) LuckyPackageRecordsView *recordsView;
@property(nonatomic, strong) LuckyPackageBannerView *demoBanner;
@end
@implementation LuckyPackageViewController
- (instancetype)initWithdelegate:(id<RoomHostDelegate>)delegate {
self = [super init];
if (self) {
self.hiddenNavBar = YES;
self.hostDelegate = delegate;
}
return self;
}
- (LuckyPackagePresenter *)createPresenter {
return [[LuckyPackagePresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.hiddenNavBar = YES;
[self setupUI];
[self displayChooseGift];
}
- (void)setupUI {
self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];
[self.view addSubview:self.createLuckyPackageContainer];
[self.createLuckyPackageContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
[self setupBG];
[self setupControlArea];
}
- (void)setupBG {
[self.view addSubview:self.closeButton];
[self.createLuckyPackageContainer addSubview:self.bgImageView];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
if (iPhoneXSeries) {
make.edges.mas_equalTo(self.createLuckyPackageContainer).insets(UIEdgeInsetsMake(kGetScaleWidth(162), 0, 0, 0));
} else {
make.edges.mas_equalTo(self.createLuckyPackageContainer).insets(UIEdgeInsetsMake(kNavigationHeight, 0, 0, 0));
}
}];
[self.createLuckyPackageContainer addSubview:self.demoBanner];
[self.demoBanner mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.bgImageView.mas_top).offset(40);
make.leading.trailing.mas_equalTo(self.createLuckyPackageContainer);
make.height.mas_equalTo(kGetScaleWidth(100));
}];
[self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.trailing.mas_equalTo(self.createLuckyPackageContainer);
make.bottom.mas_equalTo(self.demoBanner.mas_bottom);
}];
}
- (void)setupControlArea {
[self.createLuckyPackageContainer addSubview:self.giftButton];
[self.createLuckyPackageContainer addSubview:self.coinButton];
[self.createLuckyPackageContainer addSubview:self.gemImageView];
[self.giftButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(47);
make.top.mas_equalTo(self.bgImageView).offset(kGetScaleWidth(108));
make.left.mas_equalTo(self.createLuckyPackageContainer).offset(8);
make.right.mas_equalTo(self.createLuckyPackageContainer.mas_centerX).offset(-1.5);
}];
[self.coinButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(47);
make.top.mas_equalTo(self.bgImageView).offset(kGetScaleWidth(108));
make.right.mas_equalTo(self.createLuckyPackageContainer).offset(-8);
make.left.mas_equalTo(self.createLuckyPackageContainer.mas_centerX).offset(1.5);
}];
[self.gemImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.createLuckyPackageContainer);
make.centerY.mas_equalTo(self.giftButton);
make.size.mas_equalTo(CGSizeMake(62, 31));
}];
[self.createLuckyPackageContainer addSubview:self.rulesButton];
[self.createLuckyPackageContainer addSubview:self.recordsButton];
[self.rulesButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.coinButton.mas_bottom).offset(2);
make.trailing.mas_equalTo(self.createLuckyPackageContainer).offset(-5);
make.size.mas_equalTo(CGSizeMake(27, 27));
}];
[self.recordsButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.coinButton.mas_bottom).offset(2);
make.trailing.mas_equalTo(self.rulesButton.mas_leading).offset(-3);
make.size.mas_equalTo(CGSizeMake(27, 27));
}];
}
- (void)setupChooseGift {
if (!_giftContainer) {
_giftContainer = [[UIView alloc] init];
[self.giftContainer addSubview:self.chooseGift];
[self.chooseGift mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.giftContainer);
}];
}
[self.createLuckyPackageContainer addSubview:self.giftContainer];
[self.giftContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.rulesButton);
make.bottom.leading.trailing.mas_equalTo(self.view);
}];
[self.createLuckyPackageContainer bringSubviewToFront:self.rulesButton];
[self.createLuckyPackageContainer bringSubviewToFront:self.recordsButton];
}
- (void)setupChooseCoin {
if (!_coinContainer) {
_coinContainer = [[UIView alloc] init];
[self.coinContainer addSubview:self.chooseCoin];
[self.chooseCoin mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.coinContainer);
}];
}
[self.createLuckyPackageContainer addSubview:self.coinContainer];
[self.coinContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.rulesButton);
make.bottom.leading.trailing.mas_equalTo(self.view);
}];
[self.createLuckyPackageContainer bringSubviewToFront:self.rulesButton];
[self.createLuckyPackageContainer bringSubviewToFront:self.recordsButton];
}
- (void)setupComfirmChooseGift {
[self.giftContainer addSubview:self.comfirmChooseGift];
[self.comfirmChooseGift mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.giftContainer);
}];
}
- (void)readyToSendGift {
if ([[LuckyPackageLogicManager sharedInstance] loadAllSelectedGifts].count == 0) {
[XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"1.0.37_text_29")];
return;
}
self.comfirmChooseGift.alpha = 0;
[self setupComfirmChooseGift];
[self.comfirmChooseGift refreshContent];
[UIView animateWithDuration:0.25 animations:^{
self.comfirmChooseGift.alpha = 1;
self.chooseGift.alpha = 0;
}];
}
- (void)returnToModify {
[UIView animateWithDuration:0.25 animations:^{
self.comfirmChooseGift.alpha = 0;
self.chooseGift.alpha = 1;
[self.chooseGift refreshData];
} completion:^(BOOL finished) {
[self.comfirmChooseGift removeFromSuperview];
}];
}
#pragma mark -
- (void)setupData {
NSString *roomUid = @(self.hostDelegate.getRoomInfo.uid).stringValue;
[self.presenter loadGifts:roomUid];
[self.presenter loadWalletInfo];
}
- (void)loadGiftsSuccess:(NSArray <GiftInfoModel *>*)gifts {
self.chooseGift.dataSources = gifts;
}
- (void)loadWalletInfoSuccess:(WalletInfoModel *)walletInfo {
[[LuckyPackageLogicManager sharedInstance] saveWalletInfo:walletInfo];
[self.chooseGift.walletView updatePrice:walletInfo.diamonds.doubleValue];
}
- (void)loadSentLuckyBag {
@kWeakify(self);
[self.presenter loadLuckyPackageRecords:1 type:1 success:^(NSArray<RedEnvelopeListVo *> * _Nonnull array) {
@kStrongify(self);
[self.recordsView setDateSource:array];
}];
}
- (void)loadReceivedLuckyBag {
@kWeakify(self);
[self.presenter loadLuckyPackageRecords:1 type:2 success:^(NSArray<RedEnvelopeListVo *> * _Nonnull array) {
@kStrongify(self);
[self.recordsView setDateSource:array];
}];
}
- (void)sendGiftLuckyPackage {
@kWeakify(self);
[self.presenter sendGiftLuckyPackage:self.hostDelegate.getRoomInfo.uid
uid:[[AccountInfoStorage instance] getUid]
waitingTime:[[LuckyPackageLogicManager sharedInstance] loadGiftWaitingTime]
selectedGifts:[[LuckyPackageLogicManager sharedInstance] loadAllSelectedGifts]
success:^{
@kStrongify(self);
[self didTapCloseButton];
}];
}
- (void)sendCoinLuckyPackage {
@kWeakify(self);
[self.presenter sendCoinLuckyPackage:self.hostDelegate.getRoomInfo.uid
uid:[[AccountInfoStorage instance] getUid]
waitingTime:[[LuckyPackageLogicManager sharedInstance] loadCoinWaitingTime]
num:@([[LuckyPackageLogicManager sharedInstance] loadSelectedBagNum])
goldNum:@([[LuckyPackageLogicManager sharedInstance] loadSelectedBagMoney])
success:^{
@kStrongify(self);
[self didTapCloseButton];
}];
}
#pragma mark -
- (void)displayChooseGift {
if (_coinContainer) {
[self.coinContainer removeFromSuperview];
}
[self setupChooseGift];
[self setupData];
UserInfoModel *currentUser = [self.hostDelegate getUserInfo];
[self.demoBanner updateDemoFor:1 nick:currentUser.nick avatar:currentUser.avatar];
}
- (void)displayChooseCoin {
if (_giftContainer) {
[self.giftContainer removeFromSuperview];
}
[self setupChooseCoin];
UserInfoModel *currentUser = [self.hostDelegate getUserInfo];
[self.demoBanner updateDemoFor:2 nick:currentUser.nick avatar:currentUser.avatar];
}
#pragma mark -
- (void)didTapCloseButton {
[self removeFromParentViewController];
[self.view removeFromSuperview];
if (_close) {
self.close();
}
[[LuckyPackageLogicManager sharedInstance] reset];
}
- (void)didTapGiftTabButton:(UIButton *)sender {
if (sender.isSelected) {
return;
}
sender.selected = YES;
self.coinButton.selected = NO;
[self displayChooseGift];
}
- (void)didTapCoinTabButton:(UIButton *)sender {
if (sender.isSelected) {
return;
}
sender.selected = YES;
self.giftButton.selected = NO;
[self displayChooseCoin];
}
- (void)didTapRecordsButton {
if (!_recordsView) {
_recordsView = [[LuckyPackageRecordsView alloc] init];
@kWeakify(self);
[self.recordsView setTapBackButton:^{
@kStrongify(self);
[UIView animateWithDuration:0.25 animations:^{
self.recordsView.alpha = 0;
self.createLuckyPackageContainer.alpha = 1;
} completion:^(BOOL finished) {
[self.recordsView removeFromSuperview];
}];
}];
[self.recordsView setSwitchTap:^(BOOL isReceive) {
@kStrongify(self);
if (isReceive) {
[self loadReceivedLuckyBag];
} else {
[self loadSentLuckyBag];
}
}];
[self loadReceivedLuckyBag];
}
self.recordsView.alpha = 0;
[self.view addSubview:self.recordsView];
[self.recordsView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.leading.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(485);
}];
[self.recordsView updateWithUserInfo:self.hostDelegate.getUserInfo];
[UIView animateWithDuration:0.25 animations:^{
self.recordsView.alpha = 1;
self.createLuckyPackageContainer.alpha = 0;
}];
}
- (void)didTapRulesButton {
BOOL giftContainerHiddenStatus = self.createLuckyPackageContainer.hidden;
self.createLuckyPackageContainer.hidden = YES;
XPWebViewController *vc = [[XPWebViewController alloc] initWithRoomUID:[LuckyPackageLogicManager sharedInstance].roomUid];
vc.hiddenNavBar = YES;
vc.url = URLWithType(KLuckyPackageRule);
@kWeakify(vc);
[vc setCloseWebViewBlock:^(BOOL result) {
@kStrongify(vc);
[vc.view removeFromSuperview];
[vc removeFromParentViewController];
self.createLuckyPackageContainer.hidden = giftContainerHiddenStatus;
}];
vc.view.hidden = YES;
[self addChildViewController:vc];
[self.view addSubview:vc.view];
[vc.view mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.leading.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(470));
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
vc.view.hidden = NO;
});
}
#pragma mark -
- (UIButton *)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeButton addTarget:self action:@selector(didTapCloseButton) forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}
- (UIImageView *)bgImageView {
if (!_bgImageView) {
_bgImageView = [[UIImageView alloc] initWithImage:kImage(@"luck_package_main_bg")];
_bgImageView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
}
return _bgImageView;
}
- (UIButton *)giftButton {
if (!_giftButton) {
_giftButton = [UIButton buttonWithType:UIButtonTypeCustom];
_giftButton.adjustsImageWhenHighlighted = NO;
[_giftButton.titleLabel setFont:kFontSemibold(16)];
[_giftButton setTitleColor:UIColorFromRGB(0xffea5c) forState:UIControlStateNormal];
[_giftButton setTitle:YMLocalizedString(@"1.0.37_text_1") forState:UIControlStateNormal];
[_giftButton setBackgroundImage:kImage(@"luck_package_gift_button_normal") forState:UIControlStateNormal];
[_giftButton setBackgroundImage:kImage(@"luck_package_gift_button_selected") forState:UIControlStateSelected];
[_giftButton addTarget:self action:@selector(didTapGiftTabButton:) forControlEvents:UIControlEventTouchUpInside];
_giftButton.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
_giftButton.selected = YES;
}
return _giftButton;
}
- (UIButton *)coinButton {
if (!_coinButton) {
_coinButton = [UIButton buttonWithType:UIButtonTypeCustom];
_coinButton.adjustsImageWhenHighlighted = NO;
[_coinButton.titleLabel setFont:kFontSemibold(16)];
[_coinButton setTitleColor:UIColorFromRGB(0xffea5c) forState:UIControlStateNormal];
[_coinButton setTitle:YMLocalizedString(@"1.0.37_text_2") forState:UIControlStateNormal];
[_coinButton setBackgroundImage:kImage(@"luck_package_coin_button_normal") forState:UIControlStateNormal];
[_coinButton setBackgroundImage:kImage(@"luck_package_coin_button_selected") forState:UIControlStateSelected];
[_coinButton addTarget:self action:@selector(didTapCoinTabButton:) forControlEvents:UIControlEventTouchUpInside];
_coinButton.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
}
return _coinButton;
}
- (UIImageView *)gemImageView {
if (!_gemImageView) {
_gemImageView = [[UIImageView alloc] initWithImage:kImage(@"luck_package_gem")];
}
return _gemImageView;
}
- (UIButton *)recordsButton {
if (!_recordsButton) {
_recordsButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_recordsButton setBackgroundImage:kImage(@"luck_package_records") forState:UIControlStateNormal];
[_recordsButton addTarget:self action:@selector(didTapRecordsButton) forControlEvents:UIControlEventTouchUpInside];
}
return _recordsButton;
}
- (UIButton *)rulesButton {
if (!_rulesButton) {
_rulesButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_rulesButton setBackgroundImage:kImage(@"luck_package_rules") forState:UIControlStateNormal];
[_rulesButton addTarget:self action:@selector(didTapRulesButton) forControlEvents:UIControlEventTouchUpInside];
}
return _rulesButton;
}
- (ChooseCoinView *)chooseCoin {
if (!_chooseCoin) {
_chooseCoin = [[ChooseCoinView alloc] init];
@kWeakify(self);
[_chooseCoin setTapSendCoin:^{
@kStrongify(self);
[self sendCoinLuckyPackage];
}];
}
return _chooseCoin;
}
- (ChooseGiftView *)chooseGift {
if (!_chooseGift) {
_chooseGift = [[ChooseGiftView alloc] init];
@kWeakify(self);
[_chooseGift setForceClose:^{
@kStrongify(self);
[self didTapCloseButton];
}];
[_chooseGift setTapSendGift:^{
@kStrongify(self);
[self readyToSendGift];
}];
}
return _chooseGift;
}
- (ComfirmChooseGiftView *)comfirmChooseGift {
if (!_comfirmChooseGift) {
_comfirmChooseGift = [[ComfirmChooseGiftView alloc] init];
@kWeakify(self);
[_comfirmChooseGift setReturnToModity:^{
@kStrongify(self);
[self returnToModify];
}];
[_comfirmChooseGift setTapButtonForGiftLuckyPackage:^{
@kStrongify(self);
[self sendGiftLuckyPackage];
}];
}
return _comfirmChooseGift;
}
- (UIView *)createLuckyPackageContainer {
if (!_createLuckyPackageContainer) {
_createLuckyPackageContainer = [[UIView alloc] init];
}
return _createLuckyPackageContainer;
}
- (LuckyPackageBannerView *)demoBanner {
if (!_demoBanner) {
_demoBanner = [LuckyPackageBannerView demoBanner];
}
return _demoBanner;
}
@end