Files
peko-ios/YuMi/Modules/YMMine/View/IncomeRecord/XPExchangeDiamondsView.m

340 lines
12 KiB
Mathematica
Raw Normal View History

2023-07-14 18:50:55 +08:00
//
// XPExchangeDiamondsView.m
// YuMi
//
// Created by YuMi on 2022/11/17.
//
#import "XPExchangeDiamondsView.h"
///Third
#import <Masonry/Masonry.h>
#import "XPTextField.h"
#import "XNDJTDDLoadingTool.h"
#import "UIView+Corner.h"
@interface XPExchangeDiamondsView()
@property (nonatomic,strong) XPExchangeDiamondsItemView *myGoldView;
@property (nonatomic,strong) XPExchangeDiamondsItemView *myDiamondsView;
@property (nonatomic,strong) UIButton *confirmBtn;
///
@property (nonatomic,copy) NSString *goldNum;
///
@property (nonatomic,copy) NSString *diamondNum;
@property (nonatomic,assign) IncomeRecordViewType chooseType;
2024-05-29 17:14:02 +08:00
2023-07-14 18:50:55 +08:00
@end
@implementation XPExchangeDiamondsView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
2024-09-04 16:11:11 +08:00
- (void)showKeyboard {
[self.myDiamondsView becomeResponder];
}
2023-07-14 18:50:55 +08:00
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor clearColor];
2023-07-14 18:50:55 +08:00
[self addSubview:self.myDiamondsView];
2024-09-04 16:11:11 +08:00
[self addSubview:self.myGoldView];
2023-07-14 18:50:55 +08:00
[self addSubview:self.confirmBtn];
@kWeakify(self)
2024-09-04 16:11:11 +08:00
// self.myGoldView.inputCounthandle = ^(NSString *_Nonnull goldNum,NSString *_Nonnull diamondNum) {
// @kStrongify(self)
// if(goldNum.integerValue == 0 && diamondNum.integerValue == 0){
// self.confirmBtn.enabled = NO;
// self.myGoldView.text = @"";
// self.myDiamondsView.text = @"";
// return;
// }
// self.chooseType = IncomeRecord_Gold;
// self.confirmBtn.enabled = YES;
// self.goldNum = goldNum;
// self.diamondNum = diamondNum;
// self.myDiamondsView.count = diamondNum;
//
// };
2023-07-14 18:50:55 +08:00
self.myDiamondsView.inputCounthandle = ^(NSString *_Nonnull goldNum,NSString *_Nonnull diamondNum) {
@kStrongify(self)
if(goldNum.integerValue == 0 && diamondNum.integerValue == 0){
self.confirmBtn.enabled = NO;
self.myGoldView.text = @"";
self.myDiamondsView.text = @"";
return;
}
self.confirmBtn.enabled = YES;
self.goldNum = goldNum;
self.diamondNum = diamondNum;
2024-09-04 16:11:11 +08:00
self.myGoldView.count = diamondNum;
2023-07-14 18:50:55 +08:00
self.chooseType = IncomeRecord_Diamond;
};
}
- (void)initSubViewConstraints {
2024-05-29 17:14:02 +08:00
[self.myDiamondsView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(0));
2024-04-11 17:05:27 +08:00
make.leading.mas_equalTo(kGetScaleWidth(15));
make.trailing.mas_equalTo(-kGetScaleWidth(15));
2024-05-29 17:14:02 +08:00
make.height.mas_equalTo(kGetScaleWidth(72));
2023-07-14 18:50:55 +08:00
}];
2024-05-29 17:14:02 +08:00
[self.myGoldView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.width.height.equalTo(self.myDiamondsView);
make.top.equalTo(self.myDiamondsView.mas_bottom).mas_offset(kGetScaleWidth(28));
2023-07-14 18:50:55 +08:00
}];
2024-05-29 17:14:02 +08:00
2023-07-14 18:50:55 +08:00
[self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
2024-05-29 17:14:02 +08:00
make.top.equalTo(self.myGoldView.mas_bottom).mas_offset(kGetScaleWidth(33));
make.width.mas_equalTo(kGetScaleWidth(303));
make.height.mas_equalTo(kGetScaleWidth(48));
2023-07-14 18:50:55 +08:00
make.centerX.equalTo(self);
}];
2024-05-29 17:14:02 +08:00
}
///
- (void)backBtnAction {
2023-07-14 18:50:55 +08:00
}
-(void)setModel:(XPExchangeDiamondsModel *)model{
_model = model;
_myGoldView.model = _model;
_myDiamondsView.model = _model;
}
-(void)confirmAction{
2024-05-29 17:14:02 +08:00
if( self.model.diamonds < self.diamondNum.doubleValue){
2023-07-14 18:50:55 +08:00
[XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"XPExchangeDiamondsView2")];
return;
}
2024-09-04 18:26:30 +08:00
// if(self.diamondNum.doubleValue < self.model.minDiamonds){
// [XNDJTDDLoadingTool showErrorWithMessage:[NSString stringWithFormat:YMLocalizedString(@"XPExchangeDiamondsView3"),self.model.minDiamonds]];
// return;
// }
2023-07-14 18:50:55 +08:00
if(self.diamondNum.doubleValue > self.model.maxDiamonds){
[XNDJTDDLoadingTool showErrorWithMessage:[NSString stringWithFormat:YMLocalizedString(@"XPExchangeDiamondsView4"),self.model.maxDiamonds]];
return;
2023-07-14 18:50:55 +08:00
}
[self.myGoldView resignResponder];
[self.myDiamondsView resignResponder];
2024-05-29 17:14:02 +08:00
if(self.delegate && [self.delegate respondsToSelector:@selector(confirmExchangeDiamondsWithDiamond:gold:)]){
[self.delegate confirmExchangeDiamondsWithDiamond:self.diamondNum gold:self.goldNum];
2023-07-14 18:50:55 +08:00
}
}
#pragma mark -
2024-05-29 17:14:02 +08:00
2023-07-14 18:50:55 +08:00
- (XPExchangeDiamondsItemView *)myGoldView{
if (!_myGoldView){
_myGoldView = [[XPExchangeDiamondsItemView alloc]initWithFrame:CGRectZero type:IncomeRecord_Gold];
2024-05-29 17:14:02 +08:00
2023-07-14 18:50:55 +08:00
}
return _myGoldView;
}
-(XPExchangeDiamondsItemView *)myDiamondsView{
if (!_myDiamondsView){
_myDiamondsView = [[XPExchangeDiamondsItemView alloc]initWithFrame:CGRectZero type:IncomeRecord_Diamond];
2024-05-29 17:14:02 +08:00
2023-07-14 18:50:55 +08:00
}
return _myDiamondsView;
}
-(UIButton *)confirmBtn{
if (!_confirmBtn){
2024-05-29 17:14:02 +08:00
UIImage *image = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor],[DJDKMIMOMColor confirmButtonGradientMiddleColor],[DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(345), kGetScaleWidth(48))];
2023-07-14 18:50:55 +08:00
_confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_confirmBtn setTitle:YMLocalizedString(@"XPExchangeDiamondsView1") forState:UIControlStateNormal];
2024-05-29 17:14:02 +08:00
_confirmBtn.titleLabel.font = kFontHeavy(16);
2023-07-14 18:50:55 +08:00
[_confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
2024-05-29 17:14:02 +08:00
_confirmBtn.layer.cornerRadius = kGetScaleWidth(24);
2023-07-14 18:50:55 +08:00
_confirmBtn.layer.masksToBounds = YES;
_confirmBtn.enabled = NO;
[_confirmBtn setBackgroundImage:image forState:UIControlStateNormal];
[_confirmBtn addTarget:self action:@selector(confirmAction) forControlEvents:UIControlEventTouchUpInside];
}
return _confirmBtn;
}
@end
/*******************************************************线***************************************************************/
@interface XPExchangeDiamondsItemView()
///
@property (nonatomic,strong) UILabel *titleNumView;
///
@property (nonatomic,strong) UIImageView *bgImageView;
///
@property (nonatomic,strong) UIButton *iconView;
///
@property (nonatomic,strong) XPTextField *numberView;
2024-05-29 17:14:02 +08:00
2023-07-14 18:50:55 +08:00
@property (nonatomic,assign) IncomeRecordViewType type;
@end
@implementation XPExchangeDiamondsItemView
-(instancetype)initWithFrame:(CGRect)frame type:(IncomeRecordViewType)type{
self = [super initWithFrame:frame];
if(self){
self.type = type;
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
2024-05-29 17:14:02 +08:00
self.backgroundColor = [UIColor clearColor];
2023-07-14 18:50:55 +08:00
[self addSubview:self.titleNumView];
[self addSubview:self.bgImageView];
2024-05-29 17:14:02 +08:00
2023-07-14 18:50:55 +08:00
[self.bgImageView addSubview:self.iconView];
[self.bgImageView addSubview:self.numberView];
}
- (void)initSubViewConstraints {
[self.titleNumView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-04-11 17:05:27 +08:00
make.leading.mas_equalTo(kGetScaleWidth(15));
2024-05-29 17:14:02 +08:00
make.top.mas_equalTo(kGetScaleWidth(0));
make.height.mas_equalTo(kGetScaleWidth(14));
make.trailing.mas_equalTo(-kGetScaleWidth(15));
2023-07-14 18:50:55 +08:00
}];
2024-05-29 17:14:02 +08:00
2023-07-14 18:50:55 +08:00
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-05-29 17:14:02 +08:00
make.leading.mas_equalTo(kGetScaleWidth(15));
make.trailing.mas_equalTo(-kGetScaleWidth(15));
make.top.equalTo(self.titleNumView.mas_bottom).mas_offset(kGetScaleWidth(10));
make.height.mas_equalTo(kGetScaleWidth(48));
2023-07-14 18:50:55 +08:00
}];
[self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-05-29 17:14:02 +08:00
make.width.mas_equalTo(kGetScaleWidth(28));
make.height.mas_equalTo(kGetScaleWidth(28));
make.leading.mas_equalTo(kGetScaleWidth(9));
2023-07-14 18:50:55 +08:00
make.centerY.equalTo(self.bgImageView);
}];
[self.numberView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(self.bgImageView);
2024-04-11 17:05:27 +08:00
make.trailing.mas_equalTo(-kGetScaleWidth(12));
2024-05-29 17:14:02 +08:00
make.leading.equalTo(self.iconView.mas_trailing).mas_offset(8);
2023-07-14 18:50:55 +08:00
}];
}
#pragma mark -
-(void)setModel:(XPExchangeDiamondsModel *)model{
_model = model;
2024-05-29 17:14:02 +08:00
if(self.type == IncomeRecord_Gold){
_titleNumView.text = [NSString stringWithFormat:YMLocalizedString(@"XPExchangeDiamondsItemView0"),@(_model.golds)];
2024-05-29 17:14:02 +08:00
UIImage *image = [UIImage imageNamed:@"ms_exchange_coin_icon"];
2024-04-09 15:37:57 +08:00
[_iconView setImage:image forState:UIControlStateNormal];
2024-06-06 17:10:28 +08:00
2023-07-14 18:50:55 +08:00
}else{
_titleNumView.text = [NSString stringWithFormat:YMLocalizedString(@"XPExchangeDiamondsItemView1"),_model.diamonds];
2024-05-29 17:14:02 +08:00
UIImage *image = [UIImage imageNamed:@"exchange_new_diamonds_icon"];
2024-04-09 15:37:57 +08:00
[_iconView setImage:image forState:UIControlStateNormal];
2023-07-14 18:50:55 +08:00
}
}
-(void)resignResponder{
[_numberView resignFirstResponder];
}
2024-09-04 16:11:11 +08:00
-(void)becomeResponder {
[_numberView becomeFirstResponder];
}
2023-07-14 18:50:55 +08:00
-(void)setText:(NSString *)text{
_text = text;
_numberView.text = _text;
}
-(void)setCount:(NSString *)count{
_count = count;
_numberView.text = _count;
}
-(void)textFieldDidChange:(UITextField *)textField{
if (textField.text.length == 0){
if(self.inputCounthandle){
self.inputCounthandle(@"0", @"0");
}
return;
}
NSInteger count = textField.text.integerValue;
2024-09-04 16:11:11 +08:00
// if(self.type == IncomeRecord_Gold){
// NSString *goldNum = [NSString stringWithFormat:@"%.0f",ceilf(count / _model.rate)];
// if(self.inputCounthandle){
// self.inputCounthandle(goldNum, textField.text);
// }
// return;
// }
2023-07-14 18:50:55 +08:00
NSString *diamondNum = [NSString stringWithFormat:@"%.0f",floorf(count * _model.rate)];
if(self.inputCounthandle){
self.inputCounthandle(textField.text,diamondNum);
}
}
#pragma mark -
- (UILabel *)titleNumView {
if (!_titleNumView) {
_titleNumView = [[UILabel alloc] init];
2024-05-29 17:14:02 +08:00
_titleNumView.font = kFontBold(15);
_titleNumView.textColor = UIColorFromRGB(0x00223D);
NSString *title = self.type == IncomeRecord_Gold ? YMLocalizedString(@"XPExchangeDiamondsItemView0"): YMLocalizedString(@"XPExchangeDiamondsItemView1");
2023-07-14 18:50:55 +08:00
_titleNumView.text = [NSString stringWithFormat:title,@"0"];
}
return _titleNumView;
}
- (UIImageView *)bgImageView{
if (!_bgImageView){
_bgImageView = [UIImageView new];
if(self.type == IncomeRecord_Gold){
2024-05-29 17:14:02 +08:00
_bgImageView.image = kImage(@"ms_exchange_diamonds_coin_bg");
2023-07-14 18:50:55 +08:00
}else{
2024-05-29 17:14:02 +08:00
_bgImageView.image = kImage(@"ms_exchange_diamonds_diamonds_bg");
2023-07-14 18:50:55 +08:00
}
_bgImageView.userInteractionEnabled = YES;
}
return _bgImageView;
}
-(UIButton *)iconView{
if (!_iconView){
2024-05-29 17:14:02 +08:00
UIImage *image = self.type == IncomeRecord_Gold ? [UIImage imageNamed:@"ms_exchange_coin_icon"] : [UIImage imageNamed:@"exchange_new_diamonds_icon"];
2023-07-14 18:50:55 +08:00
_iconView = [UIButton buttonWithType:UIButtonTypeCustom];
[_iconView setImage:image forState:UIControlStateNormal];
}
return _iconView;
}
- (XPTextField *)numberView{
if (!_numberView){
_numberView = [[XPTextField alloc]initWithFrame:CGRectZero];
_numberView.keyboardType = UIKeyboardTypeNumberPad;
_numberView.isValidation = YES;
2024-09-04 16:11:11 +08:00
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:(self.type == IncomeRecord_Diamond) ? YMLocalizedString(@"XPExchangeDiamondsView6") : YMLocalizedString(@"XPExchangeDiamondsView7")
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16 weight:UIFontWeightMedium],
NSForegroundColorAttributeName:[UIColor colorWithWhite:1 alpha:0.6]}];
2023-07-14 18:50:55 +08:00
_numberView.attributedPlaceholder = attStr;
2024-05-29 17:14:02 +08:00
_numberView.font = kFontMedium(15);
_numberView.textColor = [UIColor whiteColor];
2023-07-14 18:50:55 +08:00
[_numberView addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
2024-09-04 16:11:11 +08:00
if (self.type == IncomeRecord_Gold) {
_numberView.userInteractionEnabled = NO;
}
2023-07-14 18:50:55 +08:00
}
return _numberView;
}
2024-05-29 17:14:02 +08:00
2023-07-14 18:50:55 +08:00
@end