Files
yinmeng-ios/xplan-ios/Main/Login/View/LoginFullInfoViewController.m
2024-01-31 10:43:03 +08:00

465 lines
15 KiB
Objective-C

//
// LoginFullInfoViewController.m
// xplan-ios
//
// Created by 冯硕 on 2021/9/14.
//
#import "LoginFullInfoViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <ReactiveObjC/ReactiveObjC.h>
///Tool
#import "XPMacro.h"
#import "ThemeColor.h"
#import "UIImage+Utils.h"
#import "UIButton+EnlargeTouchArea.h"
#import "StatisticsServiceHelper.h"
#import "AccountInfoStorage.h"
#import "TTPopup.h"
///Model
#import "ThirdUserInfo.h"
///P
#import "LoginFullInfoPresenter.h"
#import "LoginFullInfoProtocol.h"
UIKIT_EXTERN NSString * kUserCompleteInfoFinishKey;
@interface LoginFullInfoViewController ()<LoginFullInfoProtocol>
///完善资料
@property (nonatomic,strong) UILabel *titleLabel;
///性别后期无法修改
@property (nonatomic,strong) UILabel *remindLabel;
///昵称的背景
@property (nonatomic,strong) UIView * backView;
///容器
@property (nonatomic,strong) UIStackView *stackView;
///显示昵称
@property (nonatomic,strong) UILabel *nameLabel;
///输入框
@property (nonatomic,strong) UITextField *textField;
///更新
@property (nonatomic,strong) UIButton *refreshButton;
///x性别的容器
@property (nonatomic,strong) UIStackView *sexStackView;
///男用户
@property (nonatomic,strong) UIButton *maleButton;
///女用户
@property (nonatomic,strong) UIButton *femaleButton;
///下一步
@property (nonatomic,strong) UIButton *nextButton;
///邀请码
@property (nonatomic,strong) UILabel *codeLabel;
///邀请码的容器
@property (nonatomic,strong) UIView *codeContainView;
///邀请码输入框
@property (nonatomic,strong) UITextField *codeTextField;
///选填
@property (nonatomic,strong) UILabel *codeDesLabel;
///本软件只提供给18
@property (nonatomic,strong) UILabel *limitLabel;
///第三方的用户信息
@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];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
#pragma mark - Private Method
- (void)initSubViews {
[self.view addSubview:self.titleLabel];
[self.view addSubview:self.remindLabel];
[self.view addSubview:self.backView];
[self.view addSubview:self.sexStackView];
[self.view addSubview:self.codeLabel];
[self.view addSubview:self.codeContainView];
[self.view addSubview:self.nextButton];
[self.view addSubview:self.limitLabel];
[self.backView addSubview:self.stackView];
[self.stackView addArrangedSubview:self.nameLabel];
[self.stackView addArrangedSubview:self.textField];
[self.stackView addArrangedSubview:self.refreshButton];
[self.sexStackView addArrangedSubview:self.maleButton];
[self.sexStackView addArrangedSubview:self.femaleButton];
[self.codeContainView addSubview:self.codeTextField];
[self.codeContainView addSubview:self.codeDesLabel];
if ([self.presenter getThirdUserInfo] && [self.presenter getThirdUserInfo].userName.length > 0) {
self.textField.text = [self.presenter getThirdUserInfo].userName;
} else {
[self.presenter randomRequestNick];
}
}
- (void)initSubViewConstraints {
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.top.mas_equalTo(self.view).offset(60 + kSafeAreaTopHeight);
}];
[self.remindLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(8);
}];
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view).inset(52);
make.height.mas_equalTo(45);
make.top.mas_equalTo(self.remindLabel.mas_bottom).offset(49);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.backView).inset(25);
make.top.bottom.mas_equalTo(self.backView);
}];
[self.sexStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.backView);
make.top.mas_equalTo(self.backView.mas_bottom).offset(15);
}];
[self.codeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view);
make.top.mas_equalTo(self.sexStackView.mas_bottom).offset(20);
}];
[self.codeContainView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.height.mas_equalTo(self.backView);
make.top.mas_equalTo(self.codeLabel.mas_bottom).offset(11);
}];
[self.codeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.codeContainView).offset(10);
make.top.bottom.mas_equalTo(self.codeContainView);
make.right.mas_equalTo(self.codeDesLabel.mas_left).offset(-5);
}];
[self.codeDesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.codeContainView).offset(-25);
make.centerY.mas_equalTo(self.codeContainView);
}];
[self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view).inset(52);
make.height.mas_equalTo(45);
make.top.mas_equalTo(self.codeContainView.mas_bottom).offset(75);
}];
[self.limitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.view.mas_bottom).offset(-15);
}];
}
- (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)updateUserInfo {
[self.presenter complectionInfoWithAvatar:[self getAvatarUrl] gender:self.maleButton.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://yinmeng-1318633625.cos.ap-guangzhou.myqcloud.com/default_avatar.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 - LoginFullInfoProtocol
- (void)requestRandomNickSuccess:(NSString *)nick {
self.textField.text = nick;
}
- (void)complementInfoSuccess {
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventLoginRepariSuccess];
///需要重新加载一次 ticket 刷新tabbar的item
[[AccountInfoStorage instance] saveTicket:nil];
UIViewController *vc = self.presentingViewController;
while (vc.presentingViewController) {
vc = vc.presentingViewController;
}
[vc dismissViewControllerAnimated:YES completion:^{
}];
NSString * inviteCode = self.codeTextField.text.length > 0 ? self.codeTextField.text : @"";
[[NSNotificationCenter defaultCenter] postNotificationName:kUserCompleteInfoFinishKey object:inviteCode];
}
#pragma mark - Event Response
- (void)nextButtonAction:(UIButton *)sender {
if (self.codeTextField.text.length <= 0) {
TTAlertConfig * config = [[TTAlertConfig alloc] init];
config.title = @"";
config.message = @"当前未填写邀请码哦~ \n 确认继续下一步吗";
[TTPopup alertWithConfig:config confirmHandler:^{
[self updateUserInfo];
} cancelHandler:^{
}];
} else {
[self updateUserInfo];
}
}
- (void)refreshButtonAction:(UIButton *)sender {
CAKeyframeAnimation *lAni = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
lAni.duration = 1;
lAni.values=@[@0,@(M_PI*2)];
//使得动画结束后,保持动画效果
lAni.removedOnCompletion = NO;
lAni.fillMode = kCAFillModeForwards;
[sender.layer addAnimation:lAni forKey:nil];
[self.presenter randomRequestNick];
}
- (void)maleButtonAction:(UIButton *)sender {
self.femaleButton.selected = NO;
sender.selected = YES;
self.sexString = @"1";
}
- (void)femaleButtonAction:(UIButton *)sender {
sender.selected = YES;
self.maleButton.selected = NO;
self.sexString = @"2";
}
#pragma mark - Getters And Setters
- (void)setSexString:(NSString *)sexString {
_sexString = sexString;
[self updateNextButton];
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.text = @"完善资料";
_titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Bold" size:18];
_titleLabel.textColor = [ThemeColor mainTextColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _titleLabel;
}
- (UILabel *)remindLabel {
if (!_remindLabel) {
_remindLabel = [[UILabel alloc] init];
_remindLabel.text = @"性别后期无法进行修改";
_remindLabel.font = [UIFont systemFontOfSize:13];
_remindLabel.textColor = [ThemeColor secondTextColor];
}
return _remindLabel;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = 10;
}
return _stackView;
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.backgroundColor = [ThemeColor appCellBackgroundColor];
_backView.layer.masksToBounds = YES;
_backView.layer.cornerRadius = 45/2;
}
return _backView;
}
- (UILabel *)nameLabel {
if (!_nameLabel) {
_nameLabel = [[UILabel alloc] init];
_nameLabel.text = @"昵称";
_nameLabel.font = [UIFont systemFontOfSize:15];
_nameLabel.textColor = [ThemeColor secondTextColor];
[_nameLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_nameLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}
return _nameLabel;
}
- (UITextField *)textField {
if (!_textField) {
_textField = [[UITextField alloc] init];
_textField.textColor = [ThemeColor mainTextColor];
_textField.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:15.f];
_textField.borderStyle = UITextBorderStyleNone;
_textField.tintColor = [ThemeColor appMainColor];
_textField.textAlignment = NSTextAlignmentRight;
_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 = 15;
}
return _sexStackView;
}
- (UIButton *)maleButton {
if (!_maleButton) {
_maleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_maleButton setImage:[UIImage imageNamed:@"login_full_info_male_normal"] forState:UIControlStateNormal];
[_maleButton setImage:[UIImage imageNamed:@"login_full_info_male_select"] forState:UIControlStateSelected];
[_maleButton addTarget:self action:@selector(maleButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _maleButton;
}
- (UIButton *)femaleButton {
if (!_femaleButton) {
_femaleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_femaleButton setImage:[UIImage imageNamed:@"login_full_info_female_normal"] forState:UIControlStateNormal];
[_femaleButton setImage:[UIImage imageNamed:@"login_full_info_female_select"] forState:UIControlStateSelected];
[_femaleButton addTarget:self action:@selector(femaleButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _femaleButton;
}
- (UIView *)codeContainView {
if (!_codeContainView) {
_codeContainView = [[UIView alloc] init];
_codeContainView.backgroundColor = [ThemeColor appCellBackgroundColor];
_codeContainView.layer.masksToBounds= YES;
_codeContainView.layer.cornerRadius = 45/2;
}
return _codeContainView;
}
- (UITextField *)codeTextField {
if (!_codeTextField) {
_codeTextField = [[UITextField alloc] init];
_codeTextField.textColor = [ThemeColor mainTextColor];
_codeTextField.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:15.f];
_codeTextField.borderStyle = UITextBorderStyleNone;
_codeTextField.tintColor = [ThemeColor appMainColor];
_codeTextField.textAlignment = NSTextAlignmentLeft;
_codeTextField.backgroundColor = [UIColor clearColor];
}
return _codeTextField;
}
- (UILabel *)codeLabel {
if (!_codeLabel) {
_codeLabel = [[UILabel alloc] init];
_codeLabel.text = @"邀请码";
_codeLabel.font = [UIFont systemFontOfSize:18];
_codeLabel.textAlignment = NSTextAlignmentCenter;
_codeLabel.textColor = [ThemeColor secondTextColor];
}
return _codeLabel;
}
- (UILabel *)codeDesLabel {
if (!_codeDesLabel) {
_codeDesLabel = [[UILabel alloc] init];
_codeDesLabel.text = @"(选填)";
_codeDesLabel.font = [UIFont systemFontOfSize:15];
_codeDesLabel.textColor = [ThemeColor textThirdColor];
[_codeDesLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}
return _codeDesLabel;
}
- (UIButton *)nextButton{
if (!_nextButton) {
_nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
_nextButton.layer.masksToBounds = YES;
_nextButton.layer.cornerRadius = 45/2.f;
[_nextButton setTitle:@"下一步" forState:UIControlStateNormal];
_nextButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:18];
[_nextButton setTitleColor:[ThemeColor confirmButtonTextColor] forState:UIControlStateNormal];
_nextButton.enabled = NO;
UIImage *image = [UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor], [ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
[_nextButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor disableButtonColor], [ThemeColor disableButtonColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateDisabled];
[_nextButton setBackgroundImage:image forState:UIControlStateNormal];
[_nextButton addTarget:self action:@selector(nextButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _nextButton;
}
- (UILabel *)limitLabel {
if (!_limitLabel) {
_limitLabel = [[UILabel alloc] init];
_limitLabel.text = @"本软件只提供给18岁或以上用户使用";
_limitLabel.textAlignment = NSTextAlignmentCenter;
_limitLabel.font = [UIFont systemFontOfSize:12];
_limitLabel.textColor = [ThemeColor textThirdColor];
}
return _limitLabel;
}
@end