Files
peko-ios/YuMi/Modules/YMLogin/View/LoginFullInfoViewController.m
2024-12-16 19:41:23 +08:00

596 lines
22 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.

//
// LoginFullInfoViewController.m
// YUMI
//
// Created by YUMI on 2021/9/14.
//
#import "LoginFullInfoViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <ReactiveObjC/ReactiveObjC.h>
///Tool
#import "YUMIMacroUitls.h"
#import "DJDKMIMOMColor.h"
#import "UIImage+Utils.h"
#import "UIButton+EnlargeTouchArea.h"
#import "StatisticsServiceHelper.h"
#import "AccountInfoStorage.h"
#import "TTPopup.h"
#import "PIUserSexView.h"
///Model
#import "ThirdUserInfo.h"
///P
#import "LoginFullInfoPresenter.h"
#import "LoginFullInfoProtocol.h"
#import "PILoginManager.h"
#import "ClientConfig.h"
#import "RegionListViewController.h"
@interface LoginFullInfoViewController ()<LoginFullInfoProtocol, UIViewControllerTransitioningDelegate>
///背景
@property(nonatomic,strong) UIImageView *bgImageView;
///背景
@property(nonatomic,strong) UIView *bgView;
///完善资料
@property (nonatomic,strong) UILabel *titleLabel;
///性别后期无法修改
@property (nonatomic,strong) UILabel *remindLabel;
///昵称的背景
@property (nonatomic,strong) UIView * backView;
///显示昵称
@property (nonatomic,strong) UILabel *nameLabel;
///输入框
@property (nonatomic,strong) MSBaseTextField *textField;
///更新
@property (nonatomic,strong) UIButton *refreshButton;
///x性别的容器
@property (nonatomic,strong) UIStackView *sexStackView;
///男用户
@property (nonatomic,strong) PIUserSexView *maleView;
///女用户
@property (nonatomic,strong) PIUserSexView*femaleView;
///下一步
@property (nonatomic,strong) UIButton *nextButton;
@property(nonatomic, strong) UILabel *block18Tips;
///邀请码的容器
@property (nonatomic,strong) UIView *codeContainView;
///邀请码输入框
@property (nonatomic,strong) MSBaseTextField *codeTextField;
@property (nonatomic,strong) UIView *regionContainView;
@property(nonatomic, strong) UILabel *regionLabel;
@property(nonatomic, strong) NetImageView *regionFlagImageView;
///第三方的用户信息
@property (nonatomic,strong) ThirdUserInfo *thirdInfo;
///目前选择的性别
@property (nonatomic,copy) NSString *sexString;
@end
@implementation LoginFullInfoViewController
- (BOOL)isHiddenNavBar {
return YES;
}
- (LoginFullInfoPresenter *)createPresenter {
return [[LoginFullInfoPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
[self initEvents];
ClientConfig *config = [ClientConfig shareConfig];
if (config.inviteCode.length > 0){
self.inviteCode = config.inviteCode;
config.inviteCode = @"";
}
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.bgImageView];
[self.view addSubview:self.titleLabel];
[self.view addSubview:self.bgView];
[self.bgView addSubview:self.remindLabel];
[self.bgView addSubview:self.sexStackView];
[self.bgView addSubview:self.backView];
[self.view addSubview:self.codeContainView];
[self.view addSubview:self.regionContainView];
[self.view addSubview:self.nextButton];
[self.view addSubview:self.block18Tips];
[self.backView addSubview:self.textField];
[self.backView addSubview:self.refreshButton];
[self.backView addSubview:self.nameLabel];
[self.sexStackView addArrangedSubview:self.maleView];
[self.sexStackView addArrangedSubview:self.femaleView];
[self.codeContainView addSubview:self.codeTextField];
UIStackView *regionStack = [[UIStackView alloc] initWithArrangedSubviews:@[
self.regionFlagImageView,
self.regionLabel
]];
[self.regionContainView addSubview:regionStack];
[regionStack mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(24));
make.centerY.mas_equalTo(self.regionContainView);
}];
if ([self.presenter getThirdUserInfo] && [self.presenter getThirdUserInfo].userName.length > 0) {
self.textField.text = [self.presenter getThirdUserInfo].userName;
} else {
[self.presenter randomRequestNick];
}
}
- (void)initSubViewConstraints {
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.top.equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(418));
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.top.mas_equalTo(kGetScaleWidth(128));
make.leading.mas_equalTo(kGetScaleWidth(24));
make.height.mas_equalTo(kGetScaleWidth(40));
}];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.bottom.equalTo(self.view);
make.top.mas_equalTo(kGetScaleWidth(192));
}];
[self.remindLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.equalTo(self.bgView).inset(kGetScaleWidth(10));
make.top.mas_equalTo(kGetScaleWidth(48));
}];
[self.sexStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(38));
make.trailing.mas_equalTo(-kGetScaleWidth(38));
make.top.mas_equalTo(kGetScaleWidth(86));
}];
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(303));
make.height.mas_equalTo(kGetScaleWidth(52));
make.centerX.equalTo(self.bgView);
make.top.mas_equalTo(self.sexStackView.mas_bottom).offset(kGetScaleWidth(28));
}];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(-kGetScaleWidth(18));
make.centerY.equalTo(self.backView);
}];
[self.refreshButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(18));
make.centerY.equalTo(self.backView);
make.trailing.equalTo(self.nameLabel.mas_leading).mas_offset(-kGetScaleWidth(4));
}];
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(24));
make.top.bottom.equalTo(self.backView);
make.trailing.equalTo(self.refreshButton.mas_leading).mas_offset(-kGetScaleWidth(4));
}];
[self.maleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(132));
make.height.mas_equalTo(kGetScaleWidth(108));
}];
[self.femaleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(132));
make.height.mas_equalTo(kGetScaleWidth(108));
}];
[self.codeContainView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.height.mas_equalTo(self.backView);
make.top.mas_equalTo(self.backView.mas_bottom).offset(kGetScaleWidth(20));
}];
[self.codeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.codeContainView).offset(kGetScaleWidth(24));
make.top.bottom.mas_equalTo(self.codeContainView);
make.trailing.mas_equalTo(self.codeContainView).offset(-kGetScaleWidth(18));
}];
[self.regionContainView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.height.mas_equalTo(self.backView);
make.top.mas_equalTo(self.codeContainView.mas_bottom).offset(kGetScaleWidth(20));
}];
[self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(303));
make.centerX.equalTo(self.bgView);
make.height.mas_equalTo(kGetScaleWidth(48));
make.top.mas_equalTo(self.regionContainView.mas_bottom).offset(kGetScaleWidth(38));
}];
[self.block18Tips mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.nextButton);
make.top.mas_equalTo(self.nextButton.mas_bottom).offset(8);
}];
}
- (void)initEvents {
@weakify(self);
[[self.textField.rac_textSignal map:^id _Nullable(NSString * _Nullable value) {
if (value.length > 15) {
value = [value substringToIndex:15];
}
return value;
}] subscribeNext:^(id _Nullable x) {
@strongify(self);
self.textField.text = x;
[self updateNextButton];
}];
}
- (void)setInviteCode:(NSString *)inviteCode{
_inviteCode = inviteCode;
self.codeTextField.text = _inviteCode;
}
- (void)didTapRegionButton {
// TODO: display list
RegionListViewController *vc = [[RegionListViewController alloc] initForHomeTags];
// vc.modalPresentationStyle = UIModalPresentationPageSheet; // 可结合 UIModalPresentationCustom
// vc.preferredContentSize = CGSizeMake(self.view.bounds.size.width, 100); // 设置高度为 300
// vc.modalPresentationStyle = UIModalPresentationCustom;
// vc.transitioningDelegate = self; // 设置自定义的过渡代理
// [self.navigationController pushViewController:vc animated:YES];
[self presentViewController:vc animated:YES completion:nil];
}
///更新用户信息
- (void)updateUserInfo {
[XNDJTDDLoadingTool showOnlyView:self.view];
[self.presenter complectionInfoWithAvatar:[self getAvatarUrl] gender:self.maleView.selected ? @"1":@"2" nick:self.textField.text inviteCode:self.codeTextField.text roomUid:nil shareUid:nil shareChannel:nil];
}
///获取头像 可能是从第三方获取的头像
- (NSString *)getAvatarUrl {
NSString * avatar;
if ([self.presenter getThirdUserInfo] && [self.presenter getThirdUserInfo].avatarUrl.length > 0) {
avatar = [self.presenter getThirdUserInfo].avatarUrl;
} else {
avatar = @"https://image.hfighting.com/morentouxiang.png";
}
return avatar;
}
- (void)updateNextButton {
if (self.textField.text.length > 0 && self.sexString.length > 0) {
self.nextButton.enabled = YES;
} else {
self.nextButton.enabled = NO;
}
}
#pragma mark - UIViewControllerTransitioningDelegate
//
//- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented
// presentingViewController:(UIViewController *)presenting
// sourceViewController:(UIViewController *)source {
// CustomPresentationController *customPresentationController =
// [[CustomPresentationController alloc] initWithPresentedViewController:presented
// presentingViewController:presenting];
// customPresentationController.preferredHeight = 400; // 設置想要的高度
// return customPresentationController;
//}
//
//- (CGSize)sizeForChildContentContainer:(id<UIContentContainer>)container withParentContainerSize:(CGSize)parentSize {
// return CGSizeMake(parentSize.width, 300); // 设置高度为 300
//}
//
//- (CGRect)frameOfPresentedViewInContainerView {
// CGRect containerBounds = self.presentingViewController.view.bounds;
// return CGRectMake(0, containerBounds.size.height - 300, containerBounds.size.width, 300); // 从底部呈现,高度为 300
//}
#pragma mark - LoginFullInfoProtocol
- (void)requestRandomNickSuccess:(NSString *)nick {
self.textField.text = nick;
}
- (void)complementInfoSuccess {
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventLoginRepariSuccess];
///需要重新加载一次 ticket 刷新tabbar的item
[[AccountInfoStorage instance] saveTicket:nil];
NSString * inviteCode = self.codeTextField.text.length > 0 ? self.codeTextField.text : @"";
[PILoginManager jumpToHomeVCWithInviteCode:inviteCode];
}
-(void)complementInfoFail{
[XNDJTDDLoadingTool hideOnlyView:self.view];
};
#pragma mark - Event Response
- (void)nextButtonAction:(UIButton *)sender {
if (self.codeTextField.text.length <= 0) {
TTAlertConfig * config = [[TTAlertConfig alloc] init];
config.title = YMLocalizedString(@"LoginFullInfoViewController10");
config.message = YMLocalizedString(@"LoginFullInfoViewController0");
[TTPopup alertWithConfig:config confirmHandler:^{
[self updateUserInfo];
} cancelHandler:^{
}];
} else {
[self updateUserInfo];
}
}
- (void)refreshButtonAction {
CAKeyframeAnimation *lAni = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
lAni.duration = 1;
lAni.values=@[@0,@(M_PI*2)];
//使得动画结束后,保持动画效果
lAni.removedOnCompletion = NO;
lAni.fillMode = kCAFillModeForwards;
[self.refreshButton.layer addAnimation:lAni forKey:nil];
[self.presenter randomRequestNick];
}
- (void)maleButtonAction:(UITapGestureRecognizer *)tap {
PIUserSexView * view = (PIUserSexView *)tap.view;
self.femaleView.selected = NO;
view.selected = YES;
self.sexString = @"1";
}
- (void)femaleButtonAction:(UITapGestureRecognizer *)tap {
PIUserSexView * view = (PIUserSexView *)tap.view;
view.selected = YES;
self.maleView.selected = NO;
self.sexString = @"2";
}
#pragma mark - Getters And Setters
- (void)setSexString:(NSString *)sexString {
_sexString = sexString;
[self updateNextButton];
}
- (UIImageView *)bgImageView{
if(!_bgImageView){
_bgImageView = [[UIImageView alloc]init];
_bgImageView.image = kImage(@"login_phone_pwd_bg");
_bgImageView.contentMode = 2;
}
return _bgImageView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.text = YMLocalizedString(@"LoginFullInfoViewController1");
_titleLabel.font = kFontBold(28);
_titleLabel.textColor = UIColorFromRGB(0x1F1B4F);
}
return _titleLabel;
}
- (UILabel *)remindLabel {
if (!_remindLabel) {
_remindLabel = [[UILabel alloc] init];
NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",YMLocalizedString(@"LoginFullInfoViewController8"),YMLocalizedString(@"LoginFullInfoViewController2")] attributes:@{NSFontAttributeName:kFontMedium(16),NSForegroundColorAttributeName:UIColorFromRGB(0x1F1B4F)}];
[textAtt addAttributes:@{NSFontAttributeName:kFontRegular(12),NSForegroundColorAttributeName:UIColorFromRGB(0x6D6B89)} range:[textAtt.string rangeOfString:[NSString stringWithFormat:@"%@",YMLocalizedString(@"LoginFullInfoViewController2")]]];
_remindLabel.attributedText = textAtt;
_remindLabel.numberOfLines = 2;
_remindLabel.textAlignment = NSTextAlignmentCenter;
}
return _remindLabel;
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.backgroundColor = UIColorFromRGB(0xF5F6FA);
_backView.layer.masksToBounds = YES;
_backView.layer.cornerRadius = kGetScaleWidth(52)/2;
}
return _backView;
}
- (UILabel *)nameLabel {
if (!_nameLabel) {
_nameLabel = [[UILabel alloc] init];
_nameLabel.text = YMLocalizedString(@"LoginFullInfoViewController9");
_nameLabel.font = kFontRegular(14);
_nameLabel.textColor = UIColorFromRGB(0x1F1B4F);
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(refreshButtonAction)];
_nameLabel.userInteractionEnabled = YES;
[_nameLabel addGestureRecognizer:tap];
[_nameLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_nameLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}
return _nameLabel;
}
- (MSBaseTextField *)textField {
if (!_textField) {
_textField = [[MSBaseTextField alloc] init];
_textField.textColor = UIColorFromRGB(0x1F1B4F);
_textField.font = kFontMedium(16);
_textField.placeholder = YMLocalizedString(@"LoginFullInfoViewController3");
_textField.borderStyle = UITextBorderStyleNone;
_textField.tintColor = [DJDKMIMOMColor appMainColor];
_textField.backgroundColor = [UIColor clearColor];
}
return _textField;
}
- (UIButton *)refreshButton {
if (!_refreshButton) {
_refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_refreshButton setImage:[UIImage imageNamed:@"login_full_info_refresh"] forState:UIControlStateNormal];
[_refreshButton setImage:[UIImage imageNamed:@"login_full_info_refresh"] forState:UIControlStateSelected];
[_refreshButton setEnlargeEdgeWithTop:0 right:0 bottom:0 left:10];
[_refreshButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_refreshButton setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_refreshButton addTarget:self action:@selector(refreshButtonAction) forControlEvents:UIControlEventTouchUpInside];
}
return _refreshButton;
}
- (UIStackView *)sexStackView {
if (!_sexStackView) {
_sexStackView = [[UIStackView alloc] init];
_sexStackView.axis = UILayoutConstraintAxisHorizontal;
_sexStackView.distribution = UIStackViewDistributionFill;
_sexStackView.alignment = UIStackViewAlignmentCenter;
_sexStackView.spacing = kGetScaleWidth(35);
}
return _sexStackView;
}
- (PIUserSexView *)maleView {
if (!_maleView) {
_maleView = [[PIUserSexView alloc] init];
_maleView.gender = GenderType_Male;
_maleView.selected = NO;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(maleButtonAction:)];
[_maleView addGestureRecognizer:tap];
}
return _maleView;
}
- (PIUserSexView *)femaleView {
if (!_femaleView) {
_femaleView = [[PIUserSexView alloc] init];
_femaleView.gender = GenderType_Female;
_femaleView.selected = NO;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(femaleButtonAction:)];
[_femaleView addGestureRecognizer:tap];
}
return _femaleView;
}
- (UIView *)codeContainView {
if (!_codeContainView) {
_codeContainView = [[UIView alloc] init];
_codeContainView.backgroundColor = UIColorFromRGB(0xF5F6FA);
_codeContainView.layer.masksToBounds= YES;
_codeContainView.layer.cornerRadius = kGetScaleWidth(52)/2;
}
return _codeContainView;
}
- (MSBaseTextField *)codeTextField {
if (!_codeTextField) {
_codeTextField = [[MSBaseTextField alloc] init];
_codeTextField.textColor = UIColorFromRGB(0x1F1B4F);
_codeTextField.font = kFontMedium(14);
_codeTextField.borderStyle = UITextBorderStyleNone;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc]initWithString:YMLocalizedString(@"LoginFullInfoViewController5") attributes:@{NSFontAttributeName:kFontRegular(14),NSForegroundColorAttributeName:UIColorFromRGB(0xB3B3C3)}];
_codeTextField.attributedPlaceholder = placeholder;
_codeTextField.textAlignment = NSTextAlignmentLeft;
_codeTextField.backgroundColor = [UIColor clearColor];
}
return _codeTextField;
}
- (UIButton *)nextButton{
if (!_nextButton) {
_nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
_nextButton.layer.masksToBounds = YES;
_nextButton.layer.cornerRadius = kGetScaleWidth(48)/2.f;
[_nextButton setTitle:YMLocalizedString(@"LoginFullInfoViewController6") forState:UIControlStateNormal];
_nextButton.titleLabel.font = kFontMedium(16);
[_nextButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_nextButton.enabled = NO;
UIImage *image = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor], [DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
[_nextButton setBackgroundImage:image forState:UIControlStateNormal];
[_nextButton addTarget:self action:@selector(nextButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _nextButton;
}
- (UILabel *)block18Tips {
if (!_block18Tips) {
_block18Tips = [UILabel labelInitWithText:YMLocalizedString(@"1.0.30_text_25")
font:kFontRegular(11)
textColor:UIColorFromRGB(0xAFB1B3)];
}
return _block18Tips;
}
- (UIView *)bgView{
if(!_bgView){
UIView *bgView = [UIView new];
bgView.backgroundColor = [UIColor whiteColor];
bgView.layer.cornerRadius = kGetScaleWidth(20);
bgView.layer.masksToBounds = YES;
_bgView = bgView;
}
return _bgView;
}
- (UIView *)regionContainView {
if (!_regionContainView) {
_regionContainView = [[UIView alloc] init];
_regionContainView.backgroundColor = UIColorFromRGB(0xF5F6FA);
[_regionContainView setCornerRadius:kGetScaleWidth(52)/2];
UIImageView *arrow = [[UIImageView alloc] initWithImage:kImage(@"room_setting_arrow")];
arrow.contentMode = UIViewContentModeScaleAspectFit;
[_regionContainView addSubview:arrow];
[arrow mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(_regionContainView);
make.trailing.mas_equalTo(-20);
make.width.height.mas_equalTo(20);
}];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapRegionButton)];
[_regionContainView addGestureRecognizer:tap];
}
return _regionContainView;
}
- (UILabel *)regionLabel {
if (!_regionLabel) {
_regionLabel = [UILabel labelInitWithText:YMLocalizedString(@"1.0.31_text_0")
font:kFontMedium(12)
textColor:UIColorFromRGB(0xb3b3c1)];
_regionLabel.userInteractionEnabled = YES;
}
return _regionLabel;
}
- (NetImageView *)regionFlagImageView {
if (!_regionFlagImageView) {
_regionFlagImageView = [[NetImageView alloc] init];
_regionFlagImageView.contentMode = UIViewContentModeScaleAspectFit;
_regionFlagImageView.userInteractionEnabled = YES;
}
return _regionFlagImageView;
}
@end