HomeHubViewController.m 6.0 KB

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