ThingsDetailViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. //
  2. // ThingsDetailViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 3/16/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "RequestHandler.h"
  9. #import "DeviceModel.h"
  10. #import "CustomImageView.h"
  11. #import "CustomLabel.h"
  12. #import "CustomTextField.h"
  13. #import "CustomButton.h"
  14. #import "UIImageView+WebCache.h"
  15. #import "CustomTableView.h"
  16. #import "ChangeDeviceNamePopupView.h"
  17. #import "ValidateUtil.h"
  18. #import "CommandClassControlDetailView.h"
  19. #import "ThingsViewController.h"
  20. #import "ThingsDetailViewController.h"
  21. #import "ModifyDeviceNamePopupView.h"
  22. #import "JYPullToRefreshController.h"
  23. #import "ThingsForcedDelViewController.h"
  24. #import "ThingsGeneralDelViewController.h"
  25. /**
  26. Hub 명 Text Color : kUITextColor03
  27. Update 알람 Text Color : kUITextColor04
  28. Device 상태 표시 Text Color
  29. - 꺼짐 : kUITextColor01
  30. - 켜짐 : kUITextColor02
  31. - 잠김 : kUITextColor02
  32. - 열림 : kUITextColor01
  33. 도어센서 마지막 동작 Text Color : kUITextColor01
  34. 도어센서 상태표시 Text Color
  35. - 열림 : kUITextColor02
  36. - 닫힘 : kUITextColor01
  37. Offline Text Color : kUITextColor01
  38. 노드명 표시 Text Color : kUITextColor03
  39. value 표시 Text Color : kUITextColor04
  40. (이미지 명)
  41. 플러그 on : img_things_detail_06_01_plug_state_on
  42. 플러그 off : img_things_detail_06_01_plug_state_off
  43. 밸브 on : img_things_detail_05_02_valve_state_locked
  44. 밸브 off : img_things_detail_05_02_valve_state_unlocked
  45. 도어센서 on : img_things_detail_01_02_sensor_door_open
  46. 도어센서 off : img_things_detail_01_02_sensor_door_close
  47. 장치 열림,켜짐 : img_things_detail_06_99_btn_off ,~off_press
  48. 장치 닫힘,꺼짐 : img_things_detail_06_99_btn_on ,~on_press
  49. 기기 배터리 부족시 사용할 폰트 칼라
  50. color_text_07 (#ed1c24)
  51. **/
  52. @implementation ThingsDetailTitleTableViewCell
  53. @end
  54. @implementation ThingsDetailControlTableViewCell
  55. - (void)awakeFromNib {
  56. [super awakeFromNib];
  57. _controlContainer.pagingEnabled = YES;
  58. _controlContainer.scrollEnabled = NO;
  59. _pageControl.hidden = YES;
  60. }
  61. @end
  62. @implementation ThingsDetailOptionTableViewCell
  63. @end
  64. @implementation ThingsDetailDeviceIdTableViewCell
  65. @end
  66. @interface ThingsDetailViewController () <UITableViewDataSource, UITableViewDelegate ,changeDeviceNameDelegate> {
  67. DeviceDetailModel *_deviceDetail;
  68. // ModifyDeviceNamePopupView *_mpopup;
  69. NSArray<NodeModel> *_mandatoryNodes, *_optionalNodes;
  70. UIPageControl *_pageControl;
  71. NSTimer *_deviceBackgroundTimer;
  72. }
  73. @property (strong, nonatomic) JYPullToRefreshController *refreshController;
  74. @end
  75. #pragma mark - Class Definition
  76. @implementation ThingsDetailViewController
  77. - (void)viewDidLoad {
  78. [super viewDidLoad];
  79. // Do any additional setup after loading the view.
  80. [self initUI];
  81. [self prepareViewDidLoad];
  82. }
  83. - (void)initUI {
  84. //initialize tableView
  85. [self initTableViewAsDefaultStyle:_tableView];
  86. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 30.0f)];
  87. // [self setThingsDetailPopoverOptions];
  88. [self initRefreshController];
  89. [self setMoreBtnArray];
  90. }
  91. - (void)initRefreshController {
  92. //set refresh controls
  93. __weak typeof(self) weakSelf = self;
  94. self.refreshController = [[JYPullToRefreshController alloc] initWithScrollView:self.tableView];
  95. self.refreshController.pullToRefreshHandleAction = ^{
  96. [weakSelf requestDeviceDetail:@YES];
  97. };
  98. }
  99. //- (void)setThingsDetailPopoverOptions {
  100. // //set Popover Contents
  101. // __weak typeof(self) weakSelf = self;
  102. // _popooverOptionArray = [[NSMutableArray alloc] init];
  103. //
  104. // [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로 고침",nil),
  105. // @"iconName": @"img_bg_morepopup_icon_refresh",
  106. // @"target": weakSelf,
  107. // @"selector": [NSValue valueWithPointer:@selector(requestDeviceDetail:)]}];
  108. //
  109. // if ([JDFacade facade].loginUser.level > 10) {
  110. // [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"이름 변경", @"이름 변경"),
  111. // @"iconName": @"img_bg_morepopup_icon_edit",
  112. // @"target": weakSelf,
  113. // @"selector": [NSValue valueWithPointer:@selector(modifyDeviceName)]}];
  114. //
  115. // }
  116. //}
  117. - (void)prepareViewDidLoad {
  118. [self requestDeviceDetail:@YES];
  119. }
  120. //- (void)modifyDeviceName {
  121. //
  122. // _mpopup = [[ModifyDeviceNamePopupView alloc] initFromNib];
  123. // _mpopup.txtDeviceName.text = _deviceDetail.deviceName;
  124. //
  125. // [_mpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  126. // if (buttonIndex == 0) {//OK
  127. // [self requestDeviceUpdate];
  128. // }
  129. // }];
  130. //}
  131. - (void)changeDeviceName:(NSString *)deviceName {
  132. [self requestDeviceDetail:@YES];
  133. _lblTitle.text = [deviceName isEqualToString:@""] ? _deviceDetail.prdName : deviceName;
  134. }
  135. - (void)updateTitle {
  136. [self setMoreBtnArray];
  137. if ([_deviceDetail.prdName isEqualToString:_deviceDetail.prdUserName] || [_deviceDetail.prdUserName isEqualToString:@""]) {
  138. _lblTitle.text = _deviceDetail.prdName;
  139. } else {
  140. _lblTitle.text = _deviceDetail.prdUserName;
  141. }
  142. _btnUpdate.hidden = !_deviceDetail.isProfileUpdate;
  143. if (![JDFacade facade].loginUser.isHomehubOnline) {
  144. _lblTitle.text = @"홈허브 오프라인";
  145. [_lblTitle setColor:kUITextColor01 text:_lblTitle.text];
  146. return;
  147. }
  148. if (_deviceDetail && !_deviceDetail.isOnline) {
  149. _lblTitle.text = @"장치 상태를 확인하세요";
  150. [_lblTitle setColor:kUITextColor02 text:_lblTitle.text];
  151. return;
  152. }
  153. }
  154. -(NSString *)getDeviceDetailUrl
  155. {
  156. NSMutableArray *arr = [NSMutableArray array];
  157. arr[0] = _refDevice.deviceId;
  158. arr[1] = _refDevice.nodeId;
  159. return [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_NODE_DETAIL arguments:arr];
  160. }
  161. #pragma mark - Main Logic
  162. - (void)requestDeviceDetail:(id)arg {
  163. BOOL showLoadingView = NO;
  164. if (arg) {
  165. showLoadingView = [arg isKindOfClass:[NSTimer class]] ? [((NSTimer *)arg).userInfo boolValue] : [arg boolValue];
  166. }
  167. NSString *path = [NSString stringWithFormat:[self getDeviceDetailUrl], _refDevice.deviceId];
  168. [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestGET parameters:nil
  169. modelClass:[DeviceDetailModel class] showLoadingView:showLoadingView completion:^(id responseObject) {
  170. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  171. return;
  172. }
  173. _deviceDetail = (DeviceDetailModel *)responseObject;
  174. if (_deviceDetail) {//API 성공 ,
  175. [self setDeviceContents];
  176. [self requestPollingDeviceStatusInBackground];
  177. }
  178. //refresh controller
  179. if (self.refreshController && self.refreshController.refreshState == JYRefreshStateLoading) {
  180. [self.refreshController stopRefreshWithAnimated:YES completion:nil];
  181. }
  182. } failure:^(id errorObject) {
  183. [self releaseDeviceTimer];
  184. JDErrorModel *error = (JDErrorModel *)errorObject;
  185. [[JDFacade facade] alert:error.errorMessage];
  186. }];
  187. }
  188. //디바이스 상태를 3초마다 갱신함.
  189. - (void)requestPollingDeviceStatusInBackground {
  190. //schedul timer.
  191. // if (!_deviceBackgroundTimer) {
  192. // _deviceBackgroundTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(requestDeviceDetail:) userInfo:@NO repeats:YES];
  193. // }
  194. }
  195. - (void)setDeviceContents {
  196. [self updateTitle];
  197. _mandatoryNodes = (NSArray<NodeModel> *)[_deviceDetail.cmdclsList filteredArrayUsingPredicateFormat:@"cmdclsMandatoryYn == %@", @"Y"];
  198. _optionalNodes = (NSArray<NodeModel> *)[_deviceDetail.cmdclsList filteredArrayUsingPredicateFormat:@"cmdclsMandatoryYn == %@", @"N"];
  199. [_tableView reloadData];
  200. }
  201. //- (void)requestDeviceUpdate {
  202. // //parameters
  203. // NSDictionary *parameter = @{@"device_name": _mpopup.txtDeviceName.text};
  204. //
  205. // NSString *path = [NSString stringWithFormat:API_GET_DEVICE_UPDATE, _deviceDetail.deviceId];
  206. //
  207. // [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  208. //
  209. // _refDevice.deviceName = _deviceDetail.deviceName = _mpopup.txtDeviceName.text;
  210. // [_tableView reloadData];
  211. //
  212. // //리스트를 다시 로드함.
  213. // ThingsViewController *vc = [[JDFacade facade] viewControllerOnNaviationController:[ThingsViewController class]];
  214. // [vc.collectionView reloadData];
  215. //
  216. // } failure:^(id errorObject) {
  217. // JDErrorModel *error = (JDErrorModel *)errorObject;
  218. // [[JDFacade facade] alert:error.errorMessage];
  219. // }];
  220. //}
  221. - (void)requestDeleteDevice {
  222. //parameters
  223. NSString *path = [NSString stringWithFormat:API_DELETE_DEVICE, _deviceDetail.deviceId];
  224. [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestDELETE parameters:nil modelClass:[JDJSONModel class] showLoadingView:YES completion:^(id responseObject) {
  225. [[JDFacade facade] toast:NSLocalizedString(@"장치가 삭제되었습니다", @"장치가 삭제되었습니다")];
  226. // if ([JDFacade facade].loginHomeGroup.deviceId && ![[JDFacade facade].loginHomeGroup.deviceId isEmptyString]) {
  227. // if ([[JDFacade facade].loginHomeGroup.deviceId isEqualToString:_deviceDetail.deviceId]) {//현재 홈의 스마튼폰일 경우,
  228. // [JDFacade facade].loginHomeGroup.deviceId = nil;
  229. // [JDFacade facade].loginHomeGroup.deviceAuthorization = nil;
  230. // [JDFacade facade].loginHomeGroup.deviceKey = nil;
  231. // }
  232. // }
  233. //리스트를 다시 로드함.
  234. ThingsViewController *vc = [[JDFacade facade] viewControllerOnNaviationController:[ThingsViewController class]];
  235. [vc prepareViewDidLoadRefreshPopup:YES];
  236. [self.navigationController popToRootViewControllerAnimated:YES];
  237. } failure:^(id errorObject) {
  238. JDErrorModel *error = (JDErrorModel *)errorObject;
  239. [[JDFacade facade] alert:error.errorMessage];
  240. }];
  241. }
  242. #pragma mark - UITableView DataSource & Delegate
  243. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  244. return 4;
  245. }
  246. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  247. NSInteger count = 1;
  248. if (section == 1) {
  249. count = _deviceDetail && _deviceDetail.cmdclsList && _deviceDetail.cmdclsList.count > 0;
  250. } else if (section == 2) {//optional nodes
  251. count = _optionalNodes.count; //두번째 이후부터 옵셔널 노드임.
  252. }
  253. return count;
  254. }
  255. - (CGFloat)heightForMandatoryNode {
  256. CGFloat height = 0;
  257. NodeModel *node = _deviceDetail.cmdclsList.firstObject;
  258. if (node.cmdclsType == CmdClsTypeSwitchBinary || node.cmdclsType == CmdClsTypeValve) {
  259. height = 347.0f; //275 || 347
  260. } else {
  261. height = 275.0f;
  262. }
  263. height += _mandatoryNodes.count > 1 ? 75 : 0;
  264. return height;
  265. }
  266. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  267. CGFloat height = 86;
  268. NSInteger section = indexPath.section;
  269. if (section == 0) {
  270. height = 68;
  271. } else if (section == 1) {
  272. // height = [self heightForMandatoryNode] + 35.0f;
  273. height = 322;
  274. } else if (section == 2) {
  275. height = 63;
  276. // if (indexPath.row == _deviceDetail.nodes.count - 2) {
  277. // height += 35;
  278. // }
  279. } else if (section == 3) {
  280. height = 89;
  281. }
  282. return height;
  283. }
  284. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  285. UITableViewCell *cell = nil;
  286. NSInteger section = indexPath.section;
  287. if (section == 0) {//title
  288. ThingsDetailTitleTableViewCell *tcell = (ThingsDetailTitleTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"TitleCellIdentifier"];
  289. // [tcell.imgvDevice sd_setImageWithURL:[NSURL URLWithString:_deviceDetail.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
  290. tcell.lblDeviceUpdate.hidden = !_deviceDetail.isProfileUpdate;
  291. //배터리 30이하일때 메세지 우선순위
  292. NSString *battery = [self getBatteryFromNode];
  293. if (battery != nil && [battery integerValue] <= 30) {
  294. tcell.lblDeviceUpdate.hidden = NO;
  295. tcell.lblDeviceUpdate.text = @"배터리를 즉시 교체하세요.";
  296. }
  297. cell = tcell;
  298. } else if (section == 1) {//device control
  299. ThingsDetailControlTableViewCell *tcell = (ThingsDetailControlTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ControlCellIdentifier"];
  300. //뷰를 초기화함.
  301. [[tcell.controlContainer subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  302. UIView *subview = (UIView *)obj;
  303. [subview removeFromSuperview];
  304. }];
  305. if (_deviceDetail) {
  306. tcell.controlContainer.scrollEnabled = _mandatoryNodes.count > 1;
  307. tcell.controlContainer.contentSize = CGSizeMake(IPHONE_WIDTH * _mandatoryNodes.count, [self heightForMandatoryNode]);
  308. tcell.controlContainer.showsHorizontalScrollIndicator = NO;
  309. if (tcell.controlContainer.scrollEnabled) {
  310. tcell.controlContainer.delegate = self;
  311. }
  312. tcell.pageControl.hidden = !tcell.controlContainer.scrollEnabled;
  313. if (!tcell.pageControl.hidden && !_pageControl) {
  314. _pageControl = tcell.pageControl;
  315. _pageControl.numberOfPages = _mandatoryNodes.count;
  316. }
  317. __block CGFloat width = 0;
  318. for (NodeModel *node in _mandatoryNodes) {
  319. node.refDevice = _refDevice;
  320. NSLog(@"node.cmdclsType : %ld", (long)node.cmdclsType);
  321. CommandClassControlView *controlView = [CommandClassControlDetailView viewForCommandClass:node.cmdclsType];
  322. node.deviceId = _deviceDetail.deviceId;
  323. node.nodeId = _deviceDetail.nodeId;
  324. controlView.node = node;
  325. controlView.isMandatoryNode = [node.cmdclsMandatoryYn boolValue] && _mandatoryNodes.count > 1;
  326. controlView.selectHub = _selectHub;
  327. tcell.controlContainer.hidden = !controlView;
  328. if (!tcell.controlContainer.hidden) {
  329. controlView.x = width;
  330. UIView *superview = tcell.controlContainer;
  331. [superview addSubview:controlView];
  332. [controlView mas_makeConstraints:^(MASConstraintMaker *make) {
  333. make.size.mas_equalTo(controlView.frame.size);
  334. make.leading.equalTo(superview).offset(width);
  335. // make.trailing.equalTo(superview).offset(width+IPHONE_WIDTH);
  336. width += IPHONE_WIDTH;
  337. }];
  338. }
  339. }
  340. }
  341. cell = tcell;
  342. } else if (section == 2) {//option control
  343. ThingsDetailOptionTableViewCell *tcell = (ThingsDetailOptionTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"OptionCellIdentifier"];
  344. NodeModel *node = _deviceDetail.cmdclsList[indexPath.row + _mandatoryNodes.count];
  345. //NSLog(@"NodeModel : %@", node);
  346. tcell.lblNodeName.text = node.cmdclsName;
  347. tcell.lblNodeValue.text = node.contentValueMsg;
  348. cell = tcell;
  349. } else if (section == 3){ // Device Id
  350. ThingsDetailDeviceIdTableViewCell *tcell = (ThingsDetailDeviceIdTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"DeviceIdCellIdentifier"];
  351. tcell.lblDeviceName.text = _deviceDetail.deviceModelId;
  352. tcell.lblDeviceId.text = _deviceDetail.deviceId;
  353. cell = tcell;
  354. }
  355. return cell;
  356. }
  357. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  358. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  359. }
  360. - (void)setMoreBtnArray {
  361. _moreBtnArray = [NSMutableArray array];
  362. if (![[JDFacade facade].loginUser hasHomeHub]) {
  363. [_btnOption setHidden:YES];
  364. }
  365. if([[JDFacade facade].loginUser.gradeCode isEqualToString:KNEET_MEMBER_MASTER]) {
  366. for (int i = 0; i < 3; i++) {
  367. MoreBtnModel *btnModel;
  368. switch (i) {
  369. case 0:
  370. btnModel = [[MoreBtnModel alloc] initWithTyep:NameChange isEnable:YES];
  371. break;
  372. case 1:
  373. btnModel = [[MoreBtnModel alloc] initWithTyep:Del isEnable:YES];
  374. break;
  375. case 2:
  376. btnModel = [[MoreBtnModel alloc] initWithTyep:Refresh isEnable:YES];
  377. break;
  378. default:
  379. break;
  380. }
  381. [_moreBtnArray addObject:btnModel];
  382. }
  383. } else {
  384. MoreBtnModel *btnModel = [[MoreBtnModel alloc] initWithTyep:Refresh isEnable:YES];
  385. [_moreBtnArray addObject:btnModel];
  386. }
  387. }
  388. - (BOOL)checkOnlineHubAlert {
  389. if (![[JDFacade facade].loginUser onlineHomeHubFromSelectedHub:_selectHub]) {
  390. [[JDFacade facade] alert:@"허브가 오프라인 상태입니다. 허브 상태 확인 후 다시 시도해주세요." completionHander:nil];
  391. return NO;
  392. }
  393. return YES;
  394. }
  395. - (NSString*)getBatteryFromNode {
  396. for (NodeModel *model in _deviceDetail.cmdclsList) {
  397. NSLog(@"model : %@", model);
  398. if (EQUALS(model.cmdclsId, @"battery")) {
  399. return model.contentValue;
  400. }
  401. }
  402. return nil;
  403. }
  404. -(void)deviceDelete
  405. {
  406. if (![self checkOnlineHubAlert]) return ;
  407. if (![_deviceDetail isOnline]) {
  408. ThingsForcedDelViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsForcedDelViewController" storyboardName:@"Things"];
  409. vc.delDevice = _deviceDetail;
  410. [self showTransparencyModalView:vc removeSelf:NO];
  411. } else {
  412. ThingsGeneralDelViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsGeneralDelViewController" storyboardName:@"Things"];
  413. vc.delDevice = _deviceDetail;
  414. [self showTransparencyModalView:vc removeSelf:NO];
  415. }
  416. }
  417. -(void)nodeProfileUpdate
  418. {
  419. SocketRequestModel *request = [[SocketRequestModel alloc] initWithMsgType:MSG_TYPE_NODE_PROFILE_UPDATE];
  420. NSDictionary *param = @{@"device_id":_refDevice.deviceId,
  421. @"node_id":_refDevice.nodeId,
  422. @"cust_id": [[JDFacade facade].loginUser custId],
  423. @"ctrt_grp_id": [[JDFacade facade].loginUser ctrtGrpId]};
  424. [request setRequestMsg:param];
  425. [self sendDataToSocket:request modelClass:[CommandModel class] isLoading:YES];
  426. }
  427. #pragma mark - MoreButtonDelegate
  428. -(void)moreBtnAction:(id)sender
  429. {
  430. NSInteger tag = [(UIButton *)sender tag];
  431. NSLog(@"MoreBtn Action : %li", (long)tag);
  432. switch (tag) {
  433. case NameChange:
  434. {
  435. if (![self checkOnlineHubAlert]) return ;
  436. ChangeDeviceNamePopupView *popup = [[ChangeDeviceNamePopupView alloc]initFromNib:_deviceDetail];
  437. popup.deviceDetailModel = _deviceDetail;
  438. popup.delegate = self;
  439. [popup show];
  440. }
  441. break;
  442. case Del:
  443. {
  444. [self deviceDelete];
  445. }
  446. break;
  447. case Refresh:
  448. {
  449. [self requestDeviceDetail:@YES];
  450. }
  451. break;
  452. default:
  453. break;
  454. }
  455. }
  456. #pragma mark - UI Events
  457. - (IBAction)btnOptionTouched:(id)sender {
  458. // [self toggleOptions:sender];
  459. [self toggleOptionsWithArray:sender btnArray:_moreBtnArray];
  460. }
  461. //업데이트
  462. - (IBAction)btnUpdateTouched:(id)sender {
  463. if (![self checkOnlineHubAlert]) return ;
  464. [[JDFacade facade] confirmTitle:@"장치 업데이트" message:@"지금 장치를 최신 버전으로\n업데이트 하시겠습니까?" btnOKLabel:@"예" btnCancelLabel:@"아니오" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  465. if (buttonIndex == 0) {
  466. [self nodeProfileUpdate];
  467. }
  468. }];
  469. }
  470. - (IBAction)btnCloseTouched:(id)sender {
  471. [[JDFacade facade] dismissModalStack:YES completion:nil];
  472. }
  473. #pragma mark - ScrollView Delegate
  474. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  475. CGFloat pageWidth = scrollView.frame.size.width; // you need to have a **iVar** with getter for scrollView
  476. CGFloat fractionalPage = scrollView.contentOffset.x / pageWidth;
  477. NSInteger page = lround(fractionalPage);
  478. _pageControl.currentPage = page; // you need to have a **iVar** with getter for pageControl
  479. }
  480. -(void) receiveSocketData:(NSNotification *)notification {
  481. SocketModel *result = [[SocketModel alloc] initWithDictionary:notification.object error:nil];
  482. //NSLog(@"Result : %@", result);
  483. if ([result.messageType isEquestToIgnoreCase:MSG_TYPE_NODE_CONTENT]) {
  484. ContentModel *response = [[ContentModel alloc] initWithDictionary:notification.object error:nil];
  485. //NSLog(@"Response : %@", response);
  486. if ([_refDevice.deviceId isEqualToString:response.deviceId] && [_refDevice.nodeId isEqualToString:response.nodeId]) {
  487. [self requestDeviceDetail:@NO];
  488. }
  489. }
  490. if ([result.messageType isEqualToString:MSG_TYPE_NODE_PROFILE_UPDATE_RES]) {
  491. if (result.isSuccess) {
  492. [[JDFacade facade] alertTitle:@"장치 업데이트 완료" message:@"장치를 최신 버전으로 업데이트 하였습니다."];
  493. }
  494. else {
  495. [[JDFacade facade] confirmTitle:@"장치 업데이트 실패"
  496. message:@"오류가 발생하여 업데이트가 완료되지 않았습니다."
  497. btnOKLabel:@"재시도"
  498. btnCancelLabel:@"취소"
  499. completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  500. if (buttonIndex == 0) {
  501. [self btnUpdateTouched:nil];
  502. }
  503. }];
  504. }
  505. }
  506. }
  507. -(void)finishDeviveDelete {
  508. NSLog(@"tdvc finishDeviveDelete");
  509. [self btnCloseTouched:nil];
  510. }
  511. #pragma mark - MemoryWarning
  512. - (void)releaseDeviceTimer {
  513. if (_deviceBackgroundTimer) {
  514. [_deviceBackgroundTimer invalidate];
  515. _deviceBackgroundTimer = nil;
  516. }
  517. }
  518. - (void)viewWillDisappear:(BOOL)animated {
  519. [self releaseDeviceTimer];
  520. }
  521. - (void)didReceiveMemoryWarning
  522. {
  523. [super didReceiveMemoryWarning];
  524. // Dispose of any resources that can be recreated.
  525. }
  526. @end