cdts/xdts-ios 3/TreeHole/Code/Features/Profile/ViewController/EditNameViewController.m
2023-07-27 09:20:00 +08:00

85 lines
3.2 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.

//
// EditNameViewController.m
// Youth
//
// Created by mambaxie on 2022/1/2.
//
#import "EditNameViewController.h"
#import "ChatService.h"
@interface EditNameViewController ()
@property (nonatomic, strong) PYThemeTextField *textField;
@end
@implementation EditNameViewController
- (BOOL)mt_nagationBarTransparent {
return NO;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = self.isFromGroupChat ? @"群聊名称" : @"修改昵称";
WeakSelf(self);
PYThemeButton *okButton = [PYThemeButton navItemWithTitle:@"完成" action:^(UIButton * _Nonnull button) {
if (weakself.isFromGroupChat) {
[ChatService setGropuNameGroupID:weakself.groupInfo.group_id name:weakself.textField.text completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
weakself.groupInfo.group_name = weakself.textField.text;
[weakself.navigationController popViewControllerAnimated:YES];
}
}];
} else {
[UserService updateUserToRemoteWithParams:@{@"nick_name": weakself.textField.text ?: @""} completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
User *user = [UserService currentUser];
user.nickname = weakself.textField.text;
[UserService updateUser:user];
[weakself.navigationController popViewControllerAnimated:YES];
}else{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]];
});
}
}];
}
}];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:okButton];
UILabel *tipsLabel = [[UILabel alloc] init];
tipsLabel.width = 30;
tipsLabel.height = 30;
tipsLabel.textColor = COLOR_WITH_RGB(0xBEC9CF);
tipsLabel.textAlignment = NSTextAlignmentRight;
tipsLabel.font = MT_FONT_REGULAR_SIZE(12);
[self.view addSubview:tipsLabel];
PYThemeTextField *textField = [PYThemeTextField fieldWithPlaceholder:self.isFromGroupChat ? @"输入群聊名称" : @"2-15个字符支持中英文" maxLength:15];
textField.y = NAVIGATION_BAR_HEIGHT + FIX_SIZE(10);
textField.x = FIX_SIZE(15);
textField.width = SCREEN_WIDTH - textField.x * 2;
textField.textDidChangeAction = ^(PYThemeTextField * _Nonnull field) {
okButton.enabled = field.text.length >= 2 && field.text.length <= 15;
tipsLabel.text = @(field.text.length).stringValue;
};
textField.textField.text = self.isFromGroupChat ? self.groupInfo.group_name : [UserService currentUser].nickname;
tipsLabel.right = textField.right - FIX_SIZE(3);
tipsLabel.y = textField.bottom + FIX_SIZE(5);
[self.view addSubview:textField];
self.textField = textField;
self.textField.textDidChangeAction(self.textField);
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.textField.textField becomeFirstResponder];
}
@end