MobilesOverViewController.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // MobilesOverViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 6/12/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "MobilesOverViewController.h"
  9. #import "CustomLabel.h"
  10. #import "CustomRadioGroup.h"
  11. #import "JDObject.h"
  12. #import "NewMobileViewController.h"
  13. #import "CommonUtil.h"
  14. #import "RequestHandler.h"
  15. #import "CustomButton.h"
  16. @implementation MobilesOverTitleViewCell
  17. @end
  18. @implementation MobilesOverTableViewCell
  19. - (void)awakeFromNib {
  20. self.selectionStyle = UITableViewCellSelectionStyleNone;
  21. self.backgroundColor = [UIColor clearColor];
  22. }
  23. @end
  24. @interface MobilesOverViewController () <UITableViewDataSource, UITableViewDelegate> {
  25. BOOL _isNotFirstLoading;
  26. UIImage *_bgCellImage1, *_bgCellImage2;
  27. CustomRadioReusableGroup *_rgroup;
  28. }
  29. @end
  30. #pragma mark - Class Definition
  31. @implementation MobilesOverViewController
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. // initialize
  35. _rgroup = [[CustomRadioReusableGroup alloc] init];
  36. _rgroup.tableView = _tableView;
  37. [self initUI];
  38. [self prepareViewDidLoad];
  39. }
  40. - (void)initUI {
  41. //set tableview option
  42. _tableView.delegate = self;
  43. _tableView.dataSource = self;
  44. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  45. _tableView.backgroundColor = [UIColor clearColor];
  46. _tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  47. UIEdgeInsets insets = UIEdgeInsetsMake(4, 4, 4, 4);
  48. _bgCellImage1 = [CommonUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"tp_01_img_list_bg_02"]];
  49. _bgCellImage2 = [CommonUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"tp_01_img_list_bg_01"]];
  50. //Localization
  51. _lblActionInfo.text = NSLocalizedString(@"선택한 단말은 등록해제 됩니다.\n등록 해제할 단말이 홈규칙에서 위치센서로 사용되고 있나요? 이 경우, 단말을 등록해제하면 관련된 규칙이 중지됩니다. 중지된 규칙은 편집 후 다시 시작할 수 있습니다.", @"선택한 단말은 등록해제 됩니다.\n등록 해제할 단말이 홈규칙에서 위치센서로 사용되고 있나요? 이 경우, 단말을 등록해제하면 관련된 규칙이 중지됩니다. 중지된 규칙은 편집 후 다시 시작할 수 있습니다.");
  52. [_btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  53. [_btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  54. }
  55. - (void)prepareViewDidLoad {
  56. }
  57. #pragma mark - Main Logic
  58. - (void)requestReplaceMobile {
  59. MobileDeviceModel *mobile = _rgroup.valueForChecked;
  60. //parameters
  61. NSDictionary *parameter = @{@"email_id": [JDFacade facade].tmpEmailId,
  62. @"password": [JDFacade facade].tmpPassword,
  63. @"service_id": MOBILE_SERVICE_ID,
  64. @"device_sn": [JDFacade facade].deviceUUID};
  65. NSString *path = [NSString stringWithFormat:API_POST_REPLACE_MOBILE_DEVICE];
  66. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[LoginModel class] completion:^(id responseObject) {
  67. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  68. return;
  69. }
  70. LoginModel *result = (LoginModel *) responseObject;
  71. if (result) {//API 성공 ,
  72. NewMobileViewController *vc = (NewMobileViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"NewMobileViewController" storyboardName:@"SignUp"];
  73. vc.checkedAutoLogin = _checkedAutoLogin;
  74. vc.replaceDeviceSn = mobile.deviceSn;
  75. vc.nickname = result.nickname;
  76. [[JDFacade facade] presentViewControllerByPush:vc pvc:self];
  77. }
  78. } failure:^(id errorObject) {
  79. JDErrorModel *error = (JDErrorModel *)errorObject;
  80. [[JDFacade facade] alert:error.errorMessage];
  81. }];
  82. }
  83. #pragma mark - UITableView DataSource & Delegate
  84. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  85. return 1;
  86. }
  87. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  88. return _mobileList.count + 1;
  89. }
  90. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  91. CGFloat height = 100.0f;
  92. if (indexPath.row == 0) {//title
  93. height = 121.0f;
  94. }
  95. return height;
  96. }
  97. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  98. UITableViewCell *cell = nil;
  99. if (indexPath.row == 0) {//title
  100. MobilesOverTitleViewCell *tcell = [tableView dequeueReusableCellWithIdentifier:@"TitleCellIdentifier"];
  101. tcell.lblNotify.text = NSLocalizedString(@"등록 가능한 단말 수를 초과했습니다\n아래 단말 중 인증을 대체할 단말을 고르면\n현재 단말로 이용을 할 수 있습니다", @"등록 가능한 단말 수를 초과했습니다\n아래 단말 중 인증을 대체할 단말을 고르면\n현재 단말로 이용을 할 수 있습니다");
  102. cell = tcell;
  103. } else {
  104. MobilesOverTableViewCell *tcell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
  105. if (tcell == nil) {
  106. tcell = [[MobilesOverTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"];
  107. }
  108. MobileDeviceModel *mobile = _mobileList[indexPath.row - 1];
  109. tcell.lblMobileName.text = mobile.deviceName;
  110. tcell.lblCreateDate.text = mobile.createDatetime;
  111. tcell.rdoSelect.value = mobile;
  112. if (indexPath.row == 1 && !_isNotFirstLoading) {
  113. _isNotFirstLoading = YES;
  114. tcell.rdoSelect.checked = YES;
  115. } else {
  116. tcell.rdoSelect.checked = [tcell.rdoSelect getRadioStatusFromValue];
  117. }
  118. [_rgroup addRadioButton:tcell.rdoSelect];
  119. cell = tcell;
  120. //set background image
  121. if (indexPath.row % 2 == 1) {
  122. cell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage1];
  123. } else {
  124. cell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage2];
  125. }
  126. }
  127. return cell;
  128. }
  129. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  130. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  131. if (indexPath.row == 0) //제목 셀인 경우, 리턴
  132. return;
  133. MobilesOverTableViewCell *tcell = (MobilesOverTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
  134. [_rgroup someRadioButtonTouched:tcell.rdoSelect];
  135. [_tableView reloadData];
  136. }
  137. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  138. // Remove seperator inset
  139. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  140. [cell setSeparatorInset:UIEdgeInsetsZero];
  141. }
  142. // Prevent the cell from inheriting the Table View's margin settings
  143. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  144. [cell setPreservesSuperviewLayoutMargins:NO];
  145. }
  146. // Explictly set your cell's layout margins
  147. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  148. [cell setLayoutMargins:UIEdgeInsetsZero];
  149. }
  150. }
  151. #pragma mark - UI Events
  152. - (IBAction)btnConfirmTouched:(id)sender {
  153. [self requestReplaceMobile];
  154. }
  155. - (IBAction)btnCancelTouched:(id)sender {
  156. [[JDFacade facade] dismissViewControllerByPush:self];
  157. }
  158. #pragma mark - MemoryWarning
  159. - (void)didReceiveMemoryWarning
  160. {
  161. [super didReceiveMemoryWarning];
  162. // Dispose of any resources that can be recreated.
  163. }
  164. @end