HomeHubSelectPopupView.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  43. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  44. //Localization
  45. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  46. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  47. UIEdgeInsets insets = UIEdgeInsetsMake(1, 1, 1, 2);
  48. _bgCellImage1 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"common_bg_list_02"]];
  49. _bgCellImage2 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"img_list_bg_02"]];
  50. _bgCellImage3 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"color_bg_01_dis"]];
  51. _deviceList = [JDFacade facade].loginUser.deviceList;
  52. }
  53. }
  54. return self;
  55. }
  56. - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
  57. tableView.dataSource = self;
  58. tableView.delegate = self;
  59. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  60. tableView.backgroundColor = [UIColor clearColor];
  61. tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
  62. }
  63. - (void)didMoveToSuperview {
  64. }
  65. - (CommonCode *)weatherLocation {
  66. return _rgroup.valueForChecked;
  67. }
  68. #pragma mark - Main Logic
  69. #pragma mark - UITableView DataSource & Delegate
  70. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  71. return 1;
  72. }
  73. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  74. return _deviceList ? _deviceList.count : 0;
  75. }
  76. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  77. CGFloat height = 100.0f;
  78. return height;
  79. }
  80. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  81. DeviceModel *info = _deviceList[indexPath.row];
  82. HomeHubSelectPopupTableViewCell *tcell = (HomeHubSelectPopupTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HomeHubCellIdentifier"];
  83. tcell.lbTitle.text = info.deviceName;
  84. tcell.lbSerial.text = [NSString stringWithFormat:@"S/N : %@", info.deviceSn];
  85. tcell.lbDesc.text = [NSString stringWithFormat:@"추가 가능한 장치 수량 %@", info.remainCtrtCnt];
  86. tcell.btnRadio.value = info;
  87. if (indexPath.row == 0 && !_isNotFirstLoading) {
  88. _isNotFirstLoading = YES;
  89. tcell.btnRadio.checked = YES;
  90. } else {
  91. // NSLog(@"%@", BOOLToString([tcell.btnRadio getRadioStatusFromValue]));
  92. tcell.btnRadio.checked = [tcell.btnRadio getRadioStatusFromValue];
  93. }
  94. if ([info.remainCtrtCnt integerValue] < 1) {
  95. tcell.btnRadio.enabled = NO;
  96. }
  97. [_rgroup addRadioButton:tcell.btnRadio];
  98. //set background image
  99. // if (indexPath.row % 2 == 0) {
  100. // tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage1];
  101. // } else {
  102. // tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage2];
  103. // }
  104. if (tcell.btnRadio.enabled) {
  105. if (tcell.btnRadio.checked) {
  106. tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage1];
  107. } else {
  108. tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage2];
  109. }
  110. } else {
  111. tcell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage3];
  112. tcell.lbTitle.textColor = kUITextColor08;
  113. tcell.lbSerial.textColor = kUITextColor08;
  114. tcell.lbDesc.textColor = kUITextColor08;
  115. }
  116. return tcell;
  117. }
  118. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  119. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  120. HomeHubSelectPopupTableViewCell *tcell = (HomeHubSelectPopupTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
  121. if (tcell.btnRadio.enabled) {
  122. [_rgroup someRadioButtonTouched:tcell.btnRadio];
  123. [_tableView reloadData];
  124. }
  125. }
  126. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  127. // Remove seperator inset
  128. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  129. [cell setSeparatorInset:UIEdgeInsetsZero];
  130. }
  131. // Prevent the cell from inheriting the Table View's margin settings
  132. if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  133. [cell setPreservesSuperviewLayoutMargins:NO];
  134. }
  135. // Explictly set your cell's layout margins
  136. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  137. [cell setLayoutMargins:UIEdgeInsetsZero];
  138. }
  139. }
  140. @end