HomeHubInitViewController.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // HomeHubInitViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 10/23/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "ValidateUtil.h"
  9. #import "CustomTextField.h"
  10. #import "RequestHandler.h"
  11. #import "CustomLabel.h"
  12. #import "CustomButton.h"
  13. #import "HomeHubInitViewController.h"
  14. #import "DeviceModel.h"
  15. @interface HomeHubInitViewController() <CustomTextFieldDelegate> {
  16. }
  17. @end
  18. #pragma mark - Class Definition
  19. @implementation HomeHubInitViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. [self initUI];
  24. [self prepareViewDidLoad];
  25. }
  26. - (void)viewDidAppear:(BOOL)animated {
  27. [super viewDidAppear:animated];
  28. [UIView animateWithDuration:kfAnimationDur animations:^{
  29. _maskView.alpha = 0.7;
  30. } completion:^(BOOL finished) {
  31. _constraintPopViewTop.constant = 64;
  32. [UIView animateWithDuration:kfAnimationDur animations:^{
  33. [self.view layoutIfNeeded];
  34. }];
  35. }];
  36. }
  37. - (void)initUI {
  38. _txtSecureCode.secureTextEntry = YES;
  39. _txtSecureCode.returnKeyType = UIReturnKeyDone;
  40. _txtSecureCodeConfirm.delegate = self;
  41. _txtSecureCodeConfirm.secureTextEntry = YES;
  42. _txtSecureCodeConfirm.returnKeyType = UIReturnKeyDone;
  43. _txtSecureCode.customTextFieldSuperview = CustomTextFieldSuperviewIsScrollView;
  44. _txtSecureCodeConfirm.customTextFieldSuperview = CustomTextFieldSuperviewIsScrollView;
  45. _txtSecureCode.placeholder = NSLocalizedString(@"보안키", @"보안키");
  46. _txtSecureCodeConfirm.placeholder = NSLocalizedString(@"보안키 확인", @"보안키 확인");
  47. //Localization
  48. [_btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  49. }
  50. - (void)prepareViewDidLoad {
  51. }
  52. #pragma mark - Main Logic
  53. - (void)requestRegisterSecureCode {
  54. //parameters
  55. NSDictionary *parameter = @{@"activation_code" : _activationCode,
  56. @"activation_password" : _activationPassword,
  57. @"user_device_password": _txtSecureCode.text};
  58. NSString *path = [NSString stringWithFormat:API_POST_PARTNER_QR];
  59. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[DeviceModel class] completion:^(id responseObject) {
  60. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  61. return;
  62. }
  63. DeviceModel *device = (DeviceModel *)responseObject;
  64. if (device) {
  65. [JDFacade facade].loginUser.homehubDeviceId = device.deviceId;
  66. }
  67. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubCompleteViewController" storyboardName:@"HomeHub"];
  68. [self presentViewController:vc animated:YES completion:nil];
  69. } failure:^(id errorObject) {
  70. JDErrorModel *error = (JDErrorModel *)errorObject;
  71. [[JDFacade facade] alert:error.errorMessage];
  72. }];
  73. }
  74. #pragma mark - UI Events
  75. - (IBAction)btnConfirmTouched:(id)sender {
  76. //1.validate
  77. if (![ValidateUtil validateTextfiled:_txtSecureCode type:ValidateTypeNull title:NSLocalizedString(@"보안키", @"보안키")]) {
  78. return;
  79. }
  80. if (![ValidateUtil validateTextfiled:_txtSecureCodeConfirm type:ValidateTypeNull title:NSLocalizedString(@"보안키 확인", @"보안키 확인")]) {
  81. return;
  82. }
  83. if (![_txtSecureCode.text isEqualToString:_txtSecureCodeConfirm.text]) {
  84. [[JDFacade facade] alert:NSLocalizedString(@"보안키와 보안키확인이 다릅니다\n다시 입력해주세요", @"보안키와 보안키확인이 다릅니다\n다시 입력해주세요")];
  85. return;
  86. }
  87. [self requestRegisterSecureCode];
  88. }
  89. - (IBAction)btnCloseTouched:(id)sender {
  90. [[JDFacade facade] confirmTitle:@"연결취소" message:@"홈허브 연결을 취소할까요?" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  91. if (buttonIndex == 0) {//OK
  92. [[JDFacade facade] dismissModalStack:YES completion:nil];
  93. }
  94. }];
  95. }
  96. #pragma mark - CustomTextField
  97. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  98. if ([textField isEqual:_txtSecureCodeConfirm]) {
  99. [self btnConfirmTouched:nil];
  100. }
  101. return YES;
  102. }
  103. #pragma mark - MemoryWarning
  104. - (void)didReceiveMemoryWarning
  105. {
  106. [super didReceiveMemoryWarning];
  107. // Dispose of any resources that can be recreated.
  108. }
  109. @end