QRCodeInputPopupView.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // QRCodeInputPopupView.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 5/18/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "CustomLabel.h"
  12. #import "CustomTextField.h"
  13. #import "DeviceModel.h"
  14. #import "QRCodeInputPopupView.h"
  15. #import "ValidateUtil.h"
  16. @interface QRCodeInputPopupView () <CustomTextFieldDelegate> {
  17. }
  18. @end
  19. @implementation QRCodeInputPopupView
  20. - (id)initFromNib {
  21. for (UIView *view in [CommonUtil nibViews:@"QRCodeInputPopupView"]) {
  22. if ([view isKindOfClass:[QRCodeInputPopupView class]]) {
  23. self = (QRCodeInputPopupView *)view;
  24. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  25. self.frame = [UIScreen mainScreen].bounds;
  26. NSLog(@"%s\n %@", __PRETTY_FUNCTION__, self.popUpView);
  27. self.lblTitle.text = NSLocalizedString(@"홈허브 코드 직접 입력",nil);
  28. _txtActivationCode.keyboardType = UIKeyboardTypeDefault;
  29. _txtActivationCode.returnKeyType = UIReturnKeyDone;
  30. _txtPasswd.delegate = self;
  31. _txtPasswd.secureTextEntry = YES;
  32. _txtPasswd.keyboardType = UIKeyboardTypeDefault;
  33. _txtPasswd.returnKeyType = UIReturnKeyDone;
  34. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  35. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  36. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  37. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  38. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  39. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  40. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  41. }
  42. }
  43. return self;
  44. }
  45. - (void)didMoveToSuperview {
  46. self.txtActivationCode.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  47. self.txtPasswd.customTextFieldSuperview = CustomTextFieldSuperviewIsPopupContentView;
  48. }
  49. #pragma mark - Main Logic
  50. #pragma mark - UI Events
  51. - (void)btnConfirmTouched:(id)sender {
  52. #if TARGET_IPHONE_SIMULATOR
  53. if (_qrcodeType == QRCodeTypeHomeHub) {
  54. if ([_txtActivationCode.text isEmptyString]) {
  55. // _txtActivationCode.text = @"NTels-d73df166b7a8151b";
  56. _txtActivationCode.text = @"NTels-cd39b0d2526513ec";
  57. }
  58. if ([_txtPasswd.text isEmptyString]) {
  59. _txtPasswd.text = @"091377";
  60. }
  61. }
  62. #endif
  63. //1.validate
  64. if (![ValidateUtil validateTextfiled:_txtActivationCode type:ValidateTypeNull title:@"코드"]) {
  65. return;
  66. }
  67. if (![ValidateUtil validateTextfiled:_txtPasswd type:ValidateTypeNull title:@"PW"]) {
  68. return;
  69. }
  70. QRCodeViewController *vc = (QRCodeViewController *)[JDFacade facade].currentViewController;
  71. if (![vc isKindOfClass:[QRCodeViewController class]]) {
  72. vc = [[JDFacade facade] viewControllerOnPresentedViewController:[JDFacade facade].currentViewController viewControllerClass:[QRCodeViewController class]];
  73. }
  74. if (vc) {
  75. [vc requestQRAuthrize:_txtActivationCode.text password:_txtPasswd.text];
  76. }
  77. // [super btnConfirmTouched:sender];
  78. }
  79. #pragma mark - CustomTextField
  80. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  81. if ([textField isEqual:_txtPasswd]) {
  82. [self btnConfirmTouched:nil];
  83. }
  84. return YES;
  85. }
  86. @end