WFCUModifyMyProfileViewController.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // ModifyMyProfileViewController.m
  3. // WildFireChat
  4. //
  5. // Created by heavyrain.lee on 2018/5/20.
  6. // Copyright © 2018 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUModifyMyProfileViewController.h"
  9. #import "MBProgressHUD.h"
  10. #import <WFChatClient/WFCChatClient.h>
  11. #import "WFCUConfigManager.h"
  12. @interface WFCUModifyMyProfileViewController () <UITextFieldDelegate, UITextInputDelegate>
  13. @property(nonatomic, strong)UITextField *textField;
  14. @end
  15. @implementation WFCUModifyMyProfileViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[WFCCNetworkService sharedInstance].userId refresh:NO];
  19. NSString *title = nil;
  20. NSString *defaultValue = nil;
  21. switch (self.modifyType) {
  22. case Modify_Email:
  23. title = WFCString(@"ModifyEmail");
  24. defaultValue = userInfo.email;
  25. self.textField.keyboardType = UIKeyboardTypeEmailAddress;
  26. break;
  27. case Modify_Mobile:
  28. title = WFCString(@"ModifyMobile");
  29. defaultValue = userInfo.mobile;
  30. self.textField.keyboardType = UIKeyboardTypePhonePad;
  31. break;
  32. case Modify_Social:
  33. title = WFCString(@"ModifySocialAccount");
  34. defaultValue = userInfo.social;
  35. break;
  36. case Modify_Address:
  37. title = WFCString(@"ModifyAddress");
  38. defaultValue = userInfo.address;
  39. break;
  40. case Modify_Company:
  41. title = WFCString(@"ModifyCompanyInfo");
  42. defaultValue = userInfo.company;
  43. break;
  44. case Modify_DisplayName:
  45. title = WFCString(@"ModifyNickname");
  46. defaultValue = userInfo.displayName;
  47. break;
  48. default:
  49. break;
  50. }
  51. self.textField.text = defaultValue;
  52. [self setTitle:title];
  53. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:WFCString(@"Ok") style:UIBarButtonItemStyleDone target:self action:@selector(onDone:)];
  54. self.view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  55. [self.textField becomeFirstResponder];
  56. }
  57. - (void)onDone:(id)sender {
  58. [self.textField resignFirstResponder];
  59. __weak typeof(self) ws = self;
  60. __block MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  61. hud.label.text = WFCString(@"Updating");
  62. [hud showAnimated:YES];
  63. [[WFCCIMService sharedWFCIMService] modifyMyInfo:@{@(self.modifyType):self.textField.text} success:^{
  64. [hud hideAnimated:NO];
  65. self.onModified(self.modifyType, self.textField.text);
  66. [ws.navigationController popViewControllerAnimated:YES];
  67. } error:^(int error_code) {
  68. [hud hideAnimated:NO];
  69. hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  70. hud.mode = MBProgressHUDModeText;
  71. hud.label.text = WFCString(@"UpdateFailure");
  72. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  73. [hud hideAnimated:YES afterDelay:1.f];
  74. }];
  75. }
  76. - (void)didReceiveMemoryWarning {
  77. [super didReceiveMemoryWarning];
  78. // Dispose of any resources that can be recreated.
  79. }
  80. - (UITextField *)textField {
  81. if(!_textField) {
  82. _textField = [[UITextField alloc] initWithFrame:CGRectMake(0, kStatusBarAndNavigationBarHeight + 20, [UIScreen mainScreen].bounds.size.width, 32)];
  83. _textField.borderStyle = UITextBorderStyleRoundedRect;
  84. _textField.clearButtonMode = UITextFieldViewModeAlways;
  85. _textField.delegate = self;
  86. _textField.inputDelegate = self;
  87. [self.view addSubview:_textField];
  88. }
  89. return _textField;
  90. }
  91. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  92. [self onDone:textField];
  93. return YES;
  94. }
  95. #pragma mark - UITextInputDelegate
  96. - (void)textDidChange:(nullable id <UITextInput>)textInput {
  97. if (self.textField.text.length) {
  98. self.navigationItem.rightBarButtonItem.enabled = YES;
  99. } else {
  100. self.navigationItem.rightBarButtonItem.enabled = NO;
  101. }
  102. }
  103. - (void)selectionDidChange:(nullable id<UITextInput>)textInput {
  104. }
  105. - (void)selectionWillChange:(nullable id<UITextInput>)textInput {
  106. }
  107. - (void)textWillChange:(nullable id<UITextInput>)textInput {
  108. }
  109. @end