HomeHubViewController.m 7.6 KB

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