HomeHubChangeViewController.m 3.8 KB

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