HomeHubViewController.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. @implementation HomeHubTableViewCell
  13. @end
  14. @implementation HomeHubRegistTableViewCell
  15. @end
  16. @implementation HomeHubSecureTableViewCell
  17. @end
  18. @implementation HomeHubInfoTableViewCell
  19. @end
  20. @interface HomeHubViewController () {
  21. DeviceModel *_homeHubDevice;
  22. }
  23. @end
  24. #pragma mark - Class Definition
  25. @implementation HomeHubViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. // Do any additional setup after loading the view.
  29. [self initUI];
  30. [self prepareViewDidLoad];
  31. }
  32. - (void)initUI {
  33. [self initTableViewAsDefaultStyle:_tableView];
  34. }
  35. - (void)prepareViewDidLoad {
  36. [self requestHubStatus];
  37. }
  38. #pragma mark - Main Logic
  39. - (void)requestHubStatus {
  40. NSString *path = [NSString stringWithFormat:API_GET_HOMEHUB_STATUS];
  41. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[DeviceModel class] completion:^(id responseObject) {
  42. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  43. return;
  44. }
  45. DeviceModel *fetchedDevice = (DeviceModel *) responseObject;
  46. if (fetchedDevice) {//API 성공,
  47. _homeHubDevice = fetchedDevice;
  48. }
  49. [_tableView reloadData];
  50. } failure:^(id errorObject) {
  51. JDErrorModel *error = (JDErrorModel *)errorObject;
  52. [[JDFacade facade] alert:error.errorMessage];
  53. }];
  54. }
  55. #pragma mark - UITableView DataSource & Delegate
  56. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  57. return 1;
  58. }
  59. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  60. return 4;
  61. }
  62. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  63. CGFloat height = 0;
  64. if (indexPath.row == 0) {
  65. height = 110;
  66. } else if (indexPath.row == 1) {
  67. height = 110;
  68. } else if (indexPath.row == 2) {
  69. height = 195;
  70. } else if (indexPath.row == 3) {
  71. height = 150;
  72. }
  73. return height;
  74. }
  75. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  76. UITableViewCell *cell = nil;
  77. if (indexPath.row == 0) {
  78. HomeHubTableViewCell *tcell = (HomeHubTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HubCellIdentifier"];
  79. if (_homeHubDevice) {
  80. tcell.lblStatus.text = [_homeHubDevice.onlineState isEqualToString:@"ON"] ? @"온라인" : @"오프라인";
  81. } else {
  82. tcell.lblStatus.text = @"오프라인";
  83. }
  84. cell = tcell;
  85. } else if (indexPath.row == 1) {
  86. HomeHubRegistTableViewCell *tcell = (HomeHubRegistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"RegistCellIdentifier"];
  87. if (_homeHubDevice) {
  88. tcell.lblDate.text = [CommonUtil formattedDate3:_homeHubDevice.createDatetime];
  89. } else {
  90. tcell.lblDate.text = ksEmptyString;
  91. }
  92. cell = tcell;
  93. } else if (indexPath.row == 2) {
  94. HomeHubSecureTableViewCell *tcell = (HomeHubSecureTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"SecureCellIdentifier"];
  95. [tcell.lblCaution setLineSpacing:10];
  96. [tcell.lblCaution setColor:kUITextColor02 text:@"아래의 경우에 보안키가 필요합니다."];
  97. if (![tcell.btnSecure actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  98. [tcell.btnSecure addTarget:self action:@selector(btnSecureTouched:) forControlEvents:UIControlEventTouchUpInside];
  99. }
  100. cell = tcell;
  101. } else if (indexPath.row == 3) {
  102. HomeHubInfoTableViewCell *tcell = (HomeHubInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"InfoCellIdentifier"];
  103. cell = tcell;
  104. }
  105. return cell;
  106. }
  107. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  108. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  109. }
  110. #pragma mark - UI Events
  111. - (IBAction)btnSecureTouched:(id)sender {
  112. }
  113. - (void)btnCloseTouched:(id)sender {
  114. [self dismissViewControllerAnimated:YES completion:nil];
  115. }
  116. #pragma mark - MemoryWarning
  117. - (void)didReceiveMemoryWarning
  118. {
  119. [super didReceiveMemoryWarning];
  120. // Dispose of any resources that can be recreated.
  121. }
  122. @end