ThingsViewController.m 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. //
  2. // ThingsViewController.m
  3. // kneet
  4. //
  5. // Created by Jason Lee on 3/10/15.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "DeviceModel.h"
  12. #import "CustomLabel.h"
  13. #import "CustomImageView.h"
  14. #import "CustomTextField.h"
  15. #import "CustomLabelButton.h"
  16. #import "CustomButton.h"
  17. #import "JYRefreshController.h"
  18. #import "WYPopoverController.h"
  19. #import "ImageUtil.h"
  20. #import "UIImageView+WebCache.h"
  21. #import "UIButton+WebCache.h"
  22. #import "CommandClassControlView.h"
  23. #import "ThingsDetailViewController.h"
  24. #import "ThingsViewController.h"
  25. #import "ThingsAddViewController.h"
  26. #import "ThingsAddStartViewController.h"
  27. #import "CustomTableView.h"
  28. #import "JYPullToRefreshController.h"
  29. #import "HomeMemberViewController.h"
  30. #define kfThingsTableViewCellHeight 100.0f
  31. #define kiCellInset 5
  32. #define kiCellItem 2
  33. #define kiCellRatio 74
  34. #define kiCellDivision 3
  35. /**
  36. Head Text Color : kUITextColor01
  37. Device 명 Text Color : kUITextColor01
  38. Device 상태표시 Text Color
  39. - 열림 : kUITextColor02
  40. - 닫힘 : kUITextColor01
  41. 장치 추가 Text Color : kUITextColor01
  42. (이미지 명)
  43. 디바이스 아이콘 bg
  44. - Default : img_thing_icon_bg_default
  45. - Active : img_thing_icon_bg_active
  46. 도어 컨텍트 센서 : 40102
  47. 가스 밸브 : 40108
  48. 다윈 플러그 : 40402
  49. **/
  50. @interface ThingsCollectionViewCell () {
  51. NSInteger _commandStatusElapsedTime;
  52. }
  53. @property (weak, nonatomic) NSIndexPath *indexPath;
  54. @end
  55. @implementation ThingsCollectionViewCell
  56. - (void)awakeFromNib {
  57. _pcontainerView.hidden = NO;
  58. }
  59. - (void)startProgressAni {
  60. //chagne button image
  61. [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{
  62. _imgvProgress.transform = CGAffineTransformMakeRotation(M_PI);
  63. } completion:nil];
  64. }
  65. - (void)stopProgressAni {
  66. [UIView animateWithDuration:0.0f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^{
  67. _imgvProgress.transform = CGAffineTransformMakeRotation(0);
  68. } completion:nil];
  69. }
  70. @end
  71. @implementation ThingsAddCollectionCell
  72. @end
  73. @interface ThingsViewController () <UICollectionViewDataSource, UICollectionViewDelegate> {
  74. NSMutableArray *_deviceList;
  75. NSMutableArray *_deviceReOrderList;
  76. NSString *_pagingId, *_pagingType;
  77. BOOL _isNotFirstLoading, _isReOrderMode, _isDeleteMode;
  78. NSMutableArray<DeviceModel> *_commandArray;
  79. NSTimer *_devicesBackgroundTimer;
  80. NSTimer *_deviceCommandsBackgroundTimer;
  81. NSInteger _deviceFlag;
  82. UIPanGestureRecognizer *_moveCellGesture;
  83. NSIndexPath *_dragIndexPath;
  84. ThingsCollectionViewCell *_moveCell;
  85. NodeListModel *_nodeListData;
  86. DeviceModel *_selectHub;
  87. }
  88. @property (strong, nonatomic) JYPullToRefreshController *refreshController;
  89. @property (nonatomic, strong) UIView *cellFakeView;
  90. @end
  91. #pragma mark - Class Definition
  92. @implementation ThingsViewController
  93. - (void)viewDidLoad {
  94. [super viewDidLoad];
  95. [self initProperties];
  96. [self initUI];
  97. }
  98. - (void)viewWillAppear:(BOOL)animated {
  99. [super viewWillAppear:animated];
  100. [self prepareViewDidLoad];
  101. }
  102. - (void)initProperties {
  103. _deviceFlag = IS_IPHONE_6P ? 2 : 2;
  104. }
  105. - (void)initUI {
  106. //set tableview option
  107. _collectionView.delegate = self;
  108. _collectionView.dataSource = self;
  109. _collectionView.backgroundColor = [UIColor clearColor];
  110. _collectionView.alwaysBounceVertical = YES;
  111. _lblEditMode.hidden = YES;
  112. [self viewOfflineSetHidden:YES];
  113. [_btnClose setHidden:YES];
  114. [_btnOption setHidden:NO];
  115. [_viewEditMode setHidden:YES];
  116. // [self setThingsPopoverOptions];
  117. [self setMoreBtnArray];
  118. [self initRefreshController];
  119. }
  120. - (void)viewOfflineSetHidden:(BOOL)hidden{
  121. _viewHeight.constant = hidden ? 0 : 54;
  122. }
  123. - (void)initRefreshController {
  124. //set refresh controls
  125. __weak typeof(self) weakSelf = self;
  126. self.refreshController = [[JYPullToRefreshController alloc] initWithScrollView:self.collectionView];
  127. self.refreshController.pullToRefreshHandleAction = ^{
  128. [weakSelf requestDeviceList:@YES];
  129. };
  130. }
  131. - (void)setThingsPopoverOptions {
  132. //
  133. // //set Popover Contents
  134. // __weak typeof(self) weakSelf = self;
  135. // _popooverOptionArray = [[NSMutableArray alloc] init];
  136. //
  137. // [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로고침", @"새로고침"),
  138. // @"iconName": @"img_bg_morepopup_icon_refresh",
  139. // @"target": weakSelf,
  140. // @"selector": [NSValue valueWithPointer:@selector(refreshDeviceList)]}];
  141. //
  142. //// if ([JDFacade facade].loginUser.level == 90) {//권한
  143. //// [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"추가", @"추가"),
  144. //// @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
  145. //// @"target": weakSelf,
  146. //// @"selector": [NSValue valueWithPointer:@selector(addNewDevice)]}];
  147. ////
  148. //// [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"삭제", @"삭제"),
  149. //// @"iconName": @"tp_01_img_bg_morepopup_icon_group_deviceadd",
  150. //// @"target": weakSelf,
  151. //// @"selector": [NSValue valueWithPointer:@selector(toggleEditMode)]}];
  152. //// }
  153. }
  154. - (void)setMoreBtnArray {
  155. _moreBtnArray = [NSMutableArray array];
  156. if (![[JDFacade facade].loginUser hasHomeHub]) {
  157. [_btnOption setHidden:YES];
  158. }
  159. if([[JDFacade facade].loginUser.gradeCode isEqualToString:KNEET_MEMBER_MASTER]) {
  160. for (int i = 0; i < 4; i++) {
  161. MoreBtnModel *btnModel;
  162. switch (i) {
  163. case 0:{
  164. btnModel = [[MoreBtnModel alloc] initWithTyep:ReOrder isEnable:YES];
  165. btnModel.enable = [_nodeListData isCanReOrder];
  166. }
  167. break;
  168. case 1:{
  169. btnModel = [[MoreBtnModel alloc] initWithTyep:Add isEnable:YES];
  170. btnModel.enable = [_nodeListData isCanAddNode];
  171. }
  172. break;
  173. case 2:{
  174. btnModel = [[MoreBtnModel alloc] initWithTyep:Del isEnable:YES];
  175. btnModel.enable = [_nodeListData isCanDelNode];
  176. }
  177. break;
  178. case 3:
  179. btnModel = [[MoreBtnModel alloc] initWithTyep:Refresh isEnable:YES];
  180. break;
  181. default:
  182. break;
  183. }
  184. [_moreBtnArray addObject:btnModel];
  185. }
  186. }
  187. else {
  188. MoreBtnModel *btnModel = [[MoreBtnModel alloc] initWithTyep:Refresh isEnable:YES];
  189. [_moreBtnArray addObject:btnModel];
  190. }
  191. }
  192. - (void)prepareViewDidLoad {
  193. //fetch devices from server
  194. [self updateTitle];
  195. [self performSelector:@selector(requestHomeHubList) withObject:nil afterDelay:0.0f];
  196. [self performSelector:@selector(requestDeviceList:) withObject:@YES afterDelay:0.0f];
  197. }
  198. - (void)updateHomeHubStatusToDevices {
  199. [self updateTitle];
  200. for (DeviceModel *device in _deviceList) {
  201. device.onlineState = [JDFacade facade].loginUser.homehubOnlineState;
  202. }
  203. [_collectionView reloadData];
  204. }
  205. //제어를 요청한 장치상태를 조회함.
  206. - (void)requestPollingCommandStatusOfDeviceInBackground:(DeviceModel *)device {
  207. if (!_commandArray) {
  208. _commandArray = (NSMutableArray<DeviceModel> *)[[NSMutableArray alloc] init];
  209. }
  210. __block BOOL isStatusChanged = NO;
  211. if (device && [device isKindOfClass:[DeviceModel class]]) {//validate, aleady have,
  212. if (![_commandArray objectByUsingPredicateFormat:@"deviceId == %@ && nodeId == %@", device.deviceId, device.nodeId]) {//일치하는 디바이스가 있을 경우, 추가하지 않음.
  213. [_commandArray addObject:device];
  214. isStatusChanged = YES;
  215. }
  216. }
  217. if (_commandArray.count) {
  218. NSMutableString *pathParams = [[NSMutableString alloc] init];
  219. for (DeviceModel *pDevice in _commandArray) {
  220. NSString *prefix = [pathParams isEmptyString] ? ksEmptyString : @",";
  221. [pathParams appendFormat:@"%@%@_%@", prefix, pDevice.deviceId, pDevice.nodeId];
  222. }
  223. //20
  224. NSString *path = [NSString stringWithFormat:API_GET_DEVICE_NODE_STATUS, pathParams];
  225. dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{//RUN to background thread
  226. NodeListModel *fdevices = [[RequestHandler handler] sendSyncGetRequestAPIPath:path parameters:nil
  227. modelClass:[NodeListModel class] showLoadingView:YES];
  228. if (fdevices && fdevices.nodes && fdevices.nodes.count) {
  229. [_commandArray enumerateObjectsUsingBlock:^(DeviceModel *rdevice, NSUInteger idx, BOOL * _Nonnull stop) {
  230. DeviceModel *matchedDevice = (DeviceModel *)[fdevices.nodes objectByUsingPredicateFormat:@"deviceId == %@ && nodeId == %@", rdevice.deviceId, rdevice.nodeId];
  231. //실행 여부 및 10초 경과 확인
  232. BOOL isOverTimeLimit = [self elapsedSecondsFromNow:rdevice] > 10;
  233. //실행 여부 확인
  234. NSInteger elapsedTime = [self elapsedSecondsFrom:rdevice to:matchedDevice];
  235. BOOL hasChangedStatus = elapsedTime > 0;
  236. rdevice.isRequesting = [rdevice.contentValue isEqualToString:matchedDevice.contentValue] && !hasChangedStatus && !isOverTimeLimit;
  237. //TODO - home hub check
  238. // rdevice.requestTime = matchedDevice.requestTime;
  239. // rdevice.collectTime = matchedDevice.collectTime;
  240. rdevice.onlineState = matchedDevice.onlineState;
  241. if (!rdevice.isRequesting || !rdevice.isOnline || ![JDFacade facade].loginUser.isHomehubOnline) {//정상적으로 변경됨.
  242. rdevice.contentValue = matchedDevice.contentValue;
  243. [_commandArray removeObject:rdevice];
  244. isStatusChanged = YES;
  245. }
  246. #ifdef DEBUG_MODE
  247. NSLogInfo(@"==########== device command status = %@, elapsedTime = %zd ==########==", [JDFacade facade].loginUser.homehubOnlineState, elapsedTime);
  248. #endif
  249. }];
  250. } else {//
  251. NSLog(@"no devices");
  252. }
  253. if (_commandArray.count) {//커맨드 실행 중인 디바이스가 있을 경우,
  254. //schedul timer.
  255. if (!_deviceCommandsBackgroundTimer) {
  256. _deviceCommandsBackgroundTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(requestPollingCommandStatusOfDeviceInBackground:) userInfo:nil repeats:YES];
  257. }
  258. } else {
  259. [_deviceCommandsBackgroundTimer invalidate];
  260. _deviceCommandsBackgroundTimer = nil;
  261. }
  262. //리스트와 상세의 상태를 계속 매핑해줌.
  263. [self matchDeviceListWithOnCommandsDevices];
  264. //변화가 있을 경우, 컬렉션뷰를 리로드
  265. if (isStatusChanged) {
  266. [_collectionView reloadData];
  267. ThingsDetailViewController *vc = (ThingsDetailViewController *)[JDFacade facade].currentViewController;
  268. if ([vc isKindOfClass:[ThingsDetailViewController class]]) {
  269. [vc.tableView reloadData];
  270. }
  271. }
  272. });
  273. }
  274. }
  275. -(void)requestDeviceControl
  276. {
  277. [_collectionView reloadData];
  278. ThingsDetailViewController *vc = (ThingsDetailViewController *)[JDFacade facade].currentViewController;
  279. if ([vc isKindOfClass:[ThingsDetailViewController class]]) {
  280. [vc.tableView reloadData];
  281. }
  282. }
  283. - (NSInteger)elapsedSecondsFromNow:(DeviceModel *)runningDevice {
  284. NSInteger seconds = 0;
  285. if (runningDevice.requestTime && ![runningDevice.requestTime isEmptyString]) {
  286. NSDate *rdate = [CommonUtil dateFromDateString:[CommonUtil localDateFromUTC:runningDevice.requestTime]];
  287. NSTimeInterval elapsed = [[NSDate systemDate] timeIntervalSinceDate:rdate];
  288. seconds = elapsed;
  289. }
  290. return seconds;
  291. }
  292. - (NSInteger)elapsedSecondsFrom:(DeviceModel *)runningDevice to:(DeviceModel *)fetchedDevice {
  293. NSInteger seconds = 0;
  294. if (runningDevice.requestTime && ![runningDevice.requestTime isEmptyString] && fetchedDevice.collectTime && ![fetchedDevice.collectTime isEmptyString]) {
  295. NSDate *rdate = [CommonUtil dateFromDateString:[CommonUtil localDateFromUTC:runningDevice.requestTime]];
  296. NSDate *fdate = [CommonUtil dateFromDateString:[CommonUtil localDateFromUTC:fetchedDevice.collectTime]];
  297. seconds = [fdate secondsAfterDate:rdate];
  298. }
  299. return seconds;
  300. }
  301. - (void)addNewDevice {
  302. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsAddViewController" storyboardName:@"Things"];
  303. [self presentViewController:vc animated:YES completion:nil];
  304. }
  305. - (void)refreshDeviceList {
  306. [self performSelector:@selector(requestDeviceList:) withObject:@YES afterDelay:0.0f];
  307. }
  308. #pragma mark - Main Logic
  309. - (void)requestDeviceListRecently {
  310. DeviceModel *firstDevice = [_deviceList firstObject];
  311. _pagingType = ksListPagingTypeUpward;
  312. _pagingId = firstDevice.createDatetime;
  313. [self performSelector:@selector(requestDeviceList:) withObject:@YES afterDelay:0.0f];
  314. }
  315. - (void)requestDeviceListOlder {
  316. DeviceModel *lastDevice = [_deviceList lastObject];
  317. _pagingType = ksListPagingTypeDownward;
  318. _pagingId = lastDevice.createDatetime;
  319. [self performSelector:@selector(requestDeviceList:) withObject:@YES afterDelay:0.0f];
  320. }
  321. - (void)requestHomeHubList {
  322. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_DEVICE_LIST aditional:@""];
  323. [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestGET parameters:nil
  324. modelClass:[DeviceListModel class] showLoadingView:NO completion:^(id responseObject) {
  325. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  326. return;
  327. }
  328. DeviceListModel *deviceList = (DeviceListModel *)responseObject;
  329. NSMutableArray *list = [NSMutableArray array];
  330. for (DeviceModel *info in deviceList.list) {
  331. [list addObject:info];
  332. }
  333. [JDFacade facade].loginUser.deviceList = list;
  334. } failure:^(id errorObject) {
  335. // [self releaseDevicesTimer];
  336. JDErrorModel *error = (JDErrorModel *)errorObject;
  337. [[JDFacade facade] alert:error.errorMessage];
  338. }];
  339. }
  340. - (void)requestDeviceList:(id)arg {
  341. if (![JDFacade facade].loginUser.hasHomeHub) {
  342. return;
  343. }
  344. // BOOL showLoadingView = [arg isKindOfClass:[NSTimer class]] ? [((NSTimer *)arg).userInfo boolValue] : [arg boolValue];
  345. BOOL showLoadingView = YES;
  346. //parameters
  347. NSDictionary *parameter = @{@"device_id": _selectHub ? _selectHub.deviceId : ksEmptyString};
  348. // NSString *path = [NSString stringWithFormat:API_GET_DEVICE_LIST];
  349. // 멀티 홈허브 환경에서 선택된 홈허브 아이디가 있을경우 적용하기
  350. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_NODE_LIST aditional:@""];
  351. [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestPOST parameters:parameter
  352. modelClass:[NodeListModel class] showLoadingView:showLoadingView completion:^(id responseObject) {
  353. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  354. return;
  355. }
  356. _nodeListData = (NodeListModel *)responseObject;
  357. [self setMoreBtnArray];
  358. if (_nodeListData && _nodeListData.nodes && _nodeListData.nodes.count) {
  359. _deviceList = _nodeListData.nodes;
  360. _deviceReOrderList = [[NSMutableArray alloc] initWithArray:_deviceList];
  361. [self updateTitle];
  362. } else {
  363. if (!_deviceList.count) {//이미 로드된 데이터가 있을 경우는 출력하지 않음.
  364. _lblConnectHub.text = @"등록된 장치가 없습니다";
  365. _imgvHubAlert.hidden = YES;
  366. _imgvConnectHub.image = [UIImage imageNamed:@"img_1depth_nodevice"];
  367. }
  368. }
  369. [_collectionView reloadData];
  370. // [self requestPollingDevicesStatusInBackground];
  371. //refresh controller
  372. if (self.refreshController && self.refreshController.refreshState == JYRefreshStateLoading) {
  373. [self.refreshController stopRefreshWithAnimated:YES completion:nil];
  374. }
  375. } failure:^(id errorObject) {
  376. // [self releaseDevicesTimer];
  377. JDErrorModel *error = (JDErrorModel *)errorObject;
  378. [[JDFacade facade] alert:error.errorMessage];
  379. }];
  380. }
  381. - (void)requestDeviceOrderReset {
  382. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_PUT_NODE_ORDER_RESET aditional:nil];
  383. NSDictionary *parameter = @{@"type": @"node"};
  384. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  385. NSLog(@"Reset Result : %@", responseObject);
  386. [self refreshDeviceList];
  387. } failure:^(id errorObject) {
  388. JDErrorModel *error = (JDErrorModel *)errorObject;
  389. [[JDFacade facade] alert:error.errorMessage];
  390. }];
  391. }
  392. - (void)requestDeviceOrderChange {
  393. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_PUT_NODE_ORDER_CHANGE aditional:nil];
  394. NSMutableArray *nodeOrder = [NSMutableArray array];
  395. for (DeviceModel *info in _deviceReOrderList) {
  396. NSDictionary *orderInfo = @{
  397. @"device_id": info.deviceId,
  398. @"node_id": info.nodeId};
  399. [nodeOrder addObject:orderInfo];
  400. }
  401. NSDictionary *parameter = @{@"nodes": nodeOrder};
  402. [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  403. NSLog(@"ReOrder Result : %@", responseObject);
  404. // [self refreshDeviceList];
  405. } failure:^(id errorObject) {
  406. JDErrorModel *error = (JDErrorModel *)errorObject;
  407. [[JDFacade facade] alert:error.errorMessage];
  408. }];
  409. }
  410. //디바이스 상태를 3초마다 갱신함.
  411. - (void)requestPollingDevicesStatusInBackground {
  412. return;
  413. //schedul timer.
  414. if (!_devicesBackgroundTimer) {
  415. _devicesBackgroundTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(requestDeviceList:) userInfo:@NO repeats:YES];
  416. }
  417. }
  418. - (void)updateTitle {
  419. // _lblTitle.text = [NSString stringWithFormat:@"장치 전체 %zd", _deviceList.count];
  420. _lblCount.text = [NSString stringWithFormat:@"%zd", _deviceList.count];
  421. NSLog(@"HomeHubID : %@", [JDFacade facade].loginUser.homehubDeviceId);
  422. if (![JDFacade facade].loginUser.hasHomeHub) {//홈허브 아이디가 없는 경우,
  423. [_mainView bringSubviewToFront:_addHubContainerView];
  424. _addHubContainerView.hidden = NO;
  425. _collectionView.hidden = YES;
  426. _btnOption.hidden = NO;
  427. _btnClose.hidden = YES;
  428. if (![JDFacade facade].loginUser.homegrpId) {//연결한 적이 없음
  429. _lblConnectHub.text = @"초대를 받아서\n시작해 보세요";
  430. _imgvHubAlert.hidden = YES;
  431. _imgvConnectHub.image = [UIImage imageNamed:@"img_1depth_invitation"];
  432. _lblLeaveAccount.hidden = YES;
  433. _lblSimpleMemberInfo.hidden = YES;
  434. } else {//홈허브가 삭제됨.
  435. _lblTitle.text = @"홈허브 삭제됨";
  436. _imgvHubAlert.hidden = NO;
  437. _lblConnectHub.text = @"홈허브를 다시 연결하려면\n고객센터에 문의해주세요";
  438. _imgvConnectHub.image = [UIImage imageNamed:@"img_things_homehub_img_hubdelete_cscenter"];
  439. if ([JDFacade facade].loginUser.level < 90) {//일반 유저일 경우,
  440. _imgvConnectHub.image = [UIImage imageNamed:@"img_things_homehub_img_hubdelete_wait"];
  441. _lblLeaveAccount.hidden = NO;
  442. _lblSimpleMemberInfo.hidden = NO;
  443. [_lblLeaveAccount setUnderLine:_lblLeaveAccount.text];
  444. if (!_lblLeaveAccount.touchHandler) {
  445. [_lblLeaveAccount addTouchEventHandler:^(id label) {
  446. [self leaveHomegroup];
  447. }];
  448. }
  449. }
  450. }
  451. } else {
  452. NSLog(@"이쪽으로 빠짐2");
  453. if (![JDFacade facade].loginUser.isHomehubOnline) {
  454. _imgvHubAlert.hidden = NO;
  455. _lblTitle.text = @"홈허브 오프라인";
  456. [_lblTitle setColor:kUITextColor01 text:_lblTitle.text];
  457. } else {
  458. _imgvHubAlert.hidden = YES;
  459. }
  460. [_mainView bringSubviewToFront:_collectionView];
  461. _addHubContainerView.hidden = YES;
  462. _collectionView.hidden = NO;
  463. _btnOption.hidden = NO;
  464. }
  465. if ([_lblTitle.text rangeOfString:@"장치 전체"].location != NSNotFound) {
  466. [_lblTitle setColor:kUITextColor03 text:[NSString stringWithFormat:@"%zd", _deviceList.count]];
  467. }
  468. }
  469. - (void)leaveHomegroup {
  470. HomeMemberViewController *vc = [[HomeMemberViewController alloc] init];
  471. [vc leaveHomegroup];
  472. }
  473. - (void)matchDeviceListWithOnCommandsDevices {
  474. for (DeviceModel *rdevice in _commandArray) {
  475. DeviceModel *matchedDevice = [_deviceList objectByUsingPredicateFormat:@"deviceId == %@", rdevice.deviceId]; //일치하는 디바이스가 있을 경우, 추가하지 않음.
  476. // DeviceModel *matchedDevice = [_deviceList objectByUsingPredicateFormat:@"deviceId == %@ && nodeId == %@", rdevice.deviceId, rdevice.nodeId]; //일치하는 디바이스가 있을 경우, 추가하지 않음.
  477. if (matchedDevice) {
  478. matchedDevice.isRequesting = rdevice.isRequesting;
  479. matchedDevice.requestTime = rdevice.requestTime;
  480. }
  481. }
  482. // [_collectionView reloadData];
  483. }
  484. - (void)releaseDevicesTimer {
  485. if (_devicesBackgroundTimer) {
  486. [_devicesBackgroundTimer invalidate];
  487. _devicesBackgroundTimer = nil;
  488. }
  489. }
  490. #pragma mark - UICollectionView Delegate
  491. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  492. NSInteger auth = [JDFacade facade].loginUser.level == 90 && !_isDeleteMode && [_nodeListData isCanAddNode]; //마스터 권한일 경우,
  493. NSInteger count = _deviceList.count % _deviceFlag == 0 ? _deviceList.count + auth : _deviceList.count + auth; //홀수일 경우, 멤버 초대 버튼을 추가해줌.
  494. // NSInteger count = _deviceList.count;
  495. return count;
  496. }
  497. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  498. UICollectionViewCell *rcell = nil;
  499. UIPanGestureRecognizer *drag = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];
  500. if (indexPath.row < _deviceList.count) {
  501. ThingsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ThingsCellIdentifier" forIndexPath:indexPath];
  502. // [cell.btnDelete setHidden:YES];
  503. // [cell.btnChangeOrder setHidden:YES];
  504. DeviceModel *device =_deviceList[indexPath.row];
  505. cell.indexPath = indexPath;
  506. cell.lblDeviceName.text = device.prdName;
  507. // [cell.btnDevice sd_setImageWithURL:[NSURL URLWithString:device.imageFileName] forState:UIControlStateNormal
  508. // placeholderImage:nil options:SDWebImageRefreshCached completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  509. // [cell layoutIfNeeded];
  510. // }];
  511. [cell.imgDevice setImage:[UIImage imageNamed:device.deviceclassTypeId]];
  512. [cell.btnDevice addTarget:self action:@selector(btnDeviceTouched:) forControlEvents:UIControlEventTouchUpInside];
  513. cell.btnDevice.value = indexPath;
  514. //커맨드 클래스 뷰를 초기화함.
  515. [[cell.controlContainer subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  516. UIView *subview = (UIView *)obj;
  517. [subview removeFromSuperview];
  518. }];
  519. NSLog(@"Is Requesting : %@", BOOLToString(device.isRequesting));
  520. // TODO : 어떤 부분인지 내용 확인 필요
  521. cell.pcontainerView.hidden = !device.isRequesting;
  522. if (!cell.pcontainerView.hidden) {
  523. [cell startProgressAni];
  524. } else {
  525. [cell stopProgressAni];
  526. }
  527. //허브 On-Off line check
  528. // cell.lblDeviceStatus.hidden = !([[JDFacade facade].loginUser.homehubOnlineState isEqualToString:@"OFF"] || [device.onlineState isEqualToString:@"OFF"]);
  529. // cell.controlContainer.hidden = !cell.lblDeviceStatus.hidden;
  530. cell.btnDelete.hidden = !_isDeleteMode;
  531. cell.btnChangeOrder.hidden = !_isReOrderMode;
  532. if(_isDeleteMode || _isReOrderMode)
  533. {
  534. cell.btnDevice.enabled = NO;
  535. cell.btnDeviceControl.hidden = YES;
  536. }
  537. else
  538. {
  539. cell.btnDevice.enabled = YES;
  540. cell.btnDeviceControl.hidden = NO;
  541. }
  542. [cell.btnChangeOrder addGestureRecognizer:drag];
  543. cell.btnChangeOrder.value = indexPath;
  544. // 이부분 확인해 볼것
  545. if (!cell.controlContainer.hidden) {//커맨드 클래스 타입별 컨트롤 호출
  546. [cell.btnDevice setBackgroundImage:[device backgroundImageForMandatary:device.contentValue] forState:UIControlStateNormal];
  547. CommandClassControlView *controlView = [CommandClassControlView viewForCommandClass:device.cmdclsType];
  548. controlView.device = device;
  549. if(_isDeleteMode || _isReOrderMode)
  550. {
  551. controlView.isReOrderMode = YES;
  552. }
  553. else {
  554. controlView.isReOrderMode = NO;
  555. }
  556. cell.controlContainer.hidden = !controlView;
  557. if (!cell.controlContainer.hidden) {
  558. UIView *superview = cell.controlContainer;
  559. [superview addSubview:controlView];
  560. // controlView.width = IS_IPHONE_6P ? 98.0f : 120;
  561. // NSLog(@"Controll View : %f", ViewWidth(superview));
  562. // controlView.width = ViewWidth(superview);
  563. [controlView mas_makeConstraints:^(MASConstraintMaker *make) {
  564. // make.size.mas_equalTo(superview.frame.size);
  565. // make.center.equalTo(superview);
  566. make.top.equalTo(superview.mas_top).with.offset(0); //with is an optional semantic filler
  567. make.left.equalTo(superview.mas_left).with.offset(0);
  568. make.bottom.equalTo(superview.mas_bottom).with.offset(0);
  569. make.right.equalTo(superview.mas_right).with.offset(0);
  570. }];
  571. }
  572. } else {
  573. cell.lblDeviceStatus.text = @"OFFLINE";
  574. cell.lblDeviceStatus.textColor = kUITextColor01;
  575. [cell.btnDevice setBackgroundImage:[UIImage imageNamed:@"img_thing_icon_bg_default"] forState:UIControlStateNormal];
  576. }
  577. rcell = cell;
  578. } else {
  579. ThingsAddCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ThingsAddCellIdentifier" forIndexPath:indexPath];
  580. //
  581. if (![cell.btnAdd actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  582. [cell.btnAdd addTarget:self action:@selector(addNewDevice) forControlEvents:UIControlEventTouchUpInside];
  583. }
  584. rcell = cell;
  585. }
  586. return rcell;
  587. }
  588. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
  589. // return CGSizeZero;
  590. //
  591. // //FIXME : 권한 추가
  592. //// if (_memberList.count % 2 == 1 || [JDFacade facade].loginUser.level < 90 || _isDeleteMode) {//마스터 권한이 아니거나, 짝수가 아닐 경우
  593. // if (_deviceList.count % 2 == 1 || _isDeleteMode) {//마스터 권한이 아니거나, 짝수가 아닐 경우
  594. // }
  595. //
  596. // return CGSizeMake(IPHONE_WIDTH, 160.0f);
  597. //}
  598. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  599. {
  600. return CGSizeMake(ViewWidth(_collectionView), (((ViewWidth(_collectionView)-kiCellInset)+kiCellRatio) / kiCellItem) / kiCellDivision+(kiCellItem*kiCellItem));
  601. }
  602. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  603. return CGSizeMake((ViewWidth(_collectionView)-kiCellInset) / kiCellItem, ((ViewWidth(_collectionView)-kiCellInset)+kiCellRatio) / kiCellItem);
  604. }
  605. // Cell 사이 최소 간격
  606. - (CGFloat) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  607. return kiCellInset;
  608. }
  609. // Line 별 최소 간격
  610. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  611. {
  612. return kiCellInset;
  613. }
  614. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  615. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  616. if (_isReOrderMode) {
  617. [collectionView beginInteractiveMovementForItemAtIndexPath:indexPath];
  618. return;
  619. }
  620. if (indexPath.row < _deviceList.count) {//디바이스인 경우,
  621. DeviceModel *device = _deviceList[indexPath.row];
  622. ThingsDetailViewController *vc = (ThingsDetailViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ThingsDetailViewController" storyboardName:@"Things"];
  623. vc.refDevice = device;
  624. [self presentViewController:vc animated:YES completion:nil];
  625. }
  626. }
  627. -(BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath
  628. {
  629. return _isReOrderMode;
  630. }
  631. -(BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)toIndexPath
  632. {
  633. return _isReOrderMode;
  634. }
  635. - (BOOL)beginInteractiveMovementForItemAtIndexPath:(NSIndexPath *)indexPath
  636. {
  637. return _isReOrderMode;
  638. }
  639. - (void)updateInteractiveMovementTargetPosition:(CGPoint)targetPosition
  640. {
  641. }
  642. - (void)endInteractiveMovement
  643. {
  644. }
  645. - (void)cancelInteractiveMovement
  646. {
  647. }
  648. -(void)panGestureHandler:(UIGestureRecognizer *)sender
  649. {
  650. CGPoint locationPoint = [self getCellCenter:[sender locationInView:_collectionView]];
  651. switch (sender.state) {
  652. case UIGestureRecognizerStateBegan:
  653. {
  654. NSIndexPath *indexPathOfPoint = [self.collectionView indexPathForItemAtPoint:locationPoint];
  655. _moveCell = (ThingsCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPathOfPoint];
  656. UIGraphicsBeginImageContext(_moveCell.bounds.size);
  657. [_moveCell.layer renderInContext:UIGraphicsGetCurrentContext()];
  658. UIImage *cellImage = UIGraphicsGetImageFromCurrentImageContext();
  659. UIGraphicsEndImageContext();
  660. _cellFakeView = [[UIImageView alloc] initWithImage:cellImage];
  661. [_cellFakeView setCenter:locationPoint];
  662. [_collectionView addSubview:_cellFakeView];
  663. _dragIndexPath = indexPathOfPoint;
  664. _moveCell.hidden = YES;
  665. }
  666. case UIGestureRecognizerStateChanged:
  667. {
  668. [_cellFakeView setCenter:locationPoint];
  669. }
  670. break;
  671. case UIGestureRecognizerStateCancelled:
  672. case UIGestureRecognizerStateEnded:
  673. // [self.collectionView performBatchUpdates:^{
  674. // //update cell indexPath
  675. // _reorderingCellIndexPath = toIndexPath;
  676. // [self.collectionView moveItemAtIndexPath:atIndexPath toIndexPath:toIndexPath];
  677. // //did move
  678. // if ([self.datasource respondsToSelector:@selector(collectionView:itemAtIndexPath:didMoveToIndexPath:)]) {
  679. // [self.datasource collectionView:self.collectionView itemAtIndexPath:atIndexPath didMoveToIndexPath:toIndexPath];
  680. // }
  681. // } completion:nil];
  682. //
  683. // _dragIndexPath= nil;
  684. // [_cellFakeView removeFromSuperview];
  685. //
  686. [self moveItemIfNeeded];
  687. break;
  688. default:
  689. break;
  690. }
  691. }
  692. - (void)moveItemIfNeeded
  693. {
  694. // TODO : 버그 수정
  695. NSIndexPath *atIndexPath = _dragIndexPath;
  696. NSIndexPath *toIndexPath = [_collectionView indexPathForItemAtPoint:_cellFakeView.center];
  697. if (toIndexPath != nil && ![atIndexPath isEqual:toIndexPath]) {
  698. [_collectionView performBatchUpdates:^{
  699. [_collectionView moveItemAtIndexPath:atIndexPath toIndexPath:toIndexPath];
  700. [self updateDataSource:atIndexPath toIndexPath:toIndexPath];
  701. } completion:nil];
  702. }
  703. _moveCell.hidden = NO;
  704. [_cellFakeView removeFromSuperview];
  705. _dragIndexPath = nil;
  706. // [_cellInfo]
  707. }
  708. -(CGPoint)getCellCenter:(CGPoint)point
  709. {
  710. CGPoint btnCenter = _moveCell.btnChangeOrder.center;
  711. CGPoint cellCenter = _moveCell.contentView.center;
  712. CGPoint result = CGPointMake(point.x-(btnCenter.x-cellCenter.x), point.y-(btnCenter.y-cellCenter.y));
  713. return result;
  714. }
  715. -(void)updateDataSource:(NSIndexPath *)atIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  716. {
  717. NSLog(@"Update Data");
  718. NSLog(@"From Index : %li", (long)atIndexPath.item);
  719. NSLog(@"To Index : %li", (long)toIndexPath.item);
  720. DeviceModel *device =_deviceReOrderList[atIndexPath.item];
  721. NSLog(@"DeviceModel : %@", device);
  722. [_deviceReOrderList removeObjectAtIndex:atIndexPath.item];
  723. [_deviceReOrderList insertObject:device atIndex:toIndexPath.item];
  724. }
  725. #pragma mark - UI Events
  726. /**
  727. 첫번째 이미지
  728. - img_bg_morepopup_icon_thingschange
  729. - img_bg_morepopup_icon_thingschange_press
  730. 두번째 이미지 :
  731. - img_bg_morepopup_icon_add
  732. - img_bg_morepopup_icon_add_press
  733. 세번째 이미지 :
  734. - img_bg_morepopup_icon_delete
  735. - img_bg_morepopup_icon_delete_press
  736. 네번째 이미지 :
  737. - img_bg_morepopup_icon_refresh
  738. - img_bg_morepopup_icon_refresh_press
  739. **/
  740. - (IBAction)btnOptionTouched:(id)sender {
  741. [self toggleOptionsWithArray:sender btnArray:_moreBtnArray];
  742. }
  743. - (IBAction)btnReFreshTouched:(id)sender {
  744. [[JDFacade facade] confirmTitle:@"알림" message:@"장치 목록의 순서를\n장치가 등록된 순으로 초괴화합니다." btnOKLabel:@"확인" btnCancelLabel:@"취소" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  745. if (buttonIndex == 0) {
  746. [self requestDeviceOrderReset];
  747. [self toggleReOrderMode:NO];
  748. }
  749. }];
  750. }
  751. - (IBAction)btnConfirmTouched:(id)sender {
  752. [[JDFacade facade] confirmTitle:@"알림" message:@"현재 편집된 장치 목록 순서를\n저장하시겠습니까?" btnOKLabel:@"확인" btnCancelLabel:@"취소" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  753. if (buttonIndex == 0) {
  754. // TODO : 데이터 업데이트 하기
  755. _deviceList = [[NSMutableArray alloc] initWithArray:_deviceReOrderList];
  756. [self requestDeviceOrderChange];
  757. [self toggleReOrderMode:NO];
  758. }
  759. }];
  760. // _deviceList = _deviceReOrderList;
  761. // [self toggleReOrderMode:NO];
  762. }
  763. - (IBAction)btnCloseTouched:(id)sender {
  764. if (_isReOrderMode) {
  765. [[JDFacade facade] confirmTitle:@"알림" message:@"장치 목록 순서를 저장하지 않고\n이전화면으로 이동합니다." btnOKLabel:@"확인" btnCancelLabel:@"취소" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  766. if (buttonIndex == 0) {
  767. [self toggleReOrderMode:NO];
  768. }
  769. }];
  770. }
  771. else {
  772. [self toggleEditMode:NO];
  773. }
  774. }
  775. -(void)toggleReOrderMode:(Boolean)isReOrder
  776. {
  777. _isReOrderMode = isReOrder;
  778. _viewEditMode.hidden = !isReOrder;
  779. _btnOption.hidden = isReOrder;
  780. [_collectionView reloadData];
  781. _viewTitle.hidden = isReOrder;
  782. _lblEditMode.hidden = !isReOrder;
  783. _lblEditMode.text = @"장치 목록 순서 편집";
  784. }
  785. -(void)toggleEditMode:(Boolean)isEdit
  786. {
  787. _isDeleteMode = isEdit;
  788. _viewEditMode.hidden = !isEdit;
  789. _btnOption.hidden = isEdit;
  790. [_collectionView reloadData];
  791. _viewTitle.hidden = isEdit;
  792. _lblEditMode.hidden = !isEdit;
  793. _lblEditMode.text = @"장치 삭제";
  794. _btnEditSave.hidden = !isEdit;
  795. _btnEditRefresh.hidden = !isEdit;
  796. }
  797. #pragma mark - SocketService
  798. - (void) socketDidReceiveMessage:(id)message info:(NSDictionary *)info
  799. {
  800. SocketModel *result = (SocketModel *)message;
  801. NSLog(@"Result Info : %@", result);
  802. SWITCH(result.messageType)
  803. {
  804. CASE (@"node.register")
  805. {
  806. }
  807. CASE (@"node.delete")
  808. {
  809. }
  810. CASE(@"nodes.reload")
  811. {
  812. }
  813. DEFAULT
  814. {
  815. break;
  816. }
  817. }
  818. }
  819. - (void) socketDidFailWithError:(NSError *)error {
  820. [[JDFacade facade] loadIndicator:NO allowUserInteraction:YES];
  821. }
  822. -(void) receiveSocketData:(NSNotification *)notification {
  823. SocketModel *result = [[SocketModel alloc] initWithDictionary:notification.object error:nil];
  824. // CommandModel *response = [[CommandModel alloc] initWithDictionary:notification.object error:nil];
  825. NSLog(@"Result : %@", result);
  826. if ([result.messageType isEquestToIgnoreCase:MSG_TYPE_NODE_CONTENT]) {
  827. ContentModel *response = [[ContentModel alloc] initWithDictionary:notification.object error:nil];
  828. for (DeviceModel *info in _deviceList) {
  829. if ([info.deviceId isEqualToString:response.deviceId] && [info.nodeId isEqualToString:response.nodeId]) {
  830. info.collectTime = response.collectTime;
  831. id contentValue = [NSJSONSerialization JSONObjectWithData:[response.contentValue dataUsingEncoding:NSUTF8StringEncoding]
  832. options:NSJSONReadingAllowFragments
  833. error:nil];
  834. info.contentValue = contentValue[info.cmdclsId];
  835. if (info.isRequesting) {
  836. info.isRequesting = NO;
  837. }
  838. [_collectionView reloadData];
  839. break;
  840. // NSLog(@"Info : %@", contentValue[info.cmdclsId]);
  841. }
  842. }
  843. }
  844. else if ([result.messageType isEquestToIgnoreCase:MSG_TYPE_NODE_COMMAND_RES]) {
  845. }
  846. }
  847. #pragma mark - MoreButtonDelegate
  848. -(void)moreBtnAction:(id)sender
  849. {
  850. NSInteger tag = [(UIButton *)sender tag];
  851. NSLog(@"MoreBtn Action : %li", (long)tag);
  852. switch (tag) {
  853. case ReOrder:
  854. {
  855. [self toggleReOrderMode:YES];
  856. }
  857. break;
  858. case Add:
  859. {
  860. [self addNewDevice];
  861. }
  862. break;
  863. case Del:
  864. {
  865. [self toggleEditMode:YES];
  866. }
  867. break;
  868. case Refresh:
  869. {
  870. [self refreshDeviceList];
  871. }
  872. break;
  873. default:
  874. break;
  875. }
  876. }
  877. #pragma mark - MemoryWarning
  878. - (void)viewWillDisappear:(BOOL)animated {
  879. if (_deviceCommandsBackgroundTimer) {
  880. [_deviceCommandsBackgroundTimer invalidate];
  881. _deviceCommandsBackgroundTimer = nil;
  882. }
  883. [self releaseDevicesTimer];
  884. }
  885. - (void)didReceiveMemoryWarning
  886. {
  887. [super didReceiveMemoryWarning];
  888. // Dispose of any resources that can be recreated.
  889. }
  890. -(void)btnDeviceTouched:(id)sender
  891. {
  892. }
  893. @end