MultiHomeHubViewController.m 4.9 KB

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