HomeHubViewController.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // HomeHubViewController.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 10/28/15.
  6. // Copyright © 2015 ntels. All rights reserved.
  7. //
  8. #import "HomeHubViewController.h"
  9. #import "RequestHandler.h"
  10. #import "DeviceModel.h"
  11. #import "CustomTableView.h"
  12. #import "CustomButton.h"
  13. #import "Reachability.h"
  14. //#import <LGBluetooth/LGBluetooth.h>
  15. @implementation HomeHubTableViewCell
  16. @end
  17. @implementation HomeHubRegistTableViewCell
  18. - (void)didMoveToSuperview {
  19. _lblDate.hidden = YES;
  20. [self layoutIfNeeded];
  21. }
  22. @end
  23. @implementation HomeHubInfoTableViewCell
  24. @end
  25. @interface HomeHubViewController () {
  26. BOOL bleState;
  27. DeviceModel *hubInfo;
  28. }
  29. @end
  30. #pragma mark - Class Definition
  31. @implementation HomeHubViewController
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. // Do any additional setup after loading the view.
  35. [self initUI];
  36. [self prepareViewDidLoad];
  37. }
  38. - (void)initUI {
  39. [self initTableViewAsDefaultStyle:_tableView];
  40. }
  41. - (void)prepareViewDidLoad {
  42. //ble
  43. bleState = NO;
  44. BLEServiceHandler *bleService = [BLEServiceHandler sharedManager];
  45. bleService.delegate = self;
  46. if (_selectHub == nil) {
  47. hubInfo = [[JDFacade facade].loginUser getHomeHub];
  48. } else {
  49. hubInfo = _selectHub;
  50. }
  51. }
  52. - (void)updateHomeHubStatus {
  53. [_tableView reloadData];
  54. }
  55. #pragma mark - UITableView DataSource & Delegate
  56. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  57. return 1;
  58. }
  59. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  60. return 3;
  61. }
  62. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  63. CGFloat height = 86.0f;
  64. if (indexPath.row == 0) {
  65. height = 185.0f;
  66. } else if (indexPath.row == 1){
  67. height = 182.0f;
  68. } else if (indexPath.row == 2){
  69. height = 164.0f;
  70. }
  71. return height;
  72. }
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  74. UITableViewCell *cell = nil;
  75. if (indexPath.row == 0) {
  76. HomeHubTableViewCell *tcell = (HomeHubTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HubCellIdentifier"];
  77. if (![tcell.btnSet actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  78. [tcell.btnSet addTarget:self action:@selector(btnSetTouched:) forControlEvents:UIControlEventTouchUpInside];
  79. }
  80. [self masterBtn:tcell.btnSet];
  81. if ([hubInfo isDeviceOnlined]) {
  82. tcell.lblNetworkStatus.text = @"온라인";
  83. tcell.lblBrokenTime.text = @"";
  84. tcell.lblNetworkStatus.textColor = kUITextColor04;
  85. tcell.imgvStatus.hidden = YES;
  86. } else {
  87. tcell.lblNetworkStatus.text = @"오프라인";
  88. tcell.lblBrokenTime.text = [CommonUtil stringFromString:hubInfo.deviceOnlineLastDatetime];
  89. tcell.lblNetworkStatus.textColor = kUITextColor07;
  90. tcell.lblBrokenTime.textColor = kUITextColor07;
  91. tcell.imgvStatus.hidden = NO;
  92. }
  93. if([hubInfo isDeviceConn]){
  94. tcell.lblDeviceStatus.text = @"온라인";
  95. tcell.lblDeviceStatus.textColor = kUITextColor04;
  96. } else {
  97. tcell.lblDeviceStatus.text = @"오프라인";
  98. tcell.lblDeviceStatus.textColor = kUITextColor07;
  99. }
  100. cell = tcell;
  101. } else if (indexPath.row == 1) {
  102. HomeHubRegistTableViewCell *tcell = (HomeHubRegistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"RegistCellIdentifier"];
  103. // tcell.lblDate.text = [CommonUtil formattedDate3:[JDFacade facade].loginUser.homehubCreateDatetime];
  104. [self masterBtn:tcell.btnFirmUpdate];
  105. [self masterBtn:tcell.btnSoftUpdate];
  106. if (![tcell.btnFirmUpdate actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  107. [tcell.btnFirmUpdate addTarget:self action:@selector(btnFirmwareUpdateTouched:) forControlEvents:UIControlEventTouchUpInside];
  108. }
  109. if (![tcell.btnSoftUpdate actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  110. [tcell.btnSoftUpdate addTarget:self action:@selector(btnSofrwareUpdateTouched:) forControlEvents:UIControlEventTouchUpInside];
  111. }
  112. cell = tcell;
  113. } else if (indexPath.row == 2) {
  114. HomeHubInfoTableViewCell *tcell = (HomeHubInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HubInfoCellIdentifier"];
  115. cell = tcell;
  116. }
  117. return cell;
  118. }
  119. - (void)masterBtn:(CustomButton *)button{
  120. if ([JDFacade facade].loginUser.level < 90) {
  121. button.hidden = YES;
  122. } else {
  123. button.hidden = NO;
  124. }
  125. }
  126. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  127. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  128. }
  129. - (IBAction)btnEditTitleTouched:(id)sender {
  130. NSLog(@"타이틀 변경");
  131. }
  132. - (void)btnSetTouched:(id)sender {
  133. if (bleState) {
  134. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubSearchViewController" storyboardName:@"HomeHub"];
  135. [self presentViewController:vc animated:YES completion:nil];
  136. }
  137. else {
  138. [[BLEServiceHandler sharedManager] startScan] ;
  139. }
  140. }
  141. - (void)btnFirmwareUpdateTouched:(id)sender{
  142. NSLog(@"펌웨어 업데이트");
  143. }
  144. - (void)btnSofrwareUpdateTouched:(id)sender{
  145. NSLog(@"소프트웨어 업데이트");
  146. }
  147. #pragma mark - UI Events
  148. - (IBAction)btnSecureTouched:(id)sender {
  149. }
  150. - (void)btnCloseTouched:(id)sender {
  151. [self dismissViewControllerAnimated:YES completion:nil];
  152. }
  153. #pragma mark - ble service delegate
  154. - (void)BLEStateChange:(BOOL)state {
  155. NSLog(@"home hub vc ble state change!") ;
  156. bleState = state;
  157. }
  158. #pragma mark - MemoryWarning
  159. - (void)didReceiveMemoryWarning
  160. {
  161. [super didReceiveMemoryWarning];
  162. // Dispose of any resources that can be recreated.
  163. }
  164. @end