AccountViewController.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // AccountViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 5/13/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "CustomLabel.h"
  10. #import "CustomButton.h"
  11. #import "DeleteAccountPopupView.h"
  12. #import "PwdPopupView.h"
  13. #import "ConfirmPwdViewController.h"
  14. #import "AccountViewController.h"
  15. #import "UIButton+WebCache.h"
  16. #import "ChangeIconViewController.h"
  17. #import "RequestHandler.h"
  18. @interface AccountViewController () {
  19. UIView *_containerView;
  20. ChangeIconViewController *_ivc;
  21. CGFloat _containerBottom;
  22. MASConstraint *_constraintContainerBottom;
  23. }
  24. @end
  25. #pragma mark - Class Definition
  26. @implementation AccountViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. [self initUI];
  31. }
  32. - (void)viewWillAppear:(BOOL)animated {
  33. [super viewWillAppear:animated];
  34. self.title = NSLocalizedString(@"계정 정보", @"계정 정보");
  35. [self prepareViewDidLoad];
  36. }
  37. - (void)initUI {
  38. //set tableview option
  39. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  40. self.tableView.backgroundColor = [UIColor clearColor];
  41. [_lblPwdChange setUnderLine:_lblPwdChange.text];
  42. [_lblAccountDelete setUnderLine:_lblAccountDelete.text];
  43. [_lblPwdChange addTouchEventHandler:^{
  44. [self lblPwdChangeTouched];
  45. }];
  46. [_lblAccountDelete addTouchEventHandler:^{
  47. [self lblAccountDeleteTouched];
  48. }];
  49. [_btnProfile sd_setImageWithURL:[NSURL URLWithString:[JDFacade facade].loginUser.imageFileName] forState:UIControlStateNormal];
  50. _lblNameTitle.text = NSLocalizedString(@"이름", @"이름");
  51. _lblEmailTitle.text = NSLocalizedString(@"이메일", @"이메일");
  52. _lblPwdTitle.text = NSLocalizedString(@"비밀번호", @"비밀번호");
  53. _lblAccountDeleteTitle.text = NSLocalizedString(@"계정삭제", @"계정삭제");
  54. }
  55. - (void)prepareViewDidLoad {
  56. [_btnName setTitle:[JDFacade facade].loginUser.nickname forState:UIControlStateNormal];
  57. [_btnEmail setTitle:[JDFacade facade].tmpEmailId forState:UIControlStateNormal];
  58. _lblNewEmailInfo.hidden = !([JDFacade facade].loginUser.newEmailId && ![[JDFacade facade].loginUser.newEmailId isEmptyString]);
  59. if (!_lblNewEmailInfo.hidden) {//이메일 변경 요청 중
  60. _lblNewEmailInfo.text = [NSString stringWithFormat:NSLocalizedString(@"%@ 인증 대기중", @"%@ 인증 대기중"), [JDFacade facade].loginUser.newEmailId];
  61. }
  62. }
  63. #pragma mark - Main Logic
  64. - (void)requestChangeMemberIcon {
  65. //parameters
  66. NSDictionary *parameter = @{@"image_file_name": _ivc && _ivc.selectedIcon ? _ivc.selectedIcon.imageFilePath : ksEmptyString};
  67. NSString *path = [NSString stringWithFormat:API_POST_MEMBER_UPDATE, [JDFacade facade].loginUser.memberId, @"profile"];
  68. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  69. [JDFacade facade].loginUser.imageFileName = _ivc.selectedIcon.imageFileName;
  70. [_btnProfile sd_setImageWithURL:[NSURL URLWithString:[JDFacade facade].loginUser.imageFileName] forState:UIControlStateNormal];
  71. [[JDFacade facade] toast:NSLocalizedString(@"변경되었습니다", @"변경되었습니다")];
  72. [self closeChildViewController:_ivc completionHandler:nil];
  73. } failure:^(id errorObject) {
  74. JDErrorModel *error = (JDErrorModel *)errorObject;
  75. [[JDFacade facade] alert:error.errorMessage];
  76. }];
  77. }
  78. #pragma mark - UI Events
  79. - (IBAction)btnNameTouched:(id)sender {
  80. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ChangeNameViewController" storyboardName:@"Settings"];
  81. [self.navigationController pushViewController:vc animated:YES];
  82. }
  83. - (IBAction)btnEmailTouched:(id)sender {
  84. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ChangeEmailViewController" storyboardName:@"Settings"];
  85. [self.navigationController pushViewController:vc animated:YES];
  86. }
  87. - (void)lblPwdChangeTouched {
  88. ConfirmPwdViewController *vc = (ConfirmPwdViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ConfirmPwdViewController" storyboardName:@"Settings"];
  89. vc.popupName = NSStringFromClass([PwdPopupView class]);
  90. [self.navigationController pushViewController:vc animated:YES];
  91. }
  92. - (void)lblAccountDeleteTouched {
  93. ConfirmPwdViewController *vc = (ConfirmPwdViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ConfirmPwdViewController" storyboardName:@"Settings"];
  94. vc.popupName = NSStringFromClass([DeleteAccountPopupView class]);
  95. [self.navigationController pushViewController:vc animated:YES];
  96. }
  97. - (IBAction)btnProfileTouched:(id)sender {
  98. [self modifyMemberIcon];
  99. }
  100. - (void)modifyMemberIcon {
  101. if ([_ivc.view superview]) {
  102. return;
  103. }
  104. self.tableView.scrollEnabled = NO;
  105. if (!_ivc) {
  106. _ivc = (ChangeIconViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ChangeIconViewController" storyboardName:@"Settings"];
  107. [self addChildViewController:_ivc];
  108. [_ivc didMoveToParentViewController:self];
  109. }
  110. if (!_containerView) {
  111. _containerView = [[UIView alloc] initWithFrame:CGRectMake(0, IPHONE_HEIGHT+STATUS_BAR_HEIGHT, IPHONE_WIDTH, 336)];
  112. _containerView.backgroundColor = [UIColor whiteColor];
  113. [self.view addSubview:_containerView];
  114. }
  115. [_containerView addSubview:_ivc.view];
  116. if (![_ivc.btnSave actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  117. __weak typeof(self) weakSelf = self;
  118. [_ivc.btnSave addTarget:weakSelf action:@selector(btnSaveTouched:) forControlEvents:UIControlEventTouchUpInside];
  119. [_ivc.btnCancel addTarget:weakSelf action:@selector(btnCancelTouched:) forControlEvents:UIControlEventTouchUpInside];
  120. }
  121. [UIView animateWithDuration:ANIMATION_DUR animations:^{
  122. CGRect cr = _containerView.frame;
  123. cr.origin.y = IPHONE_HEIGHT - 336 - 60;
  124. _containerView.frame = cr;
  125. }];
  126. }
  127. - (void)closeChildViewController:(UIViewController *)vc completionHandler:(JDFacadeCompletionCallBackHandler)completionHander {
  128. [UIView animateWithDuration:ANIMATION_DUR animations:^{
  129. CGRect cr = _containerView.frame;
  130. cr.origin.y = IPHONE_HEIGHT + STATUS_BAR_HEIGHT;
  131. _containerView.frame = cr;
  132. } completion:^(BOOL finished) {
  133. self.tableView.scrollEnabled = YES;
  134. [vc.view removeFromSuperview];
  135. if (completionHander) {
  136. completionHander();
  137. }
  138. }];
  139. }
  140. - (void)btnSaveTouched:(id)sender {
  141. //기존이랑 같으면, 요청을 날리지 않음.
  142. //image_file_name;
  143. if ([[JDFacade facade].loginUser.imageFileName isEqualToString:_ivc.selectedIcon.imageFileName]) {
  144. [[JDFacade facade] alert:NSLocalizedString(@"프로필 이미지를 선택해주세요", @"프로필 이미지를 선택해주세요")];
  145. return;
  146. }
  147. [self requestChangeMemberIcon];
  148. }
  149. - (void)btnCancelTouched:(id)sender {
  150. [self closeChildViewController:_ivc completionHandler:nil];
  151. }
  152. #pragma mark - MemoryWarning
  153. - (void)didReceiveMemoryWarning
  154. {
  155. [super didReceiveMemoryWarning];
  156. // Dispose of any resources that can be recreated.
  157. }
  158. @end