| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- //
- // HomeHubViewController.m
- // kneet2
- //
- // Created by Jason Lee on 10/28/15.
- // Copyright © 2015 ntels. All rights reserved.
- //
- #import "HomeHubViewController.h"
- #import "RequestHandler.h"
- #import "DeviceModel.h"
- #import "CustomTableView.h"
- @implementation HomeHubTableViewCell
- @end
- @implementation HomeHubRegistTableViewCell
- @end
- @implementation HomeHubSecureTableViewCell
- @end
- @implementation HomeHubInfoTableViewCell
- @end
- @interface HomeHubViewController () {
- DeviceModel *_homeHubDevice;
- }
- @end
- #pragma mark - Class Definition
- @implementation HomeHubViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self initUI];
- [self prepareViewDidLoad];
- }
- - (void)initUI {
- [self initTableViewAsDefaultStyle:_tableView];
- }
- - (void)prepareViewDidLoad {
- [self requestHubStatus];
- }
- #pragma mark - Main Logic
- - (void)requestHubStatus {
-
- NSString *path = [NSString stringWithFormat:API_GET_HOMEHUB_STATUS];
-
- [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[DeviceModel class] completion:^(id responseObject) {
- if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
- return;
- }
-
- DeviceModel *fetchedDevice = (DeviceModel *) responseObject;
-
- if (fetchedDevice) {//API 성공,
- _homeHubDevice = fetchedDevice;
- }
-
- [_tableView reloadData];
-
- } failure:^(id errorObject) {
- JDErrorModel *error = (JDErrorModel *)errorObject;
- [[JDFacade facade] alert:error.errorMessage];
- }];
- }
- #pragma mark - UITableView DataSource & Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 4;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- CGFloat height = 0;
-
- if (indexPath.row == 0) {
- height = 110;
- } else if (indexPath.row == 1) {
- height = 110;
- } else if (indexPath.row == 2) {
- height = 195;
- } else if (indexPath.row == 3) {
- height = 150;
- }
-
- return height;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- UITableViewCell *cell = nil;
-
- if (indexPath.row == 0) {
- HomeHubTableViewCell *tcell = (HomeHubTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HubCellIdentifier"];
-
- if (_homeHubDevice) {
- tcell.lblStatus.text = [_homeHubDevice.onlineState isEqualToString:@"ON"] ? @"온라인" : @"오프라인";
- } else {
- tcell.lblStatus.text = @"오프라인";
- }
-
- cell = tcell;
- } else if (indexPath.row == 1) {
- HomeHubRegistTableViewCell *tcell = (HomeHubRegistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"RegistCellIdentifier"];
-
- if (_homeHubDevice) {
- tcell.lblDate.text = [CommonUtil formattedDate3:_homeHubDevice.createDatetime];
- } else {
- tcell.lblDate.text = ksEmptyString;
- }
-
- cell = tcell;
- } else if (indexPath.row == 2) {
- HomeHubSecureTableViewCell *tcell = (HomeHubSecureTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"SecureCellIdentifier"];
-
- [tcell.lblCaution setLineSpacing:10];
- [tcell.lblCaution setColor:kUITextColor02 text:@"아래의 경우에 보안키가 필요합니다."];
-
- if (![tcell.btnSecure actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
- [tcell.btnSecure addTarget:self action:@selector(btnSecureTouched:) forControlEvents:UIControlEventTouchUpInside];
- }
-
- cell = tcell;
-
- } else if (indexPath.row == 3) {
- HomeHubInfoTableViewCell *tcell = (HomeHubInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"InfoCellIdentifier"];
-
- cell = tcell;
- }
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [super tableView:tableView didSelectRowAtIndexPath:indexPath];
- }
- #pragma mark - UI Events
- - (IBAction)btnSecureTouched:(id)sender {
-
- }
- - (void)btnCloseTouched:(id)sender {
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma mark - MemoryWarning
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|