| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- //
- // 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"
- #import "CustomButton.h"
- #import "Reachability.h"
- //#import <LGBluetooth/LGBluetooth.h>
- @implementation HomeHubTableViewCell
- @end
- @implementation HomeHubRegistTableViewCell
- - (void)didMoveToSuperview {
- _lblDate.hidden = YES;
- [self layoutIfNeeded];
- }
- @end
- @implementation HomeHubInfoTableViewCell
- @end
- @interface HomeHubViewController () {
-
- BOOL bleState;
- DeviceModel *hubInfo;
- }
- @end
- #pragma mark - Class Definition
- @implementation HomeHubViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self initUI];
- [self prepareViewDidLoad];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- bleState = [[BLEServiceHandler sharedManager] checkBLEStatus];
- }
- - (void)initUI {
- UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
- statusBar.backgroundColor = [UIColor whiteColor];
-
- [self.navigationController.navigationBar setHidden:YES];
- self.navigationController.interactivePopGestureRecognizer.enabled = NO;
-
- [self initTableViewAsDefaultStyle:_tableView];
- }
- - (void)prepareViewDidLoad {
- //ble
- bleState = NO;
- BLEServiceHandler *bleService = [BLEServiceHandler sharedManager];
- bleService.delegate = self;
-
- if (_selectHub == nil) {
- hubInfo = [[JDFacade facade].loginUser getHomeHub];
- } else {
- hubInfo = _selectHub;
- }
- [[JDFacade facade].loginUser setHomeHubID:hubInfo.deviceId];
- }
- - (void)updateHomeHubStatus {
- [_tableView reloadData];
- }
- #pragma mark - UITableView DataSource & Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 3;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- CGFloat height = 86.0f;
-
- if (indexPath.row == 0) {
- height = 185.0f;
- } else if (indexPath.row == 1){
- height = 182.0f;
- } else if (indexPath.row == 2){
- height = 164.0f;
- }
-
- return height;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- UITableViewCell *cell = nil;
-
- if (indexPath.row == 0) {
- HomeHubTableViewCell *tcell = (HomeHubTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HubCellIdentifier"];
-
- if (![tcell.btnSet actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
- [tcell.btnSet addTarget:self action:@selector(btnSetTouched:) forControlEvents:UIControlEventTouchUpInside];
- }
-
- [self masterBtn:tcell.btnSet];
-
- if ([hubInfo isDeviceOnlined]) {
- tcell.lblNetworkStatus.text = @"온라인";
- tcell.lblBrokenTime.text = @"";
- tcell.lblNetworkStatus.textColor = kUITextColor04;
- tcell.imgvStatus.hidden = YES;
- } else {
- tcell.lblNetworkStatus.text = @"오프라인";
- tcell.lblBrokenTime.text = [CommonUtil stringFromString:hubInfo.deviceOnlineLastDatetime];
- tcell.lblNetworkStatus.textColor = kUITextColor07;
- tcell.lblBrokenTime.textColor = kUITextColor07;
- tcell.imgvStatus.hidden = NO;
- }
-
-
- if([hubInfo isDeviceConn]){
-
- tcell.lblDeviceStatus.text = @"온라인";
- tcell.lblDeviceStatus.textColor = kUITextColor04;
- } else {
- tcell.lblDeviceStatus.text = @"오프라인";
- tcell.lblDeviceStatus.textColor = kUITextColor07;
- }
-
- cell = tcell;
- } else if (indexPath.row == 1) {
- HomeHubRegistTableViewCell *tcell = (HomeHubRegistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"RegistCellIdentifier"];
-
- // tcell.lblDate.text = [CommonUtil formattedDate3:[JDFacade facade].loginUser.homehubCreateDatetime];
-
- tcell.lblFirmNewestVer.text = hubInfo.lastFirmwareVersion;
- tcell.lblFirmCurrentVer.text = hubInfo.firmwareVersion;
- tcell.lblSoftNewestVer.text = hubInfo.lastSoftwareVersion;
- tcell.lblSoftCurrentVer.text = hubInfo.softwareVersion;
-
-
- [self masterBtn:tcell.btnFirmUpdate];
- [self masterBtn:tcell.btnSoftUpdate];
-
- if (![tcell.btnFirmUpdate actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
- [tcell.btnFirmUpdate addTarget:self action:@selector(btnFirmwareUpdateTouched:) forControlEvents:UIControlEventTouchUpInside];
- }
-
- if (![tcell.btnSoftUpdate actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
- [tcell.btnSoftUpdate addTarget:self action:@selector(btnSofrwareUpdateTouched:) forControlEvents:UIControlEventTouchUpInside];
- }
-
- cell = tcell;
-
- } else if (indexPath.row == 2) {
- HomeHubInfoTableViewCell *tcell = (HomeHubInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HubInfoCellIdentifier"];
- tcell.lblModelName.text = hubInfo.deviceModelId;
- tcell.lblSerialNum.text = hubInfo.deviceSn;
-
- cell = tcell;
- }
-
- return cell;
- }
- - (void)masterBtn:(CustomButton *)button{
- if ([JDFacade facade].loginUser.level < 90) {
- button.hidden = YES;
- } else {
- button.hidden = NO;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [super tableView:tableView didSelectRowAtIndexPath:indexPath];
- }
- - (IBAction)btnEditTitleTouched:(id)sender {
- NSLog(@"타이틀 변경");
- }
- - (void)btnSetTouched:(id)sender {
-
- NSLog(@"bleState : %d", bleState) ;
-
- if (bleState) {
-
- UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubSearchViewController" storyboardName:@"HomeHub"];
-
- [self.navigationController pushViewController:vc animated:YES];
- }
- else {
-
- bleState = [[BLEServiceHandler sharedManager] checkBLEStatus] ;
- }
- }
- - (void)btnFirmwareUpdateTouched:(id)sender{
- NSLog(@"펌웨어 업데이트");
- }
- - (void)btnSofrwareUpdateTouched:(id)sender{
- NSLog(@"소프트웨어 업데이트");
- }
- #pragma mark - UI Events
- - (IBAction)btnSecureTouched:(id)sender {
-
- }
- - (void)btnCloseTouched:(id)sender {
-
- if ([[JDFacade facade].loginUser isMultiHomeHub])
- [self.navigationController popViewControllerAnimated:YES];
- else
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma mark - ble service delegate
- - (void)BLEStateChange:(BOOL)state {
- NSLog(@"home hub vc ble state change!") ;
- bleState = state;
- }
- #pragma mark - MemoryWarning
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|