MultiHomeHubViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. }
  57. - (void)operationComplite {
  58. NSLog(@"multi home hub operation complite");
  59. if (_closeWhenOperationComplite)
  60. [self btnCloseTouched:nil];
  61. }
  62. #pragma mark - TableView Delegate
  63. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  64. return 1;
  65. }
  66. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  67. return [[JDFacade facade].loginUser.deviceList count];
  68. }
  69. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  70. CGFloat height = 151.0f;
  71. return height;
  72. }
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  74. DeviceModel *info = [[JDFacade facade].loginUser.deviceList objectAtIndex:indexPath.row];
  75. MultiHomeHubTableViewCell *cell = (MultiHomeHubTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MultiHubCellIdentifier"];
  76. cell.lblTitle.text = [NSString stringWithFormat:@"%@", info.deviceName];
  77. cell.btnHubDetail.tag = indexPath.row;
  78. // 네트워크 연결상태 확인
  79. if ([info isDeviceConn]) {
  80. cell.imgNetwork.image = _imgOnline;
  81. } else {
  82. cell.imgNetwork.image = _imgOffLine;
  83. }
  84. // Z-Wave 동작상태 확인
  85. if (info.isDeviceOnlined) {
  86. cell.imgDongle.image = _imgOnline;
  87. } else {
  88. cell.imgDongle.image = _imgOffLine;
  89. }
  90. if ([info isUpdateNeed]) {
  91. cell.imgUpdate.image = _imgUptOn;
  92. } else {
  93. cell.imgUpdate.image = _imgUptOff;
  94. }
  95. return cell;
  96. }
  97. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  98. [tableView deselectRowAtIndexPath:indexPath animated:NO];
  99. [self showHomeHubDetail:indexPath];
  100. }
  101. - (IBAction)btnHubDetail:(id)sender {
  102. UIButton *senderButton = (UIButton *)sender;
  103. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:senderButton.tag inSection:0];
  104. [self showHomeHubDetail:indexPath];
  105. }
  106. -(void)showHomeHubDetail:(NSIndexPath *)indexPath
  107. {
  108. DeviceModel *info = [[JDFacade facade].loginUser.deviceList objectAtIndex:indexPath.row];
  109. HomeHubViewController *vc = (HomeHubViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubViewController" storyboardName:@"Main"];
  110. vc.selectHub = info;
  111. [self.navigationController pushViewController:vc animated:YES];
  112. // vc.providesPresentationContextTransitionStyle = YES;
  113. // vc.definesPresentationContext = YES;
  114. //
  115. // [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
  116. //
  117. // UIViewController *pvc = self.presentingViewController;
  118. // [self dismissViewControllerAnimated:NO completion:^{//TODO : UI Confirm with Mr.Mo
  119. // [pvc presentViewController:vc animated:YES completion:nil];
  120. // }];
  121. // UIViewController *pvc = self.presentingViewController;
  122. // [self dismissViewControllerAnimated:NO completion:^{
  123. // [pvc presentViewController:vc animated:YES completion:nil];
  124. // }];
  125. //
  126. // [self presentViewController:vc animated:YES completion:nil];
  127. }
  128. - (IBAction)btnCloseTouched:(id)sender {
  129. [self dismissViewControllerAnimated:YES completion:nil];
  130. }
  131. - (void)didReceiveMemoryWarning {
  132. [super didReceiveMemoryWarning];
  133. }
  134. #pragma mark - SocketService
  135. -(void) receiveSocketData:(NSNotification *)notification {
  136. SocketModel *result = [[SocketModel alloc] initWithDictionary:notification.object error:nil];
  137. //NSLog(@"receiveSocketData Result : %@", result);
  138. [self processSocket:result];
  139. }
  140. - (void) socketDidReceiveMessage:(id)message result:(SocketModel *)result {
  141. //NSLog(@"receiveSocketData Result : %@", result);
  142. [self processSocket:result];
  143. }
  144. - (void)processSocket:(SocketModel*)result {
  145. if (EQUALS(result.messageType, MSG_TYPE_DEVICE_CONN) ||
  146. EQUALS(result.messageType, MSG_TYPE_DEVICE_CONTENT)) {
  147. [_tableView reloadData];
  148. }
  149. }
  150. @end