HomeHubSelectPopupView.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // HomeHubSelectPopupView.m
  3. // OneCable
  4. //
  5. // Created by KaRam Kim on 2017. 5. 31..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "CustomLabel.h"
  12. #import "CustomTableView.h"
  13. #import "CustomButton.h"
  14. #import "CustomRadioGroup.h"
  15. #import "ImageUtil.h"
  16. #import "HomeHubSelectPopupView.h"
  17. @implementation HomeHubSelectPopupTableViewCell
  18. @end
  19. @interface HomeHubSelectPopupView () <UITableViewDataSource, UITableViewDelegate> {
  20. CustomRadioReusableGroup *_rgroup;
  21. BOOL _isNotFirstLoading;
  22. UIImage *_bgCellImage1, *_bgCellImage2, *_bgCellImage3;
  23. NSArray *_deviceList;
  24. }
  25. @end
  26. @implementation HomeHubSelectPopupView
  27. - (id)initFromNib {
  28. for (UIView *view in [CommonUtil nibViews:@"HomeHubSelectPopupView"]) {
  29. if ([view isKindOfClass:[HomeHubSelectPopupView class]]) {
  30. self = (HomeHubSelectPopupView *)view;
  31. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  32. self.frame = [UIScreen mainScreen].bounds;
  33. [self initTableViewAsDefaultStyle:_tableView];
  34. UINib *nib = [UINib nibWithNibName:@"HomeHubSelectPopupTableViewCell" bundle:nil];
  35. [_tableView registerNib:nib forCellReuseIdentifier:@"HomeHubCellIdentifier"];
  36. //set radio group
  37. _rgroup = [[CustomRadioReusableGroup alloc] init];
  38. _rgroup.tableView = _tableView;
  39. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  40. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  41. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  42. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateDisabled capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  43. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  44. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  45. //Localization
  46. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  47. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  48. UIEdgeInsets insets = UIEdgeInsetsMake(1, 1, 1, 2);
  49. _bgCellImage1 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"common_bg_list_02"]];
  50. _bgCellImage2 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"img_list_bg_02"]];
  51. _bgCellImage3 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"color_bg_01_dis"]];
  52. _deviceList = [JDFacade facade].loginUser.deviceList;
  53. self.btnConfirm.enabled = NO ;
  54. }
  55. }
  56. return self;
  57. }
  58. - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
  59. tableView.dataSource = self;
  60. tableView.delegate = self;
  61. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  62. tableView.backgroundColor = [UIColor clearColor];
  63. tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  64. }
  65. - (void)didMoveToSuperview {
  66. }
  67. - (CommonCode *)weatherLocation {
  68. return _rgroup.valueForChecked;
  69. }
  70. #pragma mark - Main Logic
  71. #pragma mark - UITableView DataSource & Delegate
  72. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  73. return 1;
  74. }
  75. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  76. return _deviceList ? _deviceList.count : 0;
  77. }
  78. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  79. CGFloat height = 100.0f;
  80. return height;
  81. }
  82. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  83. DeviceModel *info = _deviceList[indexPath.row];
  84. HomeHubSelectPopupTableViewCell *tcell = (HomeHubSelectPopupTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HomeHubCellIdentifier"];
  85. tcell.lbTitle.text = info.deviceName;
  86. tcell.lbSerial.text = [NSString stringWithFormat:@"S/N : %@", info.deviceSn];
  87. tcell.lbDesc.text = [NSString stringWithFormat:@"추가 가능한 장치 수량 %@", info.remainCtrtCnt];
  88. tcell.btnRadio.value = info;
  89. tcell.btnRadio.checked = [tcell.btnRadio getRadioStatusFromValue];
  90. // if (indexPath.row == 0 && !_isNotFirstLoading) {
  91. // _isNotFirstLoading = YES;
  92. // tcell.btnRadio.checked = YES;
  93. // } else {
  94. // NSLog(@"%@", BOOLToString([tcell.btnRadio getRadioStatusFromValue]));
  95. // tcell.btnRadio.checked = [tcell.btnRadio getRadioStatusFromValue];
  96. // }
  97. if ([info.remainCtrtCnt integerValue] < 1 || !info.isDeviceOnlined) {
  98. tcell.btnRadio.enabled = NO;
  99. }
  100. [_rgroup addRadioButton:tcell.btnRadio];
  101. //set background image
  102. // if (indexPath.row % 2 == 0) {
  103. // tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage1];
  104. // } else {
  105. // tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage2];
  106. // }
  107. if (tcell.btnRadio.enabled) {
  108. if (tcell.btnRadio.checked) {
  109. tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage1];
  110. } else {
  111. tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage2];
  112. }
  113. } else {
  114. tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage3];
  115. tcell.lbTitle.textColor = kUITextColor08;
  116. tcell.lbSerial.textColor = kUITextColor08;
  117. tcell.lbDesc.textColor = kUITextColor08;
  118. }
  119. return tcell;
  120. }
  121. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  122. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  123. HomeHubSelectPopupTableViewCell *tcell = (HomeHubSelectPopupTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
  124. if (tcell.btnRadio.enabled) {
  125. self.btnConfirm.enabled = YES;
  126. self.selectedDeviceModel = [_deviceList objectAtIndex:indexPath.row];
  127. [_rgroup someRadioButtonTouched:tcell.btnRadio];
  128. [_tableView reloadData];
  129. }
  130. }
  131. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  132. // Remove seperator inset
  133. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  134. [cell setSeparatorInset:UIEdgeInsetsZero];
  135. }
  136. // Prevent the cell from inheriting the Table View's margin settings
  137. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  138. [cell setPreservesSuperviewLayoutMargins:NO];
  139. }
  140. // Explictly set your cell's layout margins
  141. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  142. [cell setLayoutMargins:UIEdgeInsetsZero];
  143. }
  144. }
  145. @end