NickNameController.m
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//
// NickNameController.m
// DreamSleep
//
// Created by peter on 2022/4/25.
//
#import "NickNameController.h"
@interface NickNameController ()
@property (nonatomic, strong) UIView *mainView;
@property (nonatomic, strong) UIImageView *portraitIV;
@property (nonatomic, strong) UIImageView *cameraIV;
@property (nonatomic, strong) UITextField *nickTF;
@property (nonatomic, strong) UIButton *saveBtn;
@end
@implementation NickNameController
- (instancetype)initWithBlock:(SaveBlock)block {
if (self = [super init]) {
_block = block;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"修改昵称";
self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.view addSubview:self.mainView];
[self.mainView addSubview:self.portraitIV];
[self.mainView addSubview:self.cameraIV];
[self.mainView addSubview:self.nickTF];
[self.mainView addSubview:self.saveBtn];
[self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.top.equalTo(self.view).offset(83);
}];
[self.portraitIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(145, 145));
make.top.equalTo(self.mainView);
make.centerX.equalTo(self.mainView);
}];
[self.cameraIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.portraitIV).offset(-6);
make.bottom.equalTo(self.portraitIV).offset(-6);
make.size.mas_equalTo(CGSizeMake(30, 30));
}];
[self.nickTF mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.mainView);
make.top.equalTo(self.portraitIV.mas_bottom).offset(60);
make.size.mas_equalTo(CGSizeMake(155, 40));
}];
[self.saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.mainView);
make.size.equalTo(self.nickTF);
make.top.equalTo(self.nickTF.mas_bottom).offset(15);
make.bottom.equalTo(self.mainView);
}];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
#pragma mark - Actions
- (void)saveAction {
[DSProgressHUD showProgressHUDWithInfo:@""];
NSDictionary *data = @{@"nick_name" : [NSString transferEnglishDoubleQuotationMarks:self.nickTF.text]};
WS(weakSelf);
[UserRequestModel updateUserInfoWithData:data completion:^(UserRequestModel * _Nonnull requestModel) {
[DSProgressHUD dissmissProgressHUD];
if (requestModel.resCode == DSResCodeSuccess) {
[DSProgressHUD showToast:@"修改成功"];
[LoginUtils updateUserInfo:@{@"nick_name" : self.nickTF.text}];
if (weakSelf.block) { weakSelf.block(); }
[weakSelf.navigationController popViewControllerAnimated:YES];
[DataStatisticsUtil event:User_Info attributes:@{@"name":@"修改昵称"}];
// 执行修改昵称任务
[DsTaskManager excuteGeneralTaskWithType:TaskTypeNew taskItem:TaskItemNick];
}
}];
}
#pragma mark - lazy
- (UIView *)mainView {
if (!_mainView) {
_mainView = [UIView new];
}
return _mainView;
}
- (UIImageView *)portraitIV {
if (!_portraitIV) {
_portraitIV = [UIImageView new];
_portraitIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1, .5, .5);
[_portraitIV yy_setImageWithURL:[NSURL URLWithString:[LoginUtils getFaceImg]] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
[_portraitIV cornerRadius:145/2.0];
}
return _portraitIV;
}
- (UIImageView *)cameraIV {
if (!_cameraIV) {
_cameraIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cameraIcon"]];
if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
[_cameraIV addMaskWithType:MaskTypeAllCorner cornerRadius:15];
}
}
return _cameraIV;
}
- (UITextField *)nickTF {
if (!_nickTF) {
_nickTF = [UITextField new];
_nickTF.font = BoldFont(16);
_nickTF.dk_textColorPicker = DKColorPickerWithKey(TEXT);
UserModel *model = [LoginUtils getUserLoginData];
_nickTF.text = model.nick_name;
_nickTF.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, CornerViewDarkColor, DSWhite);
_nickTF.textAlignment = NSTextAlignmentCenter;
[_nickTF cornerRadius:20];
}
return _nickTF;
}
- (UIButton *)saveBtn {
if (!_saveBtn) {
_saveBtn = [UIButton btnWithTitle:@"保存" titleColor:DSWhite font:BoldFont(16) bgColor:BrandColor];
[_saveBtn addTarget:self action:@selector(saveAction) forControlEvents:UIControlEventTouchUpInside];
[_saveBtn cornerRadius:20];
}
return _saveBtn;
}
#pragma mark - 品牌模式
- (NaviStyle)navigationBarStyle {
return NaviStyleDefault;
}
@end