英文适配

This commit is contained in:
liyuhua
2024-04-11 15:47:44 +08:00
parent fd1f870c2d
commit c4ac454a15
123 changed files with 872 additions and 482 deletions

View File

@@ -27,17 +27,19 @@
#import "LoginPresenter.h"
#import "LoginProtocol.h"
#import "PILoginManager.h"
#import "XPLoginInputView.h"
#import "XPLoginAraeViewController.h"
#import "XPForgetPwdViewController.h"
UIKIT_EXTERN NSString * const kYouMiNumberCountKey;
NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
@interface XPLoginViewController ()<LoginProtocol>
@interface XPLoginViewController ()<LoginProtocol,XPLoginInputViewDelegate,XPLoginAraeViewControllerDelegate>
///
@property(nonatomic,strong) UIImageView *bgImageView;
///logo
@property(nonatomic,strong) UIImageView *logoView;
///
@property (nonatomic, strong) UIButton *quickLoginBtn;
@property(nonatomic,strong) UIImageView *quickArrowView;
///
@property (nonatomic, strong) UIButton *agreeBtn;
///
@@ -64,6 +66,34 @@ NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
///
@property(nonatomic,strong) UILabel *nextLabel;
///
@property(nonatomic,strong) UIImageView *chooseTypeView;
///
@property(nonatomic,strong) UIButton *chooseAccountBtn;
///
@property(nonatomic,strong) UIButton *chooseSMSBtn;
///
@property (nonatomic, strong) XPLoginInputView *phoneInputView;
///
@property (nonatomic, strong) XPLoginInputView *codeInputView;
/////
@property (nonatomic, strong) XPLoginInputView *accountView;
///
@property (nonatomic, strong) XPLoginInputView *accountPwdView;
///
@property (nonatomic, strong) UIButton *forgetBtn;
///
@property (nonatomic, strong) UIButton *loginBtn;
///
@property (nonatomic,copy) NSString *pi_phoneAreaCode;
///,01.
@property(nonatomic,assign) int selectType;
@end
@implementation XPLoginViewController
@@ -78,16 +108,29 @@ NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
- (void)viewDidLoad {
[super viewDidLoad];
[self createUI];
[self racBind];
self.selectType = 0;
NSString *code = [NSString getCountryCode];
self.pi_phoneAreaCode = [code stringByReplacingOccurrencesOfString:@"+" withString:@""];
[[NSNotificationCenter defaultCenter]postNotificationName:@"kInLoginVC" object:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
}
- (void)racBind {
@weakify(self);
RAC(self.loginBtn, enabled) = [[RACSignal combineLatest:@[self.phoneInputView.inputTextField.rac_textSignal, self.codeInputView.inputTextField.rac_textSignal,self.accountView.inputTextField.rac_textSignal,self.accountPwdView.inputTextField.rac_textSignal] reduce:^id _Nonnull(NSString *phone, NSString* smsCode,NSString *account,NSString *accountPwd){
@strongify(self);
if(self.selectType == 0){
return @(account.length > 0 && accountPwd.length >= 6);
}
return @((phone.length > 0) && smsCode.length > 0);
}] takeUntil:self.rac_willDeallocSignal];
}
- (void)createUI {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
@@ -96,9 +139,22 @@ NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.bgImageView];
[self.view addSubview:self.logoView];
[self.view addSubview:self.chooseAccountBtn];
[self.view addSubview:self.chooseSMSBtn];
[self.view addSubview:self.chooseTypeView];
[self.view addSubview:self.accountView];
[self.view addSubview:self.accountPwdView];
[self.view addSubview:self.phoneInputView];
[self.view addSubview:self.codeInputView];
[self.view addSubview:self.forgetBtn];
[self.view addSubview:self.loginBtn];
[self.view addSubview:self.stackView];
[self.view addSubview:self.quickLoginBtn];
[self.view addSubview:self.quickArrowView];
[self.view addSubview:self.protocolLabel];
[self.view addSubview:self.agreeBtn];
@@ -108,13 +164,7 @@ NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
if (@available(iOS 13.0, *)) {
#ifdef DEBUG
[self.stackView addArrangedSubview:self.appleButton];
#else
if(isEnterprise == YES){
[self.stackView addArrangedSubview:self.appleButton];
@@ -129,32 +179,82 @@ NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(355));
make.height.mas_equalTo(kGetScaleWidth(91));
}];
[self.logoView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_offset(kGetScaleWidth(130));
make.height.mas_equalTo(kGetScaleWidth(148));
make.width.mas_offset(kGetScaleWidth(162));
make.height.mas_equalTo(kGetScaleWidth(32));
make.centerX.equalTo(self.view);
make.top.mas_equalTo(kGetScaleWidth(100));
make.top.equalTo(self.bgImageView.mas_bottom).mas_offset(kGetScaleWidth(10));
}];
CGFloat width = KScreenWidth/2;
[self.chooseAccountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(0);
make.height.mas_equalTo(kGetScaleWidth(22));
make.width.mas_equalTo(width);
make.top.equalTo(self.logoView.mas_bottom).mas_offset(kGetScaleWidth(31));
}];
[self.chooseSMSBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(kGetScaleWidth(22));
make.width.mas_equalTo(width);
make.top.equalTo(self.logoView.mas_bottom).mas_offset(kGetScaleWidth(31));
make.trailing.mas_equalTo(0);
}];
[self.chooseTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.logoView.mas_bottom).mas_offset(kGetScaleWidth(48));
make.width.height.mas_equalTo(kGetScaleWidth(24));
make.leading.mas_equalTo(KScreenWidth/4 - kGetScaleWidth(12));
}];
[self.accountView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.width.mas_equalTo(kGetScaleWidth(303));
make.top.mas_equalTo(self.chooseTypeView.mas_bottom).offset(kGetScaleWidth(13));
make.height.mas_equalTo(kGetScaleWidth(52));
}];
[self.accountPwdView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.width.mas_equalTo(kGetScaleWidth(303));
make.top.mas_equalTo(self.phoneInputView.mas_bottom).offset(kGetScaleWidth(20));
make.height.mas_equalTo(kGetScaleWidth(52));
}];
[self.phoneInputView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.accountView);
}];
[self.codeInputView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.accountPwdView);
}];
[self.forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.codeInputView.mas_bottom).mas_offset(kGetScaleWidth(8));
make.trailing.mas_equalTo(-kGetScaleWidth(52));
make.height.mas_equalTo(kGetScaleWidth(17));
}];
[self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(303));
make.centerX.equalTo(self.view);
make.top.equalTo(self.forgetBtn.mas_bottom).mas_offset(kGetScaleWidth(23));
make.height.mas_equalTo(kGetScaleWidth(48));
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.self.logoView.mas_bottom).offset(kGetScaleWidth(60));
make.top.mas_equalTo(self.loginBtn.mas_bottom).offset(kGetScaleWidth(27));
make.centerX.mas_equalTo(self.view);
}];
[self.quickLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(22));
make.top.equalTo(self.stackView.mas_bottom).mas_offset(kGetScaleWidth(18));
}];
[self.quickArrowView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(self.quickLoginBtn.mas_trailing).mas_offset(kGetScaleWidth(2));
make.centerY.equalTo(self.quickLoginBtn);
make.width.height.mas_equalTo(kGetScaleWidth(10));
}];
[self.protocolLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view).offset(10);
make.right.mas_lessThanOrEqualTo(-10);
@@ -180,15 +280,10 @@ NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
}];
if (@available(iOS 13.0, *)) {
#ifdef DEBUG
[self.appleButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(295));
make.height.mas_equalTo(kGetScaleWidth(46));
}];
#else
if(isEnterprise == YES){
[self.appleButton mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -208,6 +303,8 @@ NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
make.width.mas_equalTo(kGetScaleWidth(295));
make.height.mas_equalTo(kGetScaleWidth(46));
}];
self.fbButtonView.hidden = YES;
self.lineButtonView.hidden = YES;
[self.lineButtonView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(295));
make.height.mas_equalTo(kGetScaleWidth(46));
@@ -220,11 +317,12 @@ NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
typeButton = self.appleButton;
}else if([type intValue] == ThirdLoginType_Gmail){
typeButton = self.googleButtonView;
}else if([type intValue] == ThirdLoginType_FB){
typeButton = self.fbButtonView;
}else if([type intValue] == ThirdLoginType_Line){
typeButton = self.lineButtonView;
}
// else if([type intValue] == ThirdLoginType_FB){
// typeButton = self.fbButtonView;
// }else if([type intValue] == ThirdLoginType_Line){
// typeButton = self.lineButtonView;
// }
if(typeButton == nil){
return;
}
@@ -324,32 +422,113 @@ NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
}];
}
}
///
- (void)loginBtnClicked {
[XNDJTDDLoadingTool showOnlyView:self.view];
if(self.selectType == 0){
NSString *phone = self.accountView.inputTextField.text;
NSString *password = self.accountPwdView.inputTextField.text;
[self.presenter loginWithPhone:phone password:password];
return;
}
NSString *phone = self.phoneInputView.inputTextField.text;
NSString *smsCode = self.codeInputView.inputTextField.text;
NSString * phoneStr = [NSString stringWithFormat:@"%@%@",self.pi_phoneAreaCode, phone];
[self.presenter loginWithPhone:phoneStr code:smsCode phoneAreaCode:self.pi_phoneAreaCode];
}
- (void)forgetBtnClicked {
XPForgetPwdViewController *forgetVC = [[XPForgetPwdViewController alloc] init];
[self.navigationController pushViewController:forgetVC animated:YES];
}
#pragma mark - LoginProtocol
- (void)loginSuccess {
- (void)loginThirdPartSuccess {
[self.codeInputView cancelTimer];
[PILoginManager loginWithVC:self isLoginPhone:NO];
[self showSuccessToast:YMLocalizedString(@"XPLoginViewController4")];
}
-(void)chooseAccountAction{
self.selectType = 0;
}
-(void)chooseSMSAction{
self.selectType = 1;
}
-(void)setSelectType:(int)selectType{
_selectType = selectType;
_chooseAccountBtn.selected = _selectType == 0;
_chooseSMSBtn.selected = _selectType != 0;
_forgetBtn.hidden = _selectType != 0;
_accountView.hidden = _selectType != 0;
_accountPwdView.hidden = _selectType != 0;
_phoneInputView.hidden = _selectType == 0;
_codeInputView.hidden = _selectType == 0;
[self.chooseTypeView.superview layoutIfNeeded];
CGFloat lead = _selectType == 0 ? KScreenWidth/4 - kGetScaleWidth(12) : KScreenWidth/4 * 3 - kGetScaleWidth(12);
[UIView animateWithDuration:0.1 animations:^{
[self.chooseTypeView mas_updateConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(lead);
}];
[self.chooseTypeView.superview layoutIfNeeded];
}];
}
#pragma mark - XPLoginInputViewDelegate
- (void)smsCodeAction {
NSString *phone = self.phoneInputView.inputTextField.text;
if (phone.length == 0 ) {
[self showErrorToast:YMLocalizedString(@"XPLoginPhoneViewController0")];
return;
}
[self.presenter phoneSmsCode:[NSString stringWithFormat:@"%@%@",self.pi_phoneAreaCode,phone] type:GetSmsType_Regist phoneAreaCode:self.pi_phoneAreaCode];
}
- (void)areaListAction {
XPLoginAraeViewController *codeVC = [XPLoginAraeViewController new];
codeVC.delegate = self;
[self.navigationController pushViewController:codeVC animated:YES];
}
#pragma mark - XPLoginAraeViewControllerDelegate
- (void)chooseAreaCodeSuccess:(NSString *)code {
if (code.length > 0) {
self.pi_phoneAreaCode = code;
[self.phoneInputView.areaCodeBtn setTitle:[NSString stringWithFormat:@"+%@", code] forState:UIControlStateNormal];
}
}
#pragma mark - LoginVerifCodeProtocol
- (void)loginWithPhoenSuccess{
[XNDJTDDLoadingTool hideOnlyView:self.view];
[[NSUserDefaults standardUserDefaults]setValue:@(ThirdLoginType_Phone) forKey:@"kLoginSuccessType"];
[[NSUserDefaults standardUserDefaults]synchronize];
[self showSuccessToast:YMLocalizedString(@"XPLoginPhoneViewController1")];
[PILoginManager loginWithVC:self isLoginPhone:YES];
}
- (void)loginSuccess {
[self.codeInputView cancelTimer];
[XNDJTDDLoadingTool hideOnlyView:self.view];
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"kLoginSuccessType"];
[self showSuccessToast:YMLocalizedString(@"XPLoginPhoneViewController1")];
[PILoginManager loginWithVC:self isLoginPhone:NO];
}
- (void)loginFailWithMsg:(NSString *)msg{
[self showErrorToast:msg];
[XNDJTDDLoadingTool hideOnlyView:self.view];
}
- (void)phoneSmsCodeSuccess {
[self showSuccessToast:YMLocalizedString(@"XPLoginPhoneViewController2")];
[self.codeInputView fireTimer];
}
#pragma mark -
- (UIButton *)quickLoginBtn {
if (!_quickLoginBtn) {
_quickLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_quickLoginBtn setTitle:YMLocalizedString(@"XPLoginViewController16") forState:UIControlStateNormal];
_quickLoginBtn.titleLabel.font = kFontRegular(14);
[_quickLoginBtn setTitleColor:UIColorFromRGB(0x1F1B4F) forState:UIControlStateNormal];
[_quickLoginBtn addTarget:self action:@selector(quickLoginBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}
return _quickLoginBtn;
}
- (UIImageView *)quickArrowView{
if(!_quickArrowView){
_quickArrowView = [UIImageView new];
_quickArrowView.image = kImage(@"login_phone_white");
}
return _quickArrowView;
}
- (UIButton *)agreeBtn {
if(!_agreeBtn) {
_agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
@@ -541,4 +720,130 @@ NSString * const HadAgreePrivacy = @"HadAgreePrivacy";
}
return _nextLabel;
}
- (XPLoginInputView *)phoneInputView {
if (!_phoneInputView) {
_phoneInputView = [[XPLoginInputView alloc] init];
_phoneInputView.areaStackView.hidden = NO;
_phoneInputView.delegate = self;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPhoneViewController5")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
_phoneInputView.inputTextField.attributedPlaceholder = placeholder;
_phoneInputView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
_phoneInputView.hidden = YES;
}
return _phoneInputView;
}
- (XPLoginInputView *)codeInputView {
if (!_codeInputView) {
_codeInputView = [[XPLoginInputView alloc] init];
_codeInputView.smsCodeBtn.hidden = NO;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPhoneViewController6")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
_codeInputView.inputTextField.attributedPlaceholder = placeholder;
_codeInputView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
_codeInputView.delegate = self;
_codeInputView.hidden = YES;
}
return _codeInputView;
}
- (UIButton *)loginBtn {
if (!_loginBtn) {
_loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *nextImage = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor],[DJDKMIMOMColor confirmButtonGradientMiddleColor],[DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(303), kGetScaleWidth(48))];
UIImage *disableImage = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xD1F9FF),UIColorFromRGB(0xDEE4FF),UIColorFromRGB(0xEEDCFF)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(303), kGetScaleWidth(48))];
[_loginBtn setImage:nextImage forState:UIControlStateNormal];
[_loginBtn setImage:disableImage forState:UIControlStateDisabled];
_loginBtn.layer.cornerRadius = kGetScaleWidth(48)/2;
_loginBtn.layer.masksToBounds = YES;
UILabel *titleView = [UILabel labelInitWithText:YMLocalizedString(@"XPLoginPhoneViewController8") font:kFontMedium(16) textColor:[UIColor whiteColor]];
titleView.textAlignment = NSTextAlignmentCenter;
[_loginBtn addSubview:titleView];
[titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.loginBtn);
}];
[_loginBtn addTarget:self action:@selector(loginBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}
return _loginBtn;
}
- (UIImageView *)chooseTypeView{
if(!_chooseTypeView){
_chooseTypeView = [UIImageView new];
_chooseTypeView.userInteractionEnabled = YES;
[_chooseTypeView setImage:kImage(@"ms_login_choose_phone_icon")];
}
return _chooseTypeView;
}
- (UIButton *)chooseAccountBtn{
if(!_chooseAccountBtn){
_chooseAccountBtn = [UIButton new];
[_chooseAccountBtn setTitle:YMLocalizedString(@"XPLoginPhoneViewController9" ) forState:UIControlStateNormal];
[_chooseAccountBtn setTitleColor:UIColorFromRGB(0x84868A) forState:UIControlStateNormal];
[_chooseAccountBtn setTitleColor:UIColorFromRGB(0x000000) forState:UIControlStateSelected];
_chooseAccountBtn.titleLabel.font = kFontMedium(16);
[_chooseAccountBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
_chooseAccountBtn.selected = YES;
[_chooseAccountBtn addTarget:self action:@selector(chooseAccountAction) forControlEvents:UIControlEventTouchUpInside];
}
return _chooseAccountBtn;
}
- (UIButton *)chooseSMSBtn{
if(!_chooseSMSBtn){
_chooseSMSBtn = [UIButton new];
[_chooseSMSBtn setTitle:YMLocalizedString(@"XPLoginPhoneViewController10") forState:UIControlStateNormal];
[_chooseSMSBtn setTitleColor:UIColorFromRGB(0x84868A) forState:UIControlStateNormal];
[_chooseSMSBtn setTitleColor:UIColorFromRGB(0x000000) forState:UIControlStateSelected];
_chooseSMSBtn.titleLabel.font = kFontMedium(16);
[_chooseSMSBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_chooseSMSBtn addTarget:self action:@selector(chooseSMSAction) forControlEvents:UIControlEventTouchUpInside];
}
return _chooseSMSBtn;
}
- (XPLoginInputView *)accountView {
if (!_accountView) {
_accountView = [[XPLoginInputView alloc] init];
_accountView.areaStackView.hidden = YES;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPwdViewController6")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB4B7BD) range:NSMakeRange(0, placeholder.length)];
_accountView.inputTextField.attributedPlaceholder = placeholder;
_accountView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
}
return _accountView;
}
- (XPLoginInputView *)accountPwdView {
if (!_accountPwdView) {
_accountPwdView = [[XPLoginInputView alloc] init];
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPwdViewController3")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB4B7BD) range:NSMakeRange(0, placeholder.length)];
_accountPwdView.inputTextField.attributedPlaceholder = placeholder;
_accountPwdView.inputTextField.keyboardType = UIKeyboardTypeAlphabet;
_accountPwdView.inputTextField.secureTextEntry = YES;
}
return _accountPwdView;
}
- (UIButton *)forgetBtn {
if (!_forgetBtn) {
_forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_forgetBtn setTitle:YMLocalizedString(@"XPRoomRedPacketPwdView1") forState:UIControlStateNormal];
[_forgetBtn setTitleColor:UIColorFromRGB(0xB4B7BD) forState:UIControlStateNormal];
_forgetBtn.titleLabel.font = kFontRegular(12);
[_forgetBtn addTarget:self action:@selector(forgetBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}
return _forgetBtn;
}
@end