// // HomeHubInitViewController.m // kneet // // Created by Jason Lee on 10/23/15. // Copyright (c) 2015 ntels. All rights reserved. // #import "ValidateUtil.h" #import "CustomTextField.h" #import "RequestHandler.h" #import "CustomLabel.h" #import "CustomButton.h" #import "HomeHubInitViewController.h" #import "DeviceModel.h" @interface HomeHubInitViewController() { } @end #pragma mark - Class Definition @implementation HomeHubInitViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self initUI]; [self prepareViewDidLoad]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [UIView animateWithDuration:kfAnimationDur animations:^{ _maskView.alpha = 0.7; } completion:^(BOOL finished) { _constraintPopViewTop.constant = (IPHONE_HEIGHT - _popView.height) / 2; [UIView animateWithDuration:kfAnimationDur animations:^{ [self.view layoutIfNeeded]; }]; }]; } - (void)initUI { _txtSecureCode.secureTextEntry = YES; _txtSecureCode.returnKeyType = UIReturnKeyDone; _txtSecureCodeConfirm.delegate = self; _txtSecureCodeConfirm.secureTextEntry = YES; _txtSecureCodeConfirm.returnKeyType = UIReturnKeyDone; _txtSecureCode.customTextFieldSuperview = CustomTextFieldSuperviewIsScrollView; _txtSecureCodeConfirm.customTextFieldSuperview = CustomTextFieldSuperviewIsScrollView; _txtSecureCode.placeholder = NSLocalizedString(@"보안키", @"보안키"); _txtSecureCodeConfirm.placeholder = NSLocalizedString(@"보안키 확인", @"보안키 확인"); //Localization [_btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal]; } - (void)prepareViewDidLoad { } #pragma mark - Main Logic - (void)requestRegisterSecureCode { //parameters NSDictionary *parameter = @{@"activation_code" : _activationCode, @"activation_password" : _activationPassword, @"user_device_password": _txtSecureCode.text}; NSString *path = [NSString stringWithFormat:API_POST_PARTNER_QR]; [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[DeviceModel class] completion:^(id responseObject) { if (!responseObject) {//응답결과가 잘못되었거나 없을 경우, return; } DeviceModel *device = (DeviceModel *)responseObject; if (device) { [JDFacade facade].loginUser.homehubDeviceId = device.deviceId; } [[JDFacade facade] updateLoginInfo:^{ UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"WelcomeViewController" storyboardName:@"Main"]; [self presentViewController:vc animated:YES completion:nil]; }]; } failure:^(id errorObject) { JDErrorModel *error = (JDErrorModel *)errorObject; [[JDFacade facade] alert:error.errorMessage]; }]; } #pragma mark - UI Events - (IBAction)btnConfirmTouched:(id)sender { //1.validate if (![ValidateUtil validateTextfiled:_txtSecureCode type:ValidateTypeNull title:NSLocalizedString(@"보안키", @"보안키")]) { return; } if (![ValidateUtil validateTextfiled:_txtSecureCodeConfirm type:ValidateTypeNull title:NSLocalizedString(@"보안키 확인", @"보안키 확인")]) { return; } if (![_txtSecureCode.text isEqualToString:_txtSecureCodeConfirm.text]) { [[JDFacade facade] alert:NSLocalizedString(@"보안키와 보안키확인이 다릅니다\n다시 입력해주세요", @"보안키와 보안키확인이 다릅니다\n다시 입력해주세요")]; return; } [self requestRegisterSecureCode]; } - (IBAction)btnCloseTouched:(id)sender { [[JDFacade facade] confirmTitle:@"연결취소" message:@"홈허브 연결을 취소할까요?" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) { if (buttonIndex == 0) {//OK [[JDFacade facade] dismissModalStack:YES completion:nil]; } }]; } #pragma mark - CustomTextField - (BOOL)textFieldShouldReturn:(UITextField *)textField { if ([textField isEqual:_txtSecureCodeConfirm]) { [self btnConfirmTouched:nil]; } return YES; } #pragma mark - MemoryWarning - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end