HomeHubViewController.m 7.3 KB

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