MultiHomeHubViewController.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. //
  2. // MultiHomeHubViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 5. 11..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "MultiHomeHubViewController.h"
  9. #import "RequestHandler.h"
  10. #import "DeviceModel.h"
  11. #import "CustomTableView.h"
  12. #import "CustomButton.h"
  13. #import "Reachability.h"
  14. #import "HomeHubViewController.h"
  15. /**
  16. 네트워크, 동글 On / Off 이미지
  17. On : img_homehub_list_connect
  18. Off : img_homehub_list_notconnect
  19. 업데이트 On / Off 이미지
  20. On : img_homehub_list_update_on
  21. Off : img_homehub_list_update_off
  22. **/
  23. @interface MultiHomeHubViewController ()
  24. {
  25. UIImage *_imgOnline, *_imgOffLine, *_imgUptOn, *_imgUptOff;
  26. }
  27. @end
  28. @implementation MultiHomeHubTableViewCell
  29. - (void)didMoveToSuperview {
  30. // [self layoutIfNeeded];
  31. }
  32. @end
  33. @implementation MultiHomeHubViewController
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. [self initUI];
  37. [self prepareViewDidLoad];
  38. }
  39. - (void)initUI {
  40. UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
  41. statusBar.backgroundColor = [UIColor whiteColor];
  42. [self.navigationController.navigationBar setHidden:YES];
  43. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  44. [self initTableViewAsDefaultStyle:_tableView];
  45. }
  46. - (void)prepareViewDidLoad {
  47. _imgOnline = [UIImage imageNamed:@"img_homehub_list_connect"];
  48. _imgOffLine = [UIImage imageNamed:@"img_homehub_list_notconnect"];
  49. _imgUptOn = [UIImage imageNamed:@"img_homehub_list_update_on"];
  50. _imgUptOff = [UIImage imageNamed:@"img_homehub_list_update_off"];
  51. }
  52. - (void)viewWillAppear:(BOOL)animated {
  53. [super viewWillAppear:animated];
  54. NSLog(@"multi home hub view will appear");
  55. [_tableView reloadData];
  56. UIViewController *vc = [CommonUtil currentViewController];
  57. NSLog(@"CommonUtil currentViewController : %@", [CommonUtil currentViewController]);
  58. }
  59. - (void)operationComplite {
  60. NSLog(@"multi home hub operation complite");
  61. if (_closeWhenOperationComplite)
  62. [self btnCloseTouched:nil];
  63. }
  64. #pragma mark - TableView Delegate
  65. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  66. return 1;
  67. }
  68. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  69. return [[JDFacade facade].loginUser.deviceList count];
  70. }
  71. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  72. CGFloat height = 151.0f;
  73. return height;
  74. }
  75. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  76. DeviceModel *info = [[JDFacade facade].loginUser.deviceList objectAtIndex:indexPath.row];
  77. MultiHomeHubTableViewCell *cell = (MultiHomeHubTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MultiHubCellIdentifier"];
  78. cell.lblTitle.text = [NSString stringWithFormat:@"%@", info.deviceName];
  79. cell.btnHubDetail.tag = indexPath.row;
  80. // 네트워크 연결상태 확인
  81. if ([info isDeviceConn]) {
  82. cell.imgNetwork.image = _imgOnline;
  83. } else {
  84. cell.imgNetwork.image = _imgOffLine;
  85. }
  86. // Z-Wave 동작상태 확인
  87. if (info.isDeviceOnlined) {
  88. cell.imgDongle.image = _imgOnline;
  89. } else {
  90. cell.imgDongle.image = _imgOffLine;
  91. }
  92. if ([info isUpdateNeed]) {
  93. cell.imgUpdate.image = _imgUptOn;
  94. } else {
  95. cell.imgUpdate.image = _imgUptOff;
  96. }
  97. return cell;
  98. }
  99. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  100. [tableView deselectRowAtIndexPath:indexPath animated:NO];
  101. [self showHomeHubDetail:indexPath];
  102. }
  103. - (IBAction)btnHubDetail:(id)sender {
  104. UIButton *senderButton = (UIButton *)sender;
  105. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:senderButton.tag inSection:0];
  106. [self showHomeHubDetail:indexPath];
  107. }
  108. -(void)showHomeHubDetail:(NSIndexPath *)indexPath
  109. {
  110. DeviceModel *info = [[JDFacade facade].loginUser.deviceList objectAtIndex:indexPath.row];
  111. HomeHubViewController *vc = (HomeHubViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubViewController" storyboardName:@"Main"];
  112. vc.selectHub = info;
  113. [self.navigationController pushViewController:vc animated:YES];
  114. // vc.providesPresentationContextTransitionStyle = YES;
  115. // vc.definesPresentationContext = YES;
  116. //
  117. // [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
  118. //
  119. // UIViewController *pvc = self.presentingViewController;
  120. // [self dismissViewControllerAnimated:NO completion:^{//TODO : UI Confirm with Mr.Mo
  121. // [pvc presentViewController:vc animated:YES completion:nil];
  122. // }];
  123. // UIViewController *pvc = self.presentingViewController;
  124. // [self dismissViewControllerAnimated:NO completion:^{
  125. // [pvc presentViewController:vc animated:YES completion:nil];
  126. // }];
  127. //
  128. // [self presentViewController:vc animated:YES completion:nil];
  129. }
  130. - (IBAction)btnCloseTouched:(id)sender {
  131. [self dismissViewControllerAnimated:YES completion:nil];
  132. }
  133. - (void)didReceiveMemoryWarning {
  134. [super didReceiveMemoryWarning];
  135. }
  136. #pragma mark - SocketService
  137. -(void) receiveSocketData:(NSNotification *)notification {
  138. SocketModel *result = [[SocketModel alloc] initWithDictionary:notification.object error:nil];
  139. //NSLog(@"receiveSocketData Result : %@", result);
  140. [self processSocket:result];
  141. }
  142. - (void) socketDidReceiveMessage:(id)message result:(SocketModel *)result {
  143. //NSLog(@"receiveSocketData Result : %@", result);
  144. [self processSocket:result];
  145. }
  146. - (void)processSocket:(SocketModel*)result {
  147. if (EQUALS(result.messageType, MSG_TYPE_DEVICE_CONN) ||
  148. EQUALS(result.messageType, MSG_TYPE_DEVICE_CONTENT)) {
  149. [_tableView reloadData];
  150. }
  151. }
  152. @end