HomeHubViewController.m 6.0 KB

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