HomeHubViewController.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
  40. statusBar.backgroundColor = [UIColor whiteColor];
  41. [self.navigationController.navigationBar setHidden:YES];
  42. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  43. [self initTableViewAsDefaultStyle:_tableView];
  44. }
  45. - (void)prepareViewDidLoad {
  46. //ble
  47. bleState = NO;
  48. BLEServiceHandler *bleService = [BLEServiceHandler sharedManager];
  49. bleService.delegate = self;
  50. if (_selectHub == nil) {
  51. hubInfo = [[JDFacade facade].loginUser getHomeHub];
  52. } else {
  53. hubInfo = _selectHub;
  54. }
  55. }
  56. - (void)updateHomeHubStatus {
  57. [_tableView reloadData];
  58. }
  59. #pragma mark - UITableView DataSource & Delegate
  60. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  61. return 1;
  62. }
  63. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  64. return 3;
  65. }
  66. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  67. CGFloat height = 86.0f;
  68. if (indexPath.row == 0) {
  69. height = 185.0f;
  70. } else if (indexPath.row == 1){
  71. height = 182.0f;
  72. } else if (indexPath.row == 2){
  73. height = 164.0f;
  74. }
  75. return height;
  76. }
  77. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  78. UITableViewCell *cell = nil;
  79. if (indexPath.row == 0) {
  80. HomeHubTableViewCell *tcell = (HomeHubTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HubCellIdentifier"];
  81. if (![tcell.btnSet actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  82. [tcell.btnSet addTarget:self action:@selector(btnSetTouched:) forControlEvents:UIControlEventTouchUpInside];
  83. }
  84. [self masterBtn:tcell.btnSet];
  85. if ([hubInfo isDeviceOnlined]) {
  86. tcell.lblNetworkStatus.text = @"온라인";
  87. tcell.lblBrokenTime.text = @"";
  88. tcell.lblNetworkStatus.textColor = kUITextColor04;
  89. tcell.imgvStatus.hidden = YES;
  90. } else {
  91. tcell.lblNetworkStatus.text = @"오프라인";
  92. tcell.lblBrokenTime.text = [CommonUtil stringFromString:hubInfo.deviceOnlineLastDatetime];
  93. tcell.lblNetworkStatus.textColor = kUITextColor07;
  94. tcell.lblBrokenTime.textColor = kUITextColor07;
  95. tcell.imgvStatus.hidden = NO;
  96. }
  97. if([hubInfo isDeviceConn]){
  98. tcell.lblDeviceStatus.text = @"온라인";
  99. tcell.lblDeviceStatus.textColor = kUITextColor04;
  100. } else {
  101. tcell.lblDeviceStatus.text = @"오프라인";
  102. tcell.lblDeviceStatus.textColor = kUITextColor07;
  103. }
  104. cell = tcell;
  105. } else if (indexPath.row == 1) {
  106. HomeHubRegistTableViewCell *tcell = (HomeHubRegistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"RegistCellIdentifier"];
  107. // tcell.lblDate.text = [CommonUtil formattedDate3:[JDFacade facade].loginUser.homehubCreateDatetime];
  108. [self masterBtn:tcell.btnFirmUpdate];
  109. [self masterBtn:tcell.btnSoftUpdate];
  110. if (![tcell.btnFirmUpdate actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  111. [tcell.btnFirmUpdate addTarget:self action:@selector(btnFirmwareUpdateTouched:) forControlEvents:UIControlEventTouchUpInside];
  112. }
  113. if (![tcell.btnSoftUpdate actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  114. [tcell.btnSoftUpdate addTarget:self action:@selector(btnSofrwareUpdateTouched:) forControlEvents:UIControlEventTouchUpInside];
  115. }
  116. cell = tcell;
  117. } else if (indexPath.row == 2) {
  118. HomeHubInfoTableViewCell *tcell = (HomeHubInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HubInfoCellIdentifier"];
  119. cell = tcell;
  120. }
  121. return cell;
  122. }
  123. - (void)masterBtn:(CustomButton *)button{
  124. if ([JDFacade facade].loginUser.level < 90) {
  125. button.hidden = YES;
  126. } else {
  127. button.hidden = NO;
  128. }
  129. }
  130. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  131. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  132. }
  133. - (IBAction)btnEditTitleTouched:(id)sender {
  134. NSLog(@"타이틀 변경");
  135. }
  136. - (void)btnSetTouched:(id)sender {
  137. if (bleState) {
  138. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubSearchViewController" storyboardName:@"HomeHub"];
  139. [self.navigationController pushViewController:vc animated:YES];
  140. }
  141. else {
  142. [[BLEServiceHandler sharedManager] checkBLEStatus] ;
  143. }
  144. }
  145. - (void)btnFirmwareUpdateTouched:(id)sender{
  146. NSLog(@"펌웨어 업데이트");
  147. }
  148. - (void)btnSofrwareUpdateTouched:(id)sender{
  149. NSLog(@"소프트웨어 업데이트");
  150. }
  151. #pragma mark - UI Events
  152. - (IBAction)btnSecureTouched:(id)sender {
  153. }
  154. - (void)btnCloseTouched:(id)sender {
  155. [self dismissViewControllerAnimated:YES completion:nil];
  156. }
  157. #pragma mark - ble service delegate
  158. - (void)BLEStateChange:(BOOL)state {
  159. NSLog(@"home hub vc ble state change!") ;
  160. bleState = state;
  161. }
  162. #pragma mark - MemoryWarning
  163. - (void)didReceiveMemoryWarning
  164. {
  165. [super didReceiveMemoryWarning];
  166. // Dispose of any resources that can be recreated.
  167. }
  168. @end