HomeHubViewController.m 7.1 KB

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